1

I have two kinds of variables in two different nc files. The dimension and other things are same, I just have to add one more variable in the existing nc file, How can I do this (using CDO or R or any other)

I used the command line (cdo selvar,varname in.nc out.nc) but it doesn't help. This command does work but deletes the existing variables. Any suggestions on how can I add new variables without deleting the variable inside the nc file? Many thanks.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • your question isn't very clear, do you mean you want to add the variable in nc1 to the file nc2? Would a command such as cdo cat nc1 nc2 output.nc do what you want? please clarify the question to make it clearer... – ClimateUnboxed Aug 03 '21 at 20:22
  • Sorry for not making it clear. I have two nc files 'aaa.nc' and 'bbb.nc'. aaa.nc file have variable name xxx, and bbb.nc file has variable yyy. Now, I want to copy yyy variable to aaa.nc (from bbb.nc). This means, I want both variables xxx and yyy to appear in aaa.nc file. Hope I make my question clear. Many thanks. – Hemraj Bhattarai Aug 04 '21 at 02:22

2 Answers2

3

The NCO solution is

ncks -A -v yyy bbb.nc aaa.nc

as documented here.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Charlie Zender
  • 5,929
  • 14
  • 19
2

From your comment of clarification, I think the cdo command you need is cat

cdo cat aaa.nc bbb.nc output.nc 

This will concatenate the fields in bbb.nc to the ones in aaa.nc and put the result in output.nc

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86