How to translate in SIMILE and "IF" function within another "IF" function?

4 views
Skip to first unread message

Francesco Benvenuti

unread,
Mar 17, 2012, 9:41:41 AM3/17/12
to ste...@googlegroups.com
I am not menaging to make Simile to accept my fomula for a parameter (see below):

actual leaf flushing = IF THEN ELSE (assimilate surplus > 0, leaf goal, IF THEN ELSE ((canopy production -stem respiration) > 0, canopy production -stem respiration, 0)) [t ODM /(Year*ha)]

My translation was this: if assimilate_surplus>0 then leaf_goal else[if (canopy_production-stem_respiration)>0 then (canopy_production-stem_respiration) else 0]

but it does not work.. :/  

Robert Muetzelfeldt

unread,
Mar 17, 2012, 10:00:29 AM3/17/12
to ste...@googlegroups.com
Hi Francesco,

You're almost there:
You simply use round brackets (...) instead of the square brackets [...]

I.e.
   if assimilate_surplus>0 then leaf_goal else (if (canopy_production-stem_respiration)>0 then (canopy_production-stem_respiration) else 0)
It's a good idea to add a space after the 'else'.
I haven't actually tested this, so get back to me if I've missed something.

The inner round brackets you used are strictly speaking not necessary, so it can simplified to :
   if assimilate_surplus>0 then leaf_goal else (if canopy_production-stem_respiration>0 then canopy_production-stem_respiration else 0)
which shows the structure somewhat more clearly.  

Square brackets are used in Simile, but have a totally different meaning (they indicate that a variable is an array - i.e. has multiple values instead of just one - or they bracket a set of comma-separate values which are to be treated together).

The Simile Help entry on conditional expressions can be found at http://www.simulistics.com/help/equations/conditions.htm.  This mentions the possibility of nesting conditionals (as you want), but does not currently explicitly mention that the use of round brackets for the nested conditional is necessary (I've just checked).  I'll fix it, so in future it should make this clear.  

Thanks for raising this issue.

Cheers,
Robert
-- 
-----
Reply all
Reply to author
Forward
0 new messages