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

[netCDF #NMP-629417]: undefined reference to nc_def_var_fill



Hi Louis,

> I am using the C interface.
> 
> I have been trying to add the _FillValue attribute to my variables.

For the netCDF-3 C interface, you can only do this by explicitly
calling the nc_put_att_TYPE function, where TYPE specifies the type of
the attribute, the same as the type of the variable.  For example, to
set a fill value of -999 for an integer variable with ID varid, you
would call

   int fill = -999;
  ...
   nc_put_att_int(ncid, varid, "_FillValue", NC_INT, 1, &fill);

when in define mode.  Note that you don't have to use a _FillValue
attribute if the default value for the type is OK, for example if use
of -2147483647 is OK as a fill value for your variable.

> I tried nc_set_fill(ncid, NC_FILL, &old_fill_mode) both before and
> after ending the define mode with out any changes in the header when
> it is printed. 

The nc_set_fill function is used for a different purpose, to specify
that no prefilling of variables with fill values should occur by calling
nc_set_fill before writing.  This is a minor optimization that should
only be used if you have measured performance and know that prefilling
variables is causing a significant slowdown.  In this case, you should
make sure you write all data values before reading them, becasue there
will be no way to later detect reading values that were not written.
The nc_set_fill function sets the behavior for all the variables in an
open file, but is not persistent after a file is closed.

>     ... When I try nc_def_var_fill I get the undefined reference
> error. I have not had this error for any other netcdf functions.

With netCDF-4, it bacame possible to set the fill mode (whether to use
fill values or not) for a single variable, which was not possible with
the netCDF-3 function nc_set_fill.  The function used for this
purpose is nc_def_var_fill, and it can also be used to create and set
a "_FillValue" attribute for a variable, so a separate call to a
nc_put_att_TYPE function is not necessary.  The nc_def_var function is
not otherwise useful, unless you have some reason to want to have the
fill value behavior be different for dirfferent variables, which is
uncommon.

> Do I need a more recent version installed.

Not if the default behavior of fill values is adequate.  If you need
different fill values than the defaults defined in netcdf.h, just use
the appropriate nc_put_att_TYPE function for each variable for which a
non-default fill value is desired.

--Russ

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



Ticket Details
===================
Ticket ID: NMP-629417
Department: Support netCDF
Priority: Normal
Status: Closed