- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have some code that makes use of backspace to print out an invalid namelist line.
2021.5.0 20211109 works as expected, but 2021.8.0 20221119 prints the line after the invalid namelist line (If I put two backspace calls in, I get the same behavior as one backspace in 2021.5.0 20211109)
Here is a small example:
```
$ cat test_namelist_backspace.f90
program test_backspace
implicit none
integer :: ios, iunit
character(len=5) :: one, two, three, four, line
namelist /nums_nml/ one, two, three, four
one = 'nope'
two = 'nope'
three = 'nope'
four = 'nope'
open(newunit=iunit, file='input.nml', action='read', iostat=ios)
read(iunit, nml=nums_nml, iostat=ios)
print*, one, two, three, four
print*, 'iostat', ios
if (ios /= 0) then
backspace(iunit)
read(iunit, '(A)') line
print*, 'bad line: ', line
endif
close(iunit)
end program test_backspace
```
```
$cat input.nml
&nums_nml
one = 'one',
two = 'two',
cake = 'three'
four = 'four'
/
```
ifort (IFORT) 2021.5.0 20211109
```
$ ifort test_backspace_namelist.f90
$ ./a.out
one two nope nope
iostat 19
bad line: cake
```
ifort (IFORT) 2021.8.0 20221119
```
$ ifort test_namelist_backspace.f90
$./a.out
one two nope nope
iostat 19
bad line: four
```
Is backspace something I shouldn't rely on for namelist reads or is this a bug?
Cheers,
Helen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't rely on this in general. The standard says two things relevant here:
1) If an error condition occurs during execution of an input/output statement, the position of the file becomes indeterminate.
2) if the statement is a READ statement or the error condition occurs in a wait operation for a transfer initiated by a READ statement, all input items or namelist group objects in the statement that initiated the transfer become undefined;
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't rely on this in general. The standard says two things relevant here:
1) If an error condition occurs during execution of an input/output statement, the position of the file becomes indeterminate.
2) if the statement is a READ statement or the error condition occurs in a wait operation for a transfer initiated by a READ statement, all input items or namelist group objects in the statement that initiated the transfer become undefined;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve, that is what I was thinking (but hoping not!).
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page