MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
ParticleTrackEventBuffer.f90
Go to the documentation of this file.
1!> @brief Particle event buffering strategies.
3
4 use kindmodule, only: dp, i4b, lgp
5 use errorutilmodule, only: pstop
6
7 implicit none
8
9 !> @brief Flat record of a particle track event.
11 integer(I4B) :: kper, kstp, imdl, iprp, irpt, ilay, icu, izone
12 integer(I4B) :: istatus, ireason
13 real(dp) :: trelease, ttrack, x, y, z
14 character(len=40) :: name
16
17 !> @brief Output file containing all or some particle pathlines.
18 !!
19 !! Can be associated with a particle release point (PRP) package
20 !! or with an entire model, and can be binary or text (CSV).
21 !<
23 private
24 integer(I4B), public :: iun = 0 !< file unit number
25 logical(LGP), public :: csv = .false. !< whether the file is binary or CSV
26 integer(I4B), public :: iprp = -1 !< -1 is model-level file, 0 is exchange PRP
28
29 !> @brief Event buffering strategy
31 integer(I4B) :: nrecords = 0 !< number of records stored
32 contains
33 procedure :: init => buffer_init !< open/allocate resources
34 procedure(buffer_append), deferred :: append !< buffer one record
35 procedure(buffer_flush), deferred :: flush !< write buffered records, reset
36 procedure(buffer_simple), deferred :: discard !< reset without writing
37 procedure(buffer_simple), deferred :: destroy !< release resources
39
40 abstract interface
41 subroutine buffer_append(this, rec)
43 class(particletrackeventbuffertype) :: this
44 type(particletrackrecordtype), intent(in) :: rec
45 end subroutine buffer_append
46
47 subroutine buffer_flush(this, files)
49 class(particletrackeventbuffertype) :: this
50 type(particletrackfiletype), intent(in) :: files(:)
51 end subroutine buffer_flush
52
53 ! Shared interface for discard and destroy: both take only `this`.
54 subroutine buffer_simple(this)
56 class(particletrackeventbuffertype) :: this
57 end subroutine buffer_simple
58 end interface
59
60contains
61
62 subroutine buffer_init(this)
63 class(particletrackeventbuffertype) :: this
64 end subroutine buffer_init
65
66 !> @brief Save an event record to a binary or CSV file.
67 subroutine save_record(iun, rec, csv)
68 integer(I4B), intent(in) :: iun
69 type(particletrackrecordtype), intent(in) :: rec
70 logical(LGP), intent(in) :: csv
71
72 if (csv) then
73 write (iun, '(*(G0,:,","))') &
74 rec%kper, rec%kstp, rec%imdl, rec%iprp, rec%irpt, &
75 rec%ilay, rec%icu, rec%izone, rec%istatus, rec%ireason, &
76 rec%trelease, rec%ttrack, rec%x, rec%y, rec%z, trim(rec%name)
77 else
78 write (iun) &
79 rec%kper, rec%kstp, rec%imdl, rec%iprp, rec%irpt, &
80 rec%ilay, rec%icu, rec%izone, rec%istatus, rec%ireason, &
81 rec%trelease, rec%ttrack, rec%x, rec%y, rec%z, rec%name
82 end if
83 end subroutine save_record
84
subroutine init()
subroutine pstop(status, message)
Stop the program, optionally specifying an error status code.
Definition ErrorUtil.f90:24
This module defines variable data types.
Definition kind.f90:8
Particle event buffering strategies.
subroutine save_record(iun, rec, csv)
Save an event record to a binary or CSV file.
Output file containing all or some particle pathlines.