B.2.1 Initialize_Real Procedure

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

  subroutine Initialize_Real_0 (R, status)

    ! Use association information.

    use Caesar_Flags_Module, only: initialize_real_flag

    ! Output variables.

    type(real), intent(out) :: R        ! Variable to be initialized.
    type(Status_type), intent(out), optional :: status ! Exit status.

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

    ! Verify requirements - none.

    ! Initialize to flag value.

    R = initialize_real_flag

    ! No errors for initialization possible for scalars.

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

    ! Verify guarantees - none.

    return
  end subroutine Initialize_Real_0

  define([REPLICATE_ROUTINE],[
    subroutine Initialize_Real_$1 (R REP_ARGS([dim[]i]), status)

      ! Use association information.

      use Caesar_Flags_Module, only: initialize_real_flag

      ! Input variables.

      REP_DECLARE([type(integer), intent(in)], [dim[]i])  ! Array dimensions.

      ! Input/Output variable.

      type(real,$1) :: R                 ! Variable to be initialized.

      ! Output variable.

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

      ! Internal variable.

      type(integer) :: allocate_status   ! Allocation Status.

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

      ! Verify requirements.

      ! The association status of a unallocated pointer is officially 
      ! undefined according to the Fortran standard. With most compilers,
      ! the status is unassociated.
      ifelse(COMPILER, NAGWare,
        [], [
        VERIFY(.not.ASSOCIATED(R), 0)   ! R starts out unassociated.
      ])

      ! Allocation (for arrays only).

      REP_ALLOCATE([R], [dim[]i], [allocate_status])

      ! Initialize to flag value.

      R = initialize_real_flag

      ! Verify guarantees and/or set status flag.

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

      return
    end subroutine Initialize_Real_$1
  ])

  REPLICATE_ARRAYS



Michael L. Hall