MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
OutputControlData.f90
Go to the documentation of this file.
1 !> @brief Output control data module.
3 
4  use basedismodule, only: disbasetype
6  use kindmodule, only: dp, i4b, lgp
8 
9  implicit none
10  private
12 
13  !> @brief Output control data type.
14  !!
15  !! Determines whether output data should be printed to a list file or saved to disk.
16  !! This type can be assigned to different variables, such as head or concentration.
17  !! This type controls the logging and saving of output data in a consistent manner.
18  !<
20  class(disbasetype), pointer :: dis => null() !< discretization package
21  type(printsavemanagertype), pointer :: psm => null() !< print/save manager
22  character(len=16), pointer :: cname => null() !< name of variable, such as HEAD
23  character(len=60), pointer :: cdatafmp => null() !< fortran format for printing
24  character(len=1), pointer :: editdesc => null() !< fortran format type (I, G, F, S, E)
25  integer(I4B), pointer :: idataun => null() !< fortran unit number for binary output
26  integer(I4B), pointer :: nvaluesp => null() !< number of values per line for printing
27  integer(I4B), pointer :: nwidthp => null() !< width of the number for printing
28  integer(I4B), pointer :: inodata => null() !< integer no data value
29  real(dp), pointer :: dnodata => null() !< no data value
30  integer(I4B), pointer, contiguous :: intdata(:) => null() !< integer data array
31  real(dp), pointer, contiguous :: dbldata(:) => null() !< double precision data array
32  contains
33  procedure :: allocate_scalars => allocate
34  procedure :: init_int
35  procedure :: init_dbl
36  procedure :: set_ocfile
37  procedure :: set_prnfmt
38  procedure :: ocd_rp_check
39  procedure :: ocd_ot
40  procedure :: ocd_da
41  end type outputcontroldatatype
42 
43 contains
44 
45  !> @ brief Create a new output control data type.
46  subroutine ocd_cr(ocdobj)
47  type(outputcontroldatatype), pointer :: ocdobj !< this instance
48  allocate (ocdobj)
49  call ocdobj%allocate_scalars()
50  end subroutine ocd_cr
51 
52  !> @ brief Check the output control data type for consistency.
53  subroutine ocd_rp_check(this, input_fname)
54  ! modules
55  use constantsmodule, only: linelength
57  ! dummy
58  class(outputcontroldatatype) :: this !< this instance
59  character(len=*) :: input_fname
60  ! locals
61  character(len=LINELENGTH) :: errmsg
62  ! formats
63  character(len=*), parameter :: fmtocsaveerr = &
64  "(1X,'REQUESTING TO SAVE ',A,' BUT ',A,' SAVE FILE NOT SPECIFIED. ', &
65  &A,' SAVE FILE MUST BE SPECIFIED IN OUTPUT CONTROL OPTIONS.')"
66 
67  ! If saving is enabled, make sure an output file was specified
68  if (this%psm%save_steps%any()) then
69  if (this%idataun == 0) then
70  write (errmsg, fmtocsaveerr) trim(adjustl(this%cname)), &
71  trim(adjustl(this%cname)), &
72  trim(adjustl(this%cname))
73  call store_error(errmsg)
74  end if
75  end if
76 
77  if (count_errors() > 0) then
78  call store_error_filename(input_fname)
79  end if
80  end subroutine ocd_rp_check
81 
82  !> @brief Write to list file and/or save to binary file, depending on settings.
83  subroutine ocd_ot(this, ipflg, kstp, endofperiod, iout, iprint_opt, isav_opt)
84  ! dummy
85  class(outputcontroldatatype) :: this !< OutputControlDataType object
86  integer(I4B), intent(inout) :: ipflg !< Flag indicating if something was printed
87  integer(I4B), intent(in) :: kstp !< Current time step
88  logical(LGP), intent(in) :: endofperiod !< End of period logical flag
89  integer(I4B), intent(in) :: iout !< Unit number for output
90  integer(I4B), optional, intent(in) :: iprint_opt !< Optional print flag override
91  integer(I4B), optional, intent(in) :: isav_opt !< Optional save flag override
92  ! local
93  integer(I4B) :: iprint
94  integer(I4B) :: idataun
95 
96  ! Initialize
97  iprint = 0
98  ipflg = 0
99  idataun = 0
100 
101  ! Determine whether or not to print the array. The present
102  ! check allows a caller to override the print/save manager
103  if (present(iprint_opt)) then
104  if (iprint_opt /= 0) then
105  iprint = 1
106  ipflg = 1
107  end if
108  else
109  if (this%psm%should_print(kstp, endofperiod)) then
110  iprint = 1
111  ipflg = 1
112  end if
113  end if
114 
115  ! Determine whether to save the array to a file
116  if (present(isav_opt)) then
117  if (isav_opt /= 0) then
118  idataun = this%idataun
119  end if
120  else
121  if (this%psm%should_save(kstp, endofperiod)) idataun = this%idataun
122  end if
123 
124  ! Record double precision array
125  if (associated(this%dbldata)) &
126  call this%dis%record_array(this%dbldata, iout, iprint, idataun, &
127  this%cname, this%cdatafmp, this%nvaluesp, &
128  this%nwidthp, this%editdesc, this%dnodata)
129 
130  ! Record integer array (not supported yet)
131  !if(associated(this%intvec)) &
132  !call this%dis%record_array(this%intvec, iout, iprint, idataun, &
133  ! this%cname, this%cdatafmp, this%nvaluesp, &
134  ! this%nwidthp, this%editdesc, this%inodata)
135  end subroutine ocd_ot
136 
137  !> @brief Deallocate the output control data type
138  subroutine ocd_da(this)
139  class(outputcontroldatatype) :: this
140 
141  deallocate (this%cname)
142  deallocate (this%cdatafmp)
143  deallocate (this%idataun)
144  deallocate (this%editdesc)
145  deallocate (this%nvaluesp)
146  deallocate (this%nwidthp)
147  deallocate (this%dnodata)
148  deallocate (this%inodata)
149  end subroutine ocd_da
150 
151  !> @brief Initialize the output control data type for double precision data.
152  subroutine init_dbl(this, cname, dblvec, dis, cdefpsm, cdeffmp, iout, &
153  dnodata)
154  class(outputcontroldatatype) :: this !< OutputControlDataType object
155  character(len=*), intent(in) :: cname !< Name of variable
156  real(DP), dimension(:), pointer, contiguous, intent(in) :: dblvec !< Data array that will be managed by this object
157  class(disbasetype), pointer, intent(in) :: dis !< Discretization package
158  character(len=*), intent(in) :: cdefpsm !< String for defining the print/save manager
159  character(len=*), intent(in) :: cdeffmp !< String for print format
160  integer(I4B), intent(in) :: iout !< Unit number for output
161  real(DP), intent(in) :: dnodata !< No data value
162 
163  this%cname = cname
164  this%dbldata => dblvec
165  this%dis => dis
166  this%dnodata = dnodata
167  if (cdefpsm /= '') call this%psm%read(cdefpsm, iout)
168  call print_format(cdeffmp, this%cdatafmp, &
169  this%editdesc, this%nvaluesp, this%nwidthp, 0)
170  end subroutine init_dbl
171 
172  !> @ brief Initialize the output control data type for integer data.
173  subroutine init_int(this, cname, intvec, dis, cdefpsm, cdeffmp, iout, &
174  inodata)
175  class(outputcontroldatatype) :: this !< OutputControlDataType object
176  character(len=*), intent(in) :: cname !< Name of variable
177  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: intvec !< Data array that will be managed by this object
178  class(disbasetype), pointer, intent(in) :: dis !< Discretization package
179  character(len=*), intent(in) :: cdefpsm !< String for defining the print/save manager
180  character(len=*), intent(in) :: cdeffmp !< String for print format
181  integer(I4B), intent(in) :: iout !< Unit number for output
182  integer(I4B), intent(in) :: inodata !< No data value
183 
184  this%cname = cname
185  this%intdata => intvec
186  this%dis => dis
187  this%inodata = inodata
188  this%editdesc = 'I'
189  if (cdefpsm /= '') call this%psm%read(cdefpsm, iout)
190  call print_format(cdeffmp, this%cdatafmp, this%editdesc, this%nvaluesp, &
191  this%nwidthp, 0)
192  end subroutine init_int
193 
194  !> @ brief Allocate scalar variables
195  subroutine allocate (this)
196  ! modules
197  use constantsmodule, only: dzero
198  ! dummy
199  class(outputcontroldatatype) :: this !< OutputControlDataType object
200 
201  allocate (this%cname)
202  allocate (this%cdatafmp)
203  allocate (this%idataun)
204  allocate (this%editdesc)
205  allocate (this%nvaluesp)
206  allocate (this%nwidthp)
207  allocate (this%dnodata)
208  allocate (this%inodata)
209 
210  this%cname = ''
211  this%cdatafmp = ''
212  this%idataun = 0
213  this%editdesc = ''
214  this%nvaluesp = 0
215  this%nwidthp = 0
216  this%dnodata = dzero
217  this%inodata = 0
218  this%psm => create_psm()
219  end subroutine allocate
220 
221  !> @ brief Set PRINT_FORMAT based on an input string.
222  subroutine set_prnfmt(this, prnfmt, inunit)
223  ! modules
225  ! dummy
226  class(outputcontroldatatype) :: this !< OutputControlDataType object
227  character(len=*), intent(in) :: prnfmt
228  integer(I4B), intent(in) :: inunit !< Unit number for input
229  ! local
230  call print_format(prnfmt, this%cdatafmp, this%editdesc, &
231  this%nvaluesp, this%nwidthp, inunit)
232  end subroutine set_prnfmt
233 
234  subroutine set_ocfile(this, ocfile, iout)
235  use constantsmodule, only: mnormal
236  use openspecmodule, only: access, form
238  ! dummy
239  class(outputcontroldatatype) :: this !< OutputControlDataType object
240  character(len=*), intent(in) :: ocfile !< OC output filename
241  integer(I4B), intent(in) :: iout !< Unit number for output
242  ! format
243  character(len=*), parameter :: fmtocsave = &
244  "(4X,A,' INFORMATION WILL BE WRITTEN TO:', &
245  &/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
246  this%idataun = getunit()
247  write (iout, fmtocsave) trim(adjustl(this%cname)), this%idataun, &
248  trim(ocfile)
249  call openfile(this%idataun, iout, ocfile, 'DATA(BINARY)', &
250  form, access, 'REPLACE', mnormal)
251  end subroutine set_ocfile
252 
253 end module outputcontroldatamodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
@ mnormal
normal output mode
Definition: Constants.f90:206
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public print_format(linein, cdatafmp, editdesc, nvaluesp, nwidthp, inunit)
Define the print or save format.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
Definition: InputOutput.f90:30
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
character(len=20) access
Definition: OpenSpec.f90:7
character(len=20) form
Definition: OpenSpec.f90:7
Output control data module.
subroutine init_dbl(this, cname, dblvec, dis, cdefpsm, cdeffmp, iout, dnodata)
Initialize the output control data type for double precision data.
subroutine ocd_da(this)
Deallocate the output control data type.
subroutine set_prnfmt(this, prnfmt, inunit)
@ brief Set PRINT_FORMAT based on an input string.
subroutine ocd_ot(this, ipflg, kstp, endofperiod, iout, iprint_opt, isav_opt)
Write to list file and/or save to binary file, depending on settings.
subroutine allocate(this)
@ brief Allocate scalar variables
subroutine ocd_rp_check(this, input_fname)
@ brief Check the output control data type for consistency.
subroutine init_int(this, cname, intvec, dis, cdefpsm, cdeffmp, iout, inodata)
@ brief Initialize the output control data type for integer data.
subroutine, public ocd_cr(ocdobj)
@ brief Create a new output control data type.
subroutine set_ocfile(this, ocfile, iout)
Print/save manager module.
type(printsavemanagertype) function, pointer, public create_psm()
Initialize or clear the print/save manager.
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
integer(i4b) function, public count_errors()
Return number of errors.
Definition: Sim.f90:59
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203