MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
prt-oc.f90
Go to the documentation of this file.
1 module prtocmodule
2 
3  use basedismodule, only: disbasetype
4  use kindmodule, only: dp, i4b, lgp
15 
16  implicit none
17  private
18  public prtoctype, oc_cr
19 
20  !> @ brief Output control for particle tracking models
21  type, extends(outputcontroltype) :: prtoctype
22  integer(I4B), pointer :: itrkout => null() !< binary output file
23  integer(I4B), pointer :: itrkhdr => null() !< output header file
24  integer(I4B), pointer :: itrkcsv => null() !< CSV output file
25  integer(I4B), pointer :: itrktls => null() !< track time list input file
26  logical(LGP), pointer :: trackrelease => null() !< whether to track release events
27  logical(LGP), pointer :: trackfeatexit => null() !< whether to track grid-scale feature exit events
28  logical(LGP), pointer :: tracktimestep => null() !< whether to track timestep events
29  logical(LGP), pointer :: trackterminate => null() !< whether to track termination events
30  logical(LGP), pointer :: trackweaksink => null() !< whether to track weak sink exit events
31  logical(LGP), pointer :: trackusertime => null() !< whether to track user-specified times
32  logical(LGP), pointer :: tracksubfexit => null() !< whether to track sub-grid-scale feature exit events
33  logical(LGP), pointer :: trackdropped => null() !< whether to track drops to water table
34  integer(I4B), pointer :: ntracktimes => null() !< number of user-specified tracking times
35  logical(LGP), pointer :: dump_event_trace => null() !< whether to dump event trace for debugging
36  type(timeselecttype), pointer :: tracktimes !< user-specified tracking times
37 
38  contains
39  procedure :: oc_ar
40  procedure :: oc_da => prt_oc_da
41  procedure :: allocate_scalars => prt_oc_allocate_scalars
42  procedure :: source_options => prt_oc_source_options
43  procedure, private :: prt_oc_source_dimensions
44  procedure, private :: prt_oc_source_tracktimes
45 
46  end type prtoctype
47 
48 contains
49 
50  !> @ brief Create an output control object
51  subroutine oc_cr(ocobj, name_model, input_mempath, inunit, iout)
52  type(prtoctype), pointer :: ocobj !< PrtOcType object
53  character(len=*), intent(in) :: name_model !< name of the model
54  character(len=*), intent(in) :: input_mempath !< input mempath of the package
55  integer(I4B), intent(in) :: inunit !< unit number for input
56  integer(I4B), intent(in) :: iout !< unit number for output
57 
58  ! Create the object
59  allocate (ocobj)
60 
61  ! Allocate scalars
62  call ocobj%allocate_scalars(name_model, input_mempath)
63 
64  ! Save unit numbers
65  ocobj%inunit = inunit
66  ocobj%iout = iout
67  end subroutine oc_cr
68 
69  subroutine prt_oc_allocate_scalars(this, name_model, input_mempath)
71  class(prtoctype) :: this
72  character(len=*), intent(in) :: name_model !< name of model
73  character(len=*), intent(in) :: input_mempath !< input mempath of the package
74  logical(LGP) :: found
75 
76  this%memoryPath = create_mem_path(name_model, 'OC')
77 
78  allocate (this%name_model)
79  allocate (this%input_fname)
80  call mem_allocate(this%dump_event_trace, 'DUMP_EVENT_TRACE', this%memoryPath)
81  call mem_allocate(this%inunit, 'INUNIT', this%memoryPath)
82  call mem_allocate(this%iout, 'IOUT', this%memoryPath)
83  call mem_allocate(this%ibudcsv, 'IBUDCSV', this%memoryPath)
84  call mem_allocate(this%iperoc, 'IPEROC', this%memoryPath)
85  call mem_allocate(this%iocrep, 'IOCREP', this%memoryPath)
86  call mem_allocate(this%itrkout, 'ITRKOUT', this%memoryPath)
87  call mem_allocate(this%itrkhdr, 'ITRKHDR', this%memoryPath)
88  call mem_allocate(this%itrkcsv, 'ITRKCSV', this%memoryPath)
89  call mem_allocate(this%itrktls, 'ITRKTLS', this%memoryPath)
90  call mem_allocate(this%trackrelease, 'ITRACKRELEASE', this%memoryPath)
91  call mem_allocate(this%trackfeatexit, 'ITRACKFEATEXIT', this%memoryPath)
92  call mem_allocate(this%tracktimestep, 'ITRACKTIMESTEP', this%memoryPath)
93  call mem_allocate(this%trackterminate, 'ITRACKTERMINATE', this%memoryPath)
94  call mem_allocate(this%trackweaksink, 'ITRACKWEAKSINK', this%memoryPath)
95  call mem_allocate(this%trackusertime, 'ITRACKUSERTIME', this%memoryPath)
96  call mem_allocate(this%tracksubfexit, 'ITRACKSUBFEXIT', this%memoryPath)
97  call mem_allocate(this%trackdropped, 'ITRACKDROPPED', this%memoryPath)
98  call mem_allocate(this%ntracktimes, 'NTRACKTIMES', this%memoryPath)
99 
100  this%name_model = name_model
101  this%input_mempath = input_mempath
102  this%input_fname = ''
103  this%dump_event_trace = .false.
104  this%inunit = 0
105  this%iout = 0
106  this%ibudcsv = 0
107  this%iperoc = 0
108  this%iocrep = 0
109  this%itrkout = 0
110  this%itrkhdr = 0
111  this%itrkcsv = 0
112  this%itrktls = 0
113  this%trackrelease = .false.
114  this%trackfeatexit = .false.
115  this%tracktimestep = .false.
116  this%trackterminate = .false.
117  this%trackweaksink = .false.
118  this%trackusertime = .false.
119  this%tracksubfexit = .false.
120  this%trackdropped = .false.
121  this%ntracktimes = 0
122 
123  if (this%input_mempath /= '') then
124  call mem_set_value(this%input_fname, 'INPUT_FNAME', &
125  this%input_mempath, found)
126  end if
127  end subroutine prt_oc_allocate_scalars
128 
129  !> @ brief Setup output control variables.
130  subroutine oc_ar(this, dis, dnodata)
131  ! dummy
132  class(prtoctype) :: this !< PrtOcType object
133  class(disbasetype), pointer, intent(in) :: dis !< model discretization package
134  real(DP), intent(in) :: dnodata !< no data value
135  ! local
136  integer(I4B) :: i, nocdobj, inodata
137  type(outputcontroldatatype), pointer :: ocdobjptr
138  real(DP), dimension(:), pointer, contiguous :: nullvec => null()
139 
140  ! Allocate and initialize variables
141  allocate (this%tracktimes)
142  call this%tracktimes%init()
143  inodata = 0
144  nocdobj = 1
145  allocate (this%ocds(nocdobj))
146  do i = 1, nocdobj
147  call ocd_cr(ocdobjptr)
148  select case (i)
149  case (1)
150  call ocdobjptr%init_dbl('BUDGET', nullvec, dis, 'PRINT LAST ', &
151  'COLUMNS 10 WIDTH 11 DIGITS 4 GENERAL ', &
152  this%iout, dnodata)
153  end select
154  this%ocds(i) = ocdobjptr
155  deallocate (ocdobjptr)
156  end do
157 
158  ! Read options, dimensions, and tracktimes
159  ! blocks if this package is enabled
160  if (this%input_mempath == '') return
161  call this%source_options()
162  call this%prt_oc_source_dimensions()
163  call this%prt_oc_source_tracktimes()
164  end subroutine oc_ar
165 
166  subroutine prt_oc_da(this)
167  ! dummy
168  class(prtoctype) :: this
169  ! local
170  integer(I4B) :: i
171 
172  call this%tracktimes%deallocate()
173 
174  do i = 1, size(this%ocds)
175  call this%ocds(i)%ocd_da()
176  end do
177  deallocate (this%ocds)
178 
179  deallocate (this%name_model)
180  call mem_deallocate(this%dump_event_trace)
181  call mem_deallocate(this%inunit)
182  call mem_deallocate(this%iout)
183  call mem_deallocate(this%ibudcsv)
184  call mem_deallocate(this%iperoc)
185  call mem_deallocate(this%iocrep)
186  call mem_deallocate(this%itrkout)
187  call mem_deallocate(this%itrkhdr)
188  call mem_deallocate(this%itrkcsv)
189  call mem_deallocate(this%itrktls)
190  call mem_deallocate(this%trackrelease)
191  call mem_deallocate(this%trackfeatexit)
192  call mem_deallocate(this%tracktimestep)
193  call mem_deallocate(this%trackterminate)
194  call mem_deallocate(this%trackweaksink)
195  call mem_deallocate(this%trackusertime)
196  call mem_deallocate(this%tracksubfexit)
197  call mem_deallocate(this%trackdropped)
198  call mem_deallocate(this%ntracktimes)
199 
200  end subroutine prt_oc_da
201 
202  subroutine prt_oc_source_options(this)
203  ! -- modules
204  use openspecmodule, only: access, form
206  use constantsmodule, only: linelength
210  ! -- dummy
211  class(prtoctype) :: this
212  ! -- local
213  character(len=LINELENGTH) :: trackfile, trackcsv
214  type(prtocparamfoundtype) :: found
215  integer(I4B), pointer :: evinput
216  ! formats
217  character(len=*), parameter :: fmttrkbin = &
218  "(4x, 'PARTICLE TRACKS WILL BE SAVED TO BINARY FILE: ', a, /4x, &
219  &'OPENED ON UNIT: ', I0)"
220  character(len=*), parameter :: fmttrkcsv = &
221  "(4x, 'PARTICLE TRACKS WILL BE SAVED TO CSV FILE: ', a, /4x, &
222  &'OPENED ON UNIT: ', I0)"
223 
224  allocate (evinput)
225 
226  write (this%iout, '(/,1x,a,/)') 'PROCESSING OC OPTIONS'
227  !
228  ! -- source base class options
229  call this%OutPutControlType%source_options()
230  !
231  ! -- source options
232  call mem_set_value(trackfile, 'TRACKFILE', this%input_mempath, &
233  found%trackfile)
234  call mem_set_value(trackcsv, 'TRACKCSVFILE', this%input_mempath, &
235  found%trackcsvfile)
236  call mem_set_value(evinput, 'TRACK_RELEASE', this%input_mempath, &
237  found%track_release)
238  call mem_set_value(evinput, 'TRACK_EXIT', this%input_mempath, &
239  found%track_exit)
240  call mem_set_value(evinput, 'TRACK_SUBF_EXIT', this%input_mempath, &
241  found%track_subf_exit)
242  call mem_set_value(evinput, 'TRACK_DROPPED', this%input_mempath, &
243  found%track_dropped)
244  call mem_set_value(evinput, 'TRACK_TIMESTEP', this%input_mempath, &
245  found%track_timestep)
246  call mem_set_value(evinput, 'TRACK_TERMINATE', this%input_mempath, &
247  found%track_terminate)
248  call mem_set_value(evinput, 'TRACK_WEAKSINK', this%input_mempath, &
249  found%track_weaksink)
250  call mem_set_value(evinput, 'TRACK_USERTIME', this%input_mempath, &
251  found%track_usertime)
252  call mem_set_value(evinput, 'DEV_DUMP_EVTRACE', this%input_mempath, &
253  found%dev_dump_evtrace)
254 
255  if (found%track_release) this%trackrelease = .true.
256  if (found%track_exit) this%trackfeatexit = .true.
257  if (found%track_subf_exit) this%tracksubfexit = .true.
258  if (found%track_dropped) this%trackdropped = .true.
259  if (found%track_timestep) this%tracktimestep = .true.
260  if (found%track_terminate) this%trackterminate = .true.
261  if (found%track_weaksink) this%trackweaksink = .true.
262  if (found%track_usertime) this%trackusertime = .true.
263  if (found%dev_dump_evtrace) this%dump_event_trace = .true.
264 
265  ! default to all events
266  if (.not. (found%track_release .or. &
267  found%track_exit .or. &
268  found%track_timestep .or. &
269  found%track_terminate .or. &
270  found%track_weaksink .or. &
271  found%track_usertime .or. &
272  found%track_dropped)) then
273  this%trackrelease = .true.
274  this%trackfeatexit = .true.
275  this%tracktimestep = .true.
276  this%trackterminate = .true.
277  this%trackweaksink = .true.
278  this%trackusertime = .true.
279  this%trackdropped = .true.
280  end if
281 
282  if (found%trackfile) then
283  ! open binary track output file
284  this%itrkout = getunit()
285  call openfile(this%itrkout, this%iout, trackfile, 'DATA(BINARY)', &
286  form, access, filstat_opt='REPLACE', &
287  mode_opt=mnormal)
288  write (this%iout, fmttrkbin) trim(adjustl(trackfile)), this%itrkout
289  ! open and write ascii track header file
290  this%itrkhdr = getunit()
291  trackfile = trim(trackfile)//'.hdr'
292  call openfile(this%itrkhdr, this%iout, trackfile, 'CSV', &
293  filstat_opt='REPLACE', mode_opt=mnormal)
294  write (this%itrkhdr, '(a,/,a)') trackheader, trackdtypes
295  end if
296 
297  if (found%trackcsvfile) then
298  this%itrkcsv = getunit()
299  call openfile(this%itrkcsv, this%iout, trackcsv, 'CSV', &
300  filstat_opt='REPLACE')
301  write (this%iout, fmttrkcsv) trim(adjustl(trackcsv)), this%itrkcsv
302  write (this%itrkcsv, '(a)') trackheader
303  end if
304 
305  write (this%iout, '(1x,a)') 'END OF OC OPTIONS'
306  deallocate (evinput)
307  end subroutine prt_oc_source_options
308 
309  !> @brief source the dimensions block.
310  subroutine prt_oc_source_dimensions(this)
311  use constantsmodule, only: linelength
315  ! dummy
316  class(prtoctype), intent(inout) :: this
317  ! local
318  type(prtocparamfoundtype) :: found
319  write (this%iout, '(/1x,a)') &
320  'PROCESSING OUTPUT CONTROL DIMENSIONS'
321  call mem_set_value(this%ntracktimes, 'NTRACKTIMES', this%input_mempath, &
322  found%ntracktimes)
323  if (found%ntracktimes) then
324  write (this%iout, '(4x,a,i7)') 'NTRACKTIMES = ', this%ntracktimes
325  end if
326  write (this%iout, '(1x,a)') &
327  'END OF OUTPUT CONTROL DIMENSIONS'
328 
329  if (this%ntracktimes < 0) then
330  write (errmsg, '(a)') &
331  'NTRACKTIMES WAS NOT SPECIFIED OR WAS SPECIFIED INCORRECTLY.'
332  call store_error(errmsg)
333  end if
334  end subroutine prt_oc_source_dimensions
335 
336  !> @brief source the tracking times block.
337  subroutine prt_oc_source_tracktimes(this)
341  ! dummy
342  class(prtoctype), intent(inout) :: this
343  ! local
344  real(DP), dimension(:), pointer, contiguous :: tracktimes
345  integer(I4B) :: n, asize
346 
347  if (this%ntracktimes <= 0) return
348 
349  call get_isize('TIME', this%input_mempath, asize)
350 
351  if (asize /= this%ntracktimes) then
352  write (errmsg, '(a, i0)') &
353  "Expected TRACKTIMES with length ", this%ntracktimes
354  call store_error(errmsg)
355  call store_error_filename(this%input_fname)
356  else
357  call mem_setptr(tracktimes, 'TIME', this%input_mempath)
358 
359  ! allocate time selection
360  call this%tracktimes%expand(this%ntracktimes)
361 
362  do n = 1, this%ntracktimes
363  this%tracktimes%times(n) = tracktimes(n)
364  end do
365  end if
366 
367  ! make sure times strictly increase
368  if (.not. this%tracktimes%increasing()) then
369  errmsg = "TRACKTIMES must strictly increase"
370  call store_error(errmsg)
371  call store_error_filename(this%input_fname)
372  end if
373  end subroutine prt_oc_source_tracktimes
374 
375 end module prtocmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
@ mnormal
normal output mode
Definition: Constants.f90:206
integer(i4b), parameter lenmodelname
maximum length of the model name
Definition: Constants.f90:22
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
Definition: InputOutput.f90:30
subroutine, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
This module defines variable data types.
Definition: kind.f90:8
This module contains the LongLineReaderType.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
character(len=20) access
Definition: OpenSpec.f90:7
character(len=20) form
Definition: OpenSpec.f90:7
Output control data module.
subroutine, public ocd_cr(ocdobj)
@ brief Create a new output control data type.
Model output control.
Particle track output module.
character(len= *), parameter, public trackheader
character(len= *), parameter, public trackdtypes
subroutine oc_ar(this, dis, dnodata)
@ brief Setup output control variables.
Definition: prt-oc.f90:131
subroutine prt_oc_source_dimensions(this)
source the dimensions block.
Definition: prt-oc.f90:311
subroutine prt_oc_da(this)
Definition: prt-oc.f90:167
subroutine prt_oc_source_tracktimes(this)
source the tracking times block.
Definition: prt-oc.f90:338
subroutine prt_oc_source_options(this)
Definition: prt-oc.f90:203
subroutine, public oc_cr(ocobj, name_model, input_mempath, inunit, iout)
@ brief Create an output control object
Definition: prt-oc.f90:52
subroutine prt_oc_allocate_scalars(this, name_model, input_mempath)
Definition: prt-oc.f90:70
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
integer(i4b) function, public count_errors()
Return number of errors.
Definition: Sim.f90:59
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
character(len=maxcharlen) warnmsg
warning message string
Specify times for some event to occur.
Definition: TimeSelect.f90:2
@ brief Controls model output. Overridden for each model type.
@ brief Output control for particle tracking models
Definition: prt-oc.f90:21
Represents a series of instants at which some event should occur.
Definition: TimeSelect.f90:30