aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/unformatted_subrecord_1.f90
blob: 02ed28863ebfc8bca9124cfba573ec8abbe0a74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
! { dg-do run { target fd_truncate } }
! { dg-options "-fmax-subrecord-length=16" }
! Test Intel record markers with 16-byte subrecord sizes.
! PR 32770:  Use explicit kinds for all integers and constants,
! to avoid problems with -fdefault-integer-8 and -fdefault-real-8
program main
  implicit none
  integer(kind=4), dimension(20) :: n
  integer(kind=4), dimension(30) :: m
  integer(kind=4) :: i
  real(kind=4) :: r
  integer(kind=4) :: k
  ! Maximum subrecord length is 16 here, or the test will fail.
  open (10, file="f10.dat", &
       form="unformatted", access="sequential")
  n = (/ (i**2, i=1, 20) /)
  write (10) n
  close (10)
  ! Read back the file, including record markers.
  open (10, file="f10.dat", form="unformatted", access="stream")
  read (10) m
  if (any(m .ne. (/ -16, 1, 4, 9, 16, 16, -16, 25, 36, 49, 64, &
       -16, -16, 81, 100, 121, 144, -16, -16, 169, 196, 225, & 
       256, -16, 16, 289, 324, 361, 400, -16 /))) call abort
  close (10)
  open (10, file="f10.dat", form="unformatted", &
       access="sequential")
  m = 42
  read (10) m(1:5)
  if (any(m(1:5) .ne. (/ 1, 4, 9, 16, 25 /))) call abort
  if (any(m(6:30) .ne. 42)) call abort
  backspace 10
  n = 0
  read (10) n(1:5)
  if (any(n(1:5) .ne. (/ 1, 4, 9, 16, 25 /))) call abort
  if (any(n(6:20) .ne. 0)) call abort
  ! Append to the end of the file
  write (10) 3.14_4
  ! Test multiple backspace statements
  backspace 10
  backspace 10
  read (10) k
  if (k .ne. 1) call abort
  read (10) r
  if (abs(r-3.14_4) .gt. 1e-7) call abort
  close (10, status="delete")
end program main