Learn R Programming

RNetCDF (version 1.9-1)

read.nc: Read a NetCDF Dataset

Description

Read all data from a NetCDF dataset.

Usage

read.nc(ncfile, unpack=TRUE)

Arguments

ncfile

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

unpack

Unpack "packed" variables if set to TRUE (default).

Value

A list with the list elements containing the variable data of the NetCDF dataset.

Details

This function reads all variable data from a NetCDF dataset into a single list. The list elements (arrays) have the same names as the variables in the NetCDF dataset.

Packed variables can optionally be returned in an unpacked state (see var.get.nc for more information).

References

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

Examples

Run this code
# NOT RUN {
##  Create a new NetCDF dataset and define two dimensions
nc <- create.nc("read.nc")

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

##  Create three variables, one as coordinate variable
var.def.nc(nc, "time", "NC_INT", "time")
var.def.nc(nc, "temperature", "NC_DOUBLE", c(0,1))
var.def.nc(nc, "name", "NC_CHAR", c("max_string_length", "station"))

##  Put some missing_value attribute for temperature
att.put.nc(nc, "temperature", "missing_value", "NC_DOUBLE", -99999.9)

##  Define variable values
mytime        <- c(1:2)
mytemperature <- c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, NA, NA, 9.9)
myname        <- c("alfa", "bravo", "charlie", "delta", "echo")

##  Put the data
var.put.nc(nc, "time", mytime, 1, length(mytime))
var.put.nc(nc, "temperature", mytemperature, c(1,1), c(5,2))
var.put.nc(nc, "name", myname, c(1,1), c(32,5))

sync.nc(nc)

##  Get the data
read.nc(nc)

close.nc(nc)
# }

Run the code above in your browser using DataLab