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?
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