[gradsusr] variables in .gs scripts

Yi-Chih Huang dscpln at gmail.com
Tue Nov 15 14:59:31 EST 2011


Hello,

    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.

################
mai = const(const(maskout(rh,rh-100),elr-malr),0,-u)

################
if (rh=100) then
   "mai=elr-malr"
else
   "mai=0"
endif
################

    Thanks,

           Yi-Chih


On Mon, Nov 14, 2011 at 10:49 PM, Yaqiang Wang <yaqiang.wang at gmail.com>wrote:

> 1. maskout the rh values less than 100 to missing: rh=maskout(rh,rh-100)
> 2. get a new rh with the negtive values which are larger than 100
> before (100 is now 0): rh=100-rh
> 3. maskout the negtive values: rh=maskout(rh,rh)
> 4. get mai values: mai=elr-malr
> 5. maskout mai: mai=maskout(mai,rh)
> 6. const mai missing values to 0: mai=const(mai,0,-u)
>
> On Tue, Nov 15, 2011 at 10:58 AM, Yi-Chih Huang <dscpln at gmail.com> wrote:
> > Hello,
> >
> >     I had read the documents about const and maskout online.  However,
> > probably my understanding about const and maskout is so shallow that I
> can't
> > use a combination of const and maskout to accomplish the function of the
> if
> > statement.  Thus, I posed the question.
> >
> >     Thanks,
> >
> >                    Yi-Chih
> >
> >
> > On Mon, Nov 14, 2011 at 9:41 PM, Yaqiang Wang <yaqiang.wang at gmail.com>
> > wrote:
> >>
> >> You can find the usage of const and maskout from online help document.
> >> http://www.iges.org/grads/gadoc/gradfuncconst.html
> >> http://www.iges.org/grads/gadoc/gradfuncmaskout.html
> >>
> >> On Tue, Nov 15, 2011 at 10:28 AM, Yi-Chih Huang <dscpln at gmail.com>
> wrote:
> >> > Hello,
> >> >
> >> >     I work on regular grads.  I have searched online for the examples
> to
> >> > use
> >> > const and maskout instead of if statement.  But I can't find any
> >> > example.
> >> > Could anyone show me an example to use const and maskout instead of if
> >> > statement?
> >> >
> >> >     Thanks much for your help,
> >> >
> >> >                    Yi-Chih
> >> >
> >> >
> >> > On Mon, Nov 14, 2011 at 4:25 PM, Arlindo da Silva <
> dasilva at alum.mit.edu>
> >> > wrote:
> >> >>
> >> >> 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)
> >> >> In regular grads, a combination of maskout()/const() functions can
> >> >> accomplish the same as the if() function above.
> >> >>    Arlindo
> >> >>
> >> >> --
> >> >> Arlindo da Silva
> >> >> dasilva at alum.mit.edu
> >> >>
> >> >> _______________________________________________
> >> >> gradsusr mailing list
> >> >> gradsusr at gradsusr.org
> >> >> http://gradsusr.org/mailman/listinfo/gradsusr
> >> >>
> >> >
> >> >
> >> > _______________________________________________
> >> > gradsusr mailing list
> >> > gradsusr at gradsusr.org
> >> > http://gradsusr.org/mailman/listinfo/gradsusr
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> *************************************************
> >> Dr. Yaqiang Wang
> >> Chinese Academy of Meteorological Sciences (CAMS)
> >> 46, Zhong-Guan-Cun South Avenue
> >> Beijing, 100081
> >> China
> >>
> >> yaqiang.wang at gmail.com
> >>
> >> http://www.meteothinker.com
> >> **************************************************
> >>
> >> _______________________________________________
> >> gradsusr mailing list
> >> gradsusr at gradsusr.org
> >> http://gradsusr.org/mailman/listinfo/gradsusr
> >
> >
> > _______________________________________________
> > gradsusr mailing list
> > gradsusr at gradsusr.org
> > http://gradsusr.org/mailman/listinfo/gradsusr
> >
> >
>
>
>
> --
> *************************************************
> Dr. Yaqiang Wang
> Chinese Academy of Meteorological Sciences (CAMS)
> 46, Zhong-Guan-Cun South Avenue
> Beijing, 100081
> China
>
> yaqiang.wang at gmail.com
>
> http://www.meteothinker.com
> **************************************************
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111115/b296aba1/attachment-0003.html 


More information about the gradsusr mailing list