- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
....
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
....
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page