2 ! PR31052 Bad IOSTAT values when readings NAMELISTs past EOF.
3 ! Patch derived from PR, submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
8 open (12, status
="scratch")
9 write (12, '(a)')"!================"
10 write (12, '(a)')"! Namelist REPORT"
11 write (12, '(a)')"!================"
12 write (12, '(a)')" &REPORT type = 'SYNOP' "
13 write (12, '(a)')" use = 'active'"
14 write (12, '(a)')" max_proc = 20"
16 write (12, '(a)')"! Other namelists..."
17 write (12, '(a)')" &OTHER i = 1 /"
20 ! Read /REPORT/ the first time
22 call position_nml (12, "REPORT", stat
)
24 if (stat
== 0) call read_report (12, stat
)
26 ! Comment out the following lines to hide the bug
28 call position_nml (12, "MISSING", stat
)
29 if (stat
.ne
.-1) STOP 2
33 call position_nml (12, "REPORT", stat
)
38 subroutine position_nml (unit
, name
, status
)
39 ! Check for presence of namelist 'name'
40 integer :: unit
, status
41 character(len
=*), intent(in
) :: name
43 character(len
=255) :: line
44 integer :: ios
, idx
, k
52 read (unit
,'(a)',iostat
=ios
) line
61 else if (ios
> 0) then
66 idx
= index (line
, "&"//trim (name
))
72 end subroutine position_nml
74 subroutine read_report (unit
, status
)
75 integer :: unit
, status
77 integer :: iuse
, ios
, k
81 character(len
=12) :: type, use
83 namelist /REPORT
/ type, use, max_proc
84 !-------------------------------------
85 ! Loop to read namelist multiple times
86 !-------------------------------------
89 !----------------------------------------
90 ! Preset namelist variables with defaults
91 !----------------------------------------
98 read (unit
, nml
=REPORT
, iostat
=ios
)
102 if (iuse
.ne
.1) STOP 4
104 end subroutine read_report