]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gfortran.dg/unf_io_convert_1.f90
arith.c (gfc_convert_integer, [...]): Move to ...
[thirdparty/gcc.git] / gcc / testsuite / gfortran.dg / unf_io_convert_1.f90
CommitLineData
ee56ac9d 1! { dg-do run }
181c9f4a
TK
2! { dg-options "-pedantic" }
3! This test verifies the most basic sequential unformatted I/O
4! with convert="swap".
5! Adapted from seq_io.f.
6! write 3 records of various sizes
7! then read them back
8program main
9 implicit none
10 integer size
11 parameter(size=100)
12 logical debug
13 data debug /.FALSE./
14! set debug to true for help in debugging failures.
15 integer m(2)
16 integer n
df8652dc 17 real r(size)
181c9f4a 18 integer i
e2ab8b09 19 character(4) str
181c9f4a 20
8dc63166
SK
21 m(1) = int(Z'11223344')
22 m(2) = int(Z'55667788')
23 n = int(Z'77AABBCC')
181c9f4a
TK
24 str = 'asdf'
25 do i = 1,size
26 r(i) = i
27 end do
28 open(9,form="unformatted",access="sequential",convert="swap") ! { dg-warning "Extension: CONVERT" }
29 write(9) m ! an array of 2
30 write(9) n ! an integer
31 write(9) r ! an array of reals
32 write(9)str ! String
33! zero all the results so we can compare after they are read back
34 do i = 1,size
35 r(i) = 0
36 end do
37 m(1) = 0
38 m(2) = 0
39 n = 0
40 str = ' '
41
42 rewind(9)
43 read(9) m
44 read(9) n
45 read(9) r
46 read(9) str
47 !
48 ! check results
8dc63166 49 if (m(1).ne.int(Z'11223344')) then
181c9f4a
TK
50 if (debug) then
51 print '(A,Z8)','m(1) incorrect. m(1) = ',m(1)
52 else
7d6ce202 53 STOP 1
181c9f4a
TK
54 endif
55 endif
56
8dc63166 57 if (m(2).ne.int(Z'55667788')) then
181c9f4a
TK
58 if (debug) then
59 print '(A,Z8)','m(2) incorrect. m(2) = ',m(2)
60 else
7d6ce202 61 STOP 2
181c9f4a
TK
62 endif
63 endif
64
8dc63166 65 if (n.ne.int(Z'77AABBCC')) then
181c9f4a
TK
66 if (debug) then
67 print '(A,Z8)','n incorrect. n = ',n
68 else
7d6ce202 69 STOP 3
181c9f4a
TK
70 endif
71 endif
72
73 do i = 1,size
74 if (int(r(i)).ne.i) then
75 if (debug) then
76 print*,'element ',i,' was ',r(i),' should be ',i
77 else
7d6ce202 78 STOP 4
181c9f4a
TK
79 endif
80 endif
81 end do
82 if (str .ne. 'asdf') then
83 if (debug) then
84 print *,'str incorrect, str = ', str
85 else
7d6ce202 86 STOP 5
181c9f4a 87 endif
181c9f4a 88 end if
d9d1a958
KG
89 ! use hexdump to look at the file "fort.9"
90 if (debug) then
91 close(9)
92 else
93 close(9,status='DELETE')
94 endif
181c9f4a 95end program main