[gradsusr] Lifted Index Formula

Charles Seman charles.seman at noaa.gov
Fri Mar 2 13:22:47 EST 2012


Mike,

I took a look at a local version of Bob Hart's plotskew.gs script, and 
found his "LiftWet" function:
**************************************************************************
function LiftWet(startt,startp,endp,display,Pmin,Pmax)

*--------------------------------------------------------------------
* Lift a parcel moist adiabatically from startp to endp.
* Init temp is startt in C.  If you wish to see the parcel's
* path plotted, display should be 1.  Returns temp of parcel at endp.
*--------------------------------------------------------------------

temp=startt
pres=startp
cont = 1
delp=10
While (pres >= endp & cont = 1)
     If (display = 1)
        xtemp=GetXLoc(temp,pres)
        "q w2xy "xtemp" "pres
        xloc=subwrd(result,3)
        yloc=subwrd(result,6)
        If (xtemp < 0 | xtemp > 100)
           cont=0
        Else
           If (pres >= Pmin & pres < Pmax & pres < startp)
              "draw line "xold" "yold" "xloc" "yloc
           Endif
        Endif
     Endif
     xold=xloc
     yold=yloc
     temp=temp-100*delp*gammaw(temp,pres-delp/2,100)
     pres=pres-delp
EndWhile
return(temp)


**************************************************************************

What we see in this function (and I believe in much of plotskew.gs) is 
the use of GrADS "script" variables, and not GrADS "defined" 
variables... In plotskew.gs, GrADS "defined" variables are used for 
variables which are plotted, like in this code:
------------------------------------------------------------
*-----------------------------
* Draw wind profile along side
*-----------------------------
...
    zz=1
    wspd=-999
    cont=1
    While (cont = 1 & zz < _zmax)
       "set z "zz
       pres=subwrd(result,4)
       "define dd="sndspd
       "d dd"
       rec=sublin(result,8)
       wspd=subwrd(rec,4)
       if (math_abs(wspd) > 500 | pres > _pmax)
           zz=zz+1
       else
           cont=0
       Endif
    Endwhile
------------------------------------------------------------

The above code is a nice example of how to use both GrADS "script" and 
"defined" variables (and how to make "defined" variables using "script" 
variables: "define dd="sndspd), and using script math functions...
http://grads.iges.org/grads/gadoc/mathfunctions.html

Could you recode your script to use "script" variables and not "defined" 
variables?  Looking at
'temp='startt
'pres='startp
'delp=10'
While (pres >= endp)
   'temp=temp-100*delp*'gammaw('temp','pres-delp/2',100)
   'pres=pres-delp'
EndWhile

one thing to note is the variable "pres" is a "defined" variable, but 
used as a "script" variable in the "While()" statement...

Hope this helps,
Chuck

