[2] | 1 | ;----------------------------------------------------------------- |
---|
| 2 | ;+ |
---|
| 3 | ; |
---|
[126] | 4 | ; @file_comments |
---|
| 5 | ; determine whether the input year is a leap year or not |
---|
[93] | 6 | ; Very useful for finding number of days in a year. |
---|
| 7 | ; eg. NUM_DAYS_IN_YR = 365 + leapyr(year) |
---|
[2] | 8 | ; |
---|
[93] | 9 | ; @categories calendar |
---|
[2] | 10 | ; |
---|
[136] | 11 | ; @param year {in}{required} |
---|
| 12 | ; year to be tested as a leap year |
---|
[2] | 13 | ; |
---|
[136] | 14 | ; @returns |
---|
| 15 | ; 0 then not a leap year, 1 then year is a leap year |
---|
[2] | 16 | ; |
---|
[93] | 17 | ; @uses cm_4cal |
---|
[2] | 18 | ; |
---|
[93] | 19 | ; @examples |
---|
| 20 | ; IDL> result = leapyr(2000) |
---|
[9] | 21 | ; |
---|
[93] | 22 | ; @history |
---|
[9] | 23 | ; |
---|
[93] | 24 | ; Originally Written by: Trevor Harris, Physics Dept., University of Adelaide, |
---|
| 25 | ;20/09/88 |
---|
[2] | 26 | ; |
---|
[9] | 27 | ; November 2004: correction for century years... S. Masson; |
---|
| 28 | ; |
---|
[126] | 29 | ; Every year divisible by 4 is a leap year. |
---|
| 30 | ; But every year divisible by 100 is NOT a leap year |
---|
[9] | 31 | ; Unless the year is also divisible by 400, then it is still a |
---|
| 32 | ; leap year. |
---|
| 33 | ; This means that year 1800, 1900, 2100, 2200, 2300 and 2500 are |
---|
[126] | 34 | ; NOT leap years, while year 2000 and 2400 are leap years. |
---|
[136] | 35 | ; + suppress the automatic change 89 -> 1989 |
---|
[9] | 36 | ; |
---|
| 37 | ; June 2005 update for new commons, Sebastien Masson. |
---|
| 38 | ; |
---|
[118] | 39 | ; |
---|
| 40 | ; @version $Id$ |
---|
| 41 | ; |
---|
[2] | 42 | ;- |
---|
[9] | 43 | ;------------------------------------------------------------ |
---|
[93] | 44 | function leapyr, year |
---|
[9] | 45 | ; include commons |
---|
[114] | 46 | ; |
---|
| 47 | compile_opt idl2, strictarrsubs |
---|
| 48 | ; |
---|
[9] | 49 | @cm_4cal |
---|
| 50 | yr = long(year) |
---|
| 51 | IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' |
---|
| 52 | ; |
---|
[126] | 53 | IF key_caltype NE 'greg' THEN BEGIN |
---|
[9] | 54 | sd = size(yr, /dimensions) |
---|
| 55 | IF sd[0] EQ 0 THEN return, 0b ELSE return, bytarr(size(yr, /dimensions)) |
---|
| 56 | ENDIF ELSE return, (yr MOD 4 EQ 0)*((yr MOD 100 NE 0) + (yr MOD 400 EQ 0)) |
---|
[2] | 57 | |
---|
[9] | 58 | end |
---|