- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using compaq fortran v6.6.
I am trying to use nonadvancing io in order to read in lines from files where the length of the line is unknown and may be very very long.
I have been trying to read in 1 character at a time using inside a do loop
read(10,fmt='(a1)',advance='no',iostat=iostatus,size=isize)ach
where ach is defined as a character and iostatus and isize are integers.
All my attempts have failed. The size parameter does not seem to produce a valid number and the read only ssems to read in the first character of a line and then only if that line begins with a character. It then looks for the next line begining with a character and just reads that character from the line.
If anyone has a working example I'd be most grateful or if they know if this is a known problem and where I can get the fix from.
Thanking you in anticipation
Colin
I am trying to use nonadvancing io in order to read in lines from files where the length of the line is unknown and may be very very long.
I have been trying to read in 1 character at a time using inside a do loop
read(10,fmt='(a1)',advance='no',iostat=iostatus,size=isize)ach
where ach is defined as a character and iostatus and isize are integers.
All my attempts have failed. The size parameter does not seem to produce a valid number and the read only ssems to read in the first character of a line and then only if that line begins with a character. It then looks for the next line begining with a character and just reads that character from the line.
If anyone has a working example I'd be most grateful or if they know if this is a known problem and where I can get the fix from.
Thanking you in anticipation
Colin
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's the value of iostatus after a read occurs?
Mike D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a small program, t1.f90, which reads its own first line using nonadvancing i/o. It is compiled in CVF 6.6C.
PROGRAM t1
IMPLICIT NONE
INTEGER :: istat, size, line_size = 0
CHARACTER(LEN=1) :: c
IMPLICIT NONE
INTEGER :: istat, size, line_size = 0
CHARACTER(LEN=1) :: c
OPEN (UNIT=1, FILE='t1.f90', ACTION='READ', STATUS='OLD')
DO
READ (1, '(A)', SIZE=size, IOSTAT=istat, ADVANCE="NO") c
IF (istat/=0) THEN
EXIT ! ---------------->
ENDIF
line_size = line_size + 1
WRITE (*, *) c, size, istat, line_size
END DO
READ (1, '(A)', SIZE=size, IOSTAT=istat, ADVANCE="NO") c
IF (istat/=0) THEN
EXIT ! ---------------->
ENDIF
line_size = line_size + 1
WRITE (*, *) c, size, istat, line_size
END DO
CLOSE (UNIT=1)
WRITE (*, *) 'End', size, istat, line_size
WRITE (*, *) 'End', size, istat, line_size
! Note that istat is -2 here. For "eof" it is -1.
END PROGRAM t1
Best wishes
Lars M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the sample program.
It is similar to the one I used which prompted my query except I distinguished between the values of iostat as I wanted to see if it reported an EOR or EOF on the final line of the file. The tests for the value of iostat where inside the do loop and on EOR I incremented the line count and looped back to read the next line whereas on EOF I exited from the do loop.
I ran your program on the following 4 line textfile:-
1234567890
z y,x
a1b2c3
I got the following screen output.
746135674 0 1
538976288 0 2
End 538976288 -1 2
I got similar output with my program.
However if I remove SIZE=size from the read statement then my program completely ignored the line of digits and read in the 'z' from the second line. It then read in the 'a' from the fourth line. Next it read in a space (not sure where that came from). Finally iostat got set to eof. No EOR was reported.
I am running the programs in a DOS box on Windows98 SE. I am using Compaq Visual Fortran 6.6.
I created the input text file in notepad.
Do you have any idea what is happening?
I was expecting the program to read each character on a line in turn, and then move onto the next line and read each of those characters in turn and so on until the end of the file was reached.
Thanks
Colin
It is similar to the one I used which prompted my query except I distinguished between the values of iostat as I wanted to see if it reported an EOR or EOF on the final line of the file. The tests for the value of iostat where inside the do loop and on EOR I incremented the line count and looped back to read the next line whereas on EOF I exited from the do loop.
I ran your program on the following 4 line textfile:-
1234567890
z y,x
a1b2c3
I got the following screen output.
746135674 0 1
538976288 0 2
End 538976288 -1 2
I got similar output with my program.
However if I remove SIZE=size from the read statement then my program completely ignored the line of digits and read in the 'z' from the second line. It then read in the 'a' from the fourth line. Next it read in a space (not sure where that came from). Finally iostat got set to eof. No EOR was reported.
I am running the programs in a DOS box on Windows98 SE. I am using Compaq Visual Fortran 6.6.
I created the input text file in notepad.
Do you have any idea what is happening?
I was expecting the program to read each character on a line in turn, and then move onto the next line and read each of those characters in turn and so on until the end of the file was reached.
Thanks
Colin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
iostat is -1 (EOF)
I ran the program on the following 4 line textfile (created with notepad)
1234567890
z y,x
a1b2c3
If i remove the size= from the read statement,
the program skipped the first line, read in the z from the second line, then the a from the fourth line, then read a space (I do not know where this came from) then
reported EOF.
If I keep the size= in the read statement, the program reads in a space, followed by another space, followed by EOF.
I am using Compaq Visual Fortran 6.6 from a DOS box in Windows98SE. The input textfile was created with notepad.
Do you have any idea what is going on?
Thanks
Colin
iostat is -1 (EOF)
I ran the program on the following 4 line textfile (created with notepad)
1234567890
z y,x
a1b2c3
If i remove the size= from the read statement,
the program skipped the first line, read in the z from the second line, then the a from the fourth line, then read a space (I do not know where this came from) then
reported EOF.
If I keep the size= in the read statement, the program reads in a space, followed by another space, followed by EOF.
I am using Compaq Visual Fortran 6.6 from a DOS box in Windows98SE. The input textfile was created with notepad.
Do you have any idea what is going on?
Thanks
Colin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Colin!
I modified my program a litlle, to read your file, here called b.txt. I removed the SIZE specifier and it seems to work ok for me.
Still in CVF 6.6C
Here it is:
PROGRAM t1
IMPLICIT NONE
INTEGER :: istat, line_size = 0
CHARACTER(LEN=1) :: c
OPEN (UNIT=1, FILE='b.txt', ACTION='READ', STATUS='OLD')
outer:&
DO
line_size = 0
DO
READ (1, '(A)', IOSTAT=istat, ADVANCE="NO") c
IF (istat==-2) THEN
WRITE (*, *) 'Exiting on EOR condition'
EXIT ! ---------------->
ELSE IF (istat==-1) THEN
WRITE (*, *) 'Exiting on EOF condition'
EXIT outer
ENDIF
line_size = line_size + 1
WRITE (*, *) c, istat, line_size
END DO
WRITE (*, *) 'line_size=', line_size
END DO outer
CLOSE (UNIT=1)
WRITE (*, *) 'End', istat, line_size
END PROGRAM t1
IMPLICIT NONE
INTEGER :: istat, line_size = 0
CHARACTER(LEN=1) :: c
OPEN (UNIT=1, FILE='b.txt', ACTION='READ', STATUS='OLD')
outer:&
DO
line_size = 0
DO
READ (1, '(A)', IOSTAT=istat, ADVANCE="NO") c
IF (istat==-2) THEN
WRITE (*, *) 'Exiting on EOR condition'
EXIT ! ---------------->
ELSE IF (istat==-1) THEN
WRITE (*, *) 'Exiting on EOF condition'
EXIT outer
ENDIF
line_size = line_size + 1
WRITE (*, *) c, istat, line_size
END DO
WRITE (*, *) 'line_size=', line_size
END DO outer
CLOSE (UNIT=1)
WRITE (*, *) 'End', istat, line_size
END PROGRAM t1
Best wishes
Lars M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
It still does not work on my computer. I do not have any problems with any other Fortran programs I have written using my current setup.
I note that iostat is either 0 or EOF. It looks as if my program is 'pattern-matching' for an alphabetic character. When it finds one it moves onto the next record (except that EOR does not seem to be recognised).
I wondered if there was something wrong with my text file in that the cr/lf was not recognised. However if I try using ordinary advancing io and a larger buffer, I can read the lines in the file OK.
I looked in help about and I am using standard CVF 6.6.0. Is there a bug that is corrected in 6.6.C?
Do you know where I can get any 6.6 updates?
Are there any compilation/linker switches which could
be causing this behaviour?
Do you have any ideas?
Thanks
Colin
It still does not work on my computer. I do not have any problems with any other Fortran programs I have written using my current setup.
I note that iostat is either 0 or EOF. It looks as if my program is 'pattern-matching' for an alphabetic character. When it finds one it moves onto the next record (except that EOR does not seem to be recognised).
I wondered if there was something wrong with my text file in that the cr/lf was not recognised. However if I try using ordinary advancing io and a larger buffer, I can read the lines in the file OK.
I looked in help about and I am using standard CVF 6.6.0. Is there a bug that is corrected in 6.6.C?
Do you know where I can get any 6.6 updates?
Are there any compilation/linker switches which could
be causing this behaviour?
Do you have any ideas?
Thanks
Colin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Colin!
Try this link:
Lars M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
many thanks
I'd been trying to find that page on the HP web site, but kept getting automatically redirected away from it.
As the down;load is large and I only have dialup, I'll download the update at the weekend and see how I get on.
In the meantime, I had played around e.g changing the format statement and also trying to use non-advancing io for writing to a file, but I always get strange results. Therefore I am convinced there is a bug in version 6.6.0 as I am sure my code is correct and even when I copy your code it does not work on my PC.
I'll let you know how I get on early next week and thanks once more for all your help
Colin
many thanks
I'd been trying to find that page on the HP web site, but kept getting automatically redirected away from it.
As the down;load is large and I only have dialup, I'll download the update at the weekend and see how I get on.
In the meantime, I had played around e.g changing the format statement and also trying to use non-advancing io for writing to a file, but I always get strange results. Therefore I am convinced there is a bug in version 6.6.0 as I am sure my code is correct and even when I copy your code it does not work on my PC.
I'll let you know how I get on early next week and thanks once more for all your help
Colin

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