Re: 20030702:nf_get_var - empty data

Hi Alexander,

> I was surprised to find that the netcdf family of calls nf_get_var...
> does not return an error status when the data to be read are "empty", ie
> the data were defined but not written in the file.
> Here is a test example that illustrates the point. The value of STATUS
> returned by NF_GET_VARA_DOUBLE does not differ from NF_NOERR even for
> data "a", which are empty. Is there a way to check that data "a" are not
> empty?

This is the way things are intended to work.  Since you can write a
few of the values of an array variable and leave the rest unwritten,
it's not an error to read a variable that contains unwritten values,
but you can detect such unwritten values by use of an appropriate
_FillValue attribute.

There's a fuller explanation of this in section "7.16 Fill Values" of
the C or Fortran User Guide:

  What happens when you try to read a value that was never written in
  an open netCDF dataset?  You might expect that this should always be
  an error, and that you should get an error message or an error
  status returned.  You do get an error if you try to read data from a
  netCDF dataset that is not open for reading, if the variable ID is
  invalid for the specified netCDF dataset, or if the specified
  indices are not properly within the range defined by the dimension
  lengths of the specified variable.  Otherwise, reading a value that
  was not written returns a special fill value used to fill in any
  undefined values when a netCDF variable is first written.

  You may ignore fill values and use the entire range of a netCDF
  external data type, but in this case you should make sure you write
  all data values before reading them. If you know you will be writing
  all the data before reading it, you can specify that no prefilling
  of variables with fill values will occur by calling
  nc_set_fill before writing. This may provide a significant
  performance gain for netCDF writes.

  The variable attribute _FillValue may be used to specify the fill
  value for a variable. Their are default fill values for each type,
  defined in the include file netcdf.h: NC_FILL_CHAR, NC_FILL_BYTE,
  NC_FILL_SHORT, NC_FILL_INT, NC_FILL_FLOAT, and NC_FILL_DOUBLE.

  The netCDF byte and character types have different default fill
  values. The default fill value for characters is the zero byte, a
  useful value for detecting the end of variable-length C character
  strings. If you need a fill value for a byte variable, it is
  recommended that you explicitly define an appropriate _FillValue
  attribute, as generic utilities such as ncdump will not assume a
  default fill value for byte variables.
  
  
<http://www.unidata.ucar.edu/packages/netcdf/guidec/guidec-12.html#MARKER-9-2925>

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
russ@xxxxxxxxxxxxxxxx                      http://my.unidata.ucar.edu



  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: