Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

var.def.nc

Define a NetCDF Variable


Description

Define a new NetCDF variable.

Usage

var.def.nc(ncfile, varname, vartype, dimensions,
                  chunking=NA, chunksizes=NULL, deflate=NA, shuffle=FALSE,
                  big_endian=NA, fletcher32=FALSE,
                  filter_id=NA, filter_params=integer(0))

Arguments

ncfile

Object of class "NetCDF" which points to the NetCDF dataset (as returned from open.nc).

varname

Variable name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore ("_"). Case is significant.

vartype

External NetCDF data type as one of the following labels: NC_BYTE, NC_UBYTE, NC_CHAR, NC_SHORT, NC_USHORT, NC_INT, NC_UINT, NC_INT64, NC_UINT64, NC_FLOAT, NC_DOUBLE, NC_STRING, or a user-defined type name.

dimensions

Vector of ndims dimension IDs or their names corresponding to the variable dimensions or NA if a scalar variable should be created. If the ID (or name) of the unlimited dimension is included, it must be last.

The following arguments are optional for datasets in "netcdf4" format (and ignored for other formats):

chunking

TRUE selects chunking, FALSE implies contiguous storage, NA allows the NetCDF library to choose a storage layout. Ignored for scalar variables.

chunksizes

Chunk size expressed as the number of elements along each dimension, in the same order as dimensions. If NULL, the NetCDF library uses a default chunking strategy, which is intended to give reasonable performance in typical applications. Ignored unless chunking is TRUE.

deflate

Integer indicating level of compression, from 0 (minimum) to 9 (maximum), or NA for no compression.

shuffle

TRUE to enable byte shuffling, which may improve compression with deflate.

big_endian

Byte order of the variable. TRUE for big-endian, FALSE for little-endian, NA for native endianness of the platform.

fletcher32

TRUE to enable the fletcher32 checksum.

filter_id

Identifier of filter to associate with the variable, or NA for no filter. For information about the available filters, please see the NetCDF documentation. Ignored if the installed NetCDF library does not support this feature.

filter_params

Vector of integer parameters for the filter specified by filter_id. The meaning of the parameters depends on the filter implementation, and RNetCDF is unable to perform any validation. Ignored if no filter is defined or if the installed NetCDF library does not support this feature.

Details

This function creates a new NetCDF variable. A NetCDF variable has a name, a type, and a shape, which are specified when it is defined. A variable may also have values, which are established later in data mode.

Ordinarily, the name, type, and shape are fixed when the variable is first defined. The name may be changed, but the type and shape of a variable cannot be changed. However, a variable defined in terms of the unlimited dimension can grow without bound in that dimension. The fastest varying dimension has to be first in dimensions, the slowest varying dimension last (this is the same way as an array is defined in R; i.e., opposite to the CDL conventions).

A NetCDF variable in an open NetCDF dataset is referred to by a small integer called a variable ID. Variable IDs are 0, 1, 2,..., in the order in which the variables were defined within a NetCDF dataset.

Attributes may be associated with a variable to specify such properties as units.

Value

NetCDF variable identifier, returned invisibly.

Author(s)

Pavel Michna, Milton Woods

References

Examples

##  Create a new NetCDF dataset and define two dimensions
file1 <- tempfile("var.def_", fileext=".nc")
nc <- create.nc(file1)

dim.def.nc(nc, "station", 5)
dim.def.nc(nc, "time", unlim=TRUE)

##  Create two variables, one as coordinate variable
var.def.nc(nc, "time", "NC_INT", "time")
var.def.nc(nc, "temperature", "NC_DOUBLE", c(0,1))

close.nc(nc)
unlink(file1)

RNetCDF

Interface to 'NetCDF' Datasets

v2.4-2
GPL (>= 2) | file LICENSE
Authors
Pavel Michna [aut], Milton Woods [aut, cre]
Initial release
2020-09-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.