2

I have a multivariable ncdf that I created and wanted to add additional data to each variable. the lat and long dimensions will remain the same but I want to extend the time dimension by appending new data to each variable. The new data set has the same number of variables, dim1 and dim2 but its dim3 starts where the time of dim3 of the first dataset ends. Existing ncdf (has 42 variable): Here is startup code:

library(ncdf4)
dim1 = ncdim_def("lat")
dim2 = ncdim_def( "long")
dim3 = ncdim_def( "time", "days since 2004-01-01", as.integer(time))
Var<-c("a","b","c","d",.....) # variables of existing "merged.nc" file
unit<-c("aa","ab","ac","ad",...)
mat<-(n by m data matrix)
mync = nc_open('merged.nc', write=TRUE)
for (k in 2:length(var)){
ncvar_put(mync,var[k],mat[,k])
}
nc_close(mync)
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Yami
  • 21
  • 1
  • 3

2 Answers2

1

You might try NCO's ncrcat

ncrcat in1.nc in2.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19
1

you can merge in time using

cdo mergetime in1.nc in2.nc out.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86