Project

General

Profile

ArrayIndexOutOfBoundsException out of ucar.grib.GribIndexReader.open when trying to read a GRIB2 file

Added by Anonymous over 12 years ago

Note: there is no need to respond to this forum entry. This contains a symptom and possible fix, and I thought I would share it with other CDO users.

I used CDO to convert from a NetCDF-classic file to GRIB2. I won't go through the details of the actual conversion, suffice it to say that I did something like this:
cdo -f grb2 copy file1.nc file2.grb2

When I took the GRIB2 file and tried to load it on Panoply or Integrated Data Viewer (IDV), I received a pop-up that said:
%%
java.lang.ArrayIndexOutOfBoundsException: 1
at ucar.grib.GribIndexReader.open(GribIndexReader.java:142)
%%

Both Panoply and IDV use the ucar Java library to read the GRIB2 file, so both show the exception above.

Here's what happens. Inside ucar.grib.grib2.Grib2Input.class, there is code that looks like this (using pseudo-code so that I don't have to worry about licensing issues):
%
if (it is a GRIB1 file) or (the discipline is 255) {
then conclude that it is a GRIB1 file, not a GRIB2 file
}
%

When CDO performs a conversion to GRIB2, the discipline defaults to 255.

The workaround is to use setparam or chparam to change the discipline to something else.
e.g.,
cdo -f grb2 chparam,90.0.255,90.129.254 file1.nc file2.grb2

This changes my parameter 90 to parameter 90, category 129, discipline 254.