1! { dg-do run } 2! PR55818 Reading a REAL from a file which doesn't end in a new line fails 3! Test case from PR reporter. 4implicit none 5integer :: stat 6!integer :: var ! << works 7real :: var ! << fails 8character(len=10) :: cvar ! << fails 9complex :: cval 10logical :: lvar 11 12open(99, file="test.dat", access="stream", form="unformatted", status="new") 13write(99) "1", new_line("") 14write(99) "2", new_line("") 15write(99) "3" 16close(99) 17 18! Test character kind 19open(99, file="test.dat") 20read (99,*, iostat=stat) cvar 21if (stat /= 0 .or. cvar /= "1") call abort() 22read (99,*, iostat=stat) cvar 23if (stat /= 0 .or. cvar /= "2") call abort() 24read (99,*, iostat=stat) cvar ! << FAILS: stat /= 0 25if (stat /= 0 .or. cvar /= "3") call abort() ! << aborts here 26 27! Test real kind 28rewind(99) 29read (99,*, iostat=stat) var 30if (stat /= 0 .or. var /= 1.0) call abort() 31read (99,*, iostat=stat) var 32if (stat /= 0 .or. var /= 2.0) call abort() 33read (99,*, iostat=stat) var ! << FAILS: stat /= 0 34if (stat /= 0 .or. var /= 3.0) call abort() 35close(99, status="delete") 36 37! Test real kind with exponents 38open(99, file="test.dat", access="stream", form="unformatted", status="new") 39write(99) "1.0e3", new_line("") 40write(99) "2.0e-03", new_line("") 41write(99) "3.0e2" 42close(99) 43 44open(99, file="test.dat") 45read (99,*, iostat=stat) var 46if (stat /= 0) call abort() 47read (99,*, iostat=stat) var 48if (stat /= 0) call abort() 49read (99,*) var ! << FAILS: stat /= 0 50if (stat /= 0) call abort() 51close(99, status="delete") 52 53! Test logical kind 54open(99, file="test.dat", access="stream", form="unformatted", status="new") 55write(99) "Tru", new_line("") 56write(99) "fal", new_line("") 57write(99) "t" 58close(99) 59 60open(99, file="test.dat") 61read (99,*, iostat=stat) lvar 62if (stat /= 0 .or. (.not.lvar)) call abort() 63read (99,*, iostat=stat) lvar 64if (stat /= 0 .or. lvar) call abort() 65read (99,*) lvar ! << FAILS: stat /= 0 66if (stat /= 0 .or. (.not.lvar)) call abort() 67close(99, status="delete") 68 69! Test combinations of Inf and Nan 70open(99, file="test.dat", access="stream", form="unformatted", status="new") 71write(99) "infinity", new_line("") 72write(99) "nan", new_line("") 73write(99) "infinity" 74close(99) 75 76open(99, file="test.dat") 77read (99,*, iostat=stat) var 78if (stat /= 0) call abort() 79read (99,*, iostat=stat) var 80if (stat /= 0) call abort() 81read (99,*) var ! << FAILS: stat /= 0 82if (stat /= 0) call abort ! << aborts here 83close(99, status="delete") 84 85open(99, file="test.dat", access="stream", form="unformatted", status="new") 86write(99) "infinity", new_line("") 87write(99) "inf", new_line("") 88write(99) "nan" 89close(99) 90 91open(99, file="test.dat") 92read (99,*, iostat=stat) var 93if (stat /= 0) call abort() 94read (99,*, iostat=stat) var 95if (stat /= 0) call abort() 96read (99,*) var ! << FAILS: stat /= 0 97if (stat /= 0) call abort ! << aborts here 98close(99, status="delete") 99 100open(99, file="test.dat", access="stream", form="unformatted", status="new") 101write(99) "infinity", new_line("") 102write(99) "nan", new_line("") 103write(99) "inf" 104close(99) 105 106open(99, file="test.dat") 107read (99,*, iostat=stat) var 108if (stat /= 0) call abort() 109read (99,*, iostat=stat) var 110if (stat /= 0) call abort() 111read (99,*) var ! << FAILS: stat /= 0 112if (stat /= 0) call abort ! << aborts here 113close(99, status="delete") 114 115! Test complex kind 116open(99, file="test.dat", access="stream", form="unformatted", status="new") 117write(99) "(1,2)", new_line("") 118write(99) "(2,3)", new_line("") 119write(99) "(4,5)" 120close(99) 121 122open(99, file="test.dat") 123read (99,*, iostat=stat) cval 124if (stat /= 0 .or. cval /= cmplx(1,2)) call abort() 125read (99,*, iostat=stat) cval 126if (stat /= 0 .or. cval /= cmplx(2,3)) call abort() 127read (99,*, iostat=stat) cval ! << FAILS: stat /= 0, value is okay 128if (stat /= 0 .or. cval /= cmplx(4,5)) call abort() 129close(99, status="delete") 130end 131