B.2.2 Finalize_Real Procedure

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

  subroutine Finalize_Real_0 (R, status)

    ! Use association information.

    use Caesar_Flags_Module, only: finalize_real_flag 

    ! Input/Output variable.

    type(real), intent(inout) :: R    ! Variable to be finalized.

    ! Output variable.

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

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

    ! Verify requirements - none.

    ! Finalization.

    R = finalize_real_flag

    ! No errors for finalization possible for scalars.

    if (PRESENT(status)) status = 'Success'

    ! Verify guarantees - none.

    return
  end subroutine Finalize_Real_0

  define([REPLICATE_ROUTINE],[
    subroutine Finalize_Real_$1 (R, status)
  
      ! Input/Output variable.
  
      type(real,$1) :: R                 ! Variable to be finalized.

      ! Output variable.

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

      ! Internal variable.

      type(integer) :: deallocate_status ! Deallocation Status.

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

      ! Verify requirements.

      VERIFY(ASSOCIATED(R),0)           ! R should be associated.
  
      ! Deallocation.
  
      DEALLOCATE(R, stat=deallocate_status)

      ! Finalization and nullification.

      NULLIFY(R)

      ! Verify guarantees and/or set status flag.

      if (PRESENT(status)) then
        WARN_IF(deallocate_status /= 0, 3)  ! Deallocation error check.
        WARN_IF(ASSOCIATED(R),3)            ! R is now unassociated.
        if (deallocate_status == 0 .and. .not.ASSOCIATED(R)) then
          status = 'Success'
        else
          status = 'Memory Error'
        end if
      else
        VERIFY(deallocate_status == 0, 0)  ! Deallocation error check.
        VERIFY(.not.ASSOCIATED(R), 0)      ! R is now unassociated.
      end if

      return
    end subroutine Finalize_Real_$1
  ])

  REPLICATE_ARRAYS



Michael L. Hall