[gradsusr] If Statements for Gridded Model Data Open GrADS
Stephen McMillan
smcmillan at planalytics.com
Wed Jun 22 12:38:36 EDT 2016
Matt,
The "if" construct you are using will not work on a gridded field, and it
appears that's what you are trying to do. The extension "if" function was
designed to work on such fields.
Here's a partial example using the first set of conditions you provided:
'define
NAMHail=if(NAMcape,>,1500,if(NAMcape,<,2200,NAMHail+1,NAMHail),NAMHail)'
That's, of course, assuming you have defined a field called "NAMHail" as
zero prior to executing the "if" function. Alternatively, you could have 0
or -u (for undefined) as your false expression, without first defining
NAMHail. After that, you could execute the "if" again by adding an
additional set of conditions, until you have applied all conditions.
Another option is to nest several conditions, but it gets a little
complicated that way.
Stephen McMillan
On Wed, Jun 22, 2016 at 12:11 PM, Baker, Matt (Quebec - Atlantic) <
matt.baker at amecfw.com> wrote:
> Thanks Bernd and Stephen,
>
>
>
> Essentially if the CAPE, LI, and 500 mb relative humidity are within a
> certain range, I want to add to NAMHail variable (NAMHail = NAMHail + 1)
> and then display the variable with contour lines.
>
>
>
> Stephen, in my code there are already if statements for this. Is there
> something wrong with my syntax and could that be the reason GrADS isn’t
> executing in the if statement?
>
>
>
> As an example, is this statement written correctly?
>
> if (NAMcape > 1500 & NAMcape < 2200)
>
> 'NAMHail = NAMHail + 1'
>
> endif
>
> Again, NAMHail is defined by: ‘NAMHail = 0’ before the if the statements.
>
>
>
> Thanks for the help!
>
>
>
> Matt
>
>
>
> *From:* gradsusr-bounces at gradsusr.org [mailto:
> gradsusr-bounces at gradsusr.org] *On Behalf Of *Stephen McMillan
> *Sent:* June-22-16 12:39 PM
> *To:* GrADS Users Forum <gradsusr at gradsusr.org>
> *Subject:* Re: [gradsusr] If Statements for Gridded Model Data Open GrADS
>
>
>
> Hi Matt,
>
>
>
> In addition to Bernd's suggestion, also check out the "if" function, which
> should have come with your opengrads package as part of the following
> extension function set:
>
>
>
> http://opengrads.org/doc/udxt/libbjt/
>
>
>
> The "if" function syntax:
> *if*(*EXPR1,OP,EXPR2,TRUE_EXPR,FALSE_EXPR*)
>
> This function compares *EXPR1* and *EXPR2*, where 5 arguments are
> expected. if their relation is true, *TRUE_EXP* is returned, otherwise
> expression *FALSE_EXPR* is returned.
>
> *OP*
>
> One of the following: ==, =, >, <, >=, <=, !=
>
> *EXPR2, TRUE_EXPR, FALSE_EXPR*
>
> These can be a expression, constant or -u.
>
>
>
> I have found this function to be very useful and much easier to handle
> than using maskout and const, although there are probably cases where the
> latter is more appropriate or advisable.
>
> Stephen McMillan
>
>
>
> On Wed, Jun 22, 2016 at 9:24 AM, Baker, Matt (Quebec - Atlantic) <
> matt.baker at amecfw.com> wrote:
>
> Hi all,
>
>
>
> I have a question regarding Open GrADS.
>
>
>
> I’m trying to use *if statements* for scalar model data (eg. GFS and NAM)
> over a grid and I’m wondering if it’s possible to do this. As an example,
> I’m using if statements for these parameters: surface based CAPE, LI, and
> 500 mb relative humidity to create an index to plot on a map. So far GrADS
> isn’t showing that this is working, however, I can plot the model data
> individually so I don’t think it’s a case of missing data.
>
>
>
> Here’s some of the code for the NAM model. Note that I define the variable
> NAMHail to equal 0 at the start of the function.
>
>
>
> if (modelNumberNAM>0)
>
> set_maps(_map,_hasNegativeNAM)
>
> 'set grads off'
>
> 'set grid off'
>
> 'set gxout contour'
>
> 'set ccolor 0'
>
> 'set clopts -1 1 0.15'
>
> 'set cint 1'
>
> 'set cthick 6'
>
> 'set clab on'
>
> 'set csmooth on'
>
>
>
> 'NAMcape = CAPEsfc.'modelNumberNAM
>
> if (NAMcape > 1500 & NAMcape < 2200)
>
> 'NAMHail = NAMHail + 1'
>
> endif
>
> if (NAMcape > 2199 & NAMcape < 3100)
>
> 'NAMHail = NAMHail + 2'
>
> endif
>
> if (NAMcape > 3099)
>
> 'NAMHail = NAMHail + 3'
>
> endif
>
>
>
> 'set lev 500'
>
> 'NAMrh500=RHprs.'modelNumberNAM
>
> if (NAMrh500 < 35)
>
> 'NAMHail = NAMHail + 3'
>
> endif
>
> if (NAMrh500 > 35 & NAMrh500 < 44)
>
> 'NAMHail = NAMHail + 1'
>
> endif
>
>
>
> endif
>
>
>
> 'set gxout contour'
>
> 'set ccolor 0'
>
> 'set clopts -1 1 0.15'
>
> 'set cint 200'
>
> 'set cthick 6'
>
> 'set clab on'
>
> 'set csmooth on'
>
>
>
> 'd NAMcape'
>
>
>
> Thanks!
>
>
>
> *Matt Baker*
>
> Meteorologist, Met-Ocean Services, Amec Foster Wheeler Environment &
> Infrastructure
>
> 133 Crosbie Road, PO Box 13216, St. John’s, NL A1B 4A5, Canada
>
> matt.baker at amecfw.com** amecfw.com
>
> ISO 9001:2008 Quality Management System (St. John's)
>
>
>
> [image: cid:image001.jpg at 01D1CC84.8BC9E9B0]
>
>
> This message is the property of Amec Foster Wheeler plc and/or its
> subsidiaries and/or affiliates and is intended only for the named
> recipient(s). Its contents (including any attachments) may be confidential,
> legally privileged or otherwise protected from disclosure by law.
> Unauthorised use, copying, distribution or disclosure of any of it may be
> unlawful and is strictly prohibited. We assume no responsibility to persons
> other than the intended named recipient(s) and do not accept liability for
> any errors or omissions which are a result of email transmission. If you
> have received this message in error, please notify us immediately by reply
> email to the sender and confirm that the original message and any
> attachments and copies have been destroyed and deleted from your system.
> This disclaimer applies to any and all messages originating from us and set
> out above. If you do not wish to receive future unsolicited commercial
> electronic messages from us, *please forward this email to:
> unsubscribe at amecfw.com <unsubscribe at amecfw.com> and include “Unsubscribe”
> in the subject line*. If applicable, you will continue to receive
> invoices, project communications and similar factual, non-commercial
> electronic communications.
>
> Please click http://amecfw.com/email-disclaimer for notices and company
> information in relation to emails originating in the UK, Italy or France.
>
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20160622/b6cc3a56/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 5711 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20160622/b6cc3a56/attachment-0001.jpg
More information about the gradsusr
mailing list