Project

General

Profile

Equivalent of ifthenelsec?

Added by David Gobbett over 10 years ago

Hi,

I'm trying to implement a relatively simple algorithm that checks whether an input is above an upper threshold,
or below a lower threshold, and returns a constant (zero) otherwise.

if HLI > UL
  Excess = HLI – UL
if HLI < LL
  Excess = HLI – LL
Else
  Excess = 0

This is how I was thinking to do this, but it seems a bit messy, but at least it is a single call...

cdo -ifthenelse -gtc,$UL $HLI -subc,$UL $HLI -ifthenelse -ltc,$LL $HLI -subc,$LL $HLI ifnotthenc,0 -ltc,$LL $HLI $RES

Is there a better way? For example an ifthenelsec operator would simplify this to

cdo -ifthenelse -gtc,$UL $HLI -subc,$UL $HLI -ifthenelsec,0 -ltc,$LL $HLI -subc,$LL $HLI $RES

but perhaps there's an even neater approach?

regards