[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #ITH-188331]: netcdf data append in f90



Rama,

Sorry, but I just noticed a question you asked over two months ago
that we didn't answer, unfortunately.  However if it's any help, I
think I have the answer.

> I notice something funny in the netcdf file which I created.
> 
> I write one variable Ramp Cal counts in 2byte integer using NF90_SHORT.
> 
> Before writing it using nf90_put_var, I scale the real data to 2 byte
> integer using the following formula:
> (-32767 to 32767 and missing value would be -32768).
> 
> scaleddata= nint((RampCalArray - AddOffset)/ScaleFactor)
> 
> 
> Where ScaleFactor = (RampCalArrayMax-RampCalArrayMin)/((2**16)-2)
> 
> and AddOffset = (RampCalArrayMax+RampCalArrayMin)/2
> 
> When the real value of RampCalArray element is zero, the scaled value
> should be -32767.
>
> It is obtaining the same result and I can print it inside the F90 code
> and see it.
> 
> But when I write it into netCDF file, using NF90_SHORT, it does not
> appear in the netCDF file
> it just shows as blank line followed by a comma like -, -, - ,
> corresponding to three zero values.
> 
> Any idea why is it not writing the three values of -32767 but showing as
> -,-,- ?
> 
> It has no problem showing missing values like -32768 or other scaled
> values. It shows problem only
> when zero is scaled to 2byte value.

The ncdump utility is displaying -32767 as "fill values", which are
data values that are supposed to represent values that were not
written.  This is because it is using the default fill value for the
signed short data type, which is defined in netcdf.inc as

      parameter (nf_fill_short = -32767)

and the parameter NF90_FILL_SHORT is defined as the same value in the
netcdf module, as is NC_FILL_SHORT in the netcdf.h file.  The default
fill value for shorts is -32767, because not all computers can
represent "-32768" in a signed short.  A few old architectures use a
different representation for integers, with both +0 and -0, and only
representing values from -32767 to +32767.

However, if you know the computers on which you will be reading data
have a -32768 short value, you can override the default for your file
by setting the _FillValue attribute for your variable to -32768, and
then the "-32767" values should be interpreted as 0 by ncdump, but it
will show "_" instead of "-32768" for missing values.  Note that the
values are read correctly, even though ncdump does not display them
correctly, in case it is using the default fill value.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: ITH-188331
Department: Support netCDF
Priority: Critical
Status: Closed