[gradsusr] About using the IF command in GrADS

James T. Potemra jimp at hawaii.edu
Tue Jan 25 20:23:31 EST 2011


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
>   



More information about the gradsusr mailing list