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