1 | module m_io |
---|
2 | |
---|
3 | ! |
---|
4 | ! Basic I/O tools |
---|
5 | ! |
---|
6 | integer, public, save :: io_eor, io_eof |
---|
7 | |
---|
8 | public :: get_unit, setup_io |
---|
9 | private :: find_eor_eof |
---|
10 | |
---|
11 | CONTAINS |
---|
12 | |
---|
13 | ! ---------------------------------------------------------------------- |
---|
14 | subroutine setup_io() |
---|
15 | call find_eor_eof(io_eor, io_eof) |
---|
16 | end subroutine setup_io |
---|
17 | |
---|
18 | ! ---------------------------------------------------------------------- |
---|
19 | subroutine get_unit(lun,iostat) |
---|
20 | |
---|
21 | ! Get an available Fortran unit number |
---|
22 | |
---|
23 | integer, intent(out) :: lun |
---|
24 | integer, intent(out) :: iostat |
---|
25 | |
---|
26 | integer :: i |
---|
27 | logical :: unit_used |
---|
28 | |
---|
29 | do i = 10, 99 |
---|
30 | lun = i |
---|
31 | inquire(unit=lun,opened=unit_used) |
---|
32 | if (.not. unit_used) then |
---|
33 | iostat = 0 |
---|
34 | return |
---|
35 | endif |
---|
36 | enddo |
---|
37 | iostat = -1 |
---|
38 | lun = -1 |
---|
39 | end subroutine get_unit |
---|
40 | ! ---------------------------------------------------------------------- |
---|
41 | |
---|
42 | subroutine find_eor_eof(io_eor,io_eof) |
---|
43 | ! |
---|
44 | ! Determines the values of the iostat values for End of File and |
---|
45 | ! End of Record (in non-advancing I/O) |
---|
46 | ! |
---|
47 | integer, intent(out) :: io_eor |
---|
48 | integer, intent(out) :: io_eof |
---|
49 | |
---|
50 | integer :: lun, iostat |
---|
51 | character(len=1) :: c |
---|
52 | |
---|
53 | call get_unit(lun,iostat) |
---|
54 | |
---|
55 | if (iostat /= 0) stop "Out of unit numbers" |
---|
56 | |
---|
57 | open(unit=lun,status="scratch",form="formatted", & |
---|
58 | action="readwrite",position="rewind",iostat=iostat) |
---|
59 | if (iostat /= 0) stop "Cannot open test file" |
---|
60 | |
---|
61 | write(unit=lun,fmt=*) "a" |
---|
62 | write(unit=lun,fmt=*) "b" |
---|
63 | |
---|
64 | rewind(unit=lun) |
---|
65 | |
---|
66 | io_eor = 0 |
---|
67 | do |
---|
68 | read(unit=lun,fmt="(a1)",advance="NO",iostat=io_eor) c |
---|
69 | if (io_eor /= 0) exit |
---|
70 | enddo |
---|
71 | |
---|
72 | io_eof = 0 |
---|
73 | do |
---|
74 | read(unit=lun,fmt=*,iostat=io_eof) |
---|
75 | if (io_eof /= 0) exit |
---|
76 | enddo |
---|
77 | |
---|
78 | !!!!!!!!print *, "IO_EOR, IO_EOF: ", io_eor, io_eof |
---|
79 | |
---|
80 | close(unit=lun,status="delete") |
---|
81 | |
---|
82 | end subroutine find_eor_eof |
---|
83 | |
---|
84 | ! ---------------------------------------------------------------------- |
---|
85 | end module m_io |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|