?? esmf_dateex.f
字號:
!=============================================================================== call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) call ESMF_DateSet(stopDateG, & ESMF_GREGORIAN, STOP_DATE, 0) incTime = ESMF_TimeInit(0, 43200) call ESMF_DateIsLater(startDateG, stopDateG, isLater) numIter = 0 do while(isLater) stopDateG = ESMF_DateDecrement(stopDateG, incTime) call ESMF_DateGet(stopDateG, retCalDate, retSecs)! print *, "Ret date ", retCalDate, " Ret secs ", retSecs call ESMF_DateIsLater(startDateG, stopDateG, isLater)! Keep this test from Looping forever. numIter = numIter + 1 if (numIter .gt. MAX_IS_LATER_IT) then isLater = .false. endif end do call ESMF_DateGet(stopDateG, retCalDate, retSecs) print *, "AT END: Ret date ", retCalDate, " Ret secs ", retSecs if (numIter .le. MAX_IS_LATER_IT) then test = ((retCalDate==START_DATE).and.(retSecs==START_SECS)) str = "ESMF_DateIsLater(Gregorian): (true result)" else test = .false. str = & "(numIter),ESMF_DateIsLater(Gregorian): (true result)" endif call ESMF_ErrorTest(test, str)!===============================================================================! Date Is Later: No Leap! Creates a Date at stop time, then decrements this in a loop! until it reaches start time.!=============================================================================== call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) call ESMF_DateSet(stopDateN, & ESMF_NO_LEAP, STOP_DATE, 0) incTime = ESMF_TimeInit(0, 43200) call ESMF_DateIsLater(startDateN, stopDateN, isLater) numIter = 0 do while(isLater) stopDateN = ESMF_DateDecrement(stopDateN, incTime) call ESMF_DateGet(stopDateN, retCalDate, retSecs)! print *, "Ret date ", retCalDate, " Ret secs ", retSecs call ESMF_DateIsLater(startDateN, stopDateN, isLater)! Keep this test from Looping forever. numIter = numIter + 1 if (numIter .gt. MAX_IS_LATER_IT) then isLater = .false. endif end do call ESMF_DateGet(stopDateN, retCalDate, retSecs) print *, "AT END: Ret date ", retCalDate, " Ret secs ", retSecs if (numIter .le. MAX_IS_LATER_IT) then test = ((retCalDate==START_DATE).and.(retSecs==START_SECS)) str = "ESMF_DateIsLater(No Leap): (true result)" else test = .false. str = & "(numIter),ESMF_DateIsLater(No Leap): (true result)" endif call ESMF_ErrorTest(test, str)!===============================================================================! Test Increment Month, invalid day: Gregorian!=============================================================================== call ESMF_DateSet(startDateG, ESMF_GREGORIAN, 20011031, 0) retDateG = ESMF_DateIncrementMonth(startDateG, 4) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20020228) .AND. (retSecs==0)) str = "ESMF_DateIncrementMonth(Gregorian): handle invalid day" call ESMF_ErrorTest(test, str) !===============================================================================! Test Increment Month, invalid day: No Leap!=============================================================================== call ESMF_DateSet(startDateN, ESMF_NO_LEAP, 20011031, 0) retDateG = ESMF_DateIncrementMonth(startDateN, 4) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20020228) .AND. (retSecs==0)) str = "ESMF_DateIncrementMonth(No Leap): handle invalid day" call ESMF_ErrorTest(test, str) !===============================================================================! Test Increment Year, invalid day: Gregorian!=============================================================================== call ESMF_DateSet(startDateG, ESMF_GREGORIAN, 20040229, 0) retDateG = ESMF_DateIncrementYear(startDateG, 1) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20050228) .AND. (retSecs==0)) str = "ESMF_DateIncrementYear(Gregorian): handle invalid day" call ESMF_ErrorTest(test, str) !===============================================================================! Test Increment Year, invalid day: No Leap ! This test does not apply to No Leap calendar.!===============================================================================!===============================================================================! GetFltDayOfYear: Gregorian!=============================================================================== calDayTester = ESMF_DateInit(ESMF_GREGORIAN, & START_DATE,START_SECS) print *, "Calendar Day Test" call ESMF_DatePrint(calDayTester) floatDay = ESMF_DateGetFltDayOfYear(calDayTester) call ESMF_DateGet(calDayTester, retCalDate, retSecs) retDays = ESMF_DateGetDayOfYear(calDayTester) print *, "float days = ", floatDay print *, "floor(floatDay) = ", floor(floatDay) print *, "secs=", (floatDay - floor(floatDay)) floatTest = retDays + (retSecs / 86400.) print *, "Local calculation got:", floatTest print *, "Difference: ", (floatTest - floatDay) test = (abs(floatTest - floatDay) < 0.0000001) str = "ESMF_DateFltDayOfYear(Gregorian): return days.seconds" call ESMF_ErrorTest(test, str) !===============================================================================! GetFltDayOfYear: No Leap!=============================================================================== calDayTester = ESMF_DateInit(ESMF_NO_LEAP, & START_DATE,START_SECS) print *, "Calendar Day Test" call ESMF_DatePrint(calDayTester) floatDay = ESMF_DateGetFltDayOfYear(calDayTester) call ESMF_DateGet(calDayTester, retCalDate, retSecs) retDays = ESMF_DateGetDayOfYear(calDayTester) print *, "float days = ", floatDay print *, "floor(floatDay) = ", floor(floatDay) print *, "secs=", (floatDay - floor(floatDay)) floatTest = retDays + (retSecs / 86400.) print *, "Local calculation got:", floatTest print *, "Difference: ", (floatTest - floatDay) test = (abs(floatTest - floatDay) < 0.0000001) str = "ESMF_DateFltDayOfYear(No Leap): return days.seconds" call ESMF_ErrorTest(test, str) !===============================================================================! ESMF_DatePrint!=============================================================================== call ESMF_DatePrint(startDateG)!===============================================================================! Extended test!! We start with a Gregorian and a No-Leap calendar at the same date.! Next, we begin adding twelve hours to the date. At each interval we ! take the difference between the current time and the start time ! for both calendars. We also check that the yymmdd and seconds agree! for both calendars. This will be the case until we hit a leap year.! When we hit a leap year, in particular Feb 29 on a leap year, we! skip the Gregorian calendar through it by adding one day. This makes! the yymmdd agree again, but we must compensate for the diff by adding! numLeap years (encountered) into the diff from the start date for the! NO-LEAP calendar.!=============================================================================== if (exhaustive_tests) then startd = EXH_LONG_STARTD endy = EXH_LONG_ENDY hourinc = EXH_LONG_HOURINC else startd = LONG_STARTD endy = LONG_ENDY hourinc = LONG_HOURINC endif call ESMF_DateSet(startDateG, ESMF_GREGORIAN, startd, 0) call ESMF_DateSet(startDateN, ESMF_NO_LEAP, startd, 0) incTime = ESMF_TimeInit(0, hourinc*3600) call ESMF_DateCopy(retDateG, startDateG) call ESMF_DateCopy(retDateN, startDateN) done = .false. bigtest = .true. numLeap = 0 lastLeap = 1969 ! Should not be a valid leap year do while(.not. done) call ESMF_DateGet(calDayTester, retCalDate, retSecs) retDateN = ESMF_DateIncrement(retDateN, incTime) retDateG = ESMF_DateIncrement(retDateG, incTime)! Difference the dates from start. Should be the same. call ESMF_DateDiff(startDateG, retDateG, retTime, isLater) call ESMF_DateDiff(startDateN, retDateN, retTime1, isLater) call ESMF_TimeGetIS(retTime, retDays, retSecs) call ESMF_TimeGetIS(retTime1, retDays1, retSecs1) if ( ((retDays1+numLeap).ne.retDays) .or. & (retSecs.ne.retSecs1)) then print *, "Date diff is wrong" bigtest = .false. endif! Decrement each date by time passed. This should be start date origDateG = ESMF_DateDecrement(retDateG, retTime) origDateN = ESMF_DateDecrement(retDateN, retTime1) call ESMF_DateGet(origDateG, retCalDate, retSecs) if ((retCalDate.ne.startd) .or. (retSecs.ne.0)) then print *, "Decrement Gregorian Failed" bigtest = .false. endif call ESMF_DateGet(origDateN, retCalDate, retSecs) if ((retCalDate.ne.startd) .or. (retSecs.ne.0)) then print *, "Decrement NO-LEAP Failed" bigtest = .false. print *, "retCalDate:", retCalDate, "retSecs:", retSecs call ESMF_DateGet(retDateN, retCalDate1, retSecs1) print *, "Ret dateN ", retCalDate1, " Ret secs ", retSecs1 print *, "N: retDays1:", retDays1, "retSecs1:", retSecs1 endif ! Get the cal Dates. Adjust for leap years passed and compare. call ESMF_DateGet(retDateG, retCalDate, retSecs) curYear = retCalDate / 10000 if ( & ((mod((curYear), 4)==0) .and. (mod(curYear,100).ne.0)) & .or. & ((mod((curYear), 4)==0) .and. (mod(curYear,400)==0)) & ) then dayOfYear = ESMF_DateGetDayOfYear(retDateG) if (dayOfYear .eq. 60) then ! Skip through the leap day retDateG = ESMF_DateIncrementDay(retDateG, 1) call ESMF_DateGet(retDateG, retCalDate, retSecs) numLeap = numLeap + 1 endif if (curYear .ne. lastLeap) then ! Leading edge lastLeap = curYear print *, "Leap Year:", retCalDate, "numLeap:", numLeap endif endif call ESMF_DateGet(retDateN, retCalDate1, retSecs1) if ((retCalDate1.ne.retCalDate) .or. (retSecs1.ne.retSecs)) then print *, "Dates no longer agree" bigtest = .false. endif if (curYear .ge. endy) done = .true. end do if (bigtest) then print *, "PASS: Long date test." else print *, "FAIL: Long date test." endif call ESMF_AppDelete(app) end program main !\end{verbatim}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -