amo
amo

Reputation: 129

multiply variables in two NetCDF files in single command

I have two netcdf files: file_1.nc with variables qty_1 and qty_2 and file_2.nc with variables qty_3, qty_4 and qty_5. I want a file with 3 variables qty_3=qty_3*qty_2; qty_4=qty_4+qty_2 and qty_5.

Now I am first copying the variables to file_2 using

ncks  -A -v qty_1,qty_2 file_1.nc file_2.nc

then I am doing math operation as,

ncap2 -A -s 'qty_3=qty_3*qty_2' -s 'qty_4=qty_4+qty_2' file_2.nc

This works, however, take some time.

Is there a way I can do this calculation in a single command ?

Upvotes: 1

Views: 1316

Answers (1)

Robert Wilson
Robert Wilson

Reputation: 3397

If you aren't totallly dependent on NCO, you could do this with CDO:

cdo -selname,qty_3,qty_4,qty_5 -aexpr,'qty_3=qty_3*qty_2;qty_4=qty_4+qty_2' -merge file_1.nc file_2.nc out.nc

Upvotes: 5

Related Questions