Re: Read a list with undefined length



On Mar 25, 3:25 pm, Allamarein <matteo.diplom...@xxxxxxxxx> wrote:
When I use the READ statement, I use data file of this kind:

npts
25

x   y
2   5
7   9
10 13
....

In other words in the file the number of records is explicit (an
INTEGER variable).
I would not specify the number of records.
I am reading the CVF guide and I found this:
"err, end, eor
Are branch specifiers if an error (ERR=label), end-of-file
(END=label), or end-of-record (EOR=label) condition occurs.
EOR can only be specified for nonadvancing READ statements."

Could I use this optional input for my purpose?
I have just posed this question, but I need a more complete answer.
Thanks

Another possibility for reading a file without explicitly knowing the
number of data points is to inquire about the file size. Knowing the
file size and data type you can deduce the number of variables.
Example:

Say you have 2 variables of data written as 8-byte floating=>

integer,parameter :: dp = selected_real_kind(15) !Gives double
precision 8-byte
real(db),allocatable :: x(:),y(:)
integer :: fsize,fid,npnts
character(200) :: fname

open(newunit=fid,file=trim(fname),access='stream',form='unformatted')

inquire(fid,size=fsize) ! find file size. Typically file size is given
in bytes but check your compiler doc

npnts = fsize/(8*2) ! Divide by 8-bytes per data point * 2 variables -
gives # points per variable

allocate(x(npnts))
allocate(y(npnts))

Of course you will have to get ride of the "header" part of the file
that tells how many variables you have.

Mr. Herrmannsfeld idea about reading and processing individual points
is interesting. I typically read in all the data at once. With really
large data sets I could see how this could be very useful. Is there a
performance advantage (other than memory) to doing this?

Eric
.