1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:daysinmonth |
---|
6 | ; |
---|
7 | ; PURPOSE:give the nomber of days in a specefic month |
---|
8 | ; |
---|
9 | ; CATEGORY: calandar |
---|
10 | ; |
---|
11 | ; CALLING SEQUENCE: ndays = daysinmonth([month[, year]]) |
---|
12 | ; |
---|
13 | ; INPUTS (optionnal): month and year. Year is used only if the |
---|
14 | ; common variable key_caltype = 'greg'. In that case, month |
---|
15 | ; and year must have the same number of elements. if not |
---|
16 | ; provided, we take month and year from "time" common variable. |
---|
17 | ; |
---|
18 | ; KEYWORD PARAMETERS: |
---|
19 | ; |
---|
20 | ; OUTPUTS: |
---|
21 | ; |
---|
22 | ; COMMON BLOCKS: cm_4cal |
---|
23 | ; |
---|
24 | ; SIDE EFFECTS: return -1 in case of error |
---|
25 | ; |
---|
26 | ; RESTRICTIONS: |
---|
27 | ; |
---|
28 | ; EXAMPLE: |
---|
29 | ; |
---|
30 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
31 | ; 2/7/98 |
---|
32 | ; update/review/english/new commons: June 2005 Sebastien Masson. |
---|
33 | ;- |
---|
34 | ;------------------------------------------------------------ |
---|
35 | ;------------------------------------------------------------ |
---|
36 | ;------------------------------------------------------------ |
---|
37 | function daysinmonth, month, year |
---|
38 | ;------------------------------------------------------------ |
---|
39 | ; include commons |
---|
40 | @cm_4cal |
---|
41 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
42 | @updatenew |
---|
43 | ENDIF |
---|
44 | ;------------------------------------------------------------ |
---|
45 | IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' |
---|
46 | CASE key_caltype OF |
---|
47 | '360d': if n_elements(month) GT 1 THEN $ |
---|
48 | return, replicate(30, n_elements(month)) ELSE return, 30 |
---|
49 | 'noleap':BEGIN |
---|
50 | days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
---|
51 | IF n_elements(month) EQ 0 THEN caldat, time, month |
---|
52 | return, days_in_mth[month-1] |
---|
53 | END |
---|
54 | 'greg':BEGIN |
---|
55 | CASE n_params() OF |
---|
56 | 0:caldat, time, month, day, year |
---|
57 | 2:IF n_elements(month) NE n_elements(year) THEN $ |
---|
58 | return, report('month and year must have the same number of elements') |
---|
59 | ELSE:return, report('daysinmonth accept 0 or 2 input parameters') |
---|
60 | ENDCASE |
---|
61 | days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
---|
62 | return, days_in_mth[month-1] + leapyr(year)*(month EQ 2) |
---|
63 | END |
---|
64 | ELSE:return, report('only 3 types of calendar are accepted: greg, 360d and noleap') |
---|
65 | ENDCASE |
---|
66 | |
---|
67 | END |
---|