chap06/kadai8.f90

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

 1program answer
 2  implicit none
 3
 4  integer, parameter :: n = 32
 5  integer :: i, ios, header, footer
 6  real(8) :: x(n), y(n), z(n)
 7
 8  open(unit=10, iostat=ios, file='helix2.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 x
17  read(10) header
18  read(10) x
19  read(10) footer
20
21  ! read y
22  read(10) header
23  read(10) y
24  read(10) footer
25
26  ! read z
27  read(10) header
28  read(10) z
29  read(10) footer
30
31  close(10)
32
33  do i = 1, n
34    write(*, '(f5.2,x,f5.2,x,f5.2)') x(i), y(i), z(i)
35  enddo
36
37  stop
38endprogram answer