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

[netCDF #YLU-405033]: dealing with missing values while writing netCDF in FORTRAN V 3.6.1



Hi,

> I have problems with writing missing values in a NetCDF file. When I am
> writing netCDF files in R using “ncdf” library, I am using the following
> codes. I can declare missing value in var.def.ncdf call. Then read the file
> in R, it is read as NA. I want to do the same with FORTRAN calls windows
> built V3.6.1. I didn’t find similar calls in Fortran interface
> documentation.  I know it is possible to declare “_FillValue” to fill not
> written or missing values.  Is it possible to declare the program that a
> particular value (say -9999.00) will be used for missing value and read it
> as NA in FORTRAN?

The handling of missing values in netCDF are documented in the Users
Guide, where information that applies to all the specific language
interfaces, such as C, Fortran, C++, and Java, is found:

  http://www.unidata.ucar.edu/software/netcdf/docs/attribute_conventions.html

As you'll see there, the _FillValue variable attribute has a default
value for each primitive type, but you can also set it to any chosen
value for a variable.  It will be dislayed as "_" rather than "NA" in
ncdump output.

There is no global attribute that specifies a missing value for all
variables in a netCDF file, as variables may have different types, and
generally no single value would be suitable.

--Russ

> * R codes to write a netCDF:*
> 
> 
> *library(ncdf)*
> 
> *missval=-9999 # missing value, missval = -9999*
> 
> *xy = matrix(c(-111.8336,-111.8336,missval,-111.8336,-111.8336,missval))*
> 
> *xdim=3*
> 
> *ydim=2*
> 
> * *
> 
> *#  Names that needs changes for each variable*
> 
> *varnameD="cc"*
> 
> *unitnameID="unitless"*
> 
> *filename="longitude.nc"*
> 
> *#  Names that needs changes for each dimension*
> 
> *xcoordName="xcoord"*
> 
> *ycoordName="ycoord"*
> 
> * *
> 
> *# netCDF starts here*
> 
> *xllcorner=0*
> 
> *yllcorner=5*
> 
> *x = xllcorner + 10*(1:xdim)*
> 
> *y = yllcorner + 10*(1:ydim)*
> 
> * *
> 
> *# define the netcdf coordinate variables -- note these have values!*
> 
> *# dim.def.ncdf(name, units, vals, unlim=FALSE, create_dimvar=TRUE)*
> 
> * *
> 
> *dim2 = dim.def.ncdf( xcoordName,"meter", as.double(x))*
> 
> *dim1 = dim.def.ncdf( ycoordName,"meter", as.double(y))*
> 
> * *
> 
> *# define the EMPTY netcdf variable*
> 
> *# var.def.ncdf(name, units, dim, missval, longname=varnameD, prec="single")
> *
> 
> *varz = var.def.ncdf(varnameD,unitnameID,
> list(dim1,dim2),missval,longname=varnameD)*
> 
> * *
> 
> *# associate the netcdf variable with a netcdf file*
> 
> *# put the variable into the file, and close*
> 
> *# create.ncdf( filename, vars, verbose=FALSE )*
> 
> *nc.ex = create.ncdf(filename,list(varz))*
> 
> * *
> 
> *put.var.ncdf(nc.ex, varz, xy)*
> 
> *close.ncdf(nc.ex)*
> 
> 
> 
> *Read it with R: *
> 
> 
> * x<-open.ncdf("C:\\longitude.nc")*
> 
> *get.var.ncdf(x,”longitude”)*
> 
> 
> 
> Result
> 
> 
> 
> *          [,1]      [,2]      [,3]*
> 
> *[1,] -111.8336        NA -111.8336*
> 
> *[2,] -111.8336 -111.8336        NA*
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: YLU-405033
Department: Support netCDF
Priority: Normal
Status: Closed