;+
;
; @file_comments
; give the number of days in a specific month
;
; @categories
; Calendar
;
; @param MONTH {in}{optional} {type=integer}
; month number
;
; @param YEAR {in}{optional} {default=from "time" common variable of cm_4cal}
; To specify the year of the month. Used only if the common variable
; key_caltype = 'greg'. In that case, month and year must have the same
; number of elements.
;
; @returns
; number of days in a month or -1 in case of error
;
; @uses
; cm_4cal
; updatenew
;
; @examples
;
; IDL> ndays = daysinmonth(2, 2000)
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; 2/7/98
; update/review/english/new commons: June 2005 Sebastien Masson.
;
; @version
; $Id$
;
;-
function daysinmonth, month, year
;
compile_opt idl2, strictarrsubs
;
@cm_4cal
IF NOT keyword_set(key_forgetold) THEN BEGIN
@updatenew
ENDIF
IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
CASE key_caltype OF
'360d': if n_elements(month) GT 1 THEN $
return, replicate(30, n_elements(month)) ELSE return, 30
'noleap':BEGIN
days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
IF n_elements(month) EQ 0 THEN caldat, time, month
return, days_in_mth[month-1]
END
'greg':BEGIN
CASE n_params() OF
0:caldat, time, month, day, year
2:IF n_elements(month) NE n_elements(year) THEN $
return, report('month and year must have the same number of elements')
ELSE:return, report('daysinmonth accept 0 or 2 input parameters')
ENDCASE
days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
return, days_in_mth[month-1] + leapyr(year)*(month EQ 2)
END
ELSE:return, report('only 3 types of calendar are accepted: greg, 360d and noleap')
ENDCASE
END