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

Last change on this file since 93 was 93, checked in by pinsard, 18 years ago

start to modify headers of Calendar and Utilities *.pro files for bet
ter idldoc output

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