att.copy.nc: Copy Attribute from One NetCDF to Another

View source: R/RNetCDF.R

att.copy.ncR Documentation

Copy Attribute from One NetCDF to Another

Description

Copy attribute from one NetCDF to another.

Usage

att.copy.nc(ncfile.in, variable.in, attribute, ncfile.out, variable.out)

Arguments

ncfile.in

Object of class NetCDF which points to the input NetCDF dataset from which the attribute will be copied (as returned from open.nc).

variable.in

ID or name of the variable in the input NetCDF dataset from which the attribute will be copied, or "NC_GLOBAL" for a global attribute.

attribute

Name or ID of the attribute in the input NetCDF dataset to be copied.

ncfile.out

Object of class NetCDF which points to the output NetCDF dataset to which the attribute will be copied (as returned from open.nc). It is permissible for the input and output NetCDF object to be the same.

variable.out

ID or name of the variable in the output NetCDF dataset to which the attribute will be copied, or "NC_GLOBAL" to copy to a global attribute.

Details

This function copies an attribute from one open NetCDF dataset to another. It can also be used to copy an attribute from one variable to another within the same NetCDF dataset.

Valid attribute ID numbers range from 0 to the number of attributes minus 1. The number of attributes of a file, group, or variable can be found using the relevant inquiry function (file.inq.nc, grp.inq.nc, or var.inq.nc).

Author(s)

Pavel Michna, Milton Woods

References

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

Examples

##  Create two new NetCDF datasets and define two dimensions
file1 <- tempfile("att.copy_", fileext=".nc")
file2 <- tempfile("att.copy_", fileext=".nc")
nc.1 <- create.nc(file1)
nc.2 <- create.nc(file2)

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

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

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

var.def.nc(nc.2, "time", "NC_INT", "time")
var.def.nc(nc.2, "temperature", "NC_DOUBLE", c(0,1))

##  Put some attributes to the first dataset
att.put.nc(nc.1, "temperature", "_FillValue", "NC_DOUBLE", -99999.9)
att.put.nc(nc.1, "NC_GLOBAL", "title", "NC_CHAR", "Data from Foo")

##  Copy the attributes to the second dataset
att.copy.nc(nc.1, 1, 0, nc.2, 1)
att.copy.nc(nc.1, "NC_GLOBAL", "title", nc.2, "NC_GLOBAL")

close.nc(nc.1)
close.nc(nc.2)
unlink(file1)
unlink(file2)

RNetCDF documentation built on May 29, 2024, 2:41 a.m.