Project

General

Profile

how to realize the condiational calculation by cdo

Added by Hongzhi Zhang over 1 year ago

Hi, all

These days, I've done the convertion job of surface temperature (°K to °F). However, when I started to calculate the heat index, I found that I don't know how to realize the conditional calculation by cdo. It would be very helpful if anyone could provide some advises.

I need to calculate heat index by considering surface temperature(TAS) and relative humidity(RH) based on following steps:

(1) cdo expr,'tas = fomula 1' -merge TAS.nc RH.nc output.nc
(2) if tas is greater than the threhold (80°F), then excute "cdo expr,'tas = fomula 2'

Thanks again for helps.

Regards
Hongzhi


Replies (2)

RE: how to realize the condiational calculation by cdo - Added by Ralf Mueller over 1 year ago

hi!

I try to re-use your pseudo-code for the formular:

cdo -expr,'tas=(tas>80.0)?formula2():tas; tas=formula1(tas,rh);' <infile> <outfile>

Just like the operators on the command line the calls area executed from right to left in the expr operator. Check the docu at. The construct is called 'Ternary Operator' its a shortcut for an IF-statement.

hth
ralf

RE: how to realize the condiational calculation by cdo - Added by Hongzhi Zhang over 1 year ago

Hi, ralf

Thanks for your kind advise. It's very helpful.

Regards
Hongzhi

    (1-2/2)