The actual term Variable-Length Array occurs in the c99 standard,
and maps onto several Fortran concepts, the most relevant of
which is the automatic array (as opposed to the allocatable
array, discussed by the other respondants):
subroutine foo( n )
integer :: n
real :: a(n) !!! automatic array
!!! <executable code>
end
I'm not sure whether you were looking for the Fortran
equivalent of C's VLAs, or whether you were using the
term in a more generic manner.
-P.
On Sun, 24 Aug 2003, 11:20am +0200, [log in to unmask] wrote:
> > Is it possible to define arrays of variable length?
> > I explain better:
> > an array whose length is unknown because it will be "filled" if a
> > certain condition is satisfied. Below is an example (does not work):
> >
>
> Well, yes, but you must allocate the array before filling it with values.
> See the code below, that does work.
>
> Hope that helps,
>
> Mike Metcalf
>
> PROGRAM proof_array
> implicit none
> integer :: i,j,n
> integer,allocatable :: A(:)
> integer, dimension(10) :: B
> n=0
> do j=1,10,1
> if (j<6) then
> B(j)=j
> n=n+1
> endif
> enddo
> allocate(A(1:n))
> a(:n) = B(:n)
> write(*,100) A(:n)
> 100 format (I)
> END PROGRAM
>
--
Peter S. Shenkin Schrodinger, Inc.
VP, Software Development 120 W. 45th St., 32nd Floor
646 366 9555 x111 Tel New York, NY 10036
646 366 9550 FAX [log in to unmask]
http://www.schrodinger.com
Pre-arranged conf. calls: 702-759-8420 or 888-867-7084; passcode 646-366
|