F.1.1 Initialize_Timer Procedure

The main documentation of the Initialize_Timer Procedure contains additional explanation of this code listing.

  subroutine Initialize_Timer (Timer, Name, status)

    ! Use association information.

    use Caesar_Numbers_Module, only: zero

    ! Input variables.

    type(character,*), intent(in) :: Name  ! Timer name.

    ! Output variables.

    type(Timer_type), intent(out) :: Timer ! Timer to be initialized.
    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(5) :: allocate_status  ! Allocation Status.
    type(Status_type) :: consolidated_status            ! Consolidated Status.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ! Verify requirements.

    VERIFY(.not.Valid_State(Timer),5)    ! Timer is not valid.
    VERIFY(Valid_State(Name),5)          ! Name is valid.

    ! Allocations and initializations.

    call Initialize (allocate_status)
    call Initialize (consolidated_status)
    call Initialize (Timer%CPU_Time%Start, allocate_status(1))
    call Initialize (Timer%CPU_Time%Statistics, 'CPU Time', &
                     allocate_status(2))
    call Initialize (Timer%Wall_Clock_Time%Start, allocate_status(3))
    call Initialize (Timer%Wall_Clock_Time%Statistics, 'Wall Clock Time', &
                     allocate_status(4))
    call Initialize (Timer%Running, allocate_status(5))

    ! Set up internals.

    Timer%Name = Name

    ! Make sure that initial values are correct.

    Timer%CPU_Time%Start = zero
    Timer%Wall_Clock_Time%Start = zero
    Timer%Running = .false.

    ! Process status variables.

    consolidated_status = allocate_status
    if (PRESENT(status)) then
      WARN_IF(Error(consolidated_status), 5)
      status = consolidated_status
    else
      VERIFY(Normal(consolidated_status), 5)
    end if
    call Finalize (consolidated_status)
    call Finalize (allocate_status)

    ! Set initialization flag.

    call Initialize (Timer%Initialized, 0)

    ! Verify guarantees.

    VERIFY(Valid_State(Timer),5)     ! Timer is now valid.

    return
  end subroutine Initialize_Timer



Michael L. Hall