summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/async_io_4.f90
blob: 1ff76b4f162c570f517e476f29165e3291d838e3 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
! { dg-do run { target fd_truncate } }
!TODO: Move these testcases to gfortran testsuite
! once compilation with pthreads is supported there

! Test BACKSPACE for synchronous and asynchronous I/O
program main
  
  integer i, n, nr
  real x(10), y(10)

  ! PR libfortran/20068
  open (20, status='scratch', asynchronous="yes")
  write (20,*, asynchronous="yes" ) 1
  write (20,*, asynchronous="yes") 2
  write (20,*, asynchronous="yes") 3
  rewind (20)
  i = 41
  read (20,*, asynchronous="yes") i
  wait (20)
  if (i .ne. 1) stop 1
  write (*,*) ' '
  backspace (20)
  i = 42
  read (20,*, asynchronous="yes") i
  close (20)
  if (i .ne. 1) stop 2

  ! PR libfortran/20125
  open (20, status='scratch', asynchronous="yes")
  write (20,*, asynchronous="yes") 7
  backspace (20)
  read (20,*, asynchronous="yes") i
  wait (20)
  if (i .ne. 7) stop 3
  close (20)

  open (20, status='scratch', form='unformatted')
  write (20) 8
  backspace (20)
  read (20) i
  if (i .ne. 8) stop 4
  close (20)

  ! PR libfortran/20471
  do n = 1, 10
     x(n) = sqrt(real(n))
  end do
  open (3, form='unformatted', status='scratch')
  write (3) (x(n),n=1,10)
  backspace (3)
  rewind (3)
  read (3) (y(n),n=1,10)

  do n = 1, 10
     if (abs(x(n)-y(n)) > 0.00001) stop 5
  end do
  close (3)

  ! PR libfortran/20156
  open (3, form='unformatted', status='scratch')
  do i = 1, 5
     x(1) = i
     write (3) n, (x(n),n=1,10)
  end do
  nr = 0
  rewind (3)
20 continue
  read (3,end=30,err=90) n, (x(n),n=1,10)
  nr = nr + 1
  goto 20
30 continue
  if (nr .ne. 5) stop 6

  do i = 1, nr+1
     backspace (3)
  end do

  do i = 1, nr
     read(3,end=70,err=90) n, (x(n),n=1,10)
     if (abs(x(1) - i) .gt. 0.001) stop 7
  end do
  close (3)
  stop

70 continue
  stop 8
90 continue
  stop 9

end program