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?