On 03/02/2012 08:23 AM, Mike Manning wrote:
> Cool will keep this in mind as well - I had been making good progress
> with everything until I hit the function for LiftWet. On plotskew.gs
> (http://moe.met.fsu.edu/~rhart/software/plotskew.gs) everything there is
> taken for a single point on a chart - I guess because I'm trying to use
> an entire chart section, it's why I'm having dramas?
>
> I've got all other functions working perfectly.. here's one for example:
>
> function Templcl(temp,dewp)
>
> *------------------------------------------------------
> * Calculate the temp at the LCL given temp & dewp in C
> *------------------------------------------------------
>
> 'tempk='temp'+273.15'
> 'dewpk='dewp'+273.15'
> 'Parta=1/(dewpk-56)'
> 'Partb=log(tempk/dewpk)/800'
> 'Tlcl=(1/(Parta+Partb)+56)-273.15'
> return(Tlcl)
>
>
> This is the function I am having trouble with, it basically gets stuck
> in the loop and never exits :(
>
> function LiftWet(startt,startp,endp)
>
> *--------------------------------------------------------------------
> * Lift a parcel moist adiabatically from startp to endp.
> * Init temp is startt in C. If you wish to see the parcel's
> * path plotted, display should be 1. Returns temp of parcel at endp.
> *--------------------------------------------------------------------
>
> 'temp='startt
> 'pres='startp
> 'delp=10'
> While (pres >= endp)
> 'temp=temp-100*delp*'gammaw('temp','pres-delp/2',100)
> 'pres=pres-delp'
> EndWhile
> return(temp)
>
>
> I call it by 'define PclTemp='LiftWet('TLcl','PLcl',500) where TLcl and
> PLcl work perfectly when I plot those 2 variables by themselves so I
> know they are all good. I just have a funny feeling now that I have hit
> a brick wall that I cannot get around - which probably explains why no
> one else has created a Lifted Index chart. I do hope I am wrong though
>
> Cheers, Mike
>
>
> On 2/03/2012 11:24 AM, Arlindo da Silva wrote:
>>
>>
>> On Thu, Mar 1, 2012 at 11:25 AM, Jeff Duda <jeffduda319 at gmail.com
>> <mailto:jeffduda319 at gmail.com>> wrote:
>>
>>     You've confused the different uses of scripting functions vs.
>>     Grads prompt functions. You can only display a variable that you
>>     have defined using the 'define ...' command (note the use of the
>>     quotes signaling that it was defined as if you typed it in at the
>>     Grads prompt). Your use of variable = satvap(...) with satvap
>>     being a script function only is causing Grads to assume variable
>>     is a script variable only, not one that can be displayed. The
>>     reason you get the other error when you put the other line in
>>     quotes is because math_exp is strictly a script version of the exp
>>     function that you would use in the Grads command prompt. Thus, you
>>     would want to change that line to
>>
>>     'es = 6.112*exp(17.67*temp/(temp+243.5))'
>>
>>     in order to display es or define any other variables that would
>>     depend on it.
>>
>>
>>
>> This is generally true but if you are using opengrads you can make the
>> script function satvap() available to the display command, say
>>
>> ga-> d satvap(t1000)
>> by putting it in its own file "satvap.gsf" and loading the
>> corresponding UDXT as described in the gsUDF documentation
>> <http://opengrads.org/doc/udxt/gsudf/>. Actually, you could in
>> principle implemented the lifted index as a gsUDF function.
>>
>> Arlindo
>>
>>
>>     Jeff Duda
>>
>>
>>     On Thu, Mar 1, 2012 at 7:06 AM, Mike Manning <michael at bsch.au.com
>>     <mailto:michael at bsch.au.com>> wrote:
>>
>>         Hi everyone,
>>
>>         I'm using data from the FNMOC model and am trying to make a
>>         function
>>         that calculates Lifted Index. I'm using bits of the code from the
>>         plotskew.gs <http://plotskew.gs> code. So far I've got the
>>         temperature (celsius) and
>>         dewpoint (celsius) worked out for each level. Now I'm
>>         calculating the
>>         parcel details.. I've pulled some of the functions and have
>>         just been
>>         testing to make sure I'm on the right track. If I have this
>>         code for
>>         example:
>>
>>         'c'
>>         'reinit'
>>         'open gfs.00z.ctl'
>>         'set t 7'
>>         'set lon 135 155'
>>         'set lat -31 -10'
>>
>>         'set lev 1000'
>>         't1000mb = TMPprs-273.14'
>>         'define dp1000mb =
>>         t1000mb-((14.55+0.114*t1000mb)*(1-0.01*RHprs)+pow((2.5+0.007*t1000mb)*(1-0.01*RHprs),3)+(15.9+0.117*t1000mb)*pow((1-0.01*RHprs),14))'
>>
>>         variable = satvap2(t1000mb)
>>
>>         'd variable'
>>
>>         function satvap2(temp)
>>
>>         *---------------------------------------------------------------
>>         * Given temp in Celsius, returns saturation vapor pressure in mb
>>         *---------------------------------------------------------------
>>
>>         es=6.112*math_exp(17.67*temp/(temp+243.5))
>>
>>         return(es)
>>         'quit'
>>
>>
>>
>>         it complains about an error? If I put the code in the satvap2
>>         function
>>         in single quotes it then says "math_exp" is not a variable or
>>         function"?
>>         I'm a little lost on how to fix this one up if it's possible.
>>
>>         Cheers, Mike
>>         _______________________________________________
>>         gradsusr mailing list
>>         gradsusr at gradsusr.org <mailto:gradsusr at gradsusr.org>
>>         http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>>
>>
>>     --
>>     Jeff Duda
>>     Graduate research assistant
>>     University of Oklahoma School of Meteorology
>>     Center for Analysis and Prediction of Storms
>>
>>
>>     _______________________________________________
>>     gradsusr mailing list
>>     gradsusr at gradsusr.org <mailto:gradsusr at gradsusr.org>
>>     http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>>
>>
>> --
>> Arlindo da Silva
>> dasilva at alum.mit.edu <mailto: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

-- 

Please note that Charles.Seman at noaa.gov should be considered my NOAA
email address, not cjs at gfdl.noaa.gov.

********************************************************************
  Charles Seman                                Charles.Seman at noaa.gov
  U.S. Department of Commerce / NOAA / OAR
  Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
  201 Forrestal Road                              fax: (609) 987-5063
  Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not reflect any
official or unofficial position of the United States Federal Government,
the United States Department of Commerce, or NOAA."



More information about the gradsusr mailing list