Hello,<br><br>    After testing the script, I got the errors below.  If the second argument must be a constant, then a combination of const and maskout would not be as powerful as I thought.  My question remains: what would be the command in GrADS for the if statement?<br>
<br>################<br>Error from CONST:  2nd argument must be a constant<br>Operation Error:  Error from const function<br>Operation Error:  Error from const function<br>  Error ocurred at column 1<br>DEFINE error:  Invalid expression.<br>
<br>################<br>if (rh=100) then<br>   &quot;mai=elr-malr&quot;<br>
else<br>
   &quot;mai=0&quot;<br>endif<br><br>################<br><br>    Thanks much, <br><br>                            Yi-Chih<br><br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 2:59 PM, Yi-Chih Huang <span dir="ltr">&lt;<a href="mailto:dscpln@gmail.com">dscpln@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br><br>    Thanks much for the elucidation.  I think the command below has the same functions as the if statement.  It is good to learn the expression of the if statement in GrADS.  But if the calculations are very complicate and include several commands, probably a combination of const and maskout would not be able to handle such complicate situations.<br>

<br>################<br><font style="font-family:arial,helvetica,sans-serif" size="2"><code><span style="font-family:arial,helvetica,sans-serif">mai = const(const(maskout(rh,rh-100),elr-malr),0,-u) </span></code></font><br>

<br>################<div class="im"><br>if (rh=100) then<br>   &quot;mai=elr-malr&quot;<br>
else<br>
   &quot;mai=0&quot;<br>endif<br></div><div>################<br><br>    Thanks,<br><font color="#888888">
<br>
           Yi-Chih<br><br></font></div><div><div></div><div class="h5"><br><div class="gmail_quote">On Mon, Nov 14, 2011 at 10:49 PM, Yaqiang Wang <span dir="ltr">&lt;<a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
