MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
MemoryBuffer.f90
Go to the documentation of this file.
1 !> @brief In-memory particle event buffer module.
2 !<
4 
5  use kindmodule, only: i4b
10 
11  implicit none
12  private
13  public :: memorybuffertype
14 
15  !> @brief In-memory particle event buffer. Records are held in a
16  !! dynamically growing array that doubles in capacity as needed.
18  type(particletrackrecordtype), allocatable :: records(:) !< buffer
19  contains
20  procedure :: append => memory_append
21  procedure :: flush => memory_flush
22  procedure :: discard => memory_discard
23  procedure :: destroy => memory_destroy
24  end type memorybuffertype
25 
26 contains
27 
28  subroutine memory_append(this, rec)
29  class(memorybuffertype) :: this
30  type(particletrackrecordtype), intent(in) :: rec
31  type(particletrackrecordtype), allocatable :: tmp(:)
32 
33  if (.not. allocated(this%records)) then
34  allocate (this%records(64))
35  else if (this%nrecords == size(this%records)) then
36  allocate (tmp(size(this%records) * 2))
37  tmp(1:this%nrecords) = this%records
38  call move_alloc(tmp, this%records)
39  end if
40  this%nrecords = this%nrecords + 1
41  this%records(this%nrecords) = rec
42  end subroutine memory_append
43 
44  subroutine memory_flush(this, files)
45  class(memorybuffertype) :: this
46  type(particletrackfiletype), intent(in) :: files(:)
47  integer(I4B) :: n, i
48  type(particletrackrecordtype) :: rec
49 
50  do n = 1, this%nrecords
51  rec = this%records(n)
52  do i = 1, size(files)
53  if (files(i)%iun > 0 .and. &
54  (files(i)%iprp == -1 .or. files(i)%iprp == rec%iprp)) &
55  call save_record(files(i)%iun, rec, files(i)%csv)
56  end do
57  end do
58  this%nrecords = 0
59  end subroutine memory_flush
60 
61  subroutine memory_discard(this)
62  class(memorybuffertype) :: this
63  this%nrecords = 0
64  end subroutine memory_discard
65 
66  subroutine memory_destroy(this)
67  class(memorybuffertype) :: this
68  if (allocated(this%records)) deallocate (this%records)
69  end subroutine memory_destroy
70 
71 end module memorybuffermodule
This module defines variable data types.
Definition: kind.f90:8
In-memory particle event buffer module.
Definition: MemoryBuffer.f90:3
subroutine memory_discard(this)
subroutine memory_append(this, rec)
subroutine memory_destroy(this)
subroutine memory_flush(this, files)
Particle event buffering strategies.
subroutine save_record(iun, rec, csv)
Save an event record to a binary or CSV file.
In-memory particle event buffer. Records are held in a dynamically growing array that doubles in capa...
Output file containing all or some particle pathlines.