Hello Yong Cheng:
One alternative would be to use the unix command "wc -l" in a system call:
CALL SYSTEM("wc -l "//yourfilename//" > number_of_lines")
open(1,number_of_lines,status="OLD")
read(1,*) n_lines
close(1)
allocate(your_array(nlines))
...
Not completely portable, but possible on many systems. Even on MS-Windows
boxes, it should be possible to use Cygwin32 or some other set of utilites
to emulate a "wc" (word-count) sort of function.
Ted
--
============================================================
Ted Stern Engineering Applications
Cray Inc. http://www.cray.com
411 First Avenue South, Suite 600 206-701-2182
Seattle, WA 98104-2860 FAX: 206-701-2500
============================================================
On Tue, 10 Jul 2001, 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
>
|