Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

IospHelper cast error, Integer to Short #638

Closed
rschmunk opened this issue Sep 19, 2016 · 6 comments
Closed

IospHelper cast error, Integer to Short #638

rschmunk opened this issue Sep 19, 2016 · 6 comments

Comments

@rschmunk
Copy link
Contributor

Trying to work with an HDF-4 dataset that has a variable described in CDL as

    short 10-day_averaged_land_surface_temperature(height=5000, width=8000);
      :_Unsigned = "true";
      :Unit = "Kelvins";
      :valid_range = 220S, 350S; // short
      :_FillValue = 65535; // int
      :Gains = 0.01f; // float
      :Offsets = 0S; // short
      :long_name = "10-day averaged land surface temperature";

When trying to retrieve the data via Variable.read(int[], int[]), I am getting a class cast error:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Short
    at ucar.nc2.iosp.IospHelper.makePrimitiveArray(IospHelper.java:678)
    at ucar.nc2.iosp.IospHelper.readDataFill(IospHelper.java:78)
    at ucar.nc2.iosp.hdf4.H4iosp.readData(H4iosp.java:104)
    at ucar.nc2.NetcdfFile.readData(NetcdfFile.java:2020)
    at ucar.nc2.Variable.reallyRead(Variable.java:913)
    at ucar.nc2.Variable._read(Variable.java:898)
    at ucar.nc2.Variable.read(Variable.java:709)
    at ucar.nc2.dataset.VariableDS.reallyRead(VariableDS.java:557)
    at ucar.nc2.dataset.VariableDS._read(VariableDS.java:537)
    at ucar.nc2.Variable.read(Variable.java:709)
    at ucar.nc2.Variable.read(Variable.java:655)
    at somewhere in my code.

The line where the exception occurs is attempting to cast the fillValue.

@rschmunk
Copy link
Contributor Author

rschmunk commented Sep 20, 2016

Fleshing this out a bit, the problem is not necessarily in IospHelper but possibly instead in the HDF-4 handler. It seems that the data are extracted as a short DataType, although the attribute _Unsigned = "true" suggests the data values would be better taken as int. But being valued as 65535, the fill value attribute is extracted as an int, and when IospHelper tries to save a copy of it, it tries to cast it to a short in order to match the DataType of the data array. Since an integer can't be cast to a short, the exception occurs.

@JohnLCaron
Copy link
Collaborator

Can you send an example file?

@rschmunk
Copy link
Contributor Author

The file that's giving me trouble is available at https://dl.dropboxusercontent.com/u/826984/sample_data/NOAA11_AVHRR_198902_01.MOS_L2B_NSMC.HDF?dl=1

@rschmunk
Copy link
Contributor Author

Possibly worth mentioning is that this problem seems to be the opposite of what is happening with an HDF-5 dataset as described in issue #593.

JohnLCaron added a commit to JohnLCaron/thredds that referenced this issue Sep 22, 2016
DennisHeimbigner added a commit that referenced this issue Sep 22, 2016
lesserwhirls added a commit to lesserwhirls/thredds that referenced this issue Sep 22, 2016
cwardgar added a commit that referenced this issue Sep 22, 2016
@cwardgar
Copy link
Contributor

Was this fixed by #642?

@rschmunk
Copy link
Contributor Author

Looks like it. The data in the sample file can now be read. There's still an problem with interpreting the data, but that's a result of how the attributes are specified and not pertinent to this actual issue/bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants