[gradsusr] If else in GRADS

Arlindo da Silva dasilva at alum.mit.edu
Tue May 1 20:14:55 EDT 2012


On Tue, May 1, 2012 at 10:17 AM, Mubashar Dogar <mubashardogar at gmail.com>wrote:

> Dear GrADS users,
>
> Could you please help me to fix the following problem. I have a file
> with one variable named NAO having different value for each year
> (1980-2002). I have two other constant gridded fields A and B. My NAO
> variable can have positive or negative values varying in between -3
> and 3. I want to calculate a formula in such a way that I need its
> values only when NAO absolute values are greater than 1. For other
> values of NAO, I want that formula to have missing (NAN) values.
>
> I am trying in the following way but it is not taking abs(NAO) instead
> it is taking all the NAO values.
>
>
> **********************************
> Note: My A and B are constant gridded fields.
> NAO is a varying means different value for each year and it is not gridded.
> ***********************************
> Following is my script lines:
>
> 'set time jan1979 jan2001'
> if ('abs(nao)' >= 1)
>

You cannot do this: mix scripting language and grads expression parser
namespace.


> 'define DT=B*nao+A'
> else
> 'define DT=-999'
> endif
> 'd DT'
>
>
If you are using opengrads, the if() can be useful here:

'd if(abs(nao),<,1,-u,b*nao+a)'

You can also use the
maskout()<http://grads.iges.org/grads/gadoc/gradfuncmaskout.html>
function
as Yan Libin suggests.

   Arlindo

-- 
Arlindo da Silva
*dasilva at alum.mit.edu*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20120501/521604cf/attachment-0003.html 


More information about the gradsusr mailing list