var.def.ncv {ncvar}R Documentation

Define a NetCDF Variable

Description

Define a new NetCDF variable object.

Usage

var.def.ncv(name, data=NULL, xtype=NULL, start=NA, count=NA, 
    dim=NULL, att=NULL, mvar=NULL, gatt=NULL, coord=FALSE, unlim=FALSE)

Arguments

name Variable name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore ("_"). Case is significant.
data The (multidimensional) array containing the data to write.
xtype One of the predefined NetCDF external data types (NC_BYTE, NC_CHAR, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE). If none is provided, NC_CHAR, NC_INT, or NC_FLOAT is chosen depending on the type of value .
start A vector of indices (1-based) indicating where to start writing the passed data. The length of this vector must equal the number of dimensions of the variable.
count A vector of integers indicating the number of values to write along each dimension. The length of this vector must equal the number of dimensions of the variable.
dim A list of dimension/coordinate objects (class "dim.ncv" or "coord.ncv"), as returned from dim.def.ncv or coord.def.ncv, respectively.
att A list of attribute objects (class "att.ncv"), as returned from att.def.ncv.
mvar A list of variable objects (class "var.ncv") as returned from dim.def.ncv.
gatt A list of attribute objects (class "att.ncv"), as returned from att.def.ncv.
coord For internal use only.
unlim For internal use only.

Details

This function creates a new variable object including all its associated metadata. Apart from the mandatory dimensions and coordinates, the variables metadata may include attributes and further NetCDF variables such as grid mappings, labels, auxillary coordinate variables, cell boundaries, cell measures, and cell methods.

Value

An object of class "var.ncv".

Author(s)

Juerg Schmidli

References

http://www.unidata.ucar.edu/packages/netcdf/
http://www.cgd.ucar.edu/cms/eaton/cf-metadata/

Examples

## define coordinate variables
rlon <- coord.def.ncv("rlon", seq(1,10), xtype="NC_FLOAT",
    att=list("axis", "X",
            "standard_name", "grid_longitude",
            "long_name", "longitude in rotated pole grid",
            "units", "degrees") )
rlat <- coord.def.ncv("rlat", 1.*seq(1,5),
    att=list("axis", "Y",
            "standard_name", "grid_latitude",
            "long_name", "latitude in rotated pole grid",
            "units", "degrees") )
hgt <- coord.def.ncv("hgt", 0.,
    att=list("axis", "Z", "long_name", "altitude", "units", "metre",
            "positive", "up") )
time <- coord.def.ncv("time", 0., 
    att=list("axis", "T", "calendar", "standard", "long_name", "time",
            "units", "days since 1979-01-01 00:00:00.0"), unlim=TRUE)

## define grid mapping variable
#gmap <- var.def.ncv("rotated_pole", 0.,
#    att=list("grid_mapping_name", "rotated_latitude_longitude",
#            "grid_north_pole_longitude", -170.,
#            "grid_north_pole_latitude", 32.5) )

## define data variable
pre <- var.def.ncv("precip", array(1., dim=c(10,5,1,1)), xtype="NC_FLOAT",
    dim=list(rlon, rlat, hgt, time),
    att=list("long_name", "precipitation", "units", "mm d-1",
            "_FillValue", -998.9, "grid_mapping", "rotated_pole"))

## write to file
var.put.ncv(paste(tempdir(),"/foo.nc",sep=""), pre)


[Package ncvar version 1.0-4 Index]