The attached program exhibits a strange problem with gfortran when repeatedly trying to position within an input file, and which I have been hunting for a long time. The program is supposed to work as follows:
- open input file - do - rewind - repeatedly search for lines containing a special text - end do The program always succeeds in finding the occurence of the first text, but fails to find the second text if the first text does *not* occur on the first text line. Example 1: % cat gfcbug69.nml ! ***Remove this line*** &FOO file='foo' / &BAR file='bar' / % gfc -g -Wall -std=f2003 gfcbug69.f90 % ./a.out inquire: after OPEN: position = ASIS nextrec = 0 ------------------------------------------------------------------ inquire: after REWIND: position = REWIND nextrec = 0 position_nml: Scanning for: FOO position_nml: SUCCESS! line= &FOO file='foo' / inquire: after position_nml: position = ASIS nextrec = 0 *** Found: &FOO file='foo' / position_nml: Scanning for: FOO position_nml: FAIL: ios= -1 inquire: after position_nml: position = APPEND nextrec = 0 ------------------------------------------------------------------ inquire: after REWIND: position = REWIND nextrec = 0 position_nml: Scanning for: BAR position_nml: FAIL: ios= -1 inquire: after position_nml: position = REWIND nextrec = 0 ------------------------------------------------------------------ Removing the indicated line from the text file leads to: % ./a.out inquire: after OPEN: position = ASIS nextrec = 0 ------------------------------------------------------------------ inquire: after REWIND: position = REWIND nextrec = 0 position_nml: Scanning for: FOO position_nml: SUCCESS! line= &FOO file='foo' / inquire: after position_nml: position = REWIND nextrec = 0 *** Found: &FOO file='foo' / position_nml: Scanning for: FOO position_nml: FAIL: ios= -1 inquire: after position_nml: position = APPEND nextrec = 0 ------------------------------------------------------------------ inquire: after REWIND: position = REWIND nextrec = 0 position_nml: Scanning for: BAR position_nml: SUCCESS! line= &BAR file='bar' / inquire: after position_nml: position = ASIS nextrec = 0 *** Found: &BAR file='bar' / position_nml: Scanning for: BAR position_nml: FAIL: ios= -1 inquire: after position_nml: position = ASIS nextrec = 0 ------------------------------------------------------------------ Comparing the two results shows: % diff -u out.fail out.success --- out.fail 2007-09-04 21:31:22.000000000 +0200 +++ out.success 2007-09-04 21:31:14.000000000 +0200 @@ -4,7 +4,7 @@ position_nml: Scanning for: FOO position_nml: SUCCESS! line= &FOO file='foo' / -inquire: after position_nml: position = ASIS nextrec = 0 +inquire: after position_nml: position = REWIND nextrec = 0 *** Found: &FOO file='foo' / @@ -15,6 +15,12 @@ inquire: after REWIND: position = REWIND nextrec = 0 position_nml: Scanning for: BAR +position_nml: SUCCESS! line= &BAR file='bar' / +inquire: after position_nml: position = ASIS nextrec = 0 + + *** Found: &BAR file='bar' / + +position_nml: Scanning for: BAR position_nml: FAIL: ios= -1 -inquire: after position_nml: position = REWIND nextrec = 0 +inquire: after position_nml: position = ASIS nextrec = 0 ------------------------------------------------------------------ For some reason the file position after attempting to find the second text is still "REWIND". This may only be a cosmetic problem, but it could be a hint towards the source of the problem. -- Summary: I/O read/positioning problem Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: anlauf at gmx dot de GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33307