H.1.2 Finalize_Monomial Procedure

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

  subroutine Finalize_Monomial (Monomial, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Monomial to be finalized.
    type(Monomial_type), intent(inout) :: Monomial  

    ! Output variables.

    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(10) :: deallocate_status !Deallocation Status.
    type(Status_type) :: consolidated_status             ! Consolidated Status.


    ! Verify requirements.

    VERIFY(Valid_State(Monomial),7) ! Monomial is valid.

    ! Unset initialization flag.

    Monomial%Initialized = uninitialized_flag

    ! Deallocations and finalizations.

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.

    call Finalize (Monomial%Exponent,    deallocate_status(1))
    call Finalize (Monomial%Coefficient, deallocate_status(2))
    call Finalize (Monomial%Phi_k,       deallocate_status(3))
    call Finalize (Monomial%Locus,       deallocate_status(4))
    call Finalize (Monomial%Name,        deallocate_status(5))
    if (Monomial%Derivative) then 
      call Finalize (Monomial%Phi_n,     deallocate_status(6))
    end if
    call Finalize (Monomial%Delta_t,     deallocate_status(7))
    call Finalize (Monomial%Variable,    deallocate_status(8))
    call Finalize (Monomial%Equation,    deallocate_status(9))
    call Finalize (Monomial%NEquations,  deallocate_status(10))

    ! Process status variables.

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

    ! Verify guarantees.

    VERIFY(.not.Valid_State(Monomial),7) ! Monomial is not valid.

  end subroutine Finalize_Monomial

Michael L. Hall