[Thread Prev][Thread Next][Index]

Re: [ferret_users] string comparison

Thank you Ansley  & Neethu,
                                             A standard function like
strcmp  was the one I was looking for though other way around works.

On Tue, Jul 28, 2009 at 10:40 PM, Ansley Manke<Ansley.B.Manke@xxxxxxxx> wrote:
> Hello,
> Yes, you can do all of this.
> Use the STRCMP function to compare the strings. (try "SHOW FUNCTION *STR*
> to see a list of most of the functions that operate on strings).  There are
> a couple of things you can do to take care of the case where there are no
> units. One is to just add a known string when defining the symbol unt, and
> take that into account when making the comparison. So your example could go
> something like this:
> use monthly_navy_winds
> ! This will create a symbol with value UWIND_UNITS if there are no units.
> def sym unt=`uwnd,r=unit`UWIND_UNITS
> if `STRCMP("($unt)", "cmUWIND_UNITS")) EQ 0` then
>   let nwnd=uwnd/100
> else
>   let nwnd=uwnd
> end if
> Another option would be to use the attribute handling syntax in Ferret to
> first check whether the variable has a units attribute.  Here I also show
> how to convert the units to uppercase before making the comparison.  If the
> input file has units listed as "CM" or "cm" you would still want to treat
> them the same way"
> use monthly_navy_winds
> let uatts = uwnd.attnames   ! a list of all the attribute names
> list uatts
> ! if one of the attributes is units, then use its upper-cased value
> if `IS_ELEMENT_OF_STR(uatts, "units")` then
>   define symbol uin = `uwnd,return=units`
>   define symbol unt = `UPCASE("($uin)")`
> else
>   define symbol unt = none
> endif
> if `STRCMP("($unt)", "CM") EQ 0` then
>    let nwnd=uwnd/100
> else
>    let nwnd=uwnd
> end if
> Sudheer Joseph wrote:
> Dear Users,
>                              Is there any way in ferret to do string
> comparison,
> ie, I want to use the unit information in netcdf variable and do
> action based on that.
> Also if there is no unit for the variable the code should not break
> instead continue echoing that there was no unit.
> it could  be some thing like below
> use monthly_navy_winds
> def sym unt=`uwnd,r=ubnit`
> if (($unt) eq "cm") then
> nwnd=uwnd/100
> else
> nwnd=uwnd
> end if
> though the above code is written it will break if a data file do not
> have unit information

with best regards


Sudheer Joseph
Indian National Centre for Ocean Information Services (INCOIS)
Ocean Valley, Post Box No# 21,
IDA Jeedimetla P.O.
Hyderabad, Ranga Reddy District - 500 055
Andhra Pradesh, India.
E-mail:sjo@xxxxxxxxxxxxxx; sudheer.joseph@xxxxxxxxx;  sjo@xxxxxxxxxxxxxx
Web- http://oppamthadathil.tripod.com
           --------------* ---------------
"The ultimate measure of a man is
not where he stands in moments of
comfort and convenience, but where
he stands at times of challenge and
                        Martin Luther King, Jr.

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement