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