?? esmf_dateex.f
字號:
! $Id: ESMF_DateEx.F,v 1.1.6.1 2002/04/24 03:25:52 erik Exp $ !\begin{verbatim}!===============================================================================! ESMF_Date F90 Unit Tests and Examples!=============================================================================== program main use ESMF_TimeMgmtMod use ESMF_AppMod implicit none integer, parameter :: START_DATE=20011128, START_SECS=43200 integer, parameter :: STOP_DATE=20041201, STOP_SECS=1200 integer, parameter :: DAY_INC=(3*365)+5, SEC_INC=86400+43200+1 integer, parameter :: MAX_IS_LATER_IT=3000 logical exhaustive_tests integer, parameter :: LONG_STARTD=19690113 integer, parameter :: LONG_ENDY=2001 integer, parameter :: LONG_HOURINC=23 ! Must be <= 24 so all days are covered.! Parameters for exhaustive tests integer, parameter :: EXH_LONG_STARTD=-47130113 integer, parameter :: EXH_LONG_ENDY=214000 integer, parameter :: EXH_LONG_HOURINC=6 ! Must be <= 24 so all days are covered. integer startd, endy, hourinc integer :: retCalDate, retDays, retSecs integer :: retCalDate1, retDays1, retSecs1 integer :: retDays1, retSecs1 integer :: numIter, numLeap, lastLeap, curYear integer :: dayOfYear logical :: test, isLater, isLater1, done, bigtest type(ESMF_Date) :: startDateG, stopDateG, retDateG, origDateG type(ESMF_Date) :: startDateN, stopDateN, retDateN, origDateN type(ESMF_Date) :: copy type(ESMF_Time) :: incTime, retTime, retTime1 type(ESMF_Date) :: calDayTester type(ESMF_App) :: app real(8) :: floatDay, floatTest character(60) :: str character(80) :: test_type app = ESMF_AppNew() print *, "==================================================" print *, "ESMF_Date F90 Unit Tests and Examples" print *, "==================================================" call getenv('ESMF_EXHTEST', test_type) print *, "test_type=", test_type if (test_type .eq. "on") then exhaustive_tests = .true. else exhaustive_tests = .false. endif!===============================================================================! Initializations!=============================================================================== retTime = ESMF_TimeInit() incTime = ESMF_TimeInit() retDateG = ESMF_DateInit() retDateN = ESMF_DateInit() !===============================================================================! Test DateInit, DateGet, DateCopyInit: Gregorian!=============================================================================== startDateG = ESMF_DateInit(ESMF_GREGORIAN, & START_DATE, START_SECS) stopDateG = ESMF_DateInit(ESMF_GREGORIAN, STOP_DATE, STOP_SECS) copy = ESMF_DateCopyInit(stopDateG) call ESMF_DateGet(startDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==START_DATE) .AND. (retSecs==START_SECS)) str = "ESMF_DateInit, ESMF_DateGet: init date and get attr" call ESMF_ErrorTest(test, str) call ESMF_DateGet(copy, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==STOP_DATE) .AND. (retSecs==STOP_SECS)) str = "ESMF_DateCopyInit(Gregorian): init date and get attr" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateInit, DateGet, DateCopyInit: No Leap!=============================================================================== startDateN = ESMF_DateInit(ESMF_NO_LEAP, & START_DATE, START_SECS) stopDateN = ESMF_DateInit(ESMF_NO_LEAP, STOP_DATE, STOP_SECS) copy = ESMF_DateCopyInit(stopDateN) call ESMF_DateGet(startDateN, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==START_DATE) .AND. (retSecs==START_SECS)) str = "ESMF_DateInit, ESMF_DateGet: init date and get attr" call ESMF_ErrorTest(test, str) call ESMF_DateGet(copy, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==STOP_DATE) .AND. (retSecs==STOP_SECS)) str = "ESMF_DateCopyInit(No Leap): init date and get attr" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateCopy: Gregorian!=============================================================================== call ESMF_DateSet(stopDateG, ESMF_GREGORIAN, STOP_DATE, STOP_SECS) copy = ESMF_DateInit() call ESMF_DateCopy(copy, stopDateG) call ESMF_DateGet(copy, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==STOP_DATE) .AND. (retSecs==STOP_SECS)) str = "ESMF_DateCopy(Gregorian): Copy date" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateCopy: No Leap!=============================================================================== call ESMF_DateSet(stopDateN, ESMF_NO_LEAP, STOP_DATE, STOP_SECS) copy = ESMF_DateInit() call ESMF_DateCopy(copy, stopDateN) call ESMF_DateGet(copy, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==STOP_DATE) .AND. (retSecs==STOP_SECS)) str = "ESMF_DateCopy(No Leap): Copy date" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrementSec: Gregorian!=============================================================================== call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) retDateG = ESMF_DateIncrementSec(startDateG, SEC_INC) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20011130) .AND. (retSecs==1)) str = & "ESMF_DateIncrementSec(Gregorian): increment date by seconds" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrementSec: No Leap!=============================================================================== call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) retDateN = ESMF_DateIncrementSec(startDateN, SEC_INC) call ESMF_DateGet(retDateN, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20011130) .AND. (retSecs==1)) str = & "ESMF_DateIncrementSec(No Leap): increment date by seconds" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrementDay: Gregorian!=============================================================================== call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) retDateG = ESMF_DateIncrementDay(startDateG, DAY_INC) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20041202) .AND. (retSecs==START_SECS)) str = & "ESMF_DateIncrementDay(Gregorian): increment date by days" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrementDay: No Leap!=============================================================================== call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) retDateN = ESMF_DateIncrementDay(startDateN, DAY_INC) call ESMF_DateGet(retDateN, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20041203) .AND. (retSecs==START_SECS)) str = & "ESMF_DateIncrementDay(No Leap): increment date by days" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrement: Gregorian!=============================================================================== incTime = ESMF_TimeInit(DAY_INC, SEC_INC) call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) retDateG = ESMF_DateIncrement(startDateG, incTime) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20041204) .AND. (retSecs==1)) str = "ESMF_DateIncrement(Gregorian): increment date" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateIncrement: No Leap!=============================================================================== incTime = ESMF_TimeInit(DAY_INC, SEC_INC) call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) retDateN = ESMF_DateIncrement(startDateN, incTime) call ESMF_DateGet(retDateN, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==20041205) .AND. (retSecs==1)) str = "ESMF_DateIncrement(No Leap): increment date" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateDecrement: Gregorian!=============================================================================== incTime = ESMF_TimeInit(DAY_INC, SEC_INC) call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) retDateG = ESMF_DateDecrement(startDateG, incTime) call ESMF_DateGet(retDateG, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==19981122) .AND. (retSecs==86399)) str = "ESMF_DateDecrement: decrement date in place" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateDecrement: No Leap!=============================================================================== incTime = ESMF_TimeInit(DAY_INC, SEC_INC) call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) retDateN = ESMF_DateDecrement(startDateN, incTime) call ESMF_DateGet(retDateN, retCalDate, retSecs) print *, "Ret date ", retCalDate, " Ret secs ", retSecs test = ((retCalDate==19981121) .AND. (retSecs==86399)) str = "ESMF_DateDecrement(No Leap): decrement date in place" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateDiff: Gregorian!=============================================================================== call ESMF_DateSet(startDateG, & ESMF_GREGORIAN, START_DATE, START_SECS) call ESMF_DateSet(stopDateG, & ESMF_GREGORIAN, STOP_DATE, STOP_SECS) call ESMF_DateDiff(startDateG, stopDateG, retTime, isLater) call ESMF_TimeGet(retTime, retDays, retSecs) print *, "Ret days ", retDays, " Ret secs ", & retSecs, "isLater", isLater test = ((retDays==1098) .AND. (retSecs==44400) & .AND. (isLater)) str = "ESMF_DateDiff(Gregorian): diff of two dates" call ESMF_ErrorTest(test, str)!===============================================================================! Test DateDiff: No Leap!=============================================================================== call ESMF_DateSet(startDateN, & ESMF_NO_LEAP, START_DATE, START_SECS) call ESMF_DateSet(stopDateN, & ESMF_NO_LEAP, STOP_DATE, STOP_SECS) call ESMF_DateDiff(startDateN, stopDateN, retTime, isLater) call ESMF_TimeGet(retTime, retDays, retSecs) print *, "Ret days ", retDays, " Ret secs ", & retSecs, "isLater", isLater test = ((retDays==1097) .AND. (retSecs==44400) & .AND. (isLater)) str = "ESMF_DateDiff(No Leap): diff of two dates" call ESMF_ErrorTest(test, str)!===============================================================================! Date Is Later: Gregorian! Creates a Date at stop time, then decrements this in a loop! until it reaches start time.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -