⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfm_dateex.f

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 F
字号:
      !\begin{verbatim}!===============================================================================! MFM_Date F90 Unit Tests and Examples!===============================================================================      program main       use MFM_TimeMgmt      implicit none      integer, parameter :: START_DATE=20011128, START_SECS=43200      integer, parameter :: STOP_DATE=20041201, STOP_SECS=1200      integer, parameter :: DAY_INC=6, SEC_INC=43200      integer :: retCalDate, retDays, retSecs      logical :: test, isLater      type(MFM_Date) :: startDateG, stopDateG, retDateG      type(MFM_Date) :: startDateN, stopDateN, retDateN      type(MFM_Date) :: copy      type(MFM_Time) :: incTime, retTime      type(MFM_Date) :: calDayTester      real(8) :: floatDay, floatTest      character(60) :: str      print *, "=================================================="      print *, "MFM_Date F90 Unit Tests and Examples"      print *, "=================================================="      startDateG = MFM_DateInit(MFM_GREGORIAN, START_DATE, START_SECS)       stopDateG = MFM_DateInit(MFM_GREGORIAN, STOP_DATE, STOP_SECS)      retDateG = MFM_DateInit()       startDateN = MFM_DateInit(MFM_NO_LEAP, START_DATE, START_SECS)       stopDateN = MFM_DateInit(MFM_NO_LEAP, STOP_DATE, STOP_SECS)      retDateN = MFM_DateInit()       copy = MFM_DateCopyInit(stopDateG)      incTime = MFM_TimeInit(DAY_INC, SEC_INC)       retTime = MFM_TimeInit()      call MFM_DateGet(startDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs       test = ((retCalDate==START_DATE) .AND. (retSecs==START_SECS))      str = "MFM_DateInit, MFM_DateGet:  init date and get attr"      call MFM_ErrorTest(test, str)      call MFM_DateGet(copy, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs       test = ((retCalDate==STOP_DATE) .AND. (retSecs==STOP_SECS))      str = "MFM_CopyInit:  init date and get attr"      call MFM_ErrorTest(test, str)      call MFM_DateCopy(copy, startDateG)      call MFM_DateGet(copy, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs       test = ((retCalDate==START_DATE) .AND. (retSecs==START_SECS))      str = "MFM_DateCopy:  copy date"      call MFM_ErrorTest(test, str)      retDateG = MFM_DateIncrementSec(startDateG, SEC_INC)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs       test = ((retCalDate==20011129) .AND. (retSecs==0))      str = "MFM_DateIncrementSec:  increment Gregorian date by seconds"        call MFM_ErrorTest(test, str)      retDateG = MFM_DateIncrementDay(startDateG, DAY_INC)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs       test = ((retCalDate==20011204) .AND. (retSecs==43200))      str = "MFM_DateIncrementDay:  increment Gregorian date by days"        call MFM_ErrorTest(test, str)      retDateG = MFM_DateIncrement(startDateG, incTime)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011205) .AND. (retSecs==0))      str = "MFM_DateIncrement:  increment Gregorian date"      call MFM_ErrorTest(test, str)      retDateG = MFM_DateDecrement(retDateG, incTime)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011128) .AND. (retSecs==43200))      str = "MFM_DateDecrement:  decrement Gregorian date in place"      call MFM_ErrorTest(test, str)      call MFM_DateDiff(startDateG, stopDateG, retTime, isLater)      call MFM_TimeGet(retTime, retDays, retSecs)      print *, "Ret days ", retDays, " Ret secs ",      &         retSecs, "isLater", isLater       test = ((retDays==1098) .AND. (retSecs==44400)      &       .AND. (isLater))      print *, "test", test      str = "MFM_DateDiff:  diff of two Gregorian dates"      call MFM_ErrorTest(test, str)      call MFM_TimeSet(incTime, 1098, 44400)      retDateG = MFM_DateDecrement(stopDateG, incTime)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011128) .AND. (retSecs==43200))      str = "MFM_DateDecrement:  decrement Gregorian date"      call MFM_ErrorTest(test, str)      call MFM_TimeSet(incTime, DAY_INC, SEC_INC)      retDateN = MFM_DateIncrement(startDateN, incTime)      call MFM_DateGet(retDateN, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011205) .AND. (retSecs==0))      str = "MFM_DateIncrement:  increment no leap date"      call MFM_ErrorTest(test, str)      retDateN = MFM_DateDecrement(retDateN, incTime)      call MFM_DateGet(retDateN, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011128) .AND. (retSecs==43200))      str = "MFM_DateDecrement:  decrement no leap date in place"      call MFM_ErrorTest(test, str)      call MFM_DateDiff(startDateN, stopDateN, retTime, isLater)      call MFM_TimeGet(retTime, retDays, retSecs)      print *, "Ret days ", retDays, " Ret secs ", retSecs,     &         "isLater", isLater      test = ((retDays==1097) .AND. (retSecs==44400)      &       .AND. (isLater))      str = "MFM_DateDiff:  diff of two no leap dates"      call MFM_ErrorTest(test, str)      call MFM_DateSet(startDateN, MFM_NO_LEAP, 19700101, 0)       call MFM_DateSet(stopDateN, MFM_NO_LEAP, 19710101, 0)      call MFM_DateDiff(startDateN, stopDateN, retTime, isLater)      call MFM_TimeGet(retTime, retDays, retSecs)      print *, "Ret days ", retDays, " Ret secs ", retSecs,     &         "isLater", isLater      test = ((retDays==365) .AND. (retSecs==0)      &       .AND. (isLater))      str = "MFM_DateDiff:  diff of two no leap dates"      call MFM_ErrorTest(test, str)      call MFM_DateSet(startDateN, MFM_NO_LEAP, 20011128, 43200)       call MFM_DateSet(stopDateN, MFM_NO_LEAP, 20041201, 1200)      call MFM_TimeSet(incTime, 1097, 44400)      retDateN = MFM_DateDecrement(stopDateN, incTime)      call MFM_DateGet(retDateN, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20011128) .AND. (retSecs==43200))      str = "MFM_DateDecrement:  decrement no leap date"      call MFM_ErrorTest(test, str)      call MFM_DateSet(retDateN, MFM_NO_LEAP, 20031224, 3500)      call MFM_DateGet(retDateN, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20031224) .AND. (retSecs==3500))      str = "MFM_DateSet:  set a no leap date"      call MFM_ErrorTest(test, str)                  call MFM_DateIsLater(startDateG, stopDateG, isLater)      print *, "isLater", isLater      test = isLater      str = "MFM_DateIsLater:  compare Gregorian dates (true result)"      call MFM_ErrorTest(test, str)      call MFM_DateIsLater(stopDateG, startDateG, isLater)      test = .NOT. isLater      str = "MFM_DateIsLater:  compare Gregorian dates (false result)"      call MFM_ErrorTest(test, str)      call MFM_DateSet(startDateG, MFM_GREGORIAN, 20011031, 0)      retDateG = MFM_DateIncrementMonth(startDateG, 4)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20020228) .AND. (retSecs==0))      str = "MFM_DateIncrementMonth:  handle invalid day"      call MFM_ErrorTest(test, str)            call MFM_DateSet(startDateG, MFM_GREGORIAN, 20040229, 0)      retDateG = MFM_DateIncrementYear(startDateG, 1)      call MFM_DateGet(retDateG, retCalDate, retSecs)      print *, "Ret date ", retCalDate, " Ret secs ", retSecs      test = ((retCalDate==20050228) .AND. (retSecs==0))      str = "MFM_DateIncrementYear:  handle invalid day"      call MFM_ErrorTest(test, str)            call MFM_DatePrint(startDateG)      calDayTester = MFM_DateInit(MFM_GREGORIAN, START_DATE, START_SECS)      print *, "Calendar Day Test"      call MFM_DatePrint(calDayTester)      floatDay = MFM_DateGetFltDayOfYear(calDayTester)      call MFM_DateGet(calDayTester, retCalDate, retSecs)      retDays = MFM_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.00001)      str = "MFM_DateFltDayOfYear:  return correct days.seconds"      call MFM_ErrorTest(test, str)            end program main !\end{verbatim}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -