Is there a nco operator to create a new variable by adding multiple variables in a single netcdf file? I know you can use ncdiff to subtract, is there anything equaivalent operator for adding?
1 Answer
Yes, NCO's ncbo function has subtraction, addition, multiplication, and division capabilities. For adding in specific, you can alternatively call ncadd. From the docs:
Definition: file_3 = file_1 + file_2
Alternate invocation: ncadd
op_typ key values: ‘add’, ‘+’, ‘addition’
Examples: ‘ncbo --op_typ=add 1.nc 2.nc 3.nc’, ‘ncadd 1.nc 2.nc 3.nc’
To add variables within a single netcdf file, you can use ncap2, e.g.
ncap2 -s 'var3=(var1+var2)' in.nc out.nc
2 Comments
user308827
thanks, ncbo seems to add multiple netcdf files. I want to add some variables within a single netcdf file
N1B4
I have edited my answer to show how to add variables within a single file.