<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><DIV>Jim,</DIV>
<DIV> </DIV>
<DIV>It works!! Thanks.!!</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Is it the IF command can only compare real numbers but when we use the command "define", the values stored are string so my previous script did not work<BR>And we are changing from string to real numbers when we use the command "subwrd" ? </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial, helvetica, sans-serif">Henry</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial, helvetica, sans-serif"><BR>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> James T. Potemra <jimp@hawaii.edu><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> GrADS Users Forum <gradsusr@gradsusr.org><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Wed, January 26, 2011 9:23:31 AM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [gradsusr] About using the IF command in GrADS<BR></FONT><BR>Henry:<BR><BR>I don't think you can do a numeric comparison with "if" in this way. <BR>Instead, try display the value, then write the result to a variable, e.g.,<BR><BR>'define check1 = ave ( spres, lon='lon1',lon='lon2')'<BR>'d check1'<BR>check2 = subwrd(result,4)<BR>if ( check2 > levmax )<BR>...<BR><BR>Jim<BR><BR>Hang wrote:<BR>> <BR>> Hi,<BR>> <BR>> I face problems when using the IF command in the script. I use the IF <BR>> command to check for some conditions but there is something wrong. I <BR>> think it may be
due to the difference in the data type of the defined <BR>> variables.<BR>> The following is the part of my script that I used and encountered the <BR>> problem.<BR>> <BR>> time=1<BR>> lat1=22.5<BR>> lat2=25<BR>> lon1=112.5<BR>> lon2=115<BR>> 'define levmax=1000'<BR>> 'set lat 'lat1<BR>> 'set lev '1000<BR>> 'set t 'time<BR>> 'define check1=ave(spres,lon='lon1',lon='lon2')'<BR>> if (check1 > levmax)<BR>> 'define levmax=925'<BR>> say '1000'<BR>> endif<BR>> <BR>> <BR>> <BR>> The value of "check1" is about 990 and so it is smaller than 1000 as <BR>> defined in levmax. So the condition should be false, however the <BR>> programme did execute the commands under
the condition "(check1 > levmax)"<BR>> <BR>> Do you know what is the reason for this? What should I do to correct <BR>> this? Are there other similar situations that I need to becare of when <BR>> I use defined variables and IF / WHILE commands?<BR>> <BR>> Thanks a lot for your help!!!<BR>> <BR>> Best,<BR>> <BR>> Henry<BR>><BR>><BR>> ------------------------------------------------------------------------<BR>><BR>> _______________________________________________<BR>> gradsusr mailing list<BR>> <A href="mailto:gradsusr@gradsusr.org" ymailto="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</A><BR>> <A href="http://gradsusr.org/mailman/listinfo/gradsusr" target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR>> <BR>_______________________________________________<BR>gradsusr mailing list<BR><A href="mailto:gradsusr@gradsusr.org"
ymailto="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</A><BR><A href="http://gradsusr.org/mailman/listinfo/gradsusr" target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR></DIV></DIV></div><br></body></html>