On Fri, May 22, 2009 at 9:11 PM, mick spillane
<Mick.Spillane@xxxxxxxx> wrote:
Hi Peter & Ansley,
I actually prefer Russell's DAYS_IN_MONTH approach which beats by miles the clunky things I've used at various times in the past in similar situations. There is a slight omission in not having a YEAR0 in the definition of YEAR and maybe its worth generalizing to situations where a monthly series did not begin in January. With these thoughts in mind, I'm putting the attached DaysPerMonth.jnl script in my toolkit. Apologies to anyone whose reaction is "duh" -- though there's probably no one like that in the ferret-users group.
Mick
PS As an example of how to use it in a situation like yours Peter (but with series starting with Feb 1960 say)
! demo of russell's days-in-month approach to mm/day --> mm/month conversion
def axis/t="15-Feb-1960":"15-JAN-1990"/npoints=360 tax ; def grid/t=tax grd
let/title="rainfall"/units="mm/day" drain=randu(t[g=grd]) ! a fake rainfall series
! generate the days/month variable for the daily rainfall variable "drain"
go dayspermonth 1960 2 drain
! and apply it to generate monthly rate
let/title="rainfall"/units="mm/month" mrain=dpm*drain
! and list some results to check dpm in leap and non-leap years
list/nohead/L=1:16 yrser,mnser,d1900,dpm,drain,mrain
15-FEB-1960 / 1: 1960. 2.00 21945. 29.00 0.6862 19.90 <== 29 days in Feb'60
16-MAR-1960 / 2: 1960. 3.00 21974. 31.00 0.6201 19.22
15-APR-1960 / 3: 1960. 4.00 22005. 30.00 0.5975 17.92
16-MAY-1960 / 4: 1960. 5.00 22035. 31.00 0.4654 14.43
15-JUN-1960 / 5: 1960. 6.00 22066. 30.00 0.6546 19.64
16-JUL-1960 / 6: 1960. 7.00 22096. 31.00 0.8547 26.50
15-AUG-1960 / 7: 1960. 8.00 22127. 31.00 0.2217 6.87
15-SEP-1960 / 8: 1960. 9.00 22158. 30.00 0.4683 14.05
15-OCT-1960 / 9: 1960. 10.00 22188. 31.00 0.8639 26.78
14-NOV-1960 / 10: 1960. 11.00 22219. 30.00 0.3296 9.89
15-DEC-1960 / 11: 1960. 12.00 22249. 31.00 0.9992 30.97
14-JAN-1961 / 12: 1961. 1.00 22280. 31.00 0.4089 12.67
14-FEB-1961 / 13: 1961. 2.00 22311. 28.00 0.7811 21.87 <== & 28 in Feb'61
16-MAR-1961 / 14: 1961. 3.00 22339. 31.00 0.4778 14.81
16-APR-1961 / 15: 1961. 4.00 22370. 30.00 0.4869 14.61
16-MAY-1961 / 16: 1961. 5.00 22400. 31.00 0.5987 18.56
! DaysPerMonth : Creates a variable "dpm" for days per month to associate with a
! particular monthly time series. Other variables introduced may
! be useful, eg mnser in generating monthly climatologies, d1900
! which is days1900 for the first of the month
! Usage Example: If series "myvar" starts May 1959 then before using "dpm"
! go DaysPerMonth 1959 5 myvar
let LVAL=L[g=$3]
let/title="Year Series" yrser=`$1`+int((LVAL+`$2`-2)/12)
let mser0=mod(LVAL+`$2`-1,12)
let/title="Month Series" mnser=if(mser0 eq 0)then 12 else mser0
let/title="Days1900 Series" d1900=days1900(yrser,mnser,1)
let/title="Days/Month" dpm=d1900[L=@shf]-d1900