att.put.nc | R Documentation |
Put an attribute to a NetCDF dataset.
att.put.nc(ncfile, variable, name, type, value)
ncfile |
Object of class |
variable |
ID or name of the variable to which the attribute will be assigned or |
name |
Attribute name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore ( |
type |
External NetCDF data type as one of the following labels: |
value |
Attribute value. This can be either a single numeric value or a vector of numeric values, or alternatively a character string. |
Names commencing with underscore ("_"
) are reserved for use by the NetCDF library. Most generic applications that process NetCDF datasets assume standard attribute conventions and it is strongly recommended that these be followed unless there are good reasons for not doing so.
Text represented by R type character
can be written to NetCDF types NC_CHAR
and NC_STRING
, and R type raw
can be written to NetCDF type NC_CHAR
.
R numeric
and integer
variables can be written to NetCDF numeric types. The NetCDF library handles type conversions, but conversions of values outside the range of a type will result in an error. Due to the lack of native support for 64-bit integers in R, this function accepts integer64
vectors.
NC_BYTE
is always interpreted as signed.
Pavel Michna, Milton Woods
https://www.unidata.ucar.edu/software/netcdf/
## Create a new NetCDF dataset and define two dimensions
file1 <- tempfile("att.put_", 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))
## Put some attributes
att.put.nc(nc, "temperature", "_FillValue", "NC_DOUBLE", -99999.9)
att.put.nc(nc, "temperature", "long_name", "NC_CHAR", "air temperature")
att.put.nc(nc, "NC_GLOBAL", "title", "NC_CHAR", "Data from Foo")
att.put.nc(nc, "NC_GLOBAL", "history", "NC_CHAR", paste("Created on", date()))
close.nc(nc)
unlink(file1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.