spidru / JGribX

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

NPE on getValue when record is constant #6

Closed pavelber closed 4 years ago

pavelber commented 5 years ago

Exception in thread "main" java.lang.NullPointerException at mt.edu.um.cf2.jgribx.grib1.Grib1RecordBDS.getValue(Grib1RecordBDS.java:276) at mt.edu.um.cf2.jgribx.grib1.Grib1Record.getValue(Grib1Record.java:296)

spidru commented 4 years ago

Hi @pavelber, I'm not quite sure what you mean by "when record is constant". Could you please clarify? Also, it would probably speed things up if you could send the GRIB file and explain what you're trying to do. Cheers!

pavelber commented 4 years ago

Small code in Kotlin, using attached file

import mt.edu.um.cf2.jgribx.GribFile
import mt.edu.um.cf2.jgribx.grib1.Grib1Record

object Test1 {
    @JvmStatic
    fun main(args: Array<String>) {
        val file = GribFile("C:\\temp\\C3_2019112600_CLCL.grb")
        val record = file.records.filter { r-> (r as Grib1Record).bds.isConstant }.first()

        println(record.forecastTime.toInstant())
        println(record.getValue(31.93, 34.7))
    }
}

C3_2019112600_CLCL.zip

spidru commented 4 years ago

Hi @pavelber,

Just to let you know that I've managed to reproduce the issue. Will keep you posted. Thanks for finding these issues!

pavelber commented 4 years ago

Thank you!

spidru commented 4 years ago

Found an issue in how the BDS is handled. Made a fix in e2f86fde57368a797fb41a461bdfb4b77e5cf687

The exception should be gone now, but I see that all values for your sample code is zero, since all records have a constant-valued BDS. Is this what you were expecting?

pavelber commented 4 years ago

Yes, exactly, believe or not but now we have hot weather w/o clouds :)

Will try the fix now.

spidru commented 4 years ago

Just checked the coords ... Gan Raveh Regional Council, Israel? Looks like a great place to be... :)

pavelber commented 4 years ago

Looks good, thank you! Fixed!

It is good place now, but terrible place in summer :)