[Thread Prev][Thread Next][Index]
Re: [ferret_users] If then elif end if
Hi Nageswara,
The IF-THEN-ELSE-ENDIF block construct is only meant for
scalars in Ferret according to user manual, Ref Sec14.1. IF-THEN-ELSE
conditional execution :
"If the expression is a numeric expression, then it may be a digit (e.g. 1 or
0), a variable, or a symbol. If it is a variable, it must evaluate to a
scalar, and be enclosed in grave accents to force its evaluation in the IF
expression. If it is a symbol, it must be evaluated with ($symbolname)."
Here is an example :
let x1 = 1
let x2 = 2
IF `x1 EQ x2` THEN
say " x1 = x2"
ELIF `x1 GT x2` THEN
say " x1 > x2"
ELIF `x1 LT x2` THEN
say " x1 < x2"
ENDIF
Note : Ferret versions previous to 6.00 got a bug : Ferret attempted to parse
commands even when they were not executed. For details see
http://ferret.wrc.noaa.gov/Ferret/Documentation/Release_Notes/
v600.html#if_immediate
User manual continues as :
If a variable is not a scalar, it cannot be used with this particular syntax
for conditional execution, however the use of masking allows you to operate on
a whole field based on a condition by defining a new variable (See Ch3 Sec2.5.
IF-THEN logic ("masking"))
So the answer to your question is to use successive "masking" steps instead
of using a block/construct as above. Here is an example :
Suppose we want to compare two arrays of similar dimensions (this is very
important), say var1 and var2. Our aim is to assign -1 for all points where
var1 < var2, 0 where var1 = var2 and 1 where var1 > var2. Remember that the
negative values should be enclosed in brackets "()". The most simpler
procedure will be as follows
let var1 = XSEQUENCE({1,2,3,4,5,6,7,8,9,10})
let var2 = XSEQUENCE({1,4,3,6,5,2,9,8,7,10})
let var_diff = var1 - var2
let var_m1 = IF var_diff LT 0 THEN (-1) ELSE var_diff ! var1 < var2
let var_p1 = IF var_m1 GT 0 THEN 1 ELSE var_m1 ! var1 > var2
! please note that var1 = var2 case will be automatically taken care off
! by var_diff and we used "var_m1" in the second IF construct for "var_p1".
! this is the trick --> carry over variables from each step (or even you
! can merge all masked variables at a later stage to get the final one).
list var1, var2, var_p1
Please note that there are several examples on "Masking" in user manual and
on Ferret FAQ page (http://ferret.wrc.noaa.gov/Ferret/FAQ/ferret_FAQ.html).
Hope this helps,
Jaison
On Fri, 24 Nov 2006, golla nageswararao wrote:
> Hi all,
> Can anyone say me how to use if then elif end if in
> ferret. I saw the ferret users guide but i didnt
> understand it and i cannot apply it to my application.
> If possible send me any jnl file which contains if
> then elif endif statement so that i can understand. i
> want multiple options for if.
> Thanks in advance.
>
>
> From,
> G.Nageswara Rao,
> Research Scholar,
> INCOIS,
> Jeeidmetla,
> Hyderabad.
>
>
>
>
>
> __________________________________________________________
> Yahoo! India Answers: Share what you know. Learn something new
> http://in.answers.yahoo.com/
>
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement