Project

General

Profile

how to calculate a difference using CDO

Added by Serge Tom over 4 years ago

Hi CDO comunity,

I have monthly file of SST containing daily data. I would like to calculate the difference between the last and first date of each month and divided by the length of the month.
Some one have any Idea on how to do it??

Thank you in advance
Serge


Replies (3)

RE: how to calculate a difference using CDO - Added by Karin Meier-Fleischer over 4 years ago

Hi Serge,

you can write a short shell script to loop over the months, select the first and last day and use divdpm to devide the result by the number of days per month.

Example ksh-script snippet (for convenience delete February 29th, use calendar 365_day):

orgfile=infile.nc

cdo -del29feb $orgfile tmp.nc

set -A dpm 31 28 31 30 31 30 31 31 30 31 30 31

typeset -i j=1

for ((i=0; i<=11; ++i))
do
   echo "-- month  $i - days ${dpm[${i}]}" 
   cdo selmon,${j} tmp.nc m_${i}.nc
   cdo -divdpm -sub -selday,${dpm[${i}]} m_${i}.nc -selday,1 m_${i}.nc o_${i}.nc
   j=++j
done

cdo -O mergetime o_*.nc outfile.nc

rm -rf m_*.nc o_*.nc tmp.nc

-Karin

RE: how to calculate a difference using CDO - Added by Serge Tom over 4 years ago

Thank you a lot Karim, my data is noleap data. so don't need to delete anythings.
but I didn't understand the line typeset -i j=1;

could you explain it to me.
thank you in advance

RE: how to calculate a difference using CDO - Added by Karin Meier-Fleischer over 4 years ago

As mentioned above it is a part of a Korn Shell script which you can run in a terminal. It is just an example how you could do it. The line 'typeset -i j=1' defines an integer variable j and initialize it to one. If you are unfamiliar with shell scripting you will find enough tutorials about it all around, but not here. Sorry.

    (1-3/3)