我有一个我创建的多变量 ncdf,并想为每个变量添加额外的数据。纬度和经度维度将保持不变,但我想通过将新数据附加到每个变量来扩展时间维度。新数据集具有相同数量的变量,dim1 和 dim2,但其 dim3 开始于第一个数据集的 dim3 时间结束的位置。现有的 ncdf(有 42 个变量):这是启动代码:
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)