1

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 1

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, ncbo seems to add multiple netcdf files. I want to add some variables within a single netcdf file
I have edited my answer to show how to add variables within a single file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.