[Thread Prev][Thread Next][Index]
Re: [ferret_users] string comparison
- To: Ansley Manke <Ansley.B.Manke@xxxxxxxx>
- Subject: Re: [ferret_users] string comparison
- From: Sudheer Joseph <sjo.india@xxxxxxxxx>
- Date: Wed, 29 Jul 2009 05:53:48 +0530
- Cc: oar.pmel.ferret_users@xxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=0MTSoHES0OGzg6tOexq68KfVXpTdY8OLJg8yz13+ETY=; b=I8p2mC+P6iFZC1fBKRUFTq7lgrFkQ8YuhQ84wU8789MYHTxS1m40fwBXrhy1kU9cur gd+ANjoeVC3wjKd5YRS7NuyE4R98k5YWVfZxy9v2Ia2339SKZ4jkrTp0bgRn7JtGV3hG LvFIKqvruxL6oy2SZ0vgcqOsUTocdRqY+wPvM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=T/WMFQDtbW3eSxTB2OmEBtu8FF4+mnhzFpkpsgmiWJMTh1E7VfP+5DuEpidHQkdQbF Z7Vjfny0DWdwDvPez2UEFJO4YHwQV82QcTAIGKqFlxgFWi/K7OgddDc3YkseT809NP/X bzJcnhZmvUDym5wG66DTwyzgfWlw2zJE34KEk=
- In-reply-to: <4A6F311E.2060309@xxxxxxxx>
- References: <a903a9720907280236xf470d39l10dc8109673adc99@xxxxxxxxxxxxxx> <4A6F311E.2060309@xxxxxxxx>
- Sender: owner-ferret_users@xxxxxxxx
Thank you Ansley & Neethu,
A standard function like
strcmp was the one I was looking for though other way around works.
rgds
sjo
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
**********************************************************************************
Sudheer Joseph
Scientist
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.
TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile)
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O)
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
controversy."
Martin Luther King, Jr.
[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Privacy Policy | Disclaimer | Accessibility Statement