Closed vespino closed 8 years ago
Thanks for your interest in the tool. This exception is raised because the file you are trying to decode have a BitMap Section (http://www.wmo.int/pages/prog/www/WDM/Guides/Guide-binary-2.html#Section3) and phpGrib is unable to decode it. I created phpGrib as a hobby project a few years ago to use it on files generated by the ETA model from CPTEC/INPE (http://etamodel.cptec.inpe.br/). Those files use simple packing, with latitude/longitude grids and no bitmap section.
Unfortunately i cant do this improvement on phpGrib as i`m working in my MSc degree right now. :( As a first approach you can try to comment the exception raised in the file decoder/GribMessageDecoder.php on line 51 as see if the data is unpacked correctly.
If not, and your need is really urgent i would suggest you to use another tool like GRIB2Json https://github.com/cambecc/grib2json to decode the data, or maybe call the wgrib utility http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html from your PHP script to decode the data.
I`m sorry for not being able to help you more at this time.
Nice! Commenting the exception works. Now to figure out what all the numbers mean :)
lat;lon;250;500;750;1000; 270000;179000;2055.00;2262.00;2787.00;2926.00;
Dear Eduardo, before all, thanks for your job.... I just needed a GRIB1 parser for a project of mines, and I was searching for a PHP library due to some portability issue. I did found your library, that is well written, but I discovered it has a 'little' bug that prevent the right computing of values in binary section. The problem is in the IBM float decoding procedure. You correctly did the unpacking of data, but didn't take in account that the sign taken from the first byte has to be applied to resulting float, but in the formula pow(16, $A-64) it's requested its absolute value. I have just fixed it and now data are decoded correctly (I use Panoply for data checking. This is my fix:
protected static function _getSingle($string, $position) { $S = 1; $A = self::_getSignedInt($string, $position, 1); if ($A < 0) { $S = -1; $A = -$A; }
$B = self::_getUInt($string, $position+1, 3);
return $S * pow(2, -24) * $B * pow(16, $A-64);
}
I also added support for rotated grids (type 10) that was requested by my GRIB files. If you want, I can send to you my patches, its are tested and working.
See you
I have been asked to build an app based on a grib file so I searched for a way to read the data using PHP. The included example file works great, but when I use my own file, I'm getting this error:
Fatal error: Uncaught GribDecoderException: BMS decoder not implemented! in /home/xxx/domains/xxx.xx/public_html/test/grib/decoder/GribMessageDecoder.php:51 Stack trace: #0 /home/xxx/domains/xxx.xx/public_html/test/grib/decoder/GribFileDecoder.php(93): GribMessageDecoder::decode('GRIB\x01>T\x01\x00\x00\x1C\xFF\x07`\x03...') #1 /home/xxx/domains/xxx.xx/public_html/test/grib/decoder/GribFileDecoder.php(45): GribFileDecoder::readMessage(Resource id #9) #2 /home/xxx/domains/xxx.xx/public_html/test/grib/examples/extractDataToCSV.php(12): GribFileDecoder::loadFile('gfs_320160910...', Array) #3 {main} thrown in /home/xxx/domains/xxx.xx/public_html/test/grib/decoder/GribMessageDecoder.php on line 51
This is the file I'm using: http://nomads.ncdc.noaa.gov/data/gfs-avn-hi/201609/20160910/gfs_3_20160910_1800_384.grb
This kind of data is completely new to me, so sorry for asking stupid questions.