MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
PrintSaveManager.f90
Go to the documentation of this file.
1 !> @brief Print/save manager module.
3 
4  use kindmodule, only: dp, i4b, lgp
6  use simmodule, only: store_error
7  use inputoutputmodule, only: urword
9 
10  implicit none
11  private
12  public :: printsavemanagertype
13  public :: create_psm
14 
15  !> @brief Print/save manager type.
16  !!
17  !! Stores user settings as configured in an input file's period block
18  !! and determines whether data should be printed to a list (log) file
19  !! or saved to disk.
20  !!
21  !! The object should be initiated with the init() procedure.
22  !!
23  !! The rp() procedure will read a character string and configure the
24  !! manager, where the character string may be of the following form:
25  !!
26  !! PRINT ALL
27  !! PRINT STEPS 1 4 5 6
28  !! PRINT FIRST
29  !! PRINT LAST
30  !! PRINT FREQUENCY 4
31  !! SAVE ALL
32  !! SAVE STEPS 1 4 5 6
33  !! SAVE FIRST
34  !! SAVE LAST
35  !! SAVE FREQUENCY 4
36  !!
37  !! The should_print() and should_save() functions indicate whether
38  !! to save or print during the current time step.
39  !<
41  private
42  type(timestepselecttype), pointer, public :: save_steps
43  type(timestepselecttype), pointer, public :: print_steps
44  contains
45  procedure :: allocate
46  procedure :: deallocate
47  procedure :: init
48  procedure :: read
49  procedure :: set
50  procedure :: should_print
51  procedure :: should_save
52  end type printsavemanagertype
53 
54 contains
55 
56  !> @brief Initialize or clear the print/save manager.
57  function create_psm() result(psm)
58  type(printsavemanagertype), pointer :: psm !< the print/save manager
59  allocate (psm)
60  call psm%allocate()
61  end function create_psm
62 
63  subroutine allocate (this)
64  class(printsavemanagertype) :: this
65  allocate (this%save_steps)
66  allocate (this%print_steps)
67  call this%save_steps%init()
68  call this%print_steps%init()
69  end subroutine allocate
70 
71  subroutine deallocate (this)
72  class(printsavemanagertype) :: this !< this instance
73  if (associated(this%save_steps)) deallocate (this%save_steps)
74  if (associated(this%print_steps)) deallocate (this%print_steps)
75  end subroutine deallocate
76 
77  subroutine init(this)
78  class(printsavemanagertype) :: this
79  call this%deallocate()
80  call this%allocate()
81  end subroutine init
82 
83  !> @ brief Read a line of input and prepare the manager.
84  subroutine read (this, linein, iout)
85  ! dummy
86  class(printsavemanagertype) :: this !< this instance
87  character(len=*), intent(in) :: linein !< input line
88  integer(I4B), intent(in) :: iout !< output file unit
89  ! local
90  character(len=len(linein)) :: line
91  integer(I4B) :: lloc, istart, istop, ival
92  real(DP) :: rval
93 
94  line(:) = linein(:)
95  lloc = 1
96  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
97 
98  select case (line(istart:istop))
99  case ('PRINT')
100  call this%print_steps%read(line(istop + 2:))
101  if (iout > 0) &
102  call this%print_steps%log(iout, verb="PRINTED")
103  case ('SAVE')
104  call this%save_steps%read(line(istop + 2:))
105  if (iout > 0) &
106  call this%save_steps%log(iout, verb="SAVED")
107  case default
108  call store_error( &
109  'Looking for PRINT or SAVE. Found: '//trim(adjustl(line)), &
110  terminate=.true.)
111  end select
112  end subroutine read
113 
114  !> @ brief set data from an input record.
115  subroutine set(this, ocaction, ocsetting, iout)
116  ! dummy
117  class(printsavemanagertype) :: this !< this instance
118  character(len=*) :: ocaction
119  character(len=*) :: ocsetting
120  integer(I4B), intent(in) :: iout !< output file unit
121  select case (ocaction)
122  case ('PRINT')
123  call this%print_steps%read(ocsetting)
124  if (iout > 0) &
125  call this%print_steps%log(iout, verb="PRINTED")
126  case ('SAVE')
127  call this%save_steps%read(ocsetting)
128  if (iout > 0) &
129  call this%save_steps%log(iout, verb="SAVED")
130  case default
131  call store_error( &
132  'Looking for PRINT or SAVE. Found: '//trim(adjustl(ocaction)), &
133  terminate=.true.)
134  end select
135  end subroutine set
136 
137  !> @ brief Determine if printing is enabled for this time step.
138  logical function should_print(this, kstp, endofperiod)
139  class(printsavemanagertype) :: this !< this instance
140  integer(I4B), intent(in) :: kstp !< current time step
141  logical(LGP), intent(in) :: endofperiod !< whether last step of stress period
142 
143  should_print = this%print_steps%is_selected(kstp, endofperiod)
144  end function should_print
145 
146  !> @ brief Determine if saving is enabled for this time step.
147  logical function should_save(this, kstp, endofperiod)
148  class(printsavemanagertype) :: this !< this instance
149  integer(I4B), intent(in) :: kstp !< current time step
150  logical(LGP), intent(in) :: endofperiod !< whether last step of stress period
151 
152  should_save = this%save_steps%is_selected(kstp, endofperiod)
153  end function should_save
154 
155 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
Print/save manager module.
subroutine set(this, ocaction, ocsetting, iout)
@ brief set data from an input record.
logical function should_print(this, kstp, endofperiod)
@ brief Determine if printing is enabled for this time step.
subroutine read(this, linein, iout)
@ brief Read a line of input and prepare the manager.
type(printsavemanagertype) function, pointer, public create_psm()
Initialize or clear the print/save manager.
subroutine allocate(this)
subroutine deallocate(this)
logical function should_save(this, kstp, endofperiod)
@ brief Determine if saving is enabled for this time step.
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
Time step selection module.