If you have some idea of an upper limit you could allocate or declare
an array that is sure to be big enough. This will waste some memory,
but most computers now have lots of it so maybe it won't matter.
Then try non advancing reads in a DO loop. Something like
Real :: array (10000000000000) !or whatever fits
Do I = 1,10000000000000
read(unit,format,whatever_else,advance='NO',EOR=100) array(I)
enddo
print *, 'array too small'
stop
100 print *, 'array size is ',I-1
There's probably a type in that somewhere, but it should give you
an idea. Also, you could make the array a pointer array and allocate
a size. When you take the normal exit from the DO, meaning the array
was too small, allocate another, bigger, array. Copy the data from
the old small array to the new big array. Deallocate the small array,
repoint the old pointer to the new big array and go back to the DO
to read in the next 10000000000000 elements. Remembering to read into
I+10000000000000, not I. Complicated, but can probably save memory.
Hope this helps
Dick Hendrickson
Zhou Yong Cheng wrote:
>
> It's maybe a simple question. Suppose you have several data files, each
> of them have different length and will be read in by your program. Usually
> you have to specify the corresponding array length in your program
> otherwise you would run in trouble in read. I want to know if there is a
> mean in Fortran to read data file without specify the size, something like
> that in MATLAB:
>
> r1=myfile(:,1)
>
> or
>
> fscanf(fid,'%g %g',[2 inf]);
>
> Thus, all the data will be read in and we can get the size of array by
> simple command size(...).
>
> Many thanks.
>
> Yongcheng
|