module share ! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/dyng.f90 ! ! Example by Michael Metcalf of allocating a global array, A. ! Posted at comp.lang.fortran on 30 May 2000. real, dimension (:), public, allocatable :: A public :: sub contains subroutine sub (n) integer, intent(in) :: n integer :: err allocate ( A(n), stat=err) if (err /=0) print *, "allocate NOT done." end subroutine sub end module share program main use share integer :: n,i,err n=250000 call sub(n) do i=1,n A(i) = i end do print *, "A(1),A(",n,")=",A(1), A(n) deallocate (A, stat=err) if (err /= 0) print *, "deallocate NOT done." print *, "all done!" end program main