var.rename.nc: Rename a NetCDF Variable

Description Usage Arguments Details Author(s) References Examples

View source: R/RNetCDF.R

Description

Rename a NetCDF variable.

Usage

1
var.rename.nc(ncfile, variable, newname)

Arguments

ncfile

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

variable

Either the ID or the name of the variable to be renamed.

newname

The new variable name.

Details

This function renames an existing variable in a NetCDF dataset open for writing. A variable cannot be renamed to have the same name as another variable.

Author(s)

Pavel Michna, Milton Woods

References

https://www.unidata.ucar.edu/software/netcdf/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
##  Create a new NetCDF dataset and define two dimensions
file1 <- tempfile("var.rename_", 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))

##  Rename these variables
var.rename.nc(nc, 0, "mytime")
var.rename.nc(nc, "temperature", "mytemperature")

close.nc(nc)
unlink(file1)

Example output



RNetCDF documentation built on Aug. 20, 2021, 9:08 a.m.