spidru / JGribX

Java GRIB-1/GRIB-2 decoder
MIT License
34 stars 14 forks source link

Getting NullPointer while loading GFS grib2 file #8

Closed jfuellgraf closed 4 years ago

jfuellgraf commented 4 years ago

I am trying to load an GFS grib2 file with this library. Unfortunately I get a NullPointerException while calling

GribFile gribFile = new GribFile(gribPath);

as following:

java.lang.NullPointerException at mt.edu.um.cf2.jgribx.grib2.Grib2RecordPDS.getLevelCode(Grib2RecordPDS.java:313) at mt.edu.um.cf2.jgribx.grib2.Grib2Record.getLevelCode(Grib2Record.java:121) at mt.edu.um.cf2.jgribx.GribFile.<init>(GribFile.java:127) at mt.edu.um.cf2.jgribx.GribFile.<init>(GribFile.java:80) at mt.edu.um.cf2.jgribx.GribFile.<init>(GribFile.java:63)

I've downloaded various files from NOAA GFS to test the import, but still the same exception.

I would appreciate any help, thanks in advance.

spidru commented 4 years ago

Hi @jfuellgraf,

I've attached the output I get when reproducing your problem using the command-line interface. Note that the errors saying that it cannot find some text files is normal, since there are many more parameter categories that need to be added to JGribX (I've left the errors as a reminder to myself that this still needs to be done. In fact, I should add a new issue on this).

Note that it reports that the parameter is Category 1 Number 22, which we can find to be Cloud Mixing Ratio (reference here). Note that this parameter falls under the Meteorological products, Moisture category. If I now look at JGribX's METEOROLOGICAL-MOISTURE.txt, I see that it only has up to number 10, which is why it doesn't find the parameter and eventually returns a NullPointerException.

I have no idea why this file only has up till number 10, but these are files that I manually fill so I'm not too surprised. I will complete the list for this file over the next days, time permitting. Or you can update the file yourself if you'd rather not wait :)

capture

spidru commented 4 years ago

Hi @jfuellgraf,

In commit c8983276b1a48ba12f00f93319fbfeab2f4c7a1f, I've made sure that unsupported GRIB2 parameters and levels are gracefully handled by simply skipping them. Could you try it out?

jfuellgraf commented 4 years ago

Hi @spidru, please apologize my late response. After some further testing in december I switched to another GRIB2 library, because I was running out of time with my project. Finally I found time to test your changes. In the attached screenshot you can see the two outputs from release v0.4 and the version I build by using gradle clean build myself. As you can see your fix works, I would recommend a new release with the recent commits. Even if I didn't used your library in the end, thank you for your fix anyway.

screenshot

spidru commented 4 years ago

Hi @jfuellgraf,

No problem at all. Thanks for finding the time to test it out! I'll definitely be releasing a new version soon, I'm just trying to find time to fit in a few more changes before doing so :)