[Thread Prev][Thread Next][Index]

Re: [ferret_users] IF syntax



Title: IF syntax

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement
Hi Mark,
There are a couple of ways to do this. You could use string functions on the value of the symbol; the function STRCMP returns 0 if the strings match.

   yes? LET year = 2000
   yes? DEF SYM seas = djf

   yes? IF `STRCMP("($seas)", "djf") EQ 0 AND year EQ 2000` THEN SAY 2000_djf
    !-> IF 1 THEN SAY 2000_djf
   2000_djf

There's also the option of symbol editing, which is a compact but powerful way to deal with possible multiple options for the value of a symbol.  Some examples:

IF `($seas%0%)` means if seas is undefined then substitute the value 0.

IF `($seas%0|djf>1%)` means if seas is undefined then substitute 0; if seas is djf then substitute 1

IF `($seas%0|djf>1|*>0%)` means if seas is undefined then substitute 0; if seas is djf then substitute 1; if seas is anything else then substitute 0.

IF `($seas%0|djf>1|abc>2|*>0%)`
puts in yet another option for the symbol being abc, in which case substitute 2.  And so on.

For our example:

   yes? IF `($seas%0|djf>1|*>0%) AND year GE 2000` THEN SAY this works too
    !-> IF 1 THEN SAY this works too
   this works too



Mark Williams wrote:

Ferret Users

I don’t know what the correct syntax is for IF …  AND …. THEN logic when using symbols.

It is easy enough when using variables, for example:

Let a = 1

Let b = 1

IF `a EQ 1 AND b EQ 1` THEN SAY both a and b are 1

Works just fine.

But what if I want to use a symbol for one of both of the conditions, for example:

Let yr = 2000

Define symbol seas = djf

Then I want to test if the yr is LT 2000 AND the seas is  DJF.

Another example is if both conditions are symbols, for example:

Define symbol dset = olr1

Define symbol seas = djf

Then I want to test if both the dset is olr1 AND the seas is djf?

What is the correct syntax?

Thanks in advance

Another question for the developers.  I am using ferret in a windows environment and am using the latest version available which is 5.53 for Windows 2000 (5.51 for Windows XP).  This works just fine, but it would be nice to have the latest version available for this platform to take advantage of some of the latest features.



Mark Williams

Regional Director, Victoria

Phone 03 9669 4968

Fax 03 9642 8280


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement