ncatt_put | R Documentation |
Writes an attribute to a netCDF file.
ncatt_put( nc, varid, attname, attval, prec=NA, verbose=FALSE,
definemode=FALSE )
nc |
An object of class |
varid |
The variable whose attribute is to be written. Can be a
character string with the variable's name, an object of class |
attname |
Name of the attribute to write. |
attval |
Attribute to write. |
prec |
Precision to write the attribute. If not specified, the written precision is the same as the variable whose attribute this is. This can be overridden by specifying this argument with a value of "short", "float", "double", or "text". |
verbose |
Can be set to TRUE if additional information is desired while the attribute is being created. |
definemode |
If FALSE (the default), it is assumed that the file is NOT already in define mode. Since the file must be in define mode for this call to work, the file will be put in define mode, the attribute defined, and then the file taken out of define mode. If this argument is set to TRUE, it is assumed the file is already in define mode, and the file is also left in define mode. If you don't know what any of this means, just leave this at the default value. |
This function write an attribute to a netCDF variable (or a global attribute to a netCDF file, if the passed argument "varid" is zero). The type of the written variable can be controlled by the "prec" argument, if the default behavior (the precision follows that of the associated variable) is not wanted.
David W. Pierce dpierce@ucsd.edu
http://dwpierce.com/software
ncatt_get
.
## Not run:
# Make a simple netCDF file
filename <- "atttest_types.nc"
dim <- ncdim_def( "X", "inches", 1:12 )
var <- ncvar_def( "Data", "unitless", dim, -1 )
ncnew <- nc_create( filename, var )
# Define some attributes of various types
attvaldbl <- 3.1415926536
ncatt_put( ncnew, var, "testatt_dbl", attvaldbl, prec="double" )
attvalfloat <- c(1.0,4.0,9.0,16.0)
ncatt_put( ncnew, var, "testatt_float", attvalfloat )
# varid=0 means it is a global attribute
ncatt_put( ncnew, 0, "globalatt_int", 32000, prec="int" )
ncatt_put( ncnew, 0, "globalatt_short", 7, prec="short" )
ncatt_put( ncnew, 0, "description",
"this is a test file with attributes of various types")
nc_close(ncnew)
# Clean up our test
file.remove( filename )
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.