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

Last change on this file since 150 was 150, checked in by navarro, 18 years ago

english and nicer header (3a)

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