chap06/kadai7.f90

サンプルコードのダウンロード

 1program answer
 2  implicit none
 3
 4  integer, parameter :: n = 10
 5  integer :: i, ios
 6  real(8) :: x(n)
 7
 8  open(unit=10, iostat=ios, file='cbinary.dat', action='read', &
 9       & access='stream', form='unformatted', status='old')
10
11  if(ios /= 0) then
12    write(*, *) 'Failed to open file'
13    stop
14  endif
15
16  read(10) x
17  close(10)
18
19  write(*, *) 'data read from binary.dat in stream access'
20  do i = 1, n
21    write(*, '(f5.2)') x(i)
22  enddo
23
24  stop
25endprogram answer