The short answer is that there is no direct Fortran equivalent.
But there is nothing to stop you writing your own code to emulate
Matlabs behaviour.
A simple approach is to read the file twice. On the first pass count the
number of elements. Then allocate storage to hold the data. Then, on the
second pass read the data into the array(s).
Alternatively, you could use a one-pass reading scheme. Preallocate
storage. Read the data and reallocate if your preallocated storage is
inadequate.
And there are probably many other alternatives.
Behind the scenes I suspect Matlab implements a dynamic (re)allocation
scheme.
David.
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
|