I like Alvaro Fernandez's idea. My suggestion is less creative and less general
but more simple (similar to Metcalf's suggestion). Which one works better will
depend of the problem at hand:
PROGRAM proof_array
implicit none
integer :: i,j,n
integer,allocatable :: A(:)
integer, dimension(10) :: B=(/(i, i=1,10,1)/)
n=0
do j=1,10,1
if (j<6) then
n=n+1
endif
enddo
allocate(A(1:n))
do j=1,10,1
if (j<6) then
A(j)=j
n=n+1
endif enddo
write(*,100) A
100 format (I)
END PROGRAM
----------------------------------------------------
Jose J. Canals-Cerda
Department of Economics
University of Colorado at Boulder
Campus Box 256
Boulder, Colorado 80309-0256
Phone: (303) 492-7869
Fax: (303) 492-8960
E-mail: [log in to unmask]
----------------------------------------------------
For art visit www.StudioArtworks.com
----------------------------------------------------
Quoting celevic <[log in to unmask]>:
> Hi!
> 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):
> Thank you,
> celevic
>
> PROGRAM proof_array
> implicit none
> integer :: i,j,n
> integer,allocatable :: A(:)
> integer, dimension(10) :: B=(/(i, i=1,10,1)/)
> n=0
> do j=1,10,1
> if (j<6) then
> A(j)=j
> n=n+1
> endif
> enddo
> allocate(A(1:n))
> write(*,100) A
> 100 format (I)
> END PROGRAM
>
|