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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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