Manual Reference Pages  - allocated (3fortran)

NAME

ALLOCATED(3) - [ARRAY:INQUIRY] Allocation status of an allocatable entity

SYNOPSIS

result = allocated(array|scalar)

         logical function allocated(array,scalar)

type(TYPE(kind=**)),allocatable,optional :: array(..) type(TYPE(kind=**)),allocatable,optional :: scalar

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o ARRAY may be any allocatable array object of any type.
o SCALAR may be any allocatable scalar of any type.
o the result is a default logical scalar

DESCRIPTION

ALLOCATED(3) checks the allocation status of both arrays and scalars.

At least one and only one of ARRAY or SCALAR must be specified.

OPTIONS

o ENTITY : the allocatable object to test.

RESULT

If the argument is allocated then the result is .true.; otherwise, it returns .false..

EXAMPLES

Sample program:

    program demo_allocated
    use,intrinsic :: iso_fortran_env, only : dp=>real64,sp=>real32
    implicit none
    real(kind=sp), allocatable :: x(:)
    character(len=256) :: message
    integer :: istat
      ! basics
       if( allocated(x)) then
           write(*,*)’do things if allocated’
       else
           write(*,*)’do things if not allocated’
       endif

! if already allocated, deallocate if ( allocated(x) ) deallocate(x,STAT=istat, ERRMSG=message ) if(istat.ne.0)then write(*,*)trim(message) stop endif

! only if not allocated, allocate if ( .not. allocated(x) ) allocate(x(20))

! allocation and intent(out) call intentout(x) write(*,*)’note it is deallocated!’,allocated(x)

contains

subroutine intentout(arr) ! note that if arr has intent(out) and is allocatable, ! arr is deallocated on entry real(kind=sp),intent(out),allocatable :: arr(:) write(*,*)’note it was allocated in calling program’,allocated(arr) end subroutine intentout

end program demo_allocated

Results:

     >  do things if not allocated
     >  note it was allocated in calling program F
     >  note it is deallocated! F

STANDARD

Fortran 95. allocatable scalar entities were added in Fortran 2003.

SEE ALSO

MOVE_ALLOC(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 allocated (3fortran) April 28, 2024
Generated by manServer 1.08 from 9fbf176c-0b0d-4e8b-aaaa-8297a745acee using man macros.