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