File: seq_io.f90

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (81 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (2)
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
! pr 15472
! sequential access files
!
!  this test verifies the most basic sequential unformatted I/O
!      write 3 records of various sizes
!      then read them back
!      and compare with what was written
!
       implicit none
       integer size
       parameter(size=100)
       logical debug 
       data debug /.FALSE./
! set debug to true for help in debugging failures.
       integer m(2)
       integer n
       real*4 r(size)
       integer i
       m(1) = int(Z'11111111')
       m(2) = int(Z'22222222')
       n    = int(Z'33333333')
       do i = 1,size
         r(i) = i
       end do
       write(9)m  ! an array of 2
       write(9)n  ! an integer
       write(9)r  ! an array of reals
! zero all the results so we can compare after they are read back
       do i = 1,size
          r(i) = 0
       end do
       m(1) = 0
       m(2) = 0
       n = 0

       rewind(9)
       read(9)m
       read(9)n
       read(9)r
!
! check results
       if (m(1).ne. int(Z'11111111')) then
         if (debug) then
            print '(A,Z8)','m(1) incorrect.  m(1) = ',m(1)
         else
            STOP 1
         endif
       endif

       if (m(2).ne. int(Z'22222222')) then
         if (debug) then
            print '(A,Z8)','m(2) incorrect.  m(2) = ',m(2)
         else
            STOP 2
         endif
       endif

       if (n.ne. int(Z'33333333')) then
         if (debug) then
            print '(A,Z8)','n incorrect.  n = ',n
         else
            STOP 3
         endif
       endif

       do i = 1,size
          if (int(r(i)).ne.i) then
            if (debug) then
              print*,'element ',i,' was ',r(i),' should be ',i
            else
              STOP 4
            endif
          endif
       end do
! use hexdump to look at the file "fort.9"
       if (debug) then
         close(9)
       else
         close(9,status='DELETE')
       endif
       end