retrieve.nc {clim.pact} | R Documentation

## Retrieve data from a netCDF file

### Description

`retrieve.nc` reads a netCDF file and picks out vectors that look like lngitude, latitude and time. Returns the first 3-D field in the file. See also `cdfextract` (large data files).

This version uses `cdfcont` to obtain vital meta data for handling the data in the netCDF file and constructing a 'field' object.

This routine reequres the `ncdf`-package is currently only available for Linux systems at the CRAN web sites, but the Windows version can can be obtained from http://www.stats.ox.ac.uk/pub/RWin/.

`fixField` is a function for eg changing the time stamp if the given time origin is wrong.

### Usage

           retrieve.nc(filename=file.path("data","air.mon.mean.nc"),v.nam="AUTO",
                            l.scale=FALSE,greenwich=TRUE,silent=FALSE,
                            x.nam="lon",y.nam="lat",z.nam="lev",t.nam="tim",
                            x.rng=NULL,y.rng=NULL,z.rng=NULL,t.rng=NULL,force.chron=TRUE,
                            force365.25=FALSE,regular=TRUE,daysayear=365.25,forceBC=TRUE,use.cdfcont=FALSE)
           fixField(x,torg=NULL,t.unit=NULL,scal=NULL,offs=NULL,
                         x.rng=NULL,y.rng=NULL,z.rng=NULL,t.rng=NULL,greenwich=TRUE)
           monthly(x,param="t2m")

### Arguments

`filename` | name of netCDF file.
`v.nam` | name of variable. "AUTO" -> smart search.
`l.scale` | 'TRUE' uses scaling.factor and add.offset.
`greenwich` | 'TRUE' centres maps on Greenwhich meridian (0 deg E).
`x.nam` | Name of x-dimension.
`y.nam` | Name of y-dimension.
`z.nam` | Name of z-dimension.
`t.nam` | Name of time-axis.
`x.rng` | Region to extract.
`y.rng` | Region to extract.
`z.rng` | Region to extract.
`t.rng` | Time interval to extract.Numerical values are used to identify indeces, e.g. `as.numeric(1)` refers to first field, `as.numeric(2)` the second field, etc. Character strings, on the other hand, refers to date. E.g. "1-Jan-1990", or "1990" (see `datestr2num` for various formats).
`force.chron` | Check for monotonic chronological order (no jumping back and forth in time).
`force365.25` | TRUE forces a natural 365.25 day year as opposed to a 360-day model year. '-1' forces a 360-day year (commonly used in climate modelling).
`regular` | TRUE for regular spacing in time (.i.e. no skipping, but one field every month or one field every day).
`daysayear` | Number of days in the year on average.
`forceBC` | TRUE for not accepting year 0 (see e.g. Press et al. (1989), Numerical Recepies in Pascal, Cambridge).
`x` | a field object.
`torg` | time origin.
`t.unit` | tim unit
`scal` | scaling factor
`offs` | constant offset
`silent` | To turn off printing to console.
`param` | Parameter to convert to monthly value
`use.cdfcont` | Flag for Linux versions only: if TRUE use old lines calling 'cdfcont()'

### Value

A "field.object" list:

dat | a 3-D matrix with the data.
lon | a vector of longitudes.
lat | a vector of latitudes.
tim | a vector of times from time.0 (see attributes).
lev | a vector of vertical levels (NULL for single level).
v.name | variable name.
id.x | ID labels for the spatial grid (for mixed fields, see `mixFields`).
id.t | ID labels for the time axis (for combined fields).
yy | a vector of years corresponding to `tim`.
mm | a vector of months corresponding to `tim`.
dd | a vector of days corresponding to `tim`.
n.fld | number of fields (for mixed fields, see `mixFields`).
id.lon | ID labels along the longitudes (for mixed fields, see `mixFields`).
id.lat | ID labels along the latitudes (for mixed fields, see `mixFields`).

.

### Author(s)

R.E. Benestad

### Examples

    ## Not run:
    X.1 <- retrieve.nc("data/mpi-gsdio_t2m.nc",
                       x.rng=c(-60,40),y.rng=c(50,75))
    X.2 <- retrieve.nc("data/mpi-gsdio_slp.nc",
                       x.rng=c(-60,40),y.rng=c(50,75))

    # The definition of a 'field' object is:
    ny<-length(slp$lat); nx<-length(slp$lon)
    slp  <- list(dat=X.2$dat,lon=X.2$lon,lat=X.2$lat,tim=X.2$tim,lev=X.2$lev,
                 v.name=X.2$v.nam,id.x=X.2$id.x,id.t=X.2$id.t,
                 yy=X.2$yy,mm=X.2$mm,dd=X.2$dd,n.fld=1,
                 id.lon=rep(X.2$v.name,nx),id.lat=rep(X.2$v.name,ny),
                 attributes=dat.att)
     class(slp) <- c("field")

    # For reading the IPCC FoAR netCDF files that uses a 365-day year (no leap years) and starts on time count year 0:
    gcm <- retrieve.nc(fname,v.nam="tas",x.rng=c(-50,50),y.rng=c(30,75),forceBC=FALSE)
    ## End(Not run)

[Package clim.pact version 2.2-1 Index]