1. Go to this page and download the library: Download okvpn/grib2-eccodes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
okvpn / grib2-eccodes example snippets
$curl = new CurlHttpClient();
// Select 174:9400873:d=2023081906:UGRD:575 mb:3 hour fcst:
// Use http 206 Partial Content feature to downlaod only one param
$res = $curl->request('GET', 'https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.<date>/<time>/atmos/gfs.t<time>z.pgrb2b.1p00.f003', ['headers' => ['Range' => 'bytes=9400873-9480145']]);
file_put_contents("VGRD.p1", $res->getContent())
use FFI;
use Okvpn\Grib2\Grib2Reader;
use Okvpn\Grib2\LibEccodes;
LibEccodes::$libPath = "libeccodes.so"; // . use fill path if installed eccodes to custom path
$reader = new Grib2Reader();
$data = $reader->read("VGRD.p1");
print_r($data);
$matrix = $reader->read2D("VGRD.p1", lat1: 48, lat2: 57, lon1: 13, lon2: 36);
foreach ($matrix as $i => &$vals) {
foreach ($vals as $j => &$val) {
$val = ($s = strlen($val = round($val))) >= 3 ? $val : $val . str_repeat(' ', 3-$s);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.