9 integer(I8B) :: pos, size
10 integer(I4B) :: kper, kstp
11 real(dp) :: pertim, totim
17 integer(I4B) :: inunit
18 integer(I4B) :: nrecords = 0
19 logical(LGP) :: indexed = .false.
20 logical(LGP) :: endoffile = .false.
21 integer(I8B),
allocatable :: record_positions(:)
38 logical(LGP),
intent(out) :: success
39 integer(I4B),
intent(in),
optional :: iout
46 logical(LGP),
intent(out) :: success
47 integer(I4B),
intent(in),
optional :: iout
55 character(len=:),
allocatable :: str
57 write (str,
'(*(G0))') &
58 'Binary file header (pos: ', this%pos, &
59 ', kper: ', this%kper, &
60 ', kstp: ', this%kstp, &
61 ', pertim: ', this%pertim, &
62 ', totim: ', this%totim, &
71 logical(LGP) :: success
74 this%indexed = .false.
77 if (
allocated(this%record_positions))
deallocate (this%record_positions)
81 call this%read_record(success)
82 if (.not. success)
exit
83 this%nrecords = this%nrecords + 1
88 allocate (this%record_positions(this%nrecords))
91 call this%read_record(success)
92 if (.not. success)
exit
94 this%record_positions(i) = this%header%pos
104 integer(I4B),
intent(in) :: index
106 integer(I4B) :: iostat
108 if (.not. this%indexed) &
109 call pstop(1,
'Cannot seek to index in unindexed file')
110 if (index < 1 .or. index > this%nrecords)
then
111 this%endoffile = .true.
115 read (this%inunit, pos=this%record_positions(index), iostat=iostat)
116 if (iostat /= 0)
call pstop(1,
'Error seeking to index position')
118 if (.not.
allocated(this%headernext)) &
119 allocate (this%headernext, mold=this%header)
120 this%endoffile = .false.
127 integer(I4B) :: iostat
129 if (.not. this%endoffile)
then
130 inquire (this%inunit, pos=this%headernext%pos)
131 read (this%inunit, iostat=iostat) this%headernext%kstp, this%headernext%kper
132 if (iostat == 0)
then
133 read (this%inunit, pos=this%headernext%pos, iostat=iostat)
134 else if (iostat < 0)
then
135 this%endoffile = .true.
136 if (
allocated(this%headernext))
deallocate (this%headernext)
146 if (
allocated(this%header))
deallocate (this%header)
147 if (
allocated(this%headernext))
deallocate (this%headernext)
151 this%headernext%pos = 1
152 this%endoffile = .false.
character(len=:) function, allocatable get_str(this)
Get a string representation of the header.
subroutine seek_to_index(this, index)
Position the file at the start of an indexed record.
subroutine rewind(this)
Rewind the file to the beginning.
subroutine build_index(this)
Build an index of record positions in the file.
subroutine peek_record(this)
Peek to see if another record is available.
subroutine pstop(status, message)
Stop the program, optionally specifying an error status code.
This module defines variable data types.