Project

General

Profile

multiply selected gridcells (or region) with a factor

Added by Natalia L about 2 years ago

I have a gridded netcdf file with several variables. I want to multiply all the variables with a constant but only for a selected region of the grid.

With -mulc you can multiply the values for the whole grid. While with setcindexbox you can only set the values to a constant value.

Is it possible to multiply only a selected region of the grid with a constant value?


Replies (1)

RE: multiply selected gridcells (or region) with a factor - Added by Karin Meier-Fleischer about 2 years ago

Hi Natalia,

yes, you can use the expr operator and the clon(var), clat(var) functionality.

The following command uses for illustration the data of the topo operator and adds 10000 to the variable in the lonlatbox 0,20,0,20 and store the output in variable topo of outfile.nc. It keeps the other values untouched.

cdo -f nc -expr,'topo=((clon(topo) >= 0.0) && (clon(topo) <= 20.0) && (clat(topo) >= 0.0) && (clat(topo) <= 20.0)) ? topo+10000 : topo ;' -topo outfile.nc

    (1-1/1)