1. maskout the rh values less than 100 to missing: rh=maskout(rh,rh-100)<br>
2. get a new rh with the negtive values which are larger than 100<br>
before (100 is now 0): rh=100-rh<br>
3. maskout the negtive values: rh=maskout(rh,rh)<br>
4. get mai values: mai=elr-malr<br>
5. maskout mai: mai=maskout(mai,rh)<br>
6. const mai missing values to 0: mai=const(mai,0,-u)<br>
<div><div></div><div><br>
On Tue, Nov 15, 2011 at 10:58 AM, Yi-Chih Huang &lt;<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt;     I had read the documents about const and maskout online.  However,<br>
&gt; probably my understanding about const and maskout is so shallow that I can&#39;t<br>
&gt; use a combination of const and maskout to accomplish the function of the if<br>
&gt; statement.  Thus, I posed the question.<br>
&gt;<br>
&gt;     Thanks,<br>
&gt;<br>
&gt;                    Yi-Chih<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Nov 14, 2011 at 9:41 PM, Yaqiang Wang &lt;<a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; You can find the usage of const and maskout from online help document.<br>
&gt;&gt; <a href="http://www.iges.org/grads/gadoc/gradfuncconst.html" target="_blank">http://www.iges.org/grads/gadoc/gradfuncconst.html</a><br>
&gt;&gt; <a href="http://www.iges.org/grads/gadoc/gradfuncmaskout.html" target="_blank">http://www.iges.org/grads/gadoc/gradfuncmaskout.html</a><br>
&gt;&gt;<br>
&gt;&gt; On Tue, Nov 15, 2011 at 10:28 AM, Yi-Chih Huang &lt;<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Hello,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     I work on regular grads.  I have searched online for the examples to<br>
&gt;&gt; &gt; use<br>
&gt;&gt; &gt; const and maskout instead of if statement.  But I can&#39;t find any<br>
&gt;&gt; &gt; example.<br>
&gt;&gt; &gt; Could anyone show me an example to use const and maskout instead of if<br>
&gt;&gt; &gt; statement?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     Thanks much for your help,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;                    Yi-Chih<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Mon, Nov 14, 2011 at 4:25 PM, Arlindo da Silva &lt;<a href="mailto:dasilva@alum.mit.edu" target="_blank">dasilva@alum.mit.edu</a>&gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Mon, Nov 14, 2011 at 3:40 PM, Yi-Chih Huang &lt;<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Hello,<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;     I want to calculate variable 2 based on the value of some variable<br>
&gt;&gt; &gt;&gt;&gt; as<br>
&gt;&gt; &gt;&gt;&gt; follows.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; When var1 = 100, then  var2 =  (calculation 1)<br>
&gt;&gt; &gt;&gt;&gt; When var1 != 100, then  var2 = (calculation 2)<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I wrote a .gs script as follows.  But the condition rh=100 did not<br>
&gt;&gt; &gt;&gt;&gt; effect.  Could anyone reveal what would be the right command in .gs<br>
&gt;&gt; &gt;&gt;&gt; script<br>
&gt;&gt; &gt;&gt;&gt; to give the condition in which variables are in the .ctl file?<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; &quot;malr=dalr*(1+2500000*q/287/tk)/(1+0.622*pow(2500000,2)*q/1004/287/tk/tk)&quot;<br>
&gt;&gt; &gt;&gt;&gt; &quot;elr=-(tk(z+1)-tk(z-1))/(height(z+1)-height(z-1))&quot;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; if (rh=100) then<br>
&gt;&gt; &gt;&gt;&gt;    &quot;mai=elr-malr&quot;<br>
&gt;&gt; &gt;&gt;&gt; else<br>
&gt;&gt; &gt;&gt;&gt;    &quot;mai=0&quot;<br>
&gt;&gt; &gt;&gt;&gt; endif<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; GrADS expression parser and the scripting language do not share the<br>
&gt;&gt; &gt;&gt; same<br>
&gt;&gt; &gt;&gt; name space. Therefore you cannot have an if statement as above where<br>
&gt;&gt; &gt;&gt; you<br>
&gt;&gt; &gt;&gt; reference a gridded variable.  If you are using opengrads, the if()<br>
&gt;&gt; &gt;&gt; function<br>
&gt;&gt; &gt;&gt; could accomplish what you want:<br>
&gt;&gt; &gt;&gt; &#39;mai = if(rh,=,0,elr-malr,0)&#39;<br>
&gt;&gt; &gt;&gt; For more information on if() see:<br>
&gt;&gt; &gt;&gt; if(EXPR1,OP,EXPR2,TRUE_EXPR,FALSE_EXPR)<br>
&gt;&gt; &gt;&gt; In regular grads, a combination of maskout()/const() functions can<br>
&gt;&gt; &gt;&gt; accomplish the same as the if() function above.<br>
&gt;&gt; &gt;&gt;    Arlindo<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; Arlindo da Silva<br>
&gt;&gt; &gt;&gt; <a href="mailto:dasilva@alum.mit.edu" target="_blank">dasilva@alum.mit.edu</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; gradsusr mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; gradsusr mailing list<br>
&gt;&gt; &gt; <a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
&gt;&gt; &gt; <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; *************************************************<br>
&gt;&gt; Dr. Yaqiang Wang<br>
&gt;&gt; Chinese Academy of Meteorological Sciences (CAMS)<br>
&gt;&gt; 46, Zhong-Guan-Cun South Avenue<br>
&gt;&gt; Beijing, 100081<br>
&gt;&gt; China<br>
&gt;&gt;<br>
&gt;&gt; <a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a><br>
&gt;&gt;<br>
&gt;&gt; <a href="http://www.meteothinker.com" target="_blank">http://www.meteothinker.com</a><br>
&gt;&gt; **************************************************<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; gradsusr mailing list<br>
&gt;&gt; <a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
&gt;&gt; <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; gradsusr mailing list<br>
&gt; <a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
&gt; <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
--<br>
*************************************************<br>
Dr. Yaqiang Wang<br>
Chinese Academy of Meteorological Sciences (CAMS)<br>
46, Zhong-Guan-Cun South Avenue<br>
Beijing, 100081<br>
China<br>
<br>
<a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a><br>
<br>
<a href="http://www.meteothinker.com" target="_blank">http://www.meteothinker.com</a><br>
**************************************************<br>
<br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org" target="_blank">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></blockquote></div><br>
</div></div></blockquote></div><br>