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