G.1.1 Initialize_Mathematic_Vector Procedure

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

  subroutine Initialize_Mathematic_Vector (MV, Structure, Name, status)

    ! Use associations.

    use Caesar_Flags_Module, only: initialized_flag

    ! Use association information.

    use Caesar_Numbers_Module, only: zero 

    ! Input variables.

    ! Base_Structure.
    type(Base_Structure_type), intent(in), target :: Structure
    type(character,*), intent(in), optional :: Name     ! Variable name.

    ! Output variables.

    ! Mathematic_Vector to be initialized.
    type(Mathematic_Vector_type), intent(out) :: MV 
    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

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

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

    ! Verify requirements.

    VERIFY(Valid_State(Structure),5)  ! Structure is valid.

    ! Set up structure pointer.

    MV%Structure => Structure

    ! Allocations and initializations.

    call Initialize (allocate_status)
    call Initialize (consolidated_status)
    call Initialize (MV%Values, Length_PE(Structure), allocate_status(1))

    ! Set up internals.

    if (PRESENT(Name)) MV%Name = Name
    call Initialize (MV%Average,                  allocate_status(2))
    call Initialize (MV%Average_is_Updated,       allocate_status(3))
    call Initialize (MV%Infinity_Norm,            allocate_status(4))
    call Initialize (MV%Infinity_Norm_is_Updated, allocate_status(5))
    call Initialize (MV%Maximum,                  allocate_status(6))
    call Initialize (MV%Maximum_is_Updated,       allocate_status(7))
    call Initialize (MV%Minimum,                  allocate_status(8))
    call Initialize (MV%Minimum_is_Updated,       allocate_status(9))
    call Initialize (MV%One_Norm,                 allocate_status(10))
    call Initialize (MV%One_Norm_is_Updated,      allocate_status(11))
    call Initialize (MV%DV_is_Updated,            allocate_status(12))
    call Initialize (MV%P_Norm,                   allocate_status(13))
    call Initialize (MV%P_Norm_Exponent,          allocate_status(14))
    call Initialize (MV%P_Norm_is_Updated,        allocate_status(15))
    call Initialize (MV%Sum,                      allocate_status(16))
    call Initialize (MV%Sum_is_Updated,           allocate_status(17))
    call Initialize (MV%Two_Norm,                 allocate_status(18))
    call Initialize (MV%Two_Norm_is_Updated,      allocate_status(19))

    ! Make sure that initial values are correct.

    MV%Average = zero
    MV%Average_is_Updated = .false.
    MV%Infinity_Norm = zero
    MV%Infinity_Norm_is_Updated = .false.
    MV%Maximum = zero
    MV%Maximum_is_Updated = .false.
    MV%Minimum = zero
    MV%Minimum_is_Updated = .false.
    MV%One_Norm = zero
    MV%One_Norm_is_Updated = .false.
    MV%DV_is_Updated = .false.
    MV%P_Norm = zero
    MV%P_Norm_Exponent = 1
    MV%P_Norm_is_Updated = .false.
    MV%Sum = zero
    MV%Sum_is_Updated = .false.
    MV%Two_Norm = zero
    MV%Two_Norm_is_Updated = .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.

    MV%Initialized = initialized_flag

    ! Verify guarantees.

    VERIFY(Valid_State(MV),5)     ! Mathematic_Vector is now valid.

    return
  end subroutine Initialize_Mathematic_Vector



Michael L. Hall