Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Need help on Read

anishtain4
Beginner
436 Views
Hi all
I want to read some data from a file, they are written in line but I don't know how many data may have been written on a line!!! total number of data is clear however. I can't find out how should I read them, as I remember we used \\ before to keep the cursure at the current position but I can't use it now (guess I'm getting old)

data are as:
0.00000e+000 3.33333e-001
1.00000e+000 1.00000e+000 0.00000e+000 3.33333e-001
3.33333e-001 6.66667e-001 3.33333e-001
6.66667e-001

code as I remember from before but is not working now:

...
do i=1,im
read(10,*)x(i),'\'
end do
....
0 Kudos
1 Solution
mecej4
Honored Contributor III
436 Views
Do not use non-standard extensions when there is a standard solution. (Ref: '')

There is no defined concept of a cursor in Fortran.

Try

read(10,*)(x(i),i=1,im)

Each READ statement causes one (or more, if needed to fill the I/O list) lines to be read. Putting the READ in a DO loop and reading only one item per loop execution causes data items 2, 3, ... on the input lines to be discarded.

View solution in original post

0 Kudos
3 Replies
mecej4
Honored Contributor III
437 Views
Do not use non-standard extensions when there is a standard solution. (Ref: '')

There is no defined concept of a cursor in Fortran.

Try

read(10,*)(x(i),i=1,im)

Each READ statement causes one (or more, if needed to fill the I/O list) lines to be read. Putting the READ in a DO loop and reading only one item per loop execution causes data items 2, 3, ... on the input lines to be discarded.
0 Kudos
anishtain4
Beginner
436 Views
Thanks, it worked perfectly for me, but just out of curiosity, how should I keep the I/O cursor at the current position when command is done?
0 Kudos
mecej4
Honored Contributor III
436 Views
Look up 'non-advancing I/O' (Fortran 9x and on) and 'stream access' (Fortran 2003+) in the documentation.

Be forewarned, however, that you seem to be going against the grain. Fortran has had for years a certain 'worldview' of how I/O is to be done. C has a quite different view. Mixing the two views in one's programs without completely thinking out the ramifications is going to cause trouble later.

0 Kudos
Reply