Project

General

Profile

Multiply all values in vertical column

Added by david moreno about 1 year ago

Hello all,

I need to multiply all values of a vertical column, something exactly like VERTSUM but for multiplication instead of sum.

Is there a CDO operator that does this?


Replies (3)

RE: Multiply all values in vertical column - Added by Karin Meier-Fleischer about 1 year ago

Hi David,

imo there is no such operator. You can write a small script to do it, e.g.

#!/usr/bin/env ksh

#-- create dummy input file
cdo -sellevel,1000,3000,5000 -selname,t $HOME/data/rectilinear_grid_3D.nc infile.nc

nlev=$(cdo -s nlevel infile.nc)

cdo splitlevel infile.nc inlev_
set -A flist $(ls inlev_*.nc)

first=${flist[0]}
for (( i=1; i<${nlev}; i++ ))
do
    cdo -mul ${first} ${flist[$i]} tmp_${i}.nc
    mv tmp_${i}.nc tmp.nc
    first=tmp.nc
done

mv tmp.nc outfile.nc

RE: Multiply all values in vertical column - Added by david moreno 12 months ago

Hi Karin, thanks for the tip!

I'm trying to use your script but I dont use korn shell... And it seems like there is some syntax difference in the set -A flist $(ls inlev_*.nc) command.

Do you think you could send me the bash (sh) equivalent of set -A flist $(ls inlev_*.nc)?

Thanks

RE: Multiply all values in vertical column - Added by Karin Meier-Fleischer 12 months ago

Instead of

set -A flist $(ls inlev_*.nc)

use the following for bash shell

flist=($(ls inlev_*.nc))
    (1-3/3)