NCO:ncap2 is the function to do it: _ncap2 -s ‘new_var=var1+var2’ in_filename.nc outfilename.nc The output file will have all of the variables that exist in the input file as well as the new_var. Add -O if your input and output files are the same (overwrite). I do not know what the -s stands for. BUT the new_var will have the same long_name as the first variable used for summing (i.e. it could make some things a bit confusing).
NCO:ncap2 and .total _ncap2 -s ‘summed_variable=variable_tosum.total($lat,$lon)’ in.nc out.nc Make sure to use single quotes. If your in.nc==out.cnc then adding -A will save you from having to specify “overwrite” (see this). _ncap2 -A -s ‘summed_variable=variable_tosum.total($lat,$lon)’ in.nc out.nc