nctoarray: nctoarray: Creates an array containing data within an nc file

Description Usage Arguments Value Examples

Description

nctoarray is used to create a three-dimensional array containing data from a .nc file.

Usage

1
nctoarray(filein, varid = NA)

Arguments

filein

A character string with the full path name of the nc file. Tilde-expansion is performed.

varid

The variable to be read from the ncfile. Can be a string with the name of the variable or an object of class ncvar4. If left unspecified, the function will determine if there is only one variable in the file and, if so, read from that. If left unspecified and there are multiple variables in the file, an error is generated.

Value

a three-dimensional array of the specified variable, permuted to dimension order 2, 1, 3.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# ========= Create nc file of random data and save to disk ============= #
longs <- ncdim_def(name="lon", units = "degrees_east",
                   vals = seq(1,10,1),longname="longitude")
lats <- ncdim_def(name="lat",  units = "degrees_north",vals=seq(1,10,1),
                  longname="latitude")
times <- ncdim_def(name="time",units="hours since 1983-01-01 00:00:00",
                   vals=c(101:110))
mydata <-ncvar_def(name="Random data", units="mm", dim = list(longs, lats, times))
ncnew <- nc_create(filename="Random.nc", mydata)
ncvar_put(ncnew, mydata, vals = array(rnorm(10000), dim = c(10,10,10)))
nc_close(ncnew)

# ========= Read in as array ============================= #
arr <- nctoarray("Random.nc", varid = "Random data")
dim(arr)

ilyamaclean/climvars documentation built on June 19, 2019, 2:22 p.m.