[gradsusr] variables in .gs scripts

Arlindo da Silva dasilva at alum.mit.edu
Mon Nov 14 16:25:56 EST 2011


On Mon, Nov 14, 2011 at 3:40 PM, Yi-Chih Huang <dscpln at gmail.com> wrote:

> Hello,
>
>     I want to calculate variable 2 based on the value of some variable as
> follows.
>
> When var1 = 100, then  var2 =  (calculation 1)
> When var1 != 100, then  var2 = (calculation 2)
>
> I wrote a .gs script as follows.  But the condition rh=100 did not
> effect.  Could anyone reveal what would be the right command in .gs script
> to give the condition in which variables are in the .ctl file?
>
> "malr=dalr*(1+2500000*q/287/tk)/(1+0.622*pow(2500000,2)*q/1004/287/tk/tk)"
> "elr=-(tk(z+1)-tk(z-1))/(height(z+1)-height(z-1))"
>
> if (rh=100) then
>    "mai=elr-malr"
> else
>    "mai=0"
> endif
>

GrADS expression parser and the scripting language do not share the same
name space. Therefore you cannot have an if statement as above where you
reference a gridded variable.  If you are using opengrads, the if()
function could accomplish what you want:

'mai = if(rh,=,0,elr-malr,0)'

For more information on if() see:

if(EXPR1,OP,EXPR2,TRUE_EXPR,FALSE_EXPR)<http://opengrads.org/doc/udxt/libbjt/libbjt.html#if_expr1_op_expr2_true_expr_false_expr_>

In regular grads, a combination of
maskout<http://grads.iges.org/grads/gadoc/gradfuncmaskout.html>
()/const() <http://grads.iges.org/grads/gadoc/gradfuncconst.html> functions
can accomplish the same as the if() function above.

   Arlindo


-- 
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111114/29d55f52/attachment-0003.html 


More information about the gradsusr mailing list