Re: [netcdfgroup] Dealing with null datasets in NetCDF

Here are some tips for recognizing fill values directly in a fortran 90
program.  The correct term for ncdump values shown as "_" is "fill value",
not "null".  "Null" can mean several other things, so that term is
confusing without more context.

If your netcdf file is well written, it should contain the attribute
hello:_FillValue, which you can see with ncdump.  In your program, read
this attribute with nf90_get_att.  Be sure to test the return status code
for errors such as "no such attribute".  When you successfully read the
_FillValue attribute, use it to compare with the returned values
from nf90_get_var, step 3 in the work flow that you showed.

If the _FillValue attribute is not present, then in some cases the
missing_value attribute contains the actual fill value.  Otherwise, if the
file is netcdf-4 format, you can use nf90_inq_var_fill to read the fill
value.  For netcdf-3 format, the default fill values are fixed parameters
in netcdf.mod.  I believe the names are nf90_fill_int, nf90_fill_float, etc .

Please refer to more fill value documentation in the netcdf users guide, in
these two places:

https://www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html#bp_Missing-Data-Values
https://www.unidata.ucar.edu/software/netcdf/docs/attribute_conventions.html

--Dave


On Tue, Jan 23, 2018 at 12:41 PM, Charlie Zender <zender@xxxxxxx> wrote:

> Others have probably explained that the underscore is a
> convenient visual stand-in for the number in the _FillValue
> attribute. ncks will print netCDF datasets with the actual
> number rather than an underscore with the --no_blank option, e.g.,
>
> ncks --no_blank in.nc # http://nco.sf.net/nco.html#no_blank
>
> Followup as per http://nco.sf.net#help
>


> HTH,
> Charlie
>


On Tue, Jan 23, 2018 at 7:48 AM, shaalin23 <shaalinnathwani@xxxxxxxxxxxxx>
wrote:

> Hi all,
> I’m having an issue with using netcdf with fortran – I have several netcdf
> files that need to be read into a fortran program and some of the variables
> in the netcdf files have null datasets.
> E.g. doing an ncdump operation as follows:
> $> ncdump –v hello hello_world.nc
> Will output
> hello = _ ;
> To the terminal because the dataset associated with it is null.
> Even though it is null, I need it to still be read in in the FORTRAN code
> because the code will be performing operations on several netcdf files –
> and
> in some of them, the variable “hello” has actual values.
> Currently in the FORTRAN code, I’m currently doing the following:
> -       Allocating an array big enough to hold the “hello” dataset.
> -       Performing an NF90_get_var operation as follows:
> o       Err = NF90_GET_VAR(ncid, 10, helloArray)
> o       Where ncid is the id for the file, 10 is the variable ID, and
> helloArray
> is the location where the data needs to be stored.
> -         Writing the array to the screen
>
> The last step, writing the array to the screen, currently produces garbage,
> I assume that it is the memory address – a random negative number
> completely
> unrelated to the value (null) in the ncdump output.
>
> Is there a way to check for nulls using the netcdf API? At the moment I
> can’t think of a way to do this and therefore my data gathering from the
> netcdf file is not accurate.
>
> A work flow as follows would be appropriate:
> -       Allocate an array big enough
> -       Perform NF90_get_var operation
> -       Check if the result obtained with null
> -       Deal with it appropriately.
>
> Look forward to hearing people’s thoughts on this!
>
> Cheers
> --
> Sent from: http://netcdf-group.1586084.n2.nabble.com/
  • 2018 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: