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> "mai=elr-malr"<br>
else<br>
"mai=0"<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"><<a href="mailto:dscpln@gmail.com">dscpln@gmail.com</a>></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> "mai=elr-malr"<br>
else<br>
"mai=0"<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"><<a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a>></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 <<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I had read the documents about const and maskout online. However,<br>
> probably my understanding about const and maskout is so shallow that I can't<br>
> use a combination of const and maskout to accomplish the function of the if<br>
> statement. Thus, I posed the question.<br>
><br>
> Thanks,<br>
><br>
> Yi-Chih<br>
><br>
><br>
> On Mon, Nov 14, 2011 at 9:41 PM, Yaqiang Wang <<a href="mailto:yaqiang.wang@gmail.com" target="_blank">yaqiang.wang@gmail.com</a>><br>
> wrote:<br>
>><br>
>> You can find the usage of const and maskout from online help document.<br>
>> <a href="http://www.iges.org/grads/gadoc/gradfuncconst.html" target="_blank">http://www.iges.org/grads/gadoc/gradfuncconst.html</a><br>
>> <a href="http://www.iges.org/grads/gadoc/gradfuncmaskout.html" target="_blank">http://www.iges.org/grads/gadoc/gradfuncmaskout.html</a><br>
>><br>
>> On Tue, Nov 15, 2011 at 10:28 AM, Yi-Chih Huang <<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>> wrote:<br>
>> > Hello,<br>
>> ><br>
>> > I work on regular grads. I have searched online for the examples to<br>
>> > use<br>
>> > const and maskout instead of if statement. But I can't find any<br>
>> > example.<br>
>> > Could anyone show me an example to use const and maskout instead of if<br>
>> > statement?<br>
>> ><br>
>> > Thanks much for your help,<br>
>> ><br>
>> > Yi-Chih<br>
>> ><br>
>> ><br>
>> > On Mon, Nov 14, 2011 at 4:25 PM, Arlindo da Silva <<a href="mailto:dasilva@alum.mit.edu" target="_blank">dasilva@alum.mit.edu</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Mon, Nov 14, 2011 at 3:40 PM, Yi-Chih Huang <<a href="mailto:dscpln@gmail.com" target="_blank">dscpln@gmail.com</a>><br>
>> >> wrote:<br>
>> >>><br>
>> >>> Hello,<br>
>> >>><br>
>> >>> I want to calculate variable 2 based on the value of some variable<br>
>> >>> as<br>
>> >>> follows.<br>
>> >>><br>
>> >>> When var1 = 100, then var2 = (calculation 1)<br>
>> >>> When var1 != 100, then var2 = (calculation 2)<br>
>> >>><br>
>> >>> I wrote a .gs script as follows. But the condition rh=100 did not<br>
>> >>> effect. Could anyone reveal what would be the right command in .gs<br>
>> >>> script<br>
>> >>> to give the condition in which variables are in the .ctl file?<br>
>> >>><br>
>> >>><br>
>> >>><br>
>> >>> "malr=dalr*(1+2500000*q/287/tk)/(1+0.622*pow(2500000,2)*q/1004/287/tk/tk)"<br>
>> >>> "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>
>> >><br>
>> >> GrADS expression parser and the scripting language do not share the<br>
>> >> same<br>
>> >> name space. Therefore you cannot have an if statement as above where<br>
>> >> you<br>
>> >> reference a gridded variable. If you are using opengrads, the if()<br>
>> >> function<br>
>> >> could accomplish what you want:<br>
>> >> 'mai = if(rh,=,0,elr-malr,0)'<br>
>> >> For more information on if() see:<br>
>> >> if(EXPR1,OP,EXPR2,TRUE_EXPR,FALSE_EXPR)<br>
>> >> In regular grads, a combination of maskout()/const() functions can<br>
>> >> accomplish the same as the if() function above.<br>
>> >> Arlindo<br>
>> >><br>
>> >> --<br>
>> >> Arlindo da Silva<br>
>> >> <a href="mailto:dasilva@alum.mit.edu" target="_blank">dasilva@alum.mit.edu</a><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>
>> >><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>
>> ><br>
>> ><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>
><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>
><br>
><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>