# [gradsusr] Help with area average script to calculate height for specific locations

Roberto Mera RMera at ucsusa.org
Tue Apr 1 22:50:13 EDT 2014

```All,

I have a script that allows me to process a text file of latitude longitudes (stations) and I'm trying to output area averages of a particular file based on the points generated from the text file.

I'm basically calculating the grid point spatially associated with a specific station.

So far it works to give me the x1, x2, y1, y2 but I can't make it loop over all the points for area average of the gridded file.

My version of grads: Config: v2.0.a9.oga.1 little-endian readline printim grib2 netcdf hdf4-sds hdf5 opendap-grids,stn athena geotiff shapefile

Here is the script (some of the material is likely obsolete as I got the code from an earlier project):

function main(arg)

file = subwrd(arg,1)
size = subwrd(arg,2)
color = subwrd(arg,3)

record = sublin(record,2)

i = 0

counter = record

while(i < counter)

record = sublin(record,2)

ilat0 = subwrd(record,2)
ilon0 = subwrd(record,1)
ilon1 = subwrd(record,3)
ilat1 = subwrd(record,4)

*say ilon0 ilat0 ilon1 ilat1

linia(ilat0,ilon0,ilon1,ilat1,size,color)

i = i + 1

endwhile

return

function linia(lon0,lat0,lon1,lat1,size,color)
* Draws a line limited by two circles in _color
'set line 'color
'q w2gr 'lon0' 'lat0
*    'q w2xy 'lon0' 'lat0
x0=subwrd(result,3)
y0=subwrd(result,6)
xlo=x0-0.0540406
xhi=x0+0.0540406
ylo=y0-0.0540406
yhi=y0+0.0540406
*   say x0' 'y0' 'lon0' 'lat0
*    say xlo' 'xhi' 'ylo' 'yhi
'areal=aave(ht,x='xlo',x='xhi',y='ylo',y='yhi')'
'd areal'
areal=subwrd(result,6)
say 'areal'
*'q w2xy 'lon1' 'lat1
*x1=subwrd(result,3)
*y1=subwrd(result,6)
*'draw line 'x0' 'y0' 'x1' 'y1
*    'draw mark 3 'x0' 'y0' 'size''
*'draw mark 3 'x1' 'y1' .07'
return
-------------- next part --------------
An HTML attachment was scrubbed...