append.nc: Append Temporally Disjunct NCDF data

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/append.nc.R

Description

define a function to append data of two ncdf files from retrieve.nc or at least have the tim,yy,mm,dd,

Usage

1
append.nc(nc1, nc2)

Arguments

nc1

~~Describe nc1 here~~

nc2

~~Describe nc2 here~~

Details

we must assume that units, extents, variable, etc. are all the same

Value

...

Note

~~further notes~~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(nc1,nc2) {
	#ensure nc1 & nc2 are from retrieve.nc
	if (all(c('dat','tim','yy','mm','dd', 'lat', 'lon') %in% names(nc1))==FALSE)
  stop('nc1 must have objects named dat, lat, lon, tim, yy, mm and dd as from
  retrieve.nc of clim.pact package')
	if (all(c('dat','tim','yy','mm','dd', 'lat', 'lon') %in% names(nc2))==FALSE)
  stop('nc2 must have objects named dat, lat, lon, tim, yy, mm and dd as from
  retrieve.nc of clim.pact package')
	#do the work
	out = nc1 #copy nc1
	out$dat = array(NA,dim=c(dim(nc1$dat)[1]+dim(nc2$dat)[1],dim(nc1$dat)[2],
  dim(nc1$dat)[3]))#redim dat
	out$dat[1:dim(nc1$dat)[1],,] = nc1$dat #add dat from nc1
	out$dat[(dim(nc1$dat)[1]+1):(dim(nc1$dat)[1]+dim(nc2$dat)[1]),,] = nc2$dat
  #add dat from nc2
	#append the time information
	out$tim = c(nc1$tim,nc2$tim)
	out$yy = c(nc1$yy,nc2$yy)
	out$mm = c(nc1$mm,nc2$mm)
	out$dd = c(nc1$dd,nc2$dd)
	if ('id.t' %in% names(nc1)) out$id.t = c(nc1$id.t,nc2$id.t)
	if ('filename' %in% names(nc1)) out$filename = NA
	if ('attributes' %in% names(nc1)) out$attributes$filename = NA
	#return the data
	return(out)
  }

## End(Not run)

jjvanderwal/climates documentation built on May 19, 2019, 11:41 a.m.