MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
PrintSaveManager.f90
Go to the documentation of this file.
1 !> @brief This module contains the PrintSaveManagerModule
2 !!
3 !! This module defines the PrintSaveManagerType, which can be used
4 !! to determine when something should be printed and/or saved. The
5 !! object should be initiated with the following call:
6 !! call psm_obj%init()
7 !!
8 !! The set method will configure the members based on the following
9 !! keywords when set is called as follows:
10 !! call psm_obj%set(nstp, line)
11 !! where line may be in the following form:
12 !! PRINT ALL
13 !! PRINT STEPS 1 4 5 6
14 !! PRINT FIRST
15 !! PRINT LAST
16 !! PRINT FREQUENCY 4
17 !! SAVE ALL
18 !! SAVE STEPS 1 4 5 6
19 !! SAVE FIRST
20 !! SAVE LAST
21 !! SAVE FREQUENCY 4
22 !!
23 !! Based on the keywords, the object can be called with
24 !! psm_obj%time_to_print(kstp, kper)
25 !! psm_obj%time_to_save(kstp, kper)
26 !! to return a logical flag indicating whether or not it
27 !! it is time to print or time to save
28 !!
29 !<
31 
32  use kindmodule, only: dp, i4b, lgp
34  use simvariablesmodule, only: errmsg
35  use simmodule, only: store_error
36  use inputoutputmodule, only: urword
37 
38  implicit none
39  private
40  public :: printsavemanagertype
41 
42  !> @ brief PrintSaveManagerType
43  !!
44  !! Object for storing information and determining whether or
45  !! not data should be printed to a list file or saved to disk.
46  !<
48  integer(I4B), allocatable, dimension(:) :: kstp_list_print
49  integer(I4B), allocatable, dimension(:) :: kstp_list_save
50  integer(I4B) :: ifreq_print
51  integer(I4B) :: ifreq_save
52  logical :: print_first
53  logical :: save_first
54  logical :: print_last
55  logical :: save_last
56  logical :: print_all
57  logical :: save_all
58  logical :: save_detected
59  logical :: print_detected
60  contains
61  procedure :: init
62  procedure :: rp
63  procedure :: kstp_to_print
64  procedure :: kstp_to_save
65  end type printsavemanagertype
66 
67 contains
68 
69  !> @ brief Initialize PrintSaveManager
70  !!
71  !! Initializes variables of a PrintSaveManagerType
72  !!
73  !<
74  subroutine init(this)
75  ! -- dummy
76  class(printsavemanagertype) :: this !< psm object to initialize
77  !
78  ! -- Initialize members to their defaults
79  if (allocated(this%kstp_list_print)) deallocate (this%kstp_list_print)
80  if (allocated(this%kstp_list_save)) deallocate (this%kstp_list_save)
81  allocate (this%kstp_list_print(0))
82  allocate (this%kstp_list_save(0))
83  this%ifreq_print = 0
84  this%ifreq_save = 0
85  this%save_first = .false.
86  this%save_last = .false.
87  this%save_all = .false.
88  this%print_first = .false.
89  this%print_last = .false.
90  this%print_all = .false.
91  this%save_detected = .false.
92  this%print_detected = .false.
93  !
94  ! -- return
95  return
96  end subroutine init
97 
98  !> @ brief Read and prepare for PrintSaveManager
99  !!
100  !! Parse information in the line and assign settings for the
101  !! PrintSaveManagerType.
102  !!
103  !<
104  subroutine rp(this, linein, iout)
105  ! -- dummy
106  class(printsavemanagertype) :: this !< psm object
107  character(len=*), intent(in) :: linein !< character line of information
108  integer(I4B), intent(in) :: iout !< unit number of output file
109  ! -- local
110  character(len=len(linein)) :: line
111  logical lp, ls
112  integer(I4B) :: n
113  integer(I4B) :: lloc, istart, istop, ival
114  real(DP) :: rval
115  ! -- formats
116  character(len=*), parameter :: fmt_steps = &
117  &"(6x,'THE FOLLOWING STEPS WILL BE ',A,': ',50(I0,' '))"
118  character(len=*), parameter :: fmt_freq = &
119  &"(6x,'THE FOLLOWING FREQUENCY WILL BE ',A,': ',I0)"
120  !
121  ! -- Set the values based on line
122  ! -- Get keyword to use in assignment
123  line(:) = linein(:)
124  lloc = 1
125  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
126  !
127  ! -- set dimension for print or save
128  lp = .false.
129  ls = .false.
130  select case (line(istart:istop))
131  case ('PRINT')
132  lp = .true.
133  case ('SAVE')
134  ls = .true.
135  case default
136  write (errmsg, '(2a)') &
137  'Looking for PRINT or SAVE. Found:', trim(adjustl(line))
138  call store_error(errmsg, terminate=.true.)
139  end select
140  !
141  ! -- set member variables
142  this%save_detected = ls
143  this%print_detected = lp
144  !
145  ! -- set the steps to print or save
146  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
147  select case (line(istart:istop))
148  case ('ALL')
149  if (lp) then
150  this%print_all = .true.
151  if (iout > 0) write (iout, "(6x,a)") 'ALL TIME STEPS WILL BE PRINTED'
152  end if
153  if (ls) then
154  this%save_all = .true.
155  if (iout > 0) write (iout, "(6x,a)") 'ALL TIME STEPS WILL BE SAVED'
156  end if
157  case ('STEPS')
158  listsearch: do
159  call urword(line, lloc, istart, istop, 2, ival, rval, -1, 0)
160  if (ival > 0) then
161  if (lp) then
162  n = size(this%kstp_list_print)
163  call expandarray(this%kstp_list_print)
164  this%kstp_list_print(n + 1) = ival
165  end if
166  if (ls) then
167  n = size(this%kstp_list_save)
168  call expandarray(this%kstp_list_save)
169  this%kstp_list_save(n + 1) = ival
170  end if
171  cycle listsearch
172  end if
173  exit listsearch
174  end do listsearch
175  if (iout > 0) then
176  if (lp) write (iout, fmt_steps) 'PRINTED', this%kstp_list_print
177  if (ls) write (iout, fmt_steps) 'SAVED', this%kstp_list_save
178  end if
179  case ('FREQUENCY')
180  call urword(line, lloc, istart, istop, 2, ival, rval, -1, 0)
181  if (lp) this%ifreq_print = ival
182  if (ls) this%ifreq_save = ival
183  if (iout > 0) then
184  if (lp) write (iout, fmt_freq) 'PRINTED', this%ifreq_print
185  if (ls) write (iout, fmt_freq) 'SAVED', this%ifreq_save
186  end if
187  case ('FIRST')
188  if (lp) then
189  this%print_first = .true.
190  if (iout > 0) write (iout, "(6x,a)") 'THE FIRST TIME STEP WILL BE PRINTED'
191  end if
192  if (ls) then
193  this%save_first = .true.
194  if (iout > 0) write (iout, "(6x,a)") 'THE FIRST TIME STEP WILL BE SAVED'
195  end if
196  case ('LAST')
197  if (lp) then
198  this%print_last = .true.
199  if (iout > 0) write (iout, "(6x,a)") 'THE LAST TIME STEP WILL BE PRINTED'
200  end if
201  if (ls) then
202  this%save_last = .true.
203  if (iout > 0) write (iout, "(6x,a)") 'THE LAST TIME STEP WILL BE SAVED'
204  end if
205  case default
206  write (errmsg, '(2a)') &
207  'Looking for ALL, STEPS, FIRST, LAST, OR FREQUENCY. Found: ', &
208  trim(adjustl(line))
209  call store_error(errmsg, terminate=.true.)
210  end select
211  !
212  ! -- return
213  return
214  end subroutine rp
215 
216  !> @ brief Determine if it is time to print the data
217  !!
218  !! Determine if data should be printed based on kstp and endofperiod
219  !!
220  !<
221  logical function kstp_to_print(this, kstp, endofperiod)
222  ! -- dummy
223  class(printsavemanagertype) :: this !< psm object
224  integer(I4B), intent(in) :: kstp !< current time step
225  logical(LGP), intent(in) :: endofperiod !< flag indicating end of stress period
226  ! -- local
227  integer(I4B) :: i, n
228  !
229  kstp_to_print = .false.
230  if (this%print_all) kstp_to_print = .true.
231  if (kstp == 1 .and. this%print_first) kstp_to_print = .true.
232  if (endofperiod .and. this%print_last) kstp_to_print = .true.
233  if (this%ifreq_print > 0) then
234  if (mod(kstp, this%ifreq_print) == 0) kstp_to_print = .true.
235  end if
236  n = size(this%kstp_list_print)
237  if (n > 0) then
238  do i = 1, n
239  if (kstp == this%kstp_list_print(i)) then
240  kstp_to_print = .true.
241  exit
242  end if
243  end do
244  end if
245  !
246  ! -- Return
247  return
248  end function kstp_to_print
249 
250  !> @ brief Determine if it is time to save the data
251  !!
252  !! Determine if data should be saved based on kstp and endofperiod
253  !!
254  !<
255  logical function kstp_to_save(this, kstp, endofperiod)
256  ! -- dummy
257  class(printsavemanagertype) :: this !< psm object
258  integer(I4B), intent(in) :: kstp !< current time step
259  logical(LGP), intent(in) :: endofperiod !< flag indicating end of stress period
260  ! -- local
261  integer(I4B) :: i, n
262  !
263  kstp_to_save = .false.
264  if (this%save_all) kstp_to_save = .true.
265  if (kstp == 1 .and. this%save_first) kstp_to_save = .true.
266  if (endofperiod .and. this%save_last) kstp_to_save = .true.
267  if (this%ifreq_save > 0) then
268  if (mod(kstp, this%ifreq_save) == 0) kstp_to_save = .true.
269  end if
270  n = size(this%kstp_list_save)
271  if (n > 0) then
272  do i = 1, n
273  if (kstp == this%kstp_list_save(i)) then
274  kstp_to_save = .true.
275  exit
276  end if
277  end do
278  end if
279  !
280  ! -- Return
281  return
282  end function kstp_to_save
283 
284 end module printsavemanagermodule
subroutine init()
Definition: GridSorting.f90:24
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 PrintSaveManagerModule.
logical function kstp_to_print(this, kstp, endofperiod)
@ brief Determine if it is time to print the data
subroutine rp(this, linein, iout)
@ brief Read and prepare for PrintSaveManager
logical function kstp_to_save(this, kstp, endofperiod)
@ brief Determine if it is time to save the data
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