[gradsusr] About using the IF command in GrADS

Hang hang_hang2004 at yahoo.com.hk
Wed Jan 26 01:39:33 EST 2011


Jim,

It works!! Thanks.!!


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
And we are changing from string to real numbers when we use the command 
"subwrd" ? 



Henry



________________________________
From: James T. Potemra <jimp at hawaii.edu>
To: GrADS Users Forum <gradsusr at gradsusr.org>
Sent: Wed, January 26, 2011 9:23:31 AM
Subject: Re: [gradsusr] About using the IF command in GrADS

Henry:

I don't think you can do a numeric comparison with "if" in this way.  
Instead, try display the value, then write the result to a variable, e.g.,

'define check1 = ave ( spres, lon='lon1',lon='lon2')'
'd check1'
check2 = subwrd(result,4)
if ( check2 > levmax )
...

Jim

Hang wrote:
>  
> Hi,
>  
> I face problems when using the IF command in the script. I use the IF 
> command to check for some conditions but there is something wrong. I 
> think it may be due to the difference in the data type of the defined 
> variables.
> The following is the part of my script that I used and encountered the 
> problem.
>  
>    time=1
>    lat1=22.5
>    lat2=25
>    lon1=112.5
>    lon2=115
>    'define levmax=1000'
>    'set lat 'lat1
>    'set lev '1000
>    'set t 'time
>    'define check1=ave(spres,lon='lon1',lon='lon2')'
>    if (check1 > levmax)
>      'define levmax=925'
>      say '1000'
>    endif
>  
>  
>  
> The value of  "check1" is about 990 and so it is smaller than 1000 as 
> defined in levmax. So the condition should be false, however the 
> programme did execute the commands under the condition "(check1 > levmax)"
>  
> Do you know what is the reason for this? What should I do to correct 
> this? Are there other similar situations that I need to becare of when 
> I use defined variables and IF / WHILE commands?
>  
> Thanks a lot for your help!!!
>  
> Best,
>  
> Henry
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>  
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org
http://gradsusr.org/mailman/listinfo/gradsusr


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20110126/83e70ba1/attachment-0003.html 


More information about the gradsusr mailing list