open.ncdf {ncdf}R Documentation

Open a netCDF File

Description

Opens an existing netCDF file for reading (or, optionally, writing).

Usage

 open.ncdf( con, write=FALSE, readunlim=TRUE, verbose=FALSE, ... )

Arguments

con Name of the existing netCDF file to be opened.
write If FALSE (default), then the file is opened read-only. If TRUE, then writing to the file is allowed.
readunlim When invoked, this function reads in the values of all dimensions from the associated variables. This can be slow for a large file with a long unlimited dimension. If set to FALSE, the values for the unlimited dimension are not automatically read in (they can be read in later, manually, using get.var.ncdf()).
... Arguments passed to or from other methods.
verbose If TRUE, then messages are printed out during execution of this function.

Details

This routine opens an existing netCDF file for reading (or, if write=TRUE, for writing). To create a new netCDF file, use create.ncdf() instead.

In addition to simply opening the file, information about the file and its contents is read in and stored in the returned object, which is of class ncdf. This class has the following user-accessible fields, all of which are read-only: 1) filename, which is a character string holding the name of the file; 2) ndims, which is an integer holding the number of dimensions in the file; 3) nvars, which is an integer holding the number of the variables in the file that are NOT coordinate variables (aka dimensional variables); 4) natts, which is an integer holding the number of global attributes; 5) unlimdimid, which is an integer holding the dimension id of the unlimited dimension, or -1 if there is none; 6) dim, which is a list of objects of class dim.ncdf; 7) var, which is a list of objects of class var.ncdf; 8) writable, which is TRUE or FALSE, depending on whether the file was opened with write=TRUE or write=FALSE.

The concept behind the R interface to a netCDF file is that the ncdf object returned by this function, as well as the list of dim.ncdf objects contained in the ncdf object's "dim" list and the var.ncdf objects contained in the ncdf object's "var" list, completely describe the netCDF file. I.e., they hold the entire contents of the file's metadata. Therefore, there are no R interfaces to the explicit netCDF query functions, such as "nc_inq_nvars" or "nc_inq_natts". The upshot is, look in the ncdf object or its children to get information about the netCDF file. (Note: the dim.ncdf object is described in the help file for dim.def.ncdf; the var.ncdf object is described in the help file for var.def.ncdf).

Value

An object of class ncdf that has the fields described below.

Author(s)

David W. Pierce dpierce@ucsd.edu

References

http://www.unidata.ucar.edu/packages/netcdf/

See Also

dim.def.ncdf, var.def.ncdf.

Examples

# Define an integer dimension 
dimState <- dim.def.ncdf( "StateNo", "count", 1:50 )

# Make an integer variable.  Note that an integer variable can have
# a double precision dimension, or vice versa; there is no fixed
# relationship between the precision of the dimension and that of the
# associated variable.  We just make an integer variable here for
# illustration purposes.
varPop <- var.def.ncdf("Pop", "count", dimState, -1, 
        longname="Population", prec="integer")

# Create a netCDF file with this variable
ncnew <- create.ncdf( "states_population.nc", varPop )

# Write some values to this variable on disk.
popAlabama <- 4447100
put.var.ncdf( ncnew, varPop, popAlabama, start=1, count=1 )

# Add source info metadata to file
att.put.ncdf( ncnew, 0, "source", "Census 2000 from census bureau web site")

close.ncdf(ncnew)

# Now open the file and read its data
ncold <- open.ncdf("states_population.nc")
data <- get.var.ncdf(ncold)
print("here is the data in the file:")
print(data)
close.ncdf( ncold )

[Package ncdf version 1.6 Index]