[9] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; |
---|
[97] | 6 | ; @file_comments give the number of days in a specific month |
---|
[9] | 7 | ; |
---|
[93] | 8 | ; @categories calendar |
---|
[9] | 9 | ; |
---|
[93] | 10 | ; @param month {in}{optional} |
---|
| 11 | ; @param year {in}{optional} |
---|
| 12 | ; Year is used only if the common variable key_caltype = 'greg'. |
---|
| 13 | ; In that case, month and year must have the same number of elements. |
---|
| 14 | ; If not provided, we take month and year from "time" common variable. |
---|
[9] | 15 | ; |
---|
[93] | 16 | ; @returns number of days in a month or -1 in case of error |
---|
[9] | 17 | ; |
---|
[93] | 18 | ; @uses cm_4cal |
---|
[9] | 19 | ; |
---|
[93] | 20 | ; @examples |
---|
| 21 | ; IDL> ndays = daysinmonth(2, 2000) |
---|
[9] | 22 | ; |
---|
[93] | 23 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[9] | 24 | ; 2/7/98 |
---|
| 25 | ; update/review/english/new commons: June 2005 Sebastien Masson. |
---|
| 26 | ;- |
---|
| 27 | ;------------------------------------------------------------ |
---|
| 28 | ;------------------------------------------------------------ |
---|
| 29 | ;------------------------------------------------------------ |
---|
| 30 | function daysinmonth, month, year |
---|
| 31 | ;------------------------------------------------------------ |
---|
| 32 | ; include commons |
---|
[114] | 33 | ; |
---|
| 34 | compile_opt idl2, strictarrsubs |
---|
| 35 | ; |
---|
[9] | 36 | @cm_4cal |
---|
| 37 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
| 38 | @updatenew |
---|
| 39 | ENDIF |
---|
| 40 | ;------------------------------------------------------------ |
---|
| 41 | IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' |
---|
| 42 | CASE key_caltype OF |
---|
| 43 | '360d': if n_elements(month) GT 1 THEN $ |
---|
| 44 | return, replicate(30, n_elements(month)) ELSE return, 30 |
---|
| 45 | 'noleap':BEGIN |
---|
| 46 | days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
---|
| 47 | IF n_elements(month) EQ 0 THEN caldat, time, month |
---|
| 48 | return, days_in_mth[month-1] |
---|
| 49 | END |
---|
| 50 | 'greg':BEGIN |
---|
| 51 | CASE n_params() OF |
---|
| 52 | 0:caldat, time, month, day, year |
---|
| 53 | 2:IF n_elements(month) NE n_elements(year) THEN $ |
---|
| 54 | return, report('month and year must have the same number of elements') |
---|
| 55 | ELSE:return, report('daysinmonth accept 0 or 2 input parameters') |
---|
| 56 | ENDCASE |
---|
| 57 | days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
---|
| 58 | return, days_in_mth[month-1] + leapyr(year)*(month EQ 2) |
---|
| 59 | END |
---|
| 60 | ELSE:return, report('only 3 types of calendar are accepted: greg, 360d and noleap') |
---|
| 61 | ENDCASE |
---|
| 62 | |
---|
| 63 | END |
---|