Averaging daily to monthly values

Arindam Chakraborty arch at IO.MET.FSU.EDU
Sat Jun 17 15:27:31 EDT 2006


hi Stefan,
        you need to write the monthly means to another file to be able
to use them as a time series. The following code is an example of
making monthly means from daily data considering leap years and
writing to output file.

* Make monthly means from daily data considering leap years.
 reinit
 mday = '31 28 31 30 31 30 31 31 30 31 30 31'
 month = 'jan feb mar apr may jun jul aug sep oct nov dec'

 'open file'
 'set x 1 ...'
 'set y 1 ...'

 'set gxout fwrite'
 'set fwrite outputfile'

 yr1 = 1961
 yr2 = 2000

 yr = yr1
 while(yr<=yr2)
  leap = 0
  if(math_mod(yr,400) = 0 | math_mod(yr,4) = 0 & math_mod(yr,100) != 0)
   leap = 1
   say yr' is a leap year.'
  endif
  imon = 1
  while(imon <= 12)
   md = subwrd(mday,imon)
   mc = subwrd(month,imon)
   if(imon = 2); md = md + leap; endif;
   time1 = '01'mc''yr
   time2 = md''mc''yr
*   say time1' 'time2
   'd ave(yourvariable,time='time1',time='time2')'
   imon = imon + 1
  endwhile
  yr = yr + 1
 endwhile



----------------------------
 ARINDAM CHAKRABORTY
 Department of Meteorology
 Florida State University
 Tallahassee, FL-32306, USA
 Tel: +001-850-6443524 (Off)
      +001-850-5758550 (Res)
 Fax: +001-850-6449642
____________________________

On Sat, 17 Jun 2006, Stefan Fronzek wrote:

> Dear Grads users,
>
> I want to calculate monthly averages from daily data covering the period
> 01jan1961 to 31dec2000. Is there any clever way of using the ave()-function
> that would account for the varying lengths of the month (including the
> handling of leap years)?
>
> Thanks for any advice,
> Stefan
>



More information about the gradsusr mailing list