source: trunk/SRC/Calendar/daysinmonth.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments give the number of days in a specific month
7;
8; @categories calendar
9;
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.
15;
16; @returns number of days in a month or -1 in case of error
17;
18; @uses cm_4cal
19;       
20; @examples
21; IDL> ndays = daysinmonth(2, 2000)
22;
23; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
24;                       2/7/98
25; update/review/english/new commons: June 2005 Sebastien Masson.
26;-
27;------------------------------------------------------------
28;------------------------------------------------------------
29;------------------------------------------------------------
30function daysinmonth, month, year
31;------------------------------------------------------------
32; include commons
33;
34  compile_opt idl2, strictarrsubs
35;
36@cm_4cal
37IF NOT keyword_set(key_forgetold) THEN BEGIN
38@updatenew
39ENDIF
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
63END
Note: See TracBrowser for help on using the repository browser.