! This file: ! http://ftp.aset.psu.edu/pub/ger/fortran/hdk/AutomaticArray.f90 ! ! Two examples of how to allocate an automatic array in a subprogram. ! Automatic arrays must be allocated in subprograms. ! This program will compile with the F-compiler. ! This subject posted by Metcalf, et al. HDK - 5 January 2004. module autotest integer, public :: worksize end module autotest program AutoArray use autotest worksize=200 call aa() print *, " " call bb(worksize) contains subroutine aa() ! use of a module to define automatic array size. use autotest integer :: i real, dimension(worksize) :: x do i=1,worksize x(i)=I*0.25 end do print *, "Use of a module to define array size:" print *, "Worksize=",worksize print *, "X(worksize)=",x(worksize) end subroutine aa subroutine bb(size) ! use of an argument to define automatic array size. integer, intent(in) :: size integer :: i real, dimension(size) :: y do i=1,worksize y(i)=I*0.25 end do print *, "Use of a subprogram argument to define array size." print *, "size=",size print *, "y(size)=",y(size) end subroutine bb end program AutoArray