MODFLOW 6  version 6.6.0.dev0
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 :: should_print
50  procedure :: should_save
51  end type printsavemanagertype
52 
53 contains
54 
55  !> @brief Initialize or clear the print/save manager.
56  function create_psm() result(psm)
57  type(printsavemanagertype), pointer :: psm !< the print/save manager
58  allocate (psm)
59  call psm%allocate()
60  end function create_psm
61 
62  subroutine allocate (this)
63  class(printsavemanagertype) :: this
64  allocate (this%save_steps)
65  allocate (this%print_steps)
66  call this%save_steps%init()
67  call this%print_steps%init()
68  end subroutine allocate
69 
70  subroutine deallocate (this)
71  class(printsavemanagertype) :: this !< this instance
72  if (associated(this%save_steps)) deallocate (this%save_steps)
73  if (associated(this%print_steps)) deallocate (this%print_steps)
74  end subroutine deallocate
75 
76  subroutine init(this)
77  class(printsavemanagertype) :: this
78  call this%deallocate()
79  call this%allocate()
80  end subroutine init
81 
82  !> @ brief Read a line of input and prepare the manager.
83  subroutine read (this, linein, iout)
84  ! dummy
85  class(printsavemanagertype) :: this !< this instance
86  character(len=*), intent(in) :: linein !< input line
87  integer(I4B), intent(in) :: iout !< output file unit
88  ! local
89  character(len=len(linein)) :: line
90  integer(I4B) :: lloc, istart, istop, ival
91  real(DP) :: rval
92 
93  line(:) = linein(:)
94  lloc = 1
95  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
96 
97  select case (line(istart:istop))
98  case ('PRINT')
99  call this%print_steps%read(line(istop + 2:))
100  if (iout > 0) &
101  call this%print_steps%log(iout, verb="PRINTED")
102  case ('SAVE')
103  call this%save_steps%read(line(istop + 2:))
104  if (iout > 0) &
105  call this%save_steps%log(iout, verb="SAVED")
106  case default
107  call store_error( &
108  'Looking for PRINT or SAVE. Found: '//trim(adjustl(line)), &
109  terminate=.true.)
110  end select
111  end subroutine read
112 
113  !> @ brief Determine if printing is enabled for this time step.
114  logical function should_print(this, kstp, endofperiod)
115  class(printsavemanagertype) :: this !< this instance
116  integer(I4B), intent(in) :: kstp !< current time step
117  logical(LGP), intent(in) :: endofperiod !< whether last step of stress period
118 
119  should_print = this%print_steps%is_selected(kstp, endofperiod)
120  end function should_print
121 
122  !> @ brief Determine if saving is enabled for this time step.
123  logical function should_save(this, kstp, endofperiod)
124  class(printsavemanagertype) :: this !< this instance
125  integer(I4B), intent(in) :: kstp !< current time step
126  logical(LGP), intent(in) :: endofperiod !< whether last step of stress period
127 
128  should_save = this%save_steps%is_selected(kstp, endofperiod)
129  end function should_save
130 
131 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.
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.