<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Dear Diego Medina,<br>
<br>
Please find below a copy of a message (copied from a "forward" email
message window) which I sent to the GrADS Listserv for a similar
problem.<br>
<br>
Perhaps you could try something like (note, I haven't tested the
following code):<br>
<br>
month_days = '31 28 31 30 31 30 31 31 30 31 30 31'<br>
*<br>
* loop over months...<br>
*<br>
m=1<br>
while ( m <= 12 )<br>
*<br>
* define number of days for this month<br>
*<br>
ndays = subwrd(month_days,m)<br>
*<br>
* open first day of month file and use it to initialize a time sum
variable...<br>
*<br>
ctl_file = '1990'm'01.ctl' * assuming you are using a GrADS ctl file
with a name like this; correct if not so...<br>
'open 'ctl_file<br>
'query file'
<br>
say result
<br>
say<br>
rec5 = sublin(result,5) ; rec6 = sublin(result,6)
<br>
xsiz = subwrd(rec5,3) ; ysiz = subwrd(rec5,6) ; zsiz = subwrd(rec5,9)
; tsiz = subwrd(rec5,12)
<br>
nvar = subwrd(rec6,5)
<br>
say ' nvar 'nvar
<br>
say ' xsiz 'xsiz
<br>
say ' ysiz 'ysiz
<br>
say ' zsiz 'zsiz
<br>
say ' tsiz 'tsiz
<br>
*
<br>
'set x 1 ' xsiz <br>
'set y 1 ' ysiz <br>
'set z 1 ' zsiz <br>
'set t 1'
* wildcard for time sum and average...<br>
'define usum = ave(u,t=1,t='tsiz')' * if you have more than one
time level per daily file...<br>
'define vsum = ave(v,t=1,t='tsiz')' * if you have more than one
time level per daily file...<br>
'define usum = u' * if you have one time level per daily file...<br>
'define vsum = v' * if you have one time level per daily file...<br>
*
<br>
* close file for this day...
<br>
*
<br>
'close 1'
<br>
*
<br>
* update "sums" for each of the rest of the days for this month...
<br>
*
<br>
n=2<br>
while ( n <= ndays )
<br>
*
<br>
* define ctl file in terms of day index "n"
<br>
*
(assuming you are using a GrADS ctl file with a name like this;
correct if not so...)<br>
*<br>
if( n < 10 )<br>
ctl_file = '1990'm'0'n'.ctl'<br>
else<br>
ctl_file = '1990'm''n'.ctl'<br>
endif<br>
'open 'ctl_file
<br>
'query file'
<br>
say result
<br>
say<br>
rec5 = sublin(result,5) ; rec6 = sublin(result,6)
<br>
xsiz = subwrd(rec5,3) ; ysiz = subwrd(rec5,6) ; zsiz =
subwrd(rec5,9) ; tsiz = subwrd(rec5,12)
<br>
nvar = subwrd(rec6,5)
<br>
say ' nvar 'nvar
<br>
say ' xsiz 'xsiz
<br>
say ' ysiz 'ysiz
<br>
say ' zsiz 'zsiz
<br>
say ' tsiz 'tsiz
<br>
*
<br>
'set x 1 ' xsiz <br>
'set y 1 ' ysiz <br>
'set z 1 ' zsiz <br>
'set t 1'
* wildcard for time sum and average...<br>
'usum = usum + ave(u,t=1,t='tsiz')' * if you have more than one
time level per daily file...<br>
'vsum = vsum + ave(v,t=1,t='tsiz')' * if you have more than one
time level per daily file...<br>
'usum = usum + u' * if you have one time level per daily file...<br>
'vsum = vsum + v' * if you have one time level per daily file...<br>
*
<br>
* close file for this day...
<br>
*
<br>
'close 1'
<br>
n=n+1
<br>
endwhile
<br>
*
<br>
* calculate the average of the daily sums for this month...
<br>
*
<br>
'define uavg = usum/'ndays
<br>
'define vavg = vsum/'ndays
<br>
*<br>
* display data: (x,y) plots over the vertical levels shown below...<br>
*<br>
zz=1<br>
while ( zz <= zsiz )<br>
'set x 1 ...'<br>
'set y 1 ...'<br>
'set z 'zz<br>
'set t 1'
* wildcard for time average...<br>
'set gxout shaded'<br>
'd uavg'
<br>
'd vavg'
<br>
zz=zz+1<br>
endwhile<br>
*
<br>
* finished for this month...
<br>
*
<br>
'undefine usum' ; 'undefine uavg'<br>
'undefine vsum' ; 'undefine vavg'<br>
*
<br>
* go to next month...
<br>
*
<br>
m=m+1<br>
endwhile<br>
<br>
I hope this helps; please let me know if you encounter any problems
with (or have any questions about) the above code, OK?<br>
<br>
Thanks,<br>
Chuck<br>
<br>
diego wrote:
<blockquote cite="mid20051003211550.1986.qmail@web53102.mail.yahoo.com"
type="cite">
<pre wrap="">Dear grads User,
I have a mean diary for u and v for sudamerica in
files :
1990101.grb
1990102.grb
1990103.grb
1990104.grb
1990105.grb
...
...
1990131.grb
1990201.grb
1990202.grb
...
...
I want to obtain monthly averages of u and v.
can you help me.
Thanks
______________________________________________
Renovamos el Correo Yahoo!
Nuevos servicios, más seguridad
<a class="moz-txt-link-freetext" href="http://correo.yahoo.es">http://correo.yahoo.es</a>
</pre>
</blockquote>
<pre>------------------------------------------------------------------------------------</pre>
-------- Original Message --------
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">Subject: </th>
<td>Re: average in reanalysis data</td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">Date: </th>
<td>Fri, 18 Mar 2005 18:22:46 -0500</td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">From: </th>
<td>Charles Seman <a class="moz-txt-link-rfc2396E" href="mailto:Charles.Seman@noaa.gov"><Charles.Seman@noaa.gov></a></td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">To: </th>
<td><a class="moz-txt-link-abbreviated" href="mailto:GRADSUSR@LIST.CINECA.IT">GRADSUSR@LIST.CINECA.IT</a></td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">References: </th>
<td><a class="moz-txt-link-rfc2396E" href="mailto:bd4c9dd96376.42385be5@unal.edu.co"><bd4c9dd96376.42385be5@unal.edu.co></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<pre>Luis,
Perhaps you could try calculating an average of 30 years of averaged
precipitation data as follows:
ts = 1961
tf = 1990
nyear = tf-ts+1
*
* initialize "pravgsum" for the first year...
*
tt=ts
*
* define reanalysis file in terms of year index "tt"
*
reanalysis_file = ... * must be defined
' open 'reanalysis_file
'query file'
say result
say ' '
rec5 = sublin(result,5) ; rec6 = sublin(result,6)
xsiz = subwrd(rec5,3) ; ysiz = subwrd(rec5,6) ; zsiz = subwrd(rec5,9) ;
tsiz = subwrd(rec5,12)
nvar = subwrd(rec6,5)
say ' nvar 'nvar
say ' xsiz 'xsiz
say ' ysiz 'ysiz
say ' zsiz 'zsiz
say ' tsiz 'tsiz
*
'set lon ...' * must be defined
'set lat ...' * must be defined
'set lev ...' * must be defined
'set t 1'
'define pravg = ave('precip_variable',t=1,t='tsiz')' * must be defined
*
* start sum of yearly precip averages...
*
'pravgsum = pravg'
'undefine pravg'
*
* close reanalysis file for this year...
*
'close 1'
*
* update "pravgsum" for each of the rest of the years...
*
tt=tt+1
while ( tt <= tf )
*
* define reanalysis file in terms of year index "tt"
*
reanalysis_file = ... * must be defined
'open 'reanalysis_file
'set lon ...' * must be defined
'set lat ...' * must be defined
'set lev ...' * must be defined
'set t 1'
'define pravg = ave('precip_variable',t=1,t='tsiz')' * must be defined
*
* update "pravgsum" using "pravg" for this year...
*
'pravgsum = pravgsum + pravg'
'undefine pravg'
*
* close reanalysis file for this year...
*
'close 1'
tt=tt+1
endwhile
*
* calculate the average of the "nyear" yearly averages...
*
'define pravg = pravgsum/'nyear
'd pravg'
....
I hope this helps... Please let me know if you find any problems with
the above technique, OK?
Thanks,
Chuck
Luis Fernando Montana R. wrote:
> Hello all,
>
> I'm using data of the reanalysis for period 1961-1990. I have 30
> files, one per year and need to calculate the average of precipitation
> for that period.
>
> There is some simplified form to do it?
>
> Thanks in advance,
>
> Luis Fernando Montana Roa
> Posgrado de Meteorologia
> Universidad Nacional de Colombia
> Bogota - Colombia - South America
>
--
********************************************************************
Charles Seman <a class="moz-txt-link-abbreviated" href="mailto:Charles.Seman@noaa.gov">Charles.Seman@noaa.gov</a>
U.S. Department of Commerce / NOAA / OAR
Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547
201 Forrestal Road fax: (609) 987-5063
Princeton, NJ 08542 <a class="moz-txt-link-freetext" href="http://www.gfdl.noaa.gov/~cjs/">http://www.gfdl.noaa.gov/~cjs/</a>
********************************************************************
"The contents of this message are mine personally and do not reflect
any position of the Government or NOAA."
------------------------------------------------------------------------------------
</pre>
<pre class="moz-signature" cols="72">--
********************************************************************
Charles Seman <a class="moz-txt-link-abbreviated" href="mailto:charles.seman@noaa.gov">charles.seman@noaa.gov</a>
U.S. Department of Commerce / NOAA / OAR
Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547
201 Forrestal Road fax: (609) 987-5063
Princeton, NJ 08540-6649 <a class="moz-txt-link-freetext" href="http://www.gfdl.noaa.gov/~cjs/">http://www.gfdl.noaa.gov/~cjs/</a>
********************************************************************
"The contents of this message are mine personally and do not reflect
any position of the Government or NOAA."
</pre>
</body>
</html>