q defval/set defval

Sestak, Dr. Michael michael.sestak at FNMOC.NAVY.MIL
Mon Oct 24 18:10:25 EDT 2005


If all the computations use only the same grid cell from several grids at a
time, as in a(1,1), b(1,1), c(1,1), not a(1,1), b(2,1), c(2,2), then you can
simply use define to make calculations for whole grids at a time, no q
defval/set defval needed.  For example, if a, b, and c are grids and d, and
e are constants you can calculate d*sin(a) + e*b + c in a single statement

define z = (d * sin(a)) + (e*b) + c

See the grads documentation for more on define
http://grads.iges.org/grads/gadoc/variable.html#new

You should also look at the list of functions that can be used in grads
http://grads.iges.org/grads/gadoc/gadocindex.html

In particular, look at the const and maskout functions.  These can be used
to create the equivalent of an if statement, again operating on whole grids,
not grid cell by grid cell.

For example:

define ones = const(const(maskout(p,p-10),1),0,-u)
define iftest = a * ones + b

creates a variable called ones that has ones everywhere p > 10, and zeroes
everywhere else.  Then iftest has values of a + b everywhere p > 10 and
values of b everywhere else.

To do this may require creating several intermediate variables, still it
should be much faster than using q defval and set defval (I had a problem
where I wanted to know the values of cells not only at, but surrounding an
observation.  For that I had to use q defval and set defval and it was
incredibly slow).

Michael Sestak
Fleet Numerical Meteorology and Oceanography Center
Monterey, CA



> -----Original Message-----
> From: Elena A. Yegorova [mailto:elenad at UMD.EDU]
> Sent: Monday, October 24, 2005 11:42 AM
> To: GRADSUSR at LIST.CINECA.IT
> Subject: q defval/set defval
>
>
> Hello GrADS users,
>
> I am trying to use "q defval" and "set defval" to compare two grids
> pixel-by-pixel and create a new grid based on the results.
> This computation
> takes a very long time. And my computation is more involved than using
> arithmetic formulas of the two grids like grid1-grid2.
> Is there a more efficient way for creating a new grid with a
> unique value
> for each grid point (other than set defval)?
> Is there a more efficient way to loop through grid points
> (other than q
> defval)?
>
> Thanks for you help.
>
> Elena
>



More information about the gradsusr mailing list