ESMF_TimePrint Subroutine

public subroutine ESMF_TimePrint(time, keywordEnforcer, options, preString, unit, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Time), intent(in) :: time
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
character(len=*), intent(in), optional :: options
character(len=*), intent(in), optional :: preString
character(len=*), intent(out), optional :: unit
integer, intent(out), optional :: rc

Source Code

      subroutine ESMF_TimePrint(time, keywordEnforcer, options, preString, unit, rc)

! !ARGUMENTS:
      type(ESMF_Time),   intent(in)            :: time
      type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      character (len=*), intent(in),  optional :: options
      character(*),      intent(in),  optional :: preString
      character(*),      intent(out), optional :: unit
      integer,           intent(out), optional :: rc

!
! !DESCRIPTION:
!     Prints out the contents of an {\tt ESMF\_Time} to {\tt stdout}, in
!     support of testing and debugging.  The options control the type of
!     information and level of detail.  For options "string" and "string
!     isofrac", YYYY format returns at least 4 digits; years <= 999 are
!     padded on the left with zeroes and years >= 10000 return the number
!     of digits required. \\
!
!     The arguments are:
!     \begin{description}
!     \item[time]
!          The {\tt ESMF\_Time} to be printed out.
!     \item[{[options]}]
!          Print options. If none specified, prints all Time property values. \\
!          "string" - prints {\tt time}'s value in ISO 8601 format for all units
!                     through seconds.  For any non-zero fractional seconds,
!                     prints in integer rational fraction form n/d.  Format is
!                     YYYY-MM-DDThh:mm:ss[:n/d], where [:n/d] is the 
!                     integer numerator and denominator of the fractional
!                     seconds value, if present.  See ~\cite{ISO} and
!                     ~\cite{ISOnotes}.  See also method
!                     {\tt ESMF\_TimeGet(..., timeString= , ...)} \\
!          "string isofrac" - prints {\tt time}'s value in strict ISO 8601
!                     format for all units, including any fractional seconds
!                     part.  Format is YYYY-MM-DDThh:mm:ss[.f] where [.f]
!                     represents fractional seconds in decimal form, if present.
!                     See ~\cite{ISO} and ~\cite{ISOnotes}.  See also method
!                     {\tt ESMF\_TimeGet(..., timeStringISOFrac= , ...)} \\
!     \item[{[preString]}]
!          Optionally prepended string. Default to empty string.
!     \item[{[unit]}]
!          Internal unit, i.e. a string. Default to printing to stdout.
!     \item[{[rc]}]
!          Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     \end{description}
!
!EOP
! !REQUIREMENTS:
!     TMGn.n.n
      integer :: localrc                        ! local return code
      integer :: yy, mm, dd, h, m, s, ms
      logical :: underscore

      ! Assume failure until success
      if (present(rc)) rc = ESMF_RC_NOT_IMPL
      localrc = ESMF_RC_NOT_IMPL
   
      ! check input
      ESMF_INIT_CHECK_SHALLOW(ESMF_TimeGetInit,time,rc)

      underscore = .false.
      if (present(options)) then
        if (trim(options)=="underscore") underscore = .true.
      endif

      if (present(unit).or.present(preString)) then
        ! simple, single line print format
        call ESMF_TimeGet(time, yy=yy, mm=mm, dd=dd, h=h, m=m, s=s, ms=ms, &
          rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
        if (present(unit)) then
          if (underscore) then
            if (present(preString)) then
              write (unit, "(A, '_', I4.4, '_', I2.2, '_', I2.2, '_', I2.2, "//&
                "'_', I2.2, '_', I2.2, '_', I3.3)") preString, &
                yy, mm, dd, h, m, s, ms
            else
              write (unit, "(I4.4, '_', I2.2, '_', I2.2, '_', I2.2, "//&
                "'_', I2.2, '_', I2.2, '_', I3.3)") &
                yy, mm, dd, h, m, s, ms
            endif
          else
            if (present(preString)) then
              write (unit, "(A, I4, I3, I3, I3, I3, I3, I4)") preString, &
                yy, mm, dd, h, m, s, ms
            else
              write (unit, "(I4, I3, I3, I3, I3, I3, I4)") &
                yy, mm, dd, h, m, s, ms
            endif
          endif
        else
          if (present(preString)) then
            write (*, "(A, I4, I3, I3, I3, I3, I3, I4)") preString, &
              yy, mm, dd, h, m, s, ms
          else
            ! cannot really reach this branch -> cover this by the deeper
            ! implementation in the bigger else block below.
            write (*, "(I4, I3, I3, I3, I3, I3, I4)") &
              yy, mm, dd, h, m, s, ms
          endif
        endif        
      else
        ! print to STDOUT
        
        ! invoke C to C++ entry point
        call ESMF_UtilIOUnitFlush (ESMF_UtilIOStdout, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

        call c_ESMC_TimePrint(time, options, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      ! Return success
      if (present(rc)) rc = ESMF_SUCCESS
      end subroutine ESMF_TimePrint