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

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

add $ in Calendar, Grid, Interpolation, Obsolete and Postscript *.pro files, add svn:keywords Id to all these files, some improvements in header

  • Property svn:executable set to *
  • Property svn:keywords set to Id
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; @version $Id$
28;
29;-
30;------------------------------------------------------------
31;------------------------------------------------------------
32;------------------------------------------------------------
33function daysinmonth, month, year
34;------------------------------------------------------------
35; include commons
36;
37  compile_opt idl2, strictarrsubs
38;
39@cm_4cal
40IF NOT keyword_set(key_forgetold) THEN BEGIN
41@updatenew
42ENDIF
43;------------------------------------------------------------
44  IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
45  CASE key_caltype OF
46    '360d': if n_elements(month) GT 1 THEN $
47        return, replicate(30, n_elements(month)) ELSE return, 30
48    'noleap':BEGIN
49      days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
50      IF n_elements(month) EQ 0 THEN caldat, time, month
51      return, days_in_mth[month-1]
52    END
53    'greg':BEGIN
54      CASE n_params() OF
55        0:caldat, time, month, day, year
56        2:IF n_elements(month) NE n_elements(year) THEN $
57          return, report('month and year must have the same number of elements')
58        ELSE:return, report('daysinmonth accept 0 or 2 input parameters')
59      ENDCASE
60      days_in_mth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
61      return, days_in_mth[month-1] + leapyr(year)*(month EQ 2)
62    END
63    ELSE:return, report('only 3 types of calendar are accepted: greg, 360d and noleap')
64  ENDCASE
65
66END
Note: See TracBrowser for help on using the repository browser.