[gradsusr] Finding the maximum location of a 3D variable

Jeffrey Duda jdduda at iastate.edu
Thu Sep 23 17:22:43 EDT 2010


After looking around, I decided to write a script to solve this problem.
The meat of it is included below for those who wish to use it.  As a final
note, I really think an inherent Grads function should be made to do this.
It could be modeled off of such other functions as aave:

example call:
amaxloc( var , lon1, lon2, lat1, lat2)

Anyway, enjoy!

*Finding the location of maximum value
max = -999999
yy = 1
while (yy <= yfinal)
 'set y 'yy
 'd maxloc('ans',x=1,x='xfinal')'
 line = sublin(result,3)
 index = subwrd(line,4)
 if (index < 1e+10)
  'set x 'index
  'd 'ans
  line = sublin(result,2)
  act_max = subwrd(line,4)
*setting index of max value into array
  max.yy.1 = index
*setting actual max value into array
  max.yy.2 = act_max
  'set x 1 'xfinal
  if (max.yy.2 > max)
   max_val = max.yy.2
   max_locx = max.yy.1
   max_locy = yy
   max = max_val
  endif
 endif
 yy = yy + 1
endwhile

In this script, 'ans' refers to a field name like 'u', 'td', 'hgtprs', etc.
This can be easily adapted for finding the location of minimum value by
changing 'maxloc' to 'minloc' and reversing the '>' sign in the last if
statement.  You can choose to change the variable names to include 'min'
instead of 'max' as well.

Jeff Duda

On Sun, Sep 19, 2010 at 11:32 PM, Jeffrey Duda <jdduda at iastate.edu> wrote:

> Hello,
> I wish to find the location of the max of a variable (say, theta-e or
> precipitation) from WRF output.  I'm assuming the maxloc function is the way
> to go, but it only seems to give you the location of max value along one
> dimension.  I want it to give me the lat,lon coords  of the max value.  How
> do I do that?
>
> Jeff Duda
>
> --
> Jeff Duda
> Iowa State University
> Meteorology Graduate Student
> 3134 Agronomy Hall
> www.meteor.iastate.edu/~jdduda <http://www.meteor.iastate.edu/%7Ejdduda>
>



-- 
Jeff Duda
Iowa State University
Meteorology Graduate Student
3134 Agronomy Hall
www.meteor.iastate.edu/~jdduda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20100923/00a04f94/attachment-0003.html 


More information about the gradsusr mailing list