MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
IdmLogger.f90
Go to the documentation of this file.
1!> @brief This module contains the Input Data Model Logger Module
2!!
3!! This module contains the subroutines for logging messages
4!! to the list file as the input data model loads model input.
5!!
6!<
8
9 use kindmodule, only: dp, lgp, i4b
11 use simmodule, only: store_error
14
15 implicit none
16 private
17 public :: idm_log_header
18 public :: idm_log_close
19 public :: idm_log_period_header
20 public :: idm_log_period_close
21 public :: idm_export
22 public :: idm_log_var
23
24 interface idm_log_var
25 module procedure idm_log_var_logical, idm_log_var_int, &
31 end interface idm_log_var
32
33 interface idm_export
34 module procedure idm_export_int1d, idm_export_int2d, &
37 end interface idm_export
38
39contains
40
41 !> @brief log a header message
42 !<
43 subroutine idm_log_header(component, subcomponent, iout)
44 character(len=*), intent(in) :: component !< component name
45 character(len=*), intent(in) :: subcomponent !< subcomponent name
46 integer(I4B), intent(in) :: iout
47 if (iparamlog > 0 .and. iout > 0) then
48 write (iout, '(1x,a)') 'Loading input for '//trim(component)//&
49 &'/'//trim(subcomponent)
50 end if
51 end subroutine idm_log_header
52
53 !> @brief log the closing message
54 !<
55 subroutine idm_log_close(component, subcomponent, iout)
56 character(len=*), intent(in) :: component !< component name
57 character(len=*), intent(in) :: subcomponent !< subcomponent name
58 integer(I4B), intent(in) :: iout
59 if (iparamlog > 0 .and. iout > 0) then
60 write (iout, '(1x,a)') 'Loading input complete...'
61 end if
62 end subroutine idm_log_close
63
64 !> @brief log a dynamic header message
65 !<
66 subroutine idm_log_period_header(component, iout)
67 use tdismodule, only: kper, kstp
68 character(len=*), intent(in) :: component !< component name
69 integer(I4B), intent(in) :: iout
70 if (iparamlog > 0 .and. iout > 0 .and. kstp == 1) then
71 write (iout, '(/1x,a,i0,a)') 'IDP PERIOD ', kper, &
72 ' load for component: '//trim(component)
73 end if
74 end subroutine idm_log_period_header
75
76 !> @brief log the period closing message
77 !<
78 subroutine idm_log_period_close(iout)
79 use tdismodule, only: kstp
80 integer(I4B), intent(in) :: iout
81 if (iparamlog > 0 .and. iout > 0 .and. kstp == 1) then
82 !backspace iout
83 write (iout, '(1x,a,/)') 'IDP component dynamic load complete...'
84 end if
85 end subroutine idm_log_period_close
86
87 !> @brief log the period closing message
88 !<
89 subroutine idm_log_var_ts(varname, mempath, iout, is_tas, detail)
90 character(len=*), intent(in) :: varname !< variable name
91 character(len=*), intent(in) :: mempath !< variable memory path
92 integer(I4B), intent(in) :: iout
93 logical(LGP), intent(in) :: is_tas
94 character(len=*), intent(in), optional :: detail !< additional info (ts name or count)
95 if (iparamlog > 0 .and. iout > 0) then
96 if (is_tas) then
97 if (present(detail)) then
98 write (iout, '(3x, a, ": ", a, " (", a, ")")') &
99 'Time-array-series controlled dynamic variable detected', &
100 trim(varname), trim(detail)
101 else
102 write (iout, '(3x, a, ": ", a)') &
103 'Time-array-series controlled dynamic variable detected', &
104 trim(varname)
105 end if
106 else
107 if (present(detail)) then
108 write (iout, '(3x, a, ": ", a, " (", a, ")")') &
109 'Time-series controlled dynamic variable detected', &
110 trim(varname), trim(detail)
111 else
112 write (iout, '(3x, a, ": ", a)') &
113 'Time-series controlled dynamic variable detected', trim(varname)
114 end if
115 end if
116 end if
117 end subroutine idm_log_var_ts
118
119 !> @brief Log type specific information logical
120 !<
121 subroutine idm_log_var_logical(p_mem, varname, mempath, iout)
122 logical(LGP), intent(in) :: p_mem !< logical scalar
123 character(len=*), intent(in) :: varname !< variable name
124 character(len=*), intent(in) :: mempath !< variable memory path
125 integer(I4B), intent(in) :: iout
126 character(len=LINELENGTH) :: description
127 if (iparamlog > 0 .and. iout > 0) then
128 description = 'Logical detected'
129 write (iout, '(3x, a, ": ", a, " = ", l1)') &
130 trim(description), trim(varname), p_mem
131 end if
132 end subroutine idm_log_var_logical
133
134 !> @brief Log type specific information integer
135 !<
136 subroutine idm_log_var_int(p_mem, varname, mempath, datatype, iout)
137 integer(I4B), intent(in) :: p_mem !< int scalar
138 character(len=*), intent(in) :: varname !< variable name
139 character(len=*), intent(in) :: mempath !< variable memory path
140 character(len=*), intent(in) :: datatype !< variable data type
141 integer(I4B), intent(in) :: iout
142 character(len=LINELENGTH) :: description
143 if (iparamlog > 0 .and. iout > 0) then
144 if (datatype == 'KEYWORD') then
145 description = 'Keyword detected'
146 write (iout, '(3x, a, ": ", a)') trim(description), trim(varname)
147 else
148 description = 'Integer detected'
149 write (iout, '(3x, a, ": ", a, " = ", i0)') &
150 trim(description), trim(varname), p_mem
151 end if
152 end if
153 end subroutine idm_log_var_int
154
155 !> @brief Log type specific information int1d
156 !<
157 subroutine idm_log_var_int1d(p_mem, varname, mempath, iout)
158 integer(I4B), dimension(:), contiguous, intent(in) :: p_mem !< 1d int array
159 character(len=*), intent(in) :: varname !< variable name
160 character(len=*), intent(in) :: mempath !< variable memory path
161 integer(I4B), intent(in) :: iout
162 integer(I4B) :: min_val, max_val
163 character(len=LINELENGTH) :: description
164 if (iparamlog > 0 .and. iout > 0) then
165 min_val = minval(p_mem)
166 max_val = maxval(p_mem)
167 if (min_val == max_val) then
168 description = 'Integer 1D constant array detected'
169 write (iout, '(3x, a, ": ", a, " = ", i0)') &
170 trim(description), trim(varname), min_val
171 else
172 description = 'Integer 1D array detected'
173 write (iout, '(3x, a, ": ", a, a, i0, a, i0)') &
174 trim(description), trim(varname), &
175 ' ranges from ', min_val, ' to ', max_val
176 end if
177 end if
178 end subroutine idm_log_var_int1d
179
180 !> @brief Log type specific information int2d
181 !<
182 subroutine idm_log_var_int2d(p_mem, varname, mempath, iout)
183 integer(I4B), dimension(:, :), contiguous, intent(in) :: p_mem !< 2d int array
184 character(len=*), intent(in) :: varname !< variable name
185 character(len=*), intent(in) :: mempath !< variable memory path
186 integer(I4B), intent(in) :: iout
187 integer(I4B) :: min_val, max_val
188 character(len=LINELENGTH) :: description
189 if (iparamlog > 0 .and. iout > 0) then
190 min_val = minval(p_mem)
191 max_val = maxval(p_mem)
192 if (min_val == max_val) then
193 description = 'Integer 2D constant array detected'
194 write (iout, '(3x, a, ": ", a, " = ", i0)') &
195 trim(description), trim(varname), min_val
196 else
197 description = 'Integer 2D array detected'
198 write (iout, '(3x, a, ": ", a, a, i0, a, i0)') &
199 trim(description), trim(varname), &
200 ' ranges from ', min_val, ' to ', max_val
201 end if
202 end if
203 end subroutine idm_log_var_int2d
204
205 !> @brief Log type specific information int3d
206 !<
207 subroutine idm_log_var_int3d(p_mem, varname, mempath, iout)
208 integer(I4B), dimension(:, :, :), contiguous, intent(in) :: p_mem !< 3d int array
209 character(len=*), intent(in) :: varname !< variable name
210 character(len=*), intent(in) :: mempath !< variable memory path
211 integer(I4B), intent(in) :: iout
212 integer(I4B) :: min_val, max_val
213 character(len=LINELENGTH) :: description
214 if (iparamlog > 0 .and. iout > 0) then
215 min_val = minval(p_mem)
216 max_val = maxval(p_mem)
217 if (min_val == max_val) then
218 description = 'Integer 3D constant array detected'
219 write (iout, '(3x, a, ": ", a, " = ", i0)') &
220 trim(description), trim(varname), min_val
221 else
222 description = 'Integer 3D array detected'
223 write (iout, '(3x, a, ": ", a, a, i0, a, i0)') &
224 trim(description), trim(varname), &
225 ' ranges from ', min_val, ' to ', max_val
226 end if
227 end if
228 end subroutine idm_log_var_int3d
229
230 !> @brief Log type specific information double
231 !<
232 subroutine idm_log_var_dbl(p_mem, varname, mempath, iout)
233 real(DP), intent(in) :: p_mem !< dbl scalar
234 character(len=*), intent(in) :: varname !< variable name
235 character(len=*), intent(in) :: mempath !< variable memory path
236 integer(I4B), intent(in) :: iout
237 character(len=LINELENGTH) :: description
238 if (iparamlog > 0 .and. iout > 0) then
239 description = 'Double detected'
240 write (iout, '(3x, a, ": ", a, " = ", G0)') &
241 trim(description), trim(varname), p_mem
242 end if
243 end subroutine idm_log_var_dbl
244
245 !> @brief Log type specific information dbl1d
246 !<
247 subroutine idm_log_var_dbl1d(p_mem, varname, mempath, iout)
248 real(DP), dimension(:), contiguous, intent(in) :: p_mem !< 1d real array
249 character(len=*), intent(in) :: varname !< variable name
250 character(len=*), intent(in) :: mempath !< variable memory path
251 integer(I4B), intent(in) :: iout
252 real(DP) :: min_val, max_val
253 character(len=LINELENGTH) :: description
254 if (iparamlog > 0 .and. iout > 0) then
255 min_val = minval(p_mem)
256 max_val = maxval(p_mem)
257 if (min_val == max_val) then
258 description = 'Double precision 1D constant array detected'
259 write (iout, '(3x, a, ": ", a, " = ", G0)') &
260 trim(description), trim(varname), min_val
261 else
262 description = 'Double precision 1D array detected'
263 write (iout, '(3x, a, ": ", a, a, G0, a, G0)') &
264 trim(description), trim(varname), &
265 ' ranges from ', min_val, ' to ', max_val
266 end if
267 end if
268 end subroutine idm_log_var_dbl1d
269
270 !> @brief Log type specific information dbl2d
271 !<
272 subroutine idm_log_var_dbl2d(p_mem, varname, mempath, iout)
273 real(DP), dimension(:, :), contiguous, intent(in) :: p_mem !< 2d dbl array
274 character(len=*), intent(in) :: varname !< variable name
275 character(len=*), intent(in) :: mempath !< variable memory path
276 integer(I4B), intent(in) :: iout
277 real(DP) :: min_val, max_val
278 character(len=LINELENGTH) :: description
279 if (iparamlog > 0 .and. iout > 0) then
280 min_val = minval(p_mem)
281 max_val = maxval(p_mem)
282 if (min_val == max_val) then
283 description = 'Double precision 2D constant array detected'
284 write (iout, '(3x, a, ": ", a, " = ", G0)') &
285 trim(description), trim(varname), min_val
286 else
287 description = 'Double precision 2D array detected'
288 write (iout, '(3x, a, ": ", a, a, G0, a, G0)') &
289 trim(description), trim(varname), &
290 ' ranges from ', min_val, ' to ', max_val
291 end if
292 end if
293 end subroutine idm_log_var_dbl2d
294
295 !> @brief Log type specific information dbl3d
296 !<
297 subroutine idm_log_var_dbl3d(p_mem, varname, mempath, iout)
298 real(DP), dimension(:, :, :), contiguous, intent(in) :: p_mem !< 3d dbl array
299 character(len=*), intent(in) :: varname !< variable name
300 character(len=*), intent(in) :: mempath !< variable memory path
301 integer(I4B), intent(in) :: iout
302 real(DP) :: min_val, max_val
303 character(len=LINELENGTH) :: description
304 if (iparamlog > 0 .and. iout > 0) then
305 min_val = minval(p_mem)
306 max_val = maxval(p_mem)
307 if (min_val == max_val) then
308 description = 'Double precision 3D constant array detected'
309 write (iout, '(3x, a, ": ", a, " = ", G0)') &
310 trim(description), trim(varname), min_val
311 else
312 description = 'Double precision 3D array detected'
313 write (iout, '(3x, a, ": ", a, a, G0, a, G0)') &
314 trim(description), trim(varname), &
315 ' ranges from ', min_val, ' to ', max_val
316 end if
317 end if
318 end subroutine idm_log_var_dbl3d
319
320 !> @brief Log type specific information str
321 !<
322 subroutine idm_log_var_str(p_mem, varname, mempath, iout)
323 character(len=*), intent(in) :: p_mem !< pointer to str scalar
324 character(len=*), intent(in) :: varname !< variable name
325 character(len=*), intent(in) :: mempath !< variable memory path
326 integer(I4B), intent(in) :: iout
327 character(len=LINELENGTH) :: description
328 if (iparamlog > 0 .and. iout > 0) then
329 description = 'String detected'
330 write (iout, '(3x, a, ": ", a, " = ", a)') &
331 trim(description), trim(varname), trim(p_mem)
332 end if
333 end subroutine idm_log_var_str
334
335 !> @brief Create export file int1d
336 !!
337 !! export layered int1d parameter files
338 !!
339 !<
340 subroutine idm_export_int1d(p_mem, varname, mempath, shapestr, iout)
343 integer(I4B), dimension(:), contiguous, intent(in) :: p_mem !< 1d integer array
344 character(len=*), intent(in) :: varname !< variable name
345 character(len=*), intent(in) :: mempath !< variable memory path
346 character(len=*), intent(in) :: shapestr !< dfn shape string
347 integer(I4B), intent(in) :: iout
348 integer(I4B), dimension(:), pointer, contiguous :: model_shape
349 integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
350 integer(I4B), dimension(:, :), pointer, contiguous :: int2d
351 integer(I4B), dimension(3) :: dis3d_shape
352 integer(I4B), dimension(2) :: dis2d_shape
353 integer(I4B), pointer :: distype
354 character(LENMEMPATH) :: input_mempath
355 character(LENCOMPONENTNAME) :: comp, subcomp
356 integer(I4B) :: i, j, k, inunit, export_dim
357 logical(LGP) :: is_layered
358
359 ! set pointer to DISENUM and MODEL_SHAPE
360 call split_mem_path(mempath, comp, subcomp)
361 input_mempath = create_mem_path(component=comp, context=idm_context)
362 call mem_setptr(distype, 'DISENUM', input_mempath)
363 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
364
365 ! set export_dim
366 export_dim = distype_export_dim(distype, shapestr, is_layered)
367
368 ! create export file(s)
369 select case (export_dim)
370 case (3)
371 ! set reshape array
372 dis3d_shape(1) = model_shape(3)
373 dis3d_shape(2) = model_shape(2)
374 dis3d_shape(3) = model_shape(1)
375 ! allocate and reshape
376 allocate (int3d(dis3d_shape(1), dis3d_shape(2), dis3d_shape(3)))
377 int3d = reshape(p_mem, dis3d_shape)
378 ! write export files 3D array
379 do k = 1, dis3d_shape(3)
380 inunit = create_export_file(varname, mempath, k, iout)
381 do i = 1, model_shape(2)
382 write (inunit, '(*(i0, " "))') (int3d(j, i, k), j=1, &
383 dis3d_shape(1))
384 end do
385 close (inunit)
386 end do
387 ! cleanup
388 deallocate (int3d)
389 case (2)
390 ! set reshape array
391 dis2d_shape(1) = model_shape(2)
392 dis2d_shape(2) = model_shape(1)
393 ! allocate and reshape
394 allocate (int2d(dis2d_shape(1), dis2d_shape(2)))
395 int2d = reshape(p_mem, dis2d_shape)
396 if (is_layered) then
397 ! write layered export files 2D array
398 do i = 1, dis2d_shape(2)
399 inunit = create_export_file(varname, mempath, i, iout)
400 write (inunit, '(*(i0, " "))') (int2d(j, i), j=1, dis2d_shape(1))
401 close (inunit)
402 end do
403 else
404 ! write export file 2D array
405 inunit = create_export_file(varname, mempath, 0, iout)
406 do i = 1, dis2d_shape(2)
407 write (inunit, '(*(i0, " "))') (int2d(j, i), j=1, dis2d_shape(1))
408 end do
409 close (inunit)
410 end if
411 ! cleanup
412 deallocate (int2d)
413 case (1)
414 ! write export file 1D array
415 inunit = create_export_file(varname, mempath, 0, iout)
416 write (inunit, '(*(i0, " "))') p_mem
417 close (inunit)
418 case default
419 write (errmsg, '(a,i0)') 'EXPORT unsupported int1d export_dim=', &
420 export_dim
421 call store_error(errmsg, .true.)
422 end select
423 end subroutine idm_export_int1d
424
425 !> @brief Create export file int2d
426 !<
427 subroutine idm_export_int2d(p_mem, varname, mempath, shapestr, iout)
430 integer(I4B), dimension(:, :), contiguous, intent(in) :: p_mem !< 2d dbl array
431 character(len=*), intent(in) :: varname !< variable name
432 character(len=*), intent(in) :: mempath !< variable memory path
433 character(len=*), intent(in) :: shapestr !< dfn shape string
434 integer(I4B), intent(in) :: iout
435 integer(I4B), dimension(:), pointer, contiguous :: model_shape
436 integer(I4B), pointer :: distype
437 character(LENMEMPATH) :: input_mempath
438 character(LENCOMPONENTNAME) :: comp, subcomp
439 integer(I4B) :: i, j, inunit, export_dim
440 logical(LGP) :: is_layered
441
442 ! set pointer to DISENUM
443 call split_mem_path(mempath, comp, subcomp)
444 input_mempath = create_mem_path(component=comp, context=idm_context)
445 call mem_setptr(distype, 'DISENUM', input_mempath)
446 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
447
448 ! set export_dim
449 export_dim = distype_export_dim(distype, shapestr, is_layered)
450
451 select case (export_dim)
452 case (1)
453 ! write export file 1D array
454 inunit = create_export_file(varname, mempath, 0, iout)
455 do i = 1, size(p_mem, dim=2)
456 write (inunit, '(*(i0, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
457 end do
458 close (inunit)
459 case (2)
460 if (is_layered) then
461 ! write layered export files 2D array
462 do i = 1, size(p_mem, dim=2)
463 inunit = create_export_file(varname, mempath, i, iout)
464 write (inunit, '(*(i0, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
465 close (inunit)
466 end do
467 else
468 ! write export file 2D array
469 inunit = create_export_file(varname, mempath, 0, iout)
470 do i = 1, size(p_mem, dim=2)
471 write (inunit, '(*(i0, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
472 end do
473 close (inunit)
474 end if
475 case default
476 write (errmsg, '(a,i0)') 'EXPORT unsupported int2d export_dim=', &
477 export_dim
478 call store_error(errmsg, .true.)
479 end select
480 end subroutine idm_export_int2d
481
482 !> @brief Create export file int3d
483 !<
484 subroutine idm_export_int3d(p_mem, varname, mempath, shapestr, iout)
487 integer(I4B), dimension(:, :, :), contiguous, intent(in) :: p_mem !< 2d dbl array
488 character(len=*), intent(in) :: varname !< variable name
489 character(len=*), intent(in) :: mempath !< variable memory path
490 character(len=*), intent(in) :: shapestr !< dfn shape string
491 integer(I4B), intent(in) :: iout
492 integer(I4B), dimension(:), pointer, contiguous :: model_shape
493 integer(I4B), pointer :: distype
494 character(LENMEMPATH) :: input_mempath
495 character(LENCOMPONENTNAME) :: comp, subcomp
496 integer(I4B) :: i, j, k, inunit, export_dim
497 logical(LGP) :: is_layered
498
499 ! set pointer to DISENUM
500 call split_mem_path(mempath, comp, subcomp)
501 input_mempath = create_mem_path(component=comp, context=idm_context)
502 call mem_setptr(distype, 'DISENUM', input_mempath)
503 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
504
505 ! set export_dim
506 export_dim = distype_export_dim(distype, shapestr, is_layered)
507
508 select case (export_dim)
509 case (3)
510 ! write export files 3D array
511 do k = 1, size(p_mem, dim=3)
512 inunit = create_export_file(varname, mempath, k, iout)
513 do i = 1, size(p_mem, dim=2)
514 write (inunit, '(*(i0, " "))') (p_mem(j, i, k), j=1, size(p_mem, dim=1))
515 end do
516 close (inunit)
517 end do
518 case default
519 write (errmsg, '(a,i0)') 'EXPORT unsupported int3d export_dim=', &
520 export_dim
521 call store_error(errmsg, .true.)
522 end select
523 end subroutine idm_export_int3d
524
525 !> @brief Create export file dbl1d
526 !!
527 !! export layered dbl1d parameters with NODES shape
528 !!
529 !<
530 subroutine idm_export_dbl1d(p_mem, varname, mempath, shapestr, iout)
533 real(DP), dimension(:), contiguous, intent(in) :: p_mem !< 1d dbl array
534 character(len=*), intent(in) :: varname !< variable name
535 character(len=*), intent(in) :: mempath !< variable memory path
536 character(len=*), intent(in) :: shapestr !< dfn shape string
537 integer(I4B), intent(in) :: iout
538 integer(I4B), dimension(:), pointer, contiguous :: model_shape
539 real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
540 real(DP), dimension(:, :), pointer, contiguous :: dbl2d
541 integer(I4B), dimension(3) :: dis3d_shape
542 integer(I4B), dimension(2) :: dis2d_shape
543 integer(I4B), pointer :: distype
544 character(LENMEMPATH) :: input_mempath
545 character(LENCOMPONENTNAME) :: comp, subcomp
546 integer(I4B) :: i, j, k, inunit, export_dim
547 logical(LGP) :: is_layered
548
549 ! set pointer to DISENUM and MODEL_SHAPE
550 call split_mem_path(mempath, comp, subcomp)
551 input_mempath = create_mem_path(component=comp, context=idm_context)
552 call mem_setptr(distype, 'DISENUM', input_mempath)
553 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
554
555 ! set export_dim
556 export_dim = distype_export_dim(distype, shapestr, is_layered)
557
558 ! create export file(s)
559 select case (export_dim)
560 case (3)
561 ! set reshape array
562 dis3d_shape(1) = model_shape(3)
563 dis3d_shape(2) = model_shape(2)
564 ! allocate and reshape
565 dis3d_shape(3) = model_shape(1)
566 allocate (dbl3d(dis3d_shape(1), dis3d_shape(2), dis3d_shape(3)))
567 dbl3d = reshape(p_mem, dis3d_shape)
568 do k = 1, dis3d_shape(3)
569 ! write export files 3D array
570 inunit = create_export_file(varname, mempath, k, iout)
571 do i = 1, model_shape(2)
572 write (inunit, '(*(G0.10, " "))') (dbl3d(j, i, k), j=1, &
573 dis3d_shape(1))
574 end do
575 close (inunit)
576 end do
577 ! cleanup
578 deallocate (dbl3d)
579 case (2)
580 ! set reshape array
581 dis2d_shape(1) = model_shape(2)
582 dis2d_shape(2) = model_shape(1)
583 ! allocate and reshape
584 allocate (dbl2d(dis2d_shape(1), dis2d_shape(2)))
585 dbl2d = reshape(p_mem, dis2d_shape)
586 if (is_layered) then
587 ! write layered export files 2D array
588 do i = 1, dis2d_shape(2)
589 inunit = create_export_file(varname, mempath, i, iout)
590 write (inunit, '(*(G0.10, " "))') (dbl2d(j, i), j=1, dis2d_shape(1))
591 close (inunit)
592 end do
593 else
594 ! write export file 2D array
595 inunit = create_export_file(varname, mempath, 0, iout)
596 do i = 1, dis2d_shape(2)
597 write (inunit, '(*(G0.10, " "))') (dbl2d(j, i), j=1, dis2d_shape(1))
598 end do
599 close (inunit)
600 end if
601 ! cleanup
602 deallocate (dbl2d)
603 case (1)
604 ! write export file 1D array
605 inunit = create_export_file(varname, mempath, 0, iout)
606 write (inunit, '(*(G0.10, " "))') p_mem
607 close (inunit)
608 case default
609 write (errmsg, '(a,i0)') 'EXPORT unsupported dbl1d export_dim=', &
610 export_dim
611 call store_error(errmsg, .true.)
612 end select
613 end subroutine idm_export_dbl1d
614
615 !> @brief Create export file dbl2d
616 !<
617 subroutine idm_export_dbl2d(p_mem, varname, mempath, shapestr, iout)
620 real(DP), dimension(:, :), contiguous, intent(in) :: p_mem !< 2d dbl array
621 character(len=*), intent(in) :: varname !< variable name
622 character(len=*), intent(in) :: mempath !< variable memory path
623 character(len=*), intent(in) :: shapestr !< dfn shape string
624 integer(I4B), intent(in) :: iout
625 integer(I4B), dimension(:), pointer, contiguous :: model_shape
626 integer(I4B), pointer :: distype
627 character(LENMEMPATH) :: input_mempath
628 character(LENCOMPONENTNAME) :: comp, subcomp
629 integer(I4B) :: i, j, inunit, export_dim
630 logical(LGP) :: is_layered
631
632 ! set pointer to DISENUM
633 call split_mem_path(mempath, comp, subcomp)
634 input_mempath = create_mem_path(component=comp, context=idm_context)
635 call mem_setptr(distype, 'DISENUM', input_mempath)
636 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
637
638 ! set export_dim
639 export_dim = distype_export_dim(distype, shapestr, is_layered)
640
641 select case (export_dim)
642 case (1)
643 ! write export file 1D array
644 inunit = create_export_file(varname, mempath, 0, iout)
645 do i = 1, size(p_mem, dim=2)
646 write (inunit, '(*(G0.10, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
647 end do
648 close (inunit)
649 case (2)
650 if (is_layered) then
651 ! write layered export files 2D array
652 do i = 1, size(p_mem, dim=2)
653 inunit = create_export_file(varname, mempath, i, iout)
654 write (inunit, '(*(G0.10, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
655 close (inunit)
656 end do
657 else
658 ! write export file 2D array
659 inunit = create_export_file(varname, mempath, 0, iout)
660 do i = 1, size(p_mem, dim=2)
661 write (inunit, '(*(G0.10, " "))') (p_mem(j, i), j=1, size(p_mem, dim=1))
662 end do
663 close (inunit)
664 end if
665 case default
666 write (errmsg, '(a,i0)') 'EXPORT unsupported dbl2d export_dim=', &
667 export_dim
668 call store_error(errmsg, .true.)
669 end select
670 end subroutine idm_export_dbl2d
671
672 !> @brief Create export file dbl3d
673 !<
674 subroutine idm_export_dbl3d(p_mem, varname, mempath, shapestr, iout)
677 real(DP), dimension(:, :, :), contiguous, intent(in) :: p_mem !< 2d dbl array
678 character(len=*), intent(in) :: varname !< variable name
679 character(len=*), intent(in) :: mempath !< variable memory path
680 character(len=*), intent(in) :: shapestr !< dfn shape string
681 integer(I4B), intent(in) :: iout
682 integer(I4B), dimension(:), pointer, contiguous :: model_shape
683 integer(I4B), pointer :: distype
684 character(LENMEMPATH) :: input_mempath
685 character(LENCOMPONENTNAME) :: comp, subcomp
686 integer(I4B) :: i, j, k, inunit, export_dim
687 logical(LGP) :: is_layered
688
689 ! set pointer to DISENUM
690 call split_mem_path(mempath, comp, subcomp)
691 input_mempath = create_mem_path(component=comp, context=idm_context)
692 call mem_setptr(distype, 'DISENUM', input_mempath)
693 call mem_setptr(model_shape, 'MODEL_SHAPE', input_mempath)
694
695 ! set export_dim
696 export_dim = distype_export_dim(distype, shapestr, is_layered)
697
698 select case (export_dim)
699 case (3)
700 ! write export files 3D array
701 do k = 1, size(p_mem, dim=3)
702 inunit = create_export_file(varname, mempath, k, iout)
703 do i = 1, size(p_mem, dim=2)
704 write (inunit, '(*(G0.10, " "))') (p_mem(j, i, k), j=1, &
705 size(p_mem, dim=1))
706 end do
707 close (inunit)
708 end do
709 case default
710 write (errmsg, '(a,i0)') 'EXPORT unsupported dbl3d export_dim=', &
711 export_dim
712 call store_error(errmsg, .true.)
713 end select
714 end subroutine idm_export_dbl3d
715
716 !> @brief Set dis type export_dim
717 !!
718 !! Set the dimension of the export
719 !<
720 function distype_export_dim(distype, shapestr, is_layered) &
721 result(export_dim)
722 integer(I4B), pointer, intent(in) :: distype
723 character(len=*), intent(in) :: shapestr !< dfn shape string
724 logical(LGP), intent(inout) :: is_layered !< does this data represent layers
725 integer(I4B) :: export_dim
726
727 ! initialize is_layered to false
728 is_layered = .false.
729
730 select case (distype)
731 case (dis)
732 if (shapestr == 'NODES') then
733 export_dim = 3
734 is_layered = .true.
735 else if (shapestr == 'NCOL NROW NLAY') then
736 export_dim = 3
737 is_layered = .true.
738 else
739 export_dim = 1
740 end if
741 case (disv)
742 if (shapestr == 'NODES') then
743 export_dim = 2
744 is_layered = .true.
745 else if (shapestr == 'NCPL NLAY') then
746 export_dim = 2
747 is_layered = .true.
748 else
749 export_dim = 1
750 end if
751 case (dis2d)
752 if (shapestr == 'NODES') then
753 export_dim = 2
754 else if (shapestr == 'NCOL NROW') then
755 export_dim = 2
756 else
757 export_dim = 1
758 end if
759 case (disu, disv1d)
760 export_dim = 1
761 case default
762 export_dim = 0
763 end select
764 end function distype_export_dim
765
766 !> @brief Create export file
767 !!
768 !! Name formats where l=layer, a=auxiliary, p=period
769 !! : <comp>-<subcomp>.varname.txt
770 !! : <comp>-<subcomp>.varname.l<num>.txt
771 !! : <comp>-<subcomp>.varname.p<num>.txt
772 !! : <comp>-<subcomp>.varname.a<num>.p<num>.txt
773 !<
774 function create_export_file(varname, mempath, layer, iout) &
775 result(inunit)
776 use constantsmodule, only: lenvarname
780 character(len=*), intent(in) :: varname !< variable name
781 character(len=*), intent(in) :: mempath !< variable memory path
782 integer(I4B), intent(in) :: layer
783 integer(I4B), intent(in) :: iout
784 integer(I4B) :: inunit
785 character(len=LENCOMPONENTNAME) :: comp, subcomp
786 character(len=LINELENGTH) :: filename, suffix
787
788 ! split the mempath
789 call split_mem_path(mempath, comp, subcomp)
790 call lowcase(comp)
791 call lowcase(subcomp)
792
793 ! build suffix
794 suffix = varname
795 call lowcase(suffix)
796 if (layer > 0) then
797 write (suffix, '(a,i0)') trim(suffix)//'.l', layer
798 end if
799 suffix = trim(suffix)//'.txt'
800
801 ! set filename
802 filename = trim(comp)//'-'//trim(subcomp)//'.'//trim(suffix)
803
804 ! silently create the array file
805 inunit = getunit()
806 call openfile(inunit, 0, filename, 'EXPORT', filstat_opt='REPLACE')
807 end function create_export_file
808
809end module idmloggermodule
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
integer(i4b), parameter lencomponentname
maximum length of a component name
Definition Constants.f90:18
@ disu
DISV6 discretization.
@ dis
DIS6 discretization.
@ disv1d
DISV1D6 discretization.
@ dis2d
DIS2D6 discretization.
@ disv
DISU6 discretization.
@ disundef
undefined discretization
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition Constants.f90:27
This module contains the Input Data Model Logger Module.
Definition IdmLogger.f90:7
subroutine idm_log_var_str(p_mem, varname, mempath, iout)
Log type specific information str.
integer(i4b) function create_export_file(varname, mempath, layer, iout)
Create export file.
subroutine idm_log_var_int(p_mem, varname, mempath, datatype, iout)
Log type specific information integer.
integer(i4b) function distype_export_dim(distype, shapestr, is_layered)
Set dis type export_dim.
subroutine idm_export_int2d(p_mem, varname, mempath, shapestr, iout)
Create export file int2d.
subroutine, public idm_log_close(component, subcomponent, iout)
log the closing message
Definition IdmLogger.f90:56
subroutine idm_export_dbl2d(p_mem, varname, mempath, shapestr, iout)
Create export file dbl2d.
subroutine, public idm_log_period_header(component, iout)
log a dynamic header message
Definition IdmLogger.f90:67
subroutine idm_log_var_dbl3d(p_mem, varname, mempath, iout)
Log type specific information dbl3d.
subroutine idm_export_int3d(p_mem, varname, mempath, shapestr, iout)
Create export file int3d.
subroutine, public idm_log_header(component, subcomponent, iout)
log a header message
Definition IdmLogger.f90:44
subroutine idm_log_var_dbl2d(p_mem, varname, mempath, iout)
Log type specific information dbl2d.
subroutine idm_export_dbl3d(p_mem, varname, mempath, shapestr, iout)
Create export file dbl3d.
subroutine idm_log_var_int1d(p_mem, varname, mempath, iout)
Log type specific information int1d.
subroutine idm_log_var_ts(varname, mempath, iout, is_tas, detail)
log the period closing message
Definition IdmLogger.f90:90
subroutine, public idm_log_period_close(iout)
log the period closing message
Definition IdmLogger.f90:79
subroutine idm_log_var_dbl(p_mem, varname, mempath, iout)
Log type specific information double.
subroutine idm_log_var_dbl1d(p_mem, varname, mempath, iout)
Log type specific information dbl1d.
subroutine idm_log_var_int2d(p_mem, varname, mempath, iout)
Log type specific information int2d.
subroutine idm_log_var_int3d(p_mem, varname, mempath, iout)
Log type specific information int3d.
subroutine idm_log_var_logical(p_mem, varname, mempath, iout)
Log type specific information logical.
subroutine idm_export_dbl1d(p_mem, varname, mempath, shapestr, iout)
Create export file dbl1d.
subroutine idm_export_int1d(p_mem, varname, mempath, shapestr, iout)
Create export file int1d.
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public lowcase(word)
Convert to lower case.
subroutine, public upcase(word)
Convert to upper case.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
This module defines variable data types.
Definition kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine split_mem_path(mem_path, component, subcomponent)
Split the memory path into component(s).
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
integer(i4b) iout
file unit number for simulation output
integer(i4b) iparamlog
input (idm) parameter logging to simulation listing file
integer(i4b), pointer, public kstp
current time step number
Definition tdis.f90:27
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26