File: file_26.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (92 lines) | stat: -rw-r--r-- 3,277 bytes parent folder | download
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
91
92
program file_26
  implicit none
  integer, parameter :: n = 5
  integer :: data_out(n), data_in(n)
  integer, allocatable :: data_out_alloc(:)
  real, allocatable :: data_out_alloc_real(:)
  real :: data_in_real(n)
  integer :: i, write_unit, read_unit, ios
  character(len=2) :: tmp
  character(len=3) :: tmp2
  data_out = (/ 1, 2, 3, 4, 5 /)
  allocate(data_out_alloc(n))
  allocate(data_out_alloc_real(n))
  data_out_alloc = [1, 2, 3, 4, 5]
  data_out_alloc_real = [1, 2, 3, 4, 5]

  open(newunit=write_unit, file='file_26_data.dat', form='unformatted', status='replace')
  write(write_unit) data_out
  write(9, *) data_out
  close(write_unit)
  open(newunit=read_unit, file='file_26_data.dat', form='unformatted', status='old')
  read(read_unit) data_in
  close(read_unit)
  print *, data_out
  print *, data_in
  if (any(data_out /= data_in)) error stop

  open(newunit=write_unit, file='file_26_data.dat', form='unformatted', status='replace', access="stream")
  write(write_unit) data_out
  write(9, *) data_out
  close(write_unit)
  open(newunit=read_unit, file='file_26_data.dat', form='unformatted', status='old', access="stream")
  read(read_unit) data_in
  close(read_unit)
  print *, data_out
  print *, data_in
  if (any(data_out /= data_in)) error stop

  open(newunit=write_unit, file='file_26_data2.dat', form='unformatted', status='replace')
  write(write_unit) "Hello"
  close(write_unit)
  open(newunit=read_unit, file='file_26_data2.dat', form='unformatted', status='old')
  read(read_unit) tmp, tmp2
  close(read_unit)
  print *, tmp, " ", tmp2
  if (tmp /= "He" .or. tmp2 /= "llo") error stop
  open(newunit=write_unit, file='file_26_data2.dat', form='unformatted', status='replace', access="stream")
  write(write_unit) "Hello"
  close(write_unit)
  open(newunit=read_unit, file='file_26_data2.dat', form='unformatted', status='old', access="stream")
  read(read_unit) tmp, tmp2
  close(read_unit)
  print *, tmp, " ", tmp2
  if (tmp /= "He" .or. tmp2 /= "llo") error stop

  open(newunit=write_unit, file='file_26_data.dat', form='unformatted', status='replace', access="stream")
  write(write_unit) data_out_alloc
  close(write_unit)
  open(newunit=read_unit, file='file_26_data.dat', form='unformatted', status='old', access="stream")
  read(read_unit) data_in
  close(read_unit)
  print *, data_out_alloc
  print *, data_in
  if (any(data_out_alloc /= data_in)) error stop

  open(newunit=write_unit, file='file_26_data.dat', form='unformatted', status='replace', access="stream")
  write(write_unit) data_out_alloc_real
  close(write_unit)
  open(newunit=read_unit, file='file_26_data.dat', form='unformatted', status='old', access="stream")
  read(read_unit) data_in_real
  close(read_unit)
  print *, data_out_alloc_real
  print *, data_in_real
  if (any(data_out_alloc_real /= data_in_real)) error stop

  call test_sub(data_out)
  if(any(data_out /= [10, 20, 30, 40, 50])) error stop
contains

subroutine test_sub(res2)
    integer :: lun
    integer, parameter :: res(5) = [10, 20, 30, 40, 50]
    integer, intent(out) :: res2(:)

    open(newunit=lun, file="file_26_data.dat", status="replace", form="unformatted", access="stream")
    write(lun) res
    rewind(lun)
    read(lun) res2
    close(lun)
    
end subroutine test_sub
end program