0
votes

I'm working in MATLAB with a fairly large netcdf file, containing the following variable:

    tg              
       Size:       272x214x23011
       Dimensions: longitude,latitude,time
       Datatype:   int16
       Attributes:
                   long_name     = 'mean temperature'
                   units         = 'Celsius'
                   standard_name = 'air_temperature'
                   _FillValue    = -1e+004
                   scale_factor  = 0.01

I'm using the ncread function to read chunks of the matrix, e.g.:

data = ncread(netcdfFile,'tg',[1 1 1],[Inf Inf 10]);

for the first 10 time steps. If there is enough memory and the 'chunk' is small enough, MATLAB will write 'data' in double precision, else it will be written in int16. If 'data' is in double precision, values equal to the value of '_FillValue' will be converted to NaN, while if 'data' is in int16 the same cells will now contain the value -9999. Why is this? -1e+004 is within the range of int16, so why does MATLAB write it as -9999, and not -10000?

Is it because int16(NaN) = 0, which then falls within the range of the data, whereafter MATLAB applies a default fillvalue of -9999 to the cells?

Can someone explain what's going on?

1
" else it will be written in int16" - did you confirm with the class with a WHOS or a CLASS call? I believe it should always be of type double if there is a _FillValue or scale_factor present. You could consider using the low level (netcdf.* functions) if you want the raw data. - Ashish Uthama
Yes, extracts over a certain size is written in int16. At least when using ncread. How do the low level functions handle this? - simondk

1 Answers

0
votes

I believe the fill value is actually -9999. Its an unfortunate display issue.

>> nccreate('/tmp/t.nc','p','FillValue',-9999)
>> ncdisp /tmp/t.nc
Source:
           /tmp/t.nc
Format:
           netcdf4_classic
Variables:
    p
           Size:       1x1
           Dimensions: 
           Datatype:   double
           Attributes:
                       _FillValue = -1e+04