1

I am trying to merge many single .nc files into one multi-file netCDF. I need to merge monthly files from 1901-2006 for a few variables e.g. temp (filename is tmp_cru-ts-4.03-gridded_1.75w50.75n1.75w50.75n_19010116)

My skills are pretty basic in R but I've tried this so far:

filenames=list.files("tmp", pattern = '*.nc', full.names = TRUE)
ldf = lapply(filenames,open.nc)             #rnetcdf function
binded = rbind(ldf)

I'm not sure if this is right, or how to now write it to a .nc file?

Thanks!

Jamster
  • 11
  • 2
  • https://stackoverflow.com/questions/45096730/merge-netcdf-files-in-r or https://stackoverflow.com/questions/29101807/how-to-merge-netcdf-file-into-one ? – Gainz Jul 13 '20 at 15:51
  • As you have tagged cdo-climate, try `cdo mergetime *.nc out.nc` or `cdo merge *.nc out.nc`, depending on what type of merge you are trying to do. – Robert Wilson Jul 13 '20 at 16:40
  • Does this answer your question? [Merge netCDF files in R](https://stackoverflow.com/questions/45096730/merge-netcdf-files-in-r) – alex_danielssen Jul 21 '20 at 14:54

2 Answers2

2

CDO can do this too

cdo cat in*.nc out.nc

or more robustly in this case where the files are for different times:

cdo mergetime in*.nc out.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
1

NCO can do this with ncrcat

ncrcat in*.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19