Re: Read a list with undefined length



Dick Hendrickson wrote in message <8v4bdnF5laU1@xxxxxxxxxxxxxxxxxx>...
On 3/25/11 2:25 PM, Allamarein wrote:
When I use the READ statement, I use data file of this kind:

npts
25

x y
2 5
7 9
10 13

I'm not sure I completely understand your question, but the normal way
to do things like this is
integer :: npts, x(1000), y(1000)
read (unit,*) npts
if (npts > 1000) stop
read (unit, *) (x(i), y(i), i=1,npts)

[ or even
do i = 1,npts
read (unit,*) x(i), y(i)
enddo ]

Where you first read in the npts value and then use this to control a
loop. You pick dimensions for x and y that you are sure should be big
enough.

That is the old-fashioned FORTRAN 77 and earlier way.
Better to allocate an array of the exact size from npts.
Then the arrays x and y are handy to pass to subroutines.


.