2 !==============================================================================
4 ! ESMF TimeInterval Module
5 module WRF_ESMF_TimeIntervalMod
7 !==============================================================================
9 ! This file contains the TimeInterval class definition and all TimeInterval
12 !------------------------------------------------------------------------------
14 #include <ESMF_TimeMgr.inc>
16 !===============================================================================
18 ! !MODULE: WRF_ESMF_TimeIntervalMod
21 ! Part of Time Manager F90 API wrapper of C++ implemenation
23 ! Defines F90 wrapper entry points for corresponding
24 ! C++ implementaion of class {\tt ESMC\_TimeInterval}
26 ! See {\tt ../include/ESMC\_TimeInterval.h} for complete description
28 !------------------------------------------------------------------------------
30 ! inherit from ESMF base class
33 ! inherit from base time class
34 use WRF_ESMF_BaseTimeMod
36 ! associated derived types
37 use WRF_ESMF_FractionMod, only : ESMF_Fraction
38 use WRF_ESMF_CalendarMod
42 !------------------------------------------------------------------------------
45 !------------------------------------------------------------------------------
48 ! ! F90 class type to match C++ TimeInterval class in size only;
49 ! ! all dereferencing within class is performed by C++ implementation
51 type ESMF_TimeInterval
52 ! time interval is expressed as basetime
53 type(ESMF_BaseTime) :: basetime ! inherit base class
54 ! Relative year and month fields support monthly or yearly time
55 ! intervals. Many operations are undefined when these fields are
57 INTEGER :: YR ! relative year
58 !jm Month has no meaning for an interval; get rid of it, 20100319
59 ! INTEGER :: MM ! relative month
62 !------------------------------------------------------------------------------
64 public ESMF_TimeInterval
65 !------------------------------------------------------------------------------
67 ! !PUBLIC MEMBER FUNCTIONS:
68 public ESMF_TimeIntervalGet
69 public ESMF_TimeIntervalSet
70 public ESMFold_TimeIntervalGetString
71 public ESMF_TimeIntervalAbsValue
72 public ESMF_TimeIntervalNegAbsValue
74 ! Required inherited and overridden ESMF_Base class methods
76 !!!!!!!!! added 20051012, JM
77 ! public WRFADDITION_TimeIntervalDIVQuot
78 !!!!!!!!! renamed to simplify testing 20060320, TH
79 public ESMF_TimeIntervalDIVQuot
81 ! This convenience routine is only used by other modules in
83 public ESMF_TimeIntervalIsPositive
86 ! !PRIVATE MEMBER FUNCTIONS:
88 ! overloaded operator functions
91 private ESMF_TimeIntervalQuotI
94 private ESMF_TimeIntervalProdI
96 ! Inherited and overloaded from ESMF_BaseTime
99 private ESMF_TimeIntervalSum
102 private ESMF_TimeIntervalDiff
104 public operator(.EQ.)
105 private ESMF_TimeIntervalEQ
107 public operator(.NE.)
108 private ESMF_TimeIntervalNE
110 public operator(.LT.)
111 private ESMF_TimeIntervalLT
113 public operator(.GT.)
114 private ESMF_TimeIntervalGT
116 public operator(.LE.)
117 private ESMF_TimeIntervalLE
119 public operator(.GE.)
120 private ESMF_TimeIntervalGE
123 !==============================================================================
127 !==============================================================================
130 interface operator(*)
132 ! !PRIVATE MEMBER FUNCTIONS:
133 module procedure ESMF_TimeIntervalProdI
136 ! This interface overloads the * operator for the {\tt ESMF\_TimeInterval}
142 !------------------------------------------------------------------------------
145 interface operator(/)
147 ! !PRIVATE MEMBER FUNCTIONS:
148 module procedure ESMF_TimeIntervalQuotI
151 ! This interface overloads the / operator for the
152 ! {\tt ESMF\_TimeInterval} class
157 !------------------------------------------------------------------------------
160 interface operator(+)
162 ! !PRIVATE MEMBER FUNCTIONS:
163 module procedure ESMF_TimeIntervalSum
166 ! This interface overloads the + operator for the
167 ! {\tt ESMF\_TimeInterval} class
172 !------------------------------------------------------------------------------
175 interface operator(-)
177 ! !PRIVATE MEMBER FUNCTIONS:
178 module procedure ESMF_TimeIntervalDiff
181 ! This interface overloads the - operator for the
182 ! {\tt ESMF\_TimeInterval} class
187 !------------------------------------------------------------------------------
190 interface operator(.EQ.)
192 ! !PRIVATE MEMBER FUNCTIONS:
193 module procedure ESMF_TimeIntervalEQ
196 ! This interface overloads the .EQ. operator for the
197 ! {\tt ESMF\_TimeInterval} class
202 !------------------------------------------------------------------------------
205 interface operator(.NE.)
207 ! !PRIVATE MEMBER FUNCTIONS:
208 module procedure ESMF_TimeIntervalNE
211 ! This interface overloads the .NE. operator for the
212 ! {\tt ESMF\_TimeInterval} class
217 !------------------------------------------------------------------------------
220 interface operator(.LT.)
222 ! !PRIVATE MEMBER FUNCTIONS:
223 module procedure ESMF_TimeIntervalLT
226 ! This interface overloads the .LT. operator for the
227 ! {\tt ESMF\_TimeInterval} class
232 !------------------------------------------------------------------------------
235 interface operator(.GT.)
237 ! !PRIVATE MEMBER FUNCTIONS:
238 module procedure ESMF_TimeIntervalGT
241 ! This interface overloads the .GT. operator for the
242 ! {\tt ESMF\_TimeInterval} class
247 !------------------------------------------------------------------------------
250 interface operator(.LE.)
252 ! !PRIVATE MEMBER FUNCTIONS:
253 module procedure ESMF_TimeIntervalLE
256 ! This interface overloads the .LE. operator for the
257 ! {\tt ESMF\_TimeInterval} class
262 !------------------------------------------------------------------------------
265 interface operator(.GE.)
267 ! !PRIVATE MEMBER FUNCTIONS:
268 module procedure ESMF_TimeIntervalGE
271 ! This interface overloads the .GE. operator for the
272 ! {\tt ESMF\_TimeInterval} class
277 !------------------------------------------------------------------------------
279 !==============================================================================
283 !==============================================================================
285 ! Generic Get/Set routines which use F90 optional arguments
287 !------------------------------------------------------------------------------
289 ! !IROUTINE: ESMF_TimeIntervalGet - Get value in user-specified units
292 subroutine ESMF_TimeIntervalGet(timeinterval, D, d_r8, S, S_i8, Sn, Sd, &
296 type(ESMF_TimeInterval), intent(in) :: timeinterval
297 integer, intent(out), optional :: D
298 real(ESMF_KIND_R8), intent(out), optional :: d_r8
299 integer(ESMF_KIND_I8), intent(out), optional :: S_i8
300 integer, intent(out), optional :: S
301 integer, intent(out), optional :: Sn
302 integer, intent(out), optional :: Sd
303 character*(*), optional, intent(out) :: TimeString
304 integer, intent(out), optional :: rc
308 ! Get the value of the {\tt ESMF\_TimeInterval} in units specified by the
309 ! user via F90 optional arguments.
311 ! Time manager represents and manipulates time internally with integers
312 ! to maintain precision. Hence, user-specified floating point values are
313 ! converted internally from integers.
315 ! See {\tt ../include/ESMC\_BaseTime.h} and
316 ! {\tt ../include/ESMC\_TimeInterval.h} for complete description.
319 ! \begin{description}
320 ! \item[timeinterval]
321 ! The object instance to query
323 ! Integer years (>= 32-bit)
325 ! Integer years (large, >= 64-bit)
327 ! Integer months (>= 32-bit)
329 ! Integer months (large, >= 64-bit)
331 ! Integer days (>= 32-bit)
333 ! Integer days (large, >= 64-bit)
339 ! Integer seconds (>= 32-bit)
341 ! Integer seconds (large, >= 64-bit)
343 ! Integer milliseconds
345 ! Integer microseconds
347 ! Integer nanoseconds
349 ! Double precision days
351 ! Double precision hours
353 ! Double precision minutes
355 ! Double precision seconds
357 ! Double precision milliseconds
359 ! Double precision microseconds
361 ! Double precision nanoseconds
363 ! Integer fractional seconds - numerator
365 ! Integer fractional seconds - denominator
367 ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
373 ! Added argument to output double precision seconds, S_i8
374 ! William.Gustafson@pnl.gov; 9-May-2008
377 INTEGER(ESMF_KIND_I8) :: seconds
381 seconds = timeinterval%basetime%S
382 ! note that S is overwritten below (if present) if other args are also
384 IF ( PRESENT(S) ) S = seconds
385 IF ( PRESENT(S_i8) ) S_i8 = seconds
386 IF ( PRESENT( D ) ) THEN
387 D = seconds / SECONDS_PER_DAY
388 IF ( PRESENT(S) ) S = MOD( seconds, SECONDS_PER_DAY )
389 IF ( PRESENT(S_i8) ) S_i8 = MOD( seconds, SECONDS_PER_DAY )
391 IF ( PRESENT( d_r8 ) ) THEN
392 D_r8 = REAL( seconds, ESMF_KIND_R8 ) / &
393 REAL( SECONDS_PER_DAY, ESMF_KIND_R8 )
394 IF ( PRESENT(S) ) S = MOD( seconds, SECONDS_PER_DAY )
395 IF ( PRESENT(S_i8) ) S_i8 = MOD( seconds, SECONDS_PER_DAY )
397 IF ( PRESENT(Sn) ) THEN
398 Sn = timeinterval%basetime%Sn
400 IF ( PRESENT(Sd) ) THEN
401 Sd = timeinterval%basetime%Sd
403 IF ( PRESENT( timeString ) ) THEN
404 CALL ESMFold_TimeIntervalGetString( timeinterval, timeString, rc=ierr )
406 IF ( PRESENT(rc) ) rc = ierr
408 end subroutine ESMF_TimeIntervalGet
410 !------------------------------------------------------------------------------
412 ! !IROUTINE: ESMF_TimeIntervalSet - Initialize via user-specified unit set
415 subroutine ESMF_TimeIntervalSet(timeinterval, YY, YYl, MM, MOl, D, Dl, &
416 H, M, S, Sl, MS, US, NS, &
417 d_, h_, m_, s_, ms_, us_, ns_, &
421 type(ESMF_TimeInterval), intent(out) :: timeinterval
422 integer, intent(in), optional :: YY
423 integer(ESMF_KIND_I8), intent(in), optional :: YYl
424 integer, intent(in), optional :: MM
425 integer(ESMF_KIND_I8), intent(in), optional :: MOl
426 integer, intent(in), optional :: D
427 integer(ESMF_KIND_I8), intent(in), optional :: Dl
428 integer, intent(in), optional :: H
429 integer, intent(in), optional :: M
430 integer, intent(in), optional :: S
431 integer(ESMF_KIND_I8), intent(in), optional :: Sl
432 integer, intent(in), optional :: MS
433 integer, intent(in), optional :: US
434 integer, intent(in), optional :: NS
435 double precision, intent(in), optional :: d_
436 double precision, intent(in), optional :: h_
437 double precision, intent(in), optional :: m_
438 double precision, intent(in), optional :: s_
439 double precision, intent(in), optional :: ms_
440 double precision, intent(in), optional :: us_
441 double precision, intent(in), optional :: ns_
442 integer, intent(in), optional :: Sn
443 integer, intent(in), optional :: Sd
444 integer, intent(out), optional :: rc
449 ! Set the value of the {\tt ESMF\_TimeInterval} in units specified by
450 ! the user via F90 optional arguments
452 ! Time manager represents and manipulates time internally with integers
453 ! to maintain precision. Hence, user-specified floating point values are
454 ! converted internally to integers.
456 ! See {\tt ../include/ESMC\_BaseTime.h} and
457 ! {\tt ../include/ESMC\_TimeInterval.h} for complete description.
460 ! \begin{description}
461 ! \item[timeinterval]
462 ! The object instance to initialize
464 ! Integer number of interval years (>= 32-bit)
466 ! Integer number of interval years (large, >= 64-bit)
468 ! Integer number of interval months (>= 32-bit)
470 ! Integer number of interval months (large, >= 64-bit)
472 ! Integer number of interval days (>= 32-bit)
474 ! Integer number of interval days (large, >= 64-bit)
480 ! Integer seconds (>= 32-bit)
482 ! Integer seconds (large, >= 64-bit)
484 ! Integer milliseconds
486 ! Integer microseconds
488 ! Integer nanoseconds
490 ! Double precision days
492 ! Double precision hours
494 ! Double precision minutes
496 ! Double precision seconds
498 ! Double precision milliseconds
500 ! Double precision microseconds
502 ! Double precision nanoseconds
504 ! Integer fractional seconds - numerator
506 ! Integer fractional seconds - denominator
508 ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
515 IF ( PRESENT(rc) ) rc = ESMF_FAILURE
516 ! note that YR and MM are relative
518 IF ( PRESENT( YY ) ) THEN
521 !jm timeinterval%MM = 0
522 !jm IF ( PRESENT( MM ) ) THEN
523 !jm timeinterval%MM = MM
525 !jm ! Rollover months to years
526 !jm IF ( abs(timeinterval%MM) .GE. MONTHS_PER_YEAR ) THEN
527 !jm timeinterval%YR = timeinterval%YR + timeinterval%MM/MONTHS_PER_YEAR
528 !jm timeinterval%MM = mod(timeinterval%MM,MONTHS_PER_YEAR)
531 timeinterval%basetime%S = 0
532 ! For 365-day calendar, immediately convert years to days since we know
533 ! how to do it in this case.
534 !$$$ replace this hack with something saner...
535 IF ( nfeb( 2004 ) == 28 ) THEN
536 timeinterval%basetime%S = timeinterval%basetime%S + &
537 ( 365_ESMF_KIND_I8 * &
538 INT( timeinterval%YR, ESMF_KIND_I8 ) * SECONDS_PER_DAY )
541 IF ( PRESENT( D ) ) THEN
542 timeinterval%basetime%S = timeinterval%basetime%S + &
543 ( SECONDS_PER_DAY * INT( D, ESMF_KIND_I8 ) )
545 !$$$ Push H,M,S,Sn,Sd,MS down into BaseTime constructor from EVERYWHERE
546 !$$$ and THEN add ESMF scaling behavior when other args are present...
547 IF ( PRESENT( H ) ) THEN
548 timeinterval%basetime%S = timeinterval%basetime%S + &
549 ( SECONDS_PER_HOUR * INT( H, ESMF_KIND_I8 ) )
551 IF ( PRESENT( M ) ) THEN
552 timeinterval%basetime%S = timeinterval%basetime%S + &
553 ( SECONDS_PER_MINUTE * INT( M, ESMF_KIND_I8 ) )
555 IF ( PRESENT( S ) ) THEN
556 timeinterval%basetime%S = timeinterval%basetime%S + &
557 INT( S, ESMF_KIND_I8 )
559 IF ( PRESENT( Sn ) .AND. ( .NOT. PRESENT( Sd ) ) ) THEN
560 CALL wrf_error_fatal( &
561 "ESMF_TimeIntervalSet: Must specify Sd if Sn is specified")
563 IF ( PRESENT( Sd ) .AND. PRESENT( MS ) ) THEN
564 CALL wrf_error_fatal( &
565 "ESMF_TimeIntervalSet: Must not specify both Sd and MS")
567 timeinterval%basetime%Sn = 0
568 timeinterval%basetime%Sd = 0
569 IF ( PRESENT( MS ) ) THEN
570 timeinterval%basetime%Sn = MS
571 timeinterval%basetime%Sd = 1000_ESMF_KIND_I8
572 ELSE IF ( PRESENT( Sd ) ) THEN
573 timeinterval%basetime%Sd = Sd
574 IF ( PRESENT( Sn ) ) THEN
575 timeinterval%basetime%Sn = Sn
578 CALL normalize_timeint( timeinterval )
580 IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
582 end subroutine ESMF_TimeIntervalSet
584 !------------------------------------------------------------------------------
586 ! !IROUTINE: ESMFold_TimeIntervalGetString - Get time interval value in string format
589 subroutine ESMFold_TimeIntervalGetString(timeinterval, TimeString, rc)
592 type(ESMF_TimeInterval), intent(in) :: timeinterval
593 character*(*), intent(out) :: TimeString
594 integer, intent(out), optional :: rc
596 integer :: signnormtimeint
598 INTEGER(ESMF_KIND_I8) :: iS, iSn, iSd, H, M, S
599 character (len=1) :: signstr
602 ! Convert {\tt ESMF\_TimeInterval}'s value into string format
605 ! \begin{description}
606 ! \item[timeinterval]
607 ! The object instance to convert
609 ! The string to return
611 ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
618 ! NOTE: YR, MM, Sn, and Sd are not yet included in the returned string...
619 !PRINT *,'DEBUG ESMFold_TimeIntervalGetString(): YR,MM,S,Sn,Sd = ', &
622 ! timeinterval%basetime%S, &
623 ! timeinterval%basetime%Sn, &
624 ! timeinterval%basetime%Sd
626 negative = ( signnormtimeint( timeInterval ) == -1 )
628 iS = -timeinterval%basetime%S
629 iSn = -timeinterval%basetime%Sn
632 iS = timeinterval%basetime%S
633 iSn = timeinterval%basetime%Sn
636 iSd = timeinterval%basetime%Sd
638 H = mod( iS, SECONDS_PER_DAY ) / SECONDS_PER_HOUR
639 M = mod( iS, SECONDS_PER_HOUR) / SECONDS_PER_MINUTE
640 S = mod( iS, SECONDS_PER_MINUTE )
642 !$$$here... need to print Sn and Sd when they are used ???
644 write(TimeString,FMT="(A,I10.10,'_',I3.3,':',I3.3,':',I3.3)") &
645 TRIM(signstr), ( iS / SECONDS_PER_DAY ), H, M, S
647 !write(0,*)'TimeIntervalGetString Sn ',timeinterval%basetime%Sn,' Sd ',timeinterval%basetime%Sd
651 end subroutine ESMFold_TimeIntervalGetString
653 !------------------------------------------------------------------------------
655 ! !IROUTINE: ESMF_TimeIntervalAbsValue - Get the absolute value of a time interval
658 function ESMF_TimeIntervalAbsValue(timeinterval)
661 type(ESMF_TimeInterval) :: ESMF_TimeIntervalAbsValue
664 type(ESMF_TimeInterval), intent(in) :: timeinterval
669 ! Return a {\tt ESMF\_TimeInterval}'s absolute value.
672 ! \begin{description}
673 ! \item[timeinterval]
674 ! The object instance to take the absolute value of.
675 ! Absolute value returned as value of function.
681 CALL timeintchecknormalized( timeinterval, 'ESMF_TimeIntervalAbsValue arg1' )
682 ESMF_TimeIntervalAbsValue = timeinterval
683 !$$$here... move implementation into BaseTime
684 ESMF_TimeIntervalAbsValue%basetime%S = &
685 abs(ESMF_TimeIntervalAbsValue%basetime%S)
686 ESMF_TimeIntervalAbsValue%basetime%Sn = &
687 abs(ESMF_TimeIntervalAbsValue%basetime%Sn )
689 end function ESMF_TimeIntervalAbsValue
691 !------------------------------------------------------------------------------
693 ! !IROUTINE: ESMF_TimeIntervalNegAbsValue - Get the negative absolute value of a time interval
696 function ESMF_TimeIntervalNegAbsValue(timeinterval)
699 type(ESMF_TimeInterval) :: ESMF_TimeIntervalNegAbsValue
702 type(ESMF_TimeInterval), intent(in) :: timeinterval
707 ! Return a {\tt ESMF\_TimeInterval}'s negative absolute value.
710 ! \begin{description}
711 ! \item[timeinterval]
712 ! The object instance to take the negative absolute value of.
713 ! Negative absolute value returned as value of function.
719 CALL timeintchecknormalized( timeinterval, 'ESMF_TimeIntervalNegAbsValue arg1' )
721 ESMF_TimeIntervalNegAbsValue = timeinterval
722 !$$$here... move implementation into BaseTime
723 ESMF_TimeIntervalNegAbsValue%basetime%S = &
724 -abs(ESMF_TimeIntervalNegAbsValue%basetime%S)
725 ESMF_TimeIntervalNegAbsValue%basetime%Sn = &
726 -abs(ESMF_TimeIntervalNegAbsValue%basetime%Sn )
728 end function ESMF_TimeIntervalNegAbsValue
730 !------------------------------------------------------------------------------
732 ! This section includes overloaded operators defined only for TimeInterval
733 ! (not inherited from BaseTime)
734 ! Note: these functions do not have a return code, since F90 forbids more
735 ! than 2 arguments for arithmetic overloaded operators
737 !------------------------------------------------------------------------------
739 !!!!!!!!!!!!!!!!!! added jm 20051012
740 ! new WRF-specific function, Divide two time intervals and return the whole integer, without remainder
741 function ESMF_TimeIntervalDIVQuot(timeinterval1, timeinterval2)
744 INTEGER :: ESMF_TimeIntervalDIVQuot
747 type(ESMF_TimeInterval), intent(in) :: timeinterval1
748 type(ESMF_TimeInterval), intent(in) :: timeinterval2
751 INTEGER :: retval, isgn, rc
752 type(ESMF_TimeInterval) :: zero, i1,i2
755 ! Returns timeinterval1 divided by timeinterval2 as a fraction quotient.
758 ! \begin{description}
759 ! \item[timeinterval1]
761 ! \item[timeinterval2]
769 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalDIVQuot arg1' )
770 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalDIVQuot arg2' )
772 call ESMF_TimeIntervalSet( zero, rc=rc )
776 if ( i1 .LT. zero ) then
777 i1 = ESMF_TimeIntervalProdI(i1, -1)
780 if ( i2 .LT. zero ) then
781 i2 = ESMF_TimeIntervalProdI(i2, -1)
784 ! repeated subtraction
786 DO WHILE ( i1 .GE. i2 )
790 retval = retval * isgn
792 ESMF_TimeIntervalDIVQuot = retval
794 end function ESMF_TimeIntervalDIVQuot
799 !------------------------------------------------------------------------------
801 ! !IROUTINE: ESMF_TimeIntervalQuotI - Divide time interval by an integer, return time interval result
804 function ESMF_TimeIntervalQuotI(timeinterval, divisor)
807 type(ESMF_TimeInterval) :: ESMF_TimeIntervalQuotI
810 type(ESMF_TimeInterval), intent(in) :: timeinterval
811 integer, intent(in) :: divisor
814 ! Divides a {\tt ESMF\_TimeInterval} by an integer divisor, returns
815 ! quotient as a {\tt ESMF\_TimeInterval}
818 ! \begin{description}
819 ! \item[timeinterval]
826 ! TMG1.5.6, TMG5.3, TMG7.2
829 !PRINT *,'DEBUG ESMF_TimeIntervalQuotI() A: S,Sn,Sd = ', &
830 ! timeinterval%basetime%S,timeinterval%basetime%Sn,timeinterval%basetime%Sd
831 !PRINT *,'DEBUG ESMF_TimeIntervalQuotI() A: divisor = ', divisor
833 CALL timeintchecknormalized( timeinterval, 'ESMF_TimeIntervalQuotI arg1' )
835 IF ( divisor == 0 ) THEN
836 CALL wrf_error_fatal( 'ESMF_TimeIntervalQuotI: divide by zero' )
838 ESMF_TimeIntervalQuotI = timeinterval
839 !PRINT *,'DEBUG ESMF_TimeIntervalQuotI() B: S,Sn,Sd = ', &
840 ! ESMF_TimeIntervalQuotI%basetime%S,ESMF_TimeIntervalQuotI%basetime%Sn,ESMF_TimeIntervalQuotI%basetime%Sd
841 ESMF_TimeIntervalQuotI%basetime = &
842 timeinterval%basetime / divisor
843 !PRINT *,'DEBUG ESMF_TimeIntervalQuotI() C: S,Sn,Sd = ', &
844 ! ESMF_TimeIntervalQuotI%basetime%S,ESMF_TimeIntervalQuotI%basetime%Sn,ESMF_TimeIntervalQuotI%basetime%Sd
846 CALL normalize_timeint( ESMF_TimeIntervalQuotI )
847 !PRINT *,'DEBUG ESMF_TimeIntervalQuotI() D: S,Sn,Sd = ', &
848 ! ESMF_TimeIntervalQuotI%basetime%S,ESMF_TimeIntervalQuotI%basetime%Sn,ESMF_TimeIntervalQuotI%basetime%Sd
850 end function ESMF_TimeIntervalQuotI
852 !------------------------------------------------------------------------------
854 ! !IROUTINE: ESMF_TimeIntervalProdI - Multiply a time interval by an integer
857 function ESMF_TimeIntervalProdI(timeinterval, multiplier)
860 type(ESMF_TimeInterval) :: ESMF_TimeIntervalProdI
863 type(ESMF_TimeInterval), intent(in) :: timeinterval
864 integer, intent(in) :: multiplier
869 ! Multiply a {\tt ESMF\_TimeInterval} by an integer, return product as a
870 ! {\tt ESMF\_TimeInterval}
873 ! \begin{description}
874 ! \item[timeinterval]
883 CALL timeintchecknormalized( timeinterval, 'ESMF_TimeIntervalProdI arg1' )
885 CALL ESMF_TimeIntervalSet( ESMF_TimeIntervalProdI, rc=rc )
886 !$$$move this into overloaded operator(*) in BaseTime
887 ESMF_TimeIntervalProdI%basetime%S = &
888 timeinterval%basetime%S * INT( multiplier, ESMF_KIND_I8 )
889 ESMF_TimeIntervalProdI%basetime%Sn = &
890 timeinterval%basetime%Sn * INT( multiplier, ESMF_KIND_I8 )
892 ESMF_TimeIntervalProdI%basetime%Sd = timeinterval%basetime%Sd
893 CALL normalize_timeint( ESMF_TimeIntervalProdI )
895 end function ESMF_TimeIntervalProdI
897 !------------------------------------------------------------------------------
899 ! This section includes the inherited ESMF_BaseTime class overloaded operators
901 !------------------------------------------------------------------------------
903 ! !IROUTINE: ESMF_TimeIntervalSum - Add two time intervals together
906 function ESMF_TimeIntervalSum(timeinterval1, timeinterval2)
909 type(ESMF_TimeInterval) :: ESMF_TimeIntervalSum
912 type(ESMF_TimeInterval), intent(in) :: timeinterval1
913 type(ESMF_TimeInterval), intent(in) :: timeinterval2
917 ! Add two {\tt ESMF\_TimeIntervals}, return sum as a
918 ! {\tt ESMF\_TimeInterval}. Maps overloaded (+) operator interface
919 ! function to {\tt ESMF\_BaseTime} base class.
922 ! \begin{description}
923 ! \item[timeinterval1]
925 ! \item[timeinterval2]
930 ! TMG1.5.4, TMG2.4.4, TMG2.4.5, TMG2.4.6, TMG5.1, TMG5.2,
933 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalSum arg1' )
934 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalSum arg2' )
936 ESMF_TimeIntervalSum = timeinterval1
937 ESMF_TimeIntervalSum%basetime = ESMF_TimeIntervalSum%basetime + &
938 timeinterval2%basetime
940 CALL normalize_timeint( ESMF_TimeIntervalSum )
942 end function ESMF_TimeIntervalSum
944 !------------------------------------------------------------------------------
946 ! !IROUTINE: ESMF_TimeIntervalDiff - Subtract one time interval from another
949 function ESMF_TimeIntervalDiff(timeinterval1, timeinterval2)
952 type(ESMF_TimeInterval) :: ESMF_TimeIntervalDiff
955 type(ESMF_TimeInterval), intent(in) :: timeinterval1
956 type(ESMF_TimeInterval), intent(in) :: timeinterval2
960 ! Subtract timeinterval2 from timeinterval1, return remainder as a
961 ! {\tt ESMF\_TimeInterval}.
962 ! Map overloaded (-) operator interface function to {\tt ESMF\_BaseTime}
966 ! \begin{description}
967 ! \item[timeinterval1]
969 ! \item[timeinterval2]
974 ! TMG1.5.4, TMG2.4.4, TMG2.4.5, TMG2.4.6, TMG5.1, TMG5.2, TMG7.2
976 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalDiff arg1' )
977 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalDiff arg2' )
979 ESMF_TimeIntervalDiff = timeinterval1
980 ESMF_TimeIntervalDiff%basetime = ESMF_TimeIntervalDiff%basetime - &
981 timeinterval2%basetime
982 CALL normalize_timeint( ESMF_TimeIntervalDiff )
984 end function ESMF_TimeIntervalDiff
986 !------------------------------------------------------------------------------
988 ! !IROUTINE: ESMF_TimeIntervalEQ - Compare two time intervals for equality
991 function ESMF_TimeIntervalEQ(timeinterval1, timeinterval2)
994 logical :: ESMF_TimeIntervalEQ
997 type(ESMF_TimeInterval), intent(in) :: timeinterval1
998 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1001 ! Return true if both given time intervals are equal, false otherwise.
1002 ! Maps overloaded (==) operator interface function to {\tt ESMF\_BaseTime}
1005 ! The arguments are:
1006 ! \begin{description}
1007 ! \item[timeinterval1]
1008 ! First time interval to compare
1009 ! \item[timeinterval2]
1010 ! Second time interval to compare
1014 ! TMG1.5.3, TMG2.4.3, TMG7.2
1016 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalEQ arg1' )
1017 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalEQ arg2' )
1019 !$$$here... move all this out of Meat.F90 ?
1020 ! call ESMC_BaseTime base class function
1021 call c_ESMC_BaseTimeIntEQ(timeinterval1, timeinterval2, ESMF_TimeIntervalEQ)
1023 end function ESMF_TimeIntervalEQ
1025 !------------------------------------------------------------------------------
1027 ! !IROUTINE: ESMF_TimeIntervalNE - Compare two time intervals for inequality
1030 function ESMF_TimeIntervalNE(timeinterval1, timeinterval2)
1033 logical :: ESMF_TimeIntervalNE
1036 type(ESMF_TimeInterval), intent(in) :: timeinterval1
1037 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1040 ! Return true if both given time intervals are not equal, false otherwise.
1041 ! Maps overloaded (/=) operator interface function to {\tt ESMF\_BaseTime}
1044 ! The arguments are:
1045 ! \begin{description}
1046 ! \item[timeinterval1]
1047 ! First time interval to compare
1048 ! \item[timeinterval2]
1049 ! Second time interval to compare
1053 ! TMG1.5.3, TMG2.4.3, TMG7.2
1055 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalNE arg1' )
1056 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalNE arg2' )
1058 ! call ESMC_BaseTime base class function
1059 call c_ESMC_BaseTimeIntNE(timeinterval1, timeinterval2, ESMF_TimeIntervalNE)
1061 end function ESMF_TimeIntervalNE
1063 !------------------------------------------------------------------------------
1065 ! !IROUTINE: ESMF_TimeIntervalLT - Time interval 1 less than time interval 2 ?
1068 function ESMF_TimeIntervalLT(timeinterval1, timeinterval2)
1071 logical :: ESMF_TimeIntervalLT
1074 type(ESMF_TimeInterval), intent(in) :: timeinterval1
1075 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1078 ! Return true if first time interval is less than second time interval,
1079 ! false otherwise. Maps overloaded (<) operator interface function to
1080 ! {\tt ESMF\_BaseTime} base class.
1082 ! The arguments are:
1083 ! \begin{description}
1084 ! \item[timeinterval1]
1085 ! First time interval to compare
1086 ! \item[timeinterval2]
1087 ! Second time interval to compare
1091 ! TMG1.5.3, TMG2.4.3, TMG7.2
1093 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalLT arg1' )
1094 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalLT arg2' )
1096 ! call ESMC_BaseTime base class function
1097 call c_ESMC_BaseTimeIntLT(timeinterval1, timeinterval2, ESMF_TimeIntervalLT)
1099 end function ESMF_TimeIntervalLT
1101 !------------------------------------------------------------------------------
1103 ! !IROUTINE: ESMF_TimeIntervalGT - Time interval 1 greater than time interval 2?
1106 function ESMF_TimeIntervalGT(timeinterval1, timeinterval2)
1109 logical :: ESMF_TimeIntervalGT
1112 type(ESMF_TimeInterval), intent(in) :: timeinterval1
1113 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1116 ! Return true if first time interval is greater than second time interval,
1117 ! false otherwise. Maps overloaded (>) operator interface function to
1118 ! {\tt ESMF\_BaseTime} base class.
1120 ! The arguments are:
1121 ! \begin{description}
1122 ! \item[timeinterval1]
1123 ! First time interval to compare
1124 ! \item[timeinterval2]
1125 ! Second time interval to compare
1129 ! TMG1.5.3, TMG2.4.3, TMG7.2
1131 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalGT arg1' )
1132 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalGT arg2' )
1134 ! call ESMC_BaseTime base class function
1135 call c_ESMC_BaseTimeIntGT(timeinterval1, timeinterval2, ESMF_TimeIntervalGT)
1137 end function ESMF_TimeIntervalGT
1139 !------------------------------------------------------------------------------
1141 ! !IROUTINE: ESMF_TimeIntervalLE - Time interval 1 less than or equal to time interval 2 ?
1144 function ESMF_TimeIntervalLE(timeinterval1, timeinterval2)
1147 logical :: ESMF_TimeIntervalLE
1150 type(ESMF_TimeInterval), intent(in) :: timeinterval1
1151 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1154 ! Return true if first time interval is less than or equal to second time
1155 ! interval, false otherwise.
1156 ! Maps overloaded (<=) operator interface function to {\tt ESMF\_BaseTime}
1159 ! The arguments are:
1160 ! \begin{description}
1161 ! \item[timeinterval1]
1162 ! First time interval to compare
1163 ! \item[timeinterval2]
1164 ! Second time interval to compare
1168 ! TMG1.5.3, TMG2.4.3, TMG7.2
1170 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalLE arg1' )
1171 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalLE arg2' )
1173 ! call ESMC_BaseTime base class function
1174 call c_ESMC_BaseTimeIntLE(timeinterval1, timeinterval2, ESMF_TimeIntervalLE)
1176 end function ESMF_TimeIntervalLE
1178 !------------------------------------------------------------------------------
1180 ! !IROUTINE: ESMF_TimeIntervalGE - Time interval 1 greater than or equal to time interval 2 ?
1183 function ESMF_TimeIntervalGE(timeinterval1, timeinterval2)
1186 logical :: ESMF_TimeIntervalGE
1189 type(ESMF_TimeInterval), intent(in) :: timeinterval1
1190 type(ESMF_TimeInterval), intent(in) :: timeinterval2
1193 ! Return true if first time interval is greater than or equal to second
1194 ! time interval, false otherwise. Maps overloaded (>=) operator interface
1195 ! function to {\tt ESMF\_BaseTime} base class.
1197 ! The arguments are:
1198 ! \begin{description}
1199 ! \item[timeinterval1]
1200 ! First time interval to compare
1201 ! \item[timeinterval2]
1202 ! Second time interval to compare
1206 ! TMG1.5.3, TMG2.4.3, TMG7.2
1208 CALL timeintchecknormalized( timeinterval1, 'ESMF_TimeIntervalGE arg1' )
1209 CALL timeintchecknormalized( timeinterval2, 'ESMF_TimeIntervalGE arg2' )
1211 ! call ESMC_BaseTime base class function
1212 call c_ESMC_BaseTimeIntGE(timeinterval1, timeinterval2, ESMF_TimeIntervalGE)
1214 end function ESMF_TimeIntervalGE
1217 !------------------------------------------------------------------------------
1219 ! !IROUTINE: ESMF_TimeIntervalIsPositive - Time interval greater than zero?
1222 function ESMF_TimeIntervalIsPositive(timeinterval)
1225 logical :: ESMF_TimeIntervalIsPositive
1228 type(ESMF_TimeInterval), intent(in) :: timeinterval
1231 type(ESMF_TimeInterval) :: zerotimeint
1235 ! Return true if time interval is greater than zero,
1238 ! The arguments are:
1239 ! \begin{description}
1240 ! \item[timeinterval]
1241 ! Time interval to compare
1244 CALL timeintchecknormalized( timeinterval, &
1245 'ESMF_TimeIntervalIsPositive arg' )
1247 CALL ESMF_TimeIntervalSet ( zerotimeint, rc=rcint )
1248 IF ( rcint /= ESMF_SUCCESS ) THEN
1249 CALL wrf_error_fatal( &
1250 'ESMF_TimeIntervalIsPositive: ESMF_TimeIntervalSet failed' )
1252 ! hack for bug in PGI 5.1-x
1253 ! ESMF_TimeIntervalIsPositive = timeinterval > zerotimeint
1254 ESMF_TimeIntervalIsPositive = ESMF_TimeIntervalGT( timeinterval, &
1256 end function ESMF_TimeIntervalIsPositive
1258 end module WRF_ESMF_TimeIntervalMod