At 11:20 24-08-2003 +0200, Michael Metcalf 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) ! Is this F2K maybe ??
100 format(10I5)
>END PROGRAM
--
Met vriendelijke groet,
___ ___
/ \/ / /
__/ /__/
Jan van Oosterwijk
2264 TB Leidschendam
mailto: Jan.vanOosterwijk @ DTO.TUDelft.nl
mailto: Jan.vanOosterwijk @ HCCnet.nl
mailto: Jan.vanOosterwijk @ wanadoo.nl
|