C @(#)leapyear.f 1.2 02/04/00 C logical function leapyear (nyear) c This function decides whether a particular year is a leap year c Rule 1: Years not exactly divisible by four are not leap years c Rule 2: Years not exactly divisible by one hundred are leap years c Rule 3: Years not exactly divisible by four hundred are not leapyears c Years exactly divisible by four hundred are leapyears c prior to the adoption of Gregorian Calendar in 1583 October, dates are c assumed to be Julian i.e. Rule 1 only applies. 1700 is the first year c affected by this change. logical test integer*4 nyear_local test(n) = (nyear_local/n)*n .eq. nyear_local nyear_local = nyear c tests to guarantee all possibilities re Y2K - PD - 01/02/00 c further amended -3/7/00 - using local 'nyear' variable so c that incorrect nyear not returned (only happened when leapyear c called with a 2 digit year) c if nyear is 2 digits (including zero) & possible 100-200 range if (nyear_local .lt. 200) then if (nyear_local .le. 95) then nyear_local = 2000 + nyear_local else nyear_local = 1900 + nyear_local end if end if if (nyear_local .gt. 0) then else if (nyear_local .lt. 0) then call abort('Rules for BC leap years undetermined') else call abort('Year zero does not exist: 1 AD follows 1 BC') end if leapyear = test(4) if (leapyear .and. nyear_local .ge. 1700) then leapyear = .not.test(100) if (.not.leapyear) leapyear = test(400) end if return end