Averaging daily to monthly values

Arindam Chakraborty arch at IO.MET.FSU.EDU
Wed Jun 21 13:11:29 EDT 2006


hi Eric and Stefan,
        Eric's solution is better in the sense that one need not worry
about the definition of calendar in the descriptor file (standard or
no-leap year). To take into account this feature in my code, it
requires a patch (or manual setting of leap = 0 for 365_day_calendar
always).

thanks,

arindam
----------------------------
 Dr. 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 Tue, 20 Jun 2006, Stefan Fronzek wrote:

> Dear Arindam,
>
> Thanks a lot for your solution -- that is exactly what I was looking for.
>
> See copied below also an alternative solution that Eric DeWeaver has send to
> me directly and which I think missed the list (thanks also to Eric).
>
> Regards,
> Stefan
>
> On Sat, 17 Jun 2006 15:27:31 -0400, Arindam Chakraborty
> <arch at IO.MET.FSU.EDU> wrote:
>
> >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
> >>
>
> Von: Eric DeWeaver <deweaver at ...>
> An: Stefan Fronzek <sfronzek at ...>
> Betreff: Re: Averaging daily to monthly values
> Datum: 17.06.2006 20:32:44
> Hi Stefan,
>
> Here's a loop that does something like that:
>
>
> mostr='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
> yr   =1961
> yrend=2000
> whle(yr <= yrend)
>    mo=1
>    while (mo <= 12)
>      mo1=mo+1;yr1=yr;if(mo1=13);mo1=1;yr1=yr+1;endif
>     'set time 00z01'subwrd(mostr,mo)%yr
>     'q dims';line=sublin(result,5);d0=subwrd(line,6);t0=subwrd(line,9)
>     'set time 00z01'subwrd(mostr,mo1)%yr1
>     'q dims';line=sublin(result,5);d1=subwrd(line,6);t1=subwrd(line,9)-1
>      say d0'  'd1'  't0'   't1
>     'monmean = ave(data,t='t0',t='t1')'
>    endwhile
>    yr=yr+1
> endwhile
>
>
> The idea is that you start by finding the time index t1 for February
> 1.  You don't know whether February has 28 or 29 days, so you figure out
> the time index t1 for March 1 and then subtract 1.  That gives you the
> time index for the last day of February regardless of leap years.
>
> I haven't run this exact code, so there may be errors.
>
> Best Wishes,
>
> Eric
>



More information about the gradsusr mailing list