On Mon, Nov 14, 2011 at 3:40 PM, Yi-Chih Huang <span dir="ltr"><<a href="mailto:dscpln@gmail.com">dscpln@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br><div><div><br> I want to calculate variable 2 based on the value of some variable as follows. <br><div><br>When var1 = 100, then var2 = (calculation 1)<br>When var1 != 100, then var2 = (calculation 2)<br>
<br></div>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? <br><br></div>"malr=dalr*(1+2500000*q/287/tk)/(1+0.622*pow(2500000,2)*q/1004/287/tk/tk)"<div><div><div>"elr=-(tk(z+1)-tk(z-1))/(height(z+1)-height(z-1))"<br>
<br>if (rh=100) then<br> "mai=elr-malr"<br>
else<br>
"mai=0"<br>endif<br></div></div></div></div></blockquote><div><br></div><div>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:</div>
<div><br></div><div>'mai = if(rh,=,0,elr-malr,0)'</div><div><br></div><div>For more information on if() see:</div><div><br></div><div><a href="http://opengrads.org/doc/udxt/libbjt/libbjt.html#if_expr1_op_expr2_true_expr_false_expr_">if(EXPR1,OP,EXPR2,TRUE_EXPR,FALSE_EXPR)</a></div>
<div><br></div><div>In regular grads, a combination of <a href="http://grads.iges.org/grads/gadoc/gradfuncmaskout.html">maskout</a>()/<a href="http://grads.iges.org/grads/gadoc/gradfuncconst.html">const()</a> functions can accomplish the same as the if() function above.</div>
<div><br></div><div> Arlindo</div><div> </div></div><div><br></div>-- <br>Arlindo da Silva<br><a href="mailto:dasilva@alum.mit.edu">dasilva@alum.mit.edu</a><br>