2 ! PR55818 Reading a REAL from a file which doesn't end in a new line fails
3 ! Test case from PR reporter.
6 !integer :: var ! << works
8 character(len
=10) :: cvar
! << fails
12 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
13 write(99) "1", new_line("")
14 write(99) "2", new_line("")
19 open(99, file
="test.dat")
20 read (99,*, iostat
=stat
) cvar
21 if (stat
/= 0 .or
. cvar
/= "1") STOP 1
22 read (99,*, iostat
=stat
) cvar
23 if (stat
/= 0 .or
. cvar
/= "2") STOP 2
24 read (99,*, iostat
=stat
) cvar
! << FAILS: stat /= 0
25 if (stat
/= 0 .or
. cvar
/= "3") STOP 3 ! << aborts here
29 read (99,*, iostat
=stat
) var
30 if (stat
/= 0 .or
. var
/= 1.0) STOP 4
31 read (99,*, iostat
=stat
) var
32 if (stat
/= 0 .or
. var
/= 2.0) STOP 5
33 read (99,*, iostat
=stat
) var
! << FAILS: stat /= 0
34 if (stat
/= 0 .or
. var
/= 3.0) STOP 6
35 close(99, status
="delete")
37 ! Test real kind with exponents
38 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
39 write(99) "1.0e3", new_line("")
40 write(99) "2.0e-03", new_line("")
44 open(99, file
="test.dat")
45 read (99,*, iostat
=stat
) var
47 read (99,*, iostat
=stat
) var
49 read (99,*) var
! << FAILS: stat /= 0
51 close(99, status
="delete")
54 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
55 write(99) "Tru", new_line("")
56 write(99) "fal", new_line("")
60 open(99, file
="test.dat")
61 read (99,*, iostat
=stat
) lvar
62 if (stat
/= 0 .or
. (.not
.lvar
)) STOP 10
63 read (99,*, iostat
=stat
) lvar
64 if (stat
/= 0 .or
. lvar
) STOP 11
65 read (99,*) lvar
! << FAILS: stat /= 0
66 if (stat
/= 0 .or
. (.not
.lvar
)) STOP 12
67 close(99, status
="delete")
69 ! Test combinations of Inf and Nan
70 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
71 write(99) "infinity", new_line("")
72 write(99) "nan", new_line("")
76 open(99, file
="test.dat")
77 read (99,*, iostat
=stat
) var
78 if (stat
/= 0) STOP 13
79 read (99,*, iostat
=stat
) var
80 if (stat
/= 0) STOP 14
81 read (99,*) var
! << FAILS: stat /= 0
82 if (stat
/= 0) STOP 1! << aborts here
83 close(99, status
="delete")
85 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
86 write(99) "infinity", new_line("")
87 write(99) "inf", new_line("")
91 open(99, file
="test.dat")
92 read (99,*, iostat
=stat
) var
93 if (stat
/= 0) STOP 15
94 read (99,*, iostat
=stat
) var
95 if (stat
/= 0) STOP 16
96 read (99,*) var
! << FAILS: stat /= 0
97 if (stat
/= 0) STOP 2! << aborts here
98 close(99, status
="delete")
100 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
101 write(99) "infinity", new_line("")
102 write(99) "nan", new_line("")
106 open(99, file
="test.dat")
107 read (99,*, iostat
=stat
) var
108 if (stat
/= 0) STOP 17
109 read (99,*, iostat
=stat
) var
110 if (stat
/= 0) STOP 18
111 read (99,*) var
! << FAILS: stat /= 0
112 if (stat
/= 0) STOP 3! << aborts here
113 close(99, status
="delete")
116 open(99, file
="test.dat", access
="stream", form
="unformatted", status
="new")
117 write(99) "(1,2)", new_line("")
118 write(99) "(2,3)", new_line("")
122 open(99, file
="test.dat")
123 read (99,*, iostat
=stat
) cval
124 if (stat
/= 0 .or
. cval
/= cmplx(1,2)) STOP 19
125 read (99,*, iostat
=stat
) cval
126 if (stat
/= 0 .or
. cval
/= cmplx(2,3)) STOP 20
127 read (99,*, iostat
=stat
) cval
! << FAILS: stat /= 0, value is okay
128 if (stat
/= 0 .or
. cval
/= cmplx(4,5)) STOP 21
129 close(99, status
="delete")