MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
OutputControlData.f90
Go to the documentation of this file.
1 !> @brief This module contains the OutputControlDataModule
2 !!
3 !! This module defines the OutputControlDataType. This type
4 !! can be assigned to different model variables, such as head
5 !! or concentration. The variables are then printed and/or
6 !! saved in a consistent manner.
7 !!
8 !<
10 
11  use basedismodule, only: disbasetype
13  use kindmodule, only: dp, i4b, lgp
15 
16  implicit none
17  private
19 
20  !> @ brief OutputControlDataType
21  !!
22  !! Object for storing information and determining whether or
23  !! not model data should be printed to a list file or saved to disk.
24  !<
26  character(len=16), pointer :: cname => null() !< name of variable, such as HEAD
27  character(len=60), pointer :: cdatafmp => null() !< fortran format for printing
28  integer(I4B), pointer :: idataun => null() !< fortran unit number for binary output
29  character(len=1), pointer :: editdesc => null() !< fortran format type (I, G, F, S, E)
30  integer(I4B), pointer :: nvaluesp => null() !< number of values per line for printing
31  integer(I4B), pointer :: nwidthp => null() !< width of the number for printing
32  real(dp), pointer :: dnodata => null() !< no data value
33  integer(I4B), pointer :: inodata => null() !< integer no data value
34  real(dp), dimension(:), pointer, contiguous :: dblvec => null() !< pointer to double precision data array
35  integer(I4B), dimension(:), pointer, contiguous :: intvec => null() !< pointer to integer data array
36  class(disbasetype), pointer :: dis => null() !< pointer to discretization package
37  type(printsavemanagertype), pointer :: psmobj => null() !< print/save manager object
38  contains
39  procedure :: allocate_scalars
40  procedure :: init_int
41  procedure :: init_dbl
42  procedure :: set_option
43  procedure :: ocd_rp_check
44  procedure :: ocd_ot
45  procedure :: ocd_da
46  end type outputcontroldatatype
47 
48 contains
49 
50  !> @ brief Create OutputControlDataType
51  !!
52  !! Create by allocating a new OutputControlDataType object
53  !!
54  !<
55  subroutine ocd_cr(ocdobj)
56  ! -- dummy
57  type(outputcontroldatatype), pointer :: ocdobj !< OutputControlDataType object
58  !
59  ! -- Create the object
60  allocate (ocdobj)
61  !
62  ! -- Allocate scalars
63  call ocdobj%allocate_scalars()
64  !
65  ! -- Return
66  return
67  end subroutine ocd_cr
68 
69  !> @ brief Check OutputControlDataType object
70  !!
71  !! Perform a consistency check
72  !!
73  !<
74  subroutine ocd_rp_check(this, inunit)
75  ! -- modules
76  use constantsmodule, only: linelength
78  ! -- dummy
79  class(outputcontroldatatype) :: this !< OutputControlDataType object
80  integer(I4B), intent(in) :: inunit !< Unit number for input
81  ! -- locals
82  character(len=LINELENGTH) :: errmsg
83  ! -- formats
84  character(len=*), parameter :: fmtocsaveerr = &
85  "(1X,'REQUESTING TO SAVE ',A,' BUT ',A,' SAVE FILE NOT SPECIFIED. ', &
86  &A,' SAVE FILE MUST BE SPECIFIED IN OUTPUT CONTROL OPTIONS.')"
87  !
88  ! -- Check to make sure save file was specified
89  if (this%psmobj%save_detected) then
90  if (this%idataun == 0) then
91  write (errmsg, fmtocsaveerr) trim(adjustl(this%cname)), &
92  trim(adjustl(this%cname)), &
93  trim(adjustl(this%cname))
94  call store_error(errmsg)
95  end if
96  end if
97  !
98  if (count_errors() > 0) then
99  call store_error_unit(inunit)
100  end if
101  !
102  ! -- return
103  return
104  end subroutine ocd_rp_check
105 
106  !> @ brief Output data
107  !!
108  !! Depending on the settings, print the data to a listing file and/or
109  !! save the data to a binary file.
110  !!
111  !<
112  subroutine ocd_ot(this, ipflg, kstp, endofperiod, iout, iprint_opt, isav_opt)
113  ! -- dummy
114  class(outputcontroldatatype) :: this !< OutputControlDataType object
115  integer(I4B), intent(inout) :: ipflg !< Flag indicating if something was printed
116  integer(I4B), intent(in) :: kstp !< Current time step
117  logical(LGP), intent(in) :: endofperiod !< End of period logical flag
118  integer(I4B), intent(in) :: iout !< Unit number for output
119  integer(I4B), optional, intent(in) :: iprint_opt !< Optional print flag override
120  integer(I4B), optional, intent(in) :: isav_opt !< Optional save flag override
121  ! -- local
122  integer(I4B) :: iprint
123  integer(I4B) :: idataun
124  !
125  ! -- initialize
126  iprint = 0
127  ipflg = 0
128  idataun = 0
129  !
130  ! -- Determine whether or not to print the array. The present
131  ! check allows a caller to override the print/save manager
132  if (present(iprint_opt)) then
133  if (iprint_opt /= 0) then
134  iprint = 1
135  ipflg = 1
136  end if
137  else
138  if (this%psmobj%kstp_to_print(kstp, endofperiod)) then
139  iprint = 1
140  ipflg = 1
141  end if
142  end if
143  !
144  ! -- determine whether or not to save the array to a file
145  if (present(isav_opt)) then
146  if (isav_opt /= 0) then
147  idataun = this%idataun
148  end if
149  else
150  if (this%psmobj%kstp_to_save(kstp, endofperiod)) idataun = this%idataun
151  end if
152  !
153  ! -- Record double precision array
154  if (associated(this%dblvec)) &
155  call this%dis%record_array(this%dblvec, iout, iprint, idataun, &
156  this%cname, this%cdatafmp, this%nvaluesp, &
157  this%nwidthp, this%editdesc, this%dnodata)
158  !
159  ! -- Record integer array (not supported yet)
160  !if(associated(this%intvec)) &
161  !call this%dis%record_array(this%intvec, iout, iprint, idataun, &
162  ! this%cname, this%cdatafmp, this%nvaluesp, &
163  ! this%nwidthp, this%editdesc, this%inodata)
164  !
165  ! -- Return
166  return
167  end subroutine ocd_ot
168 
169  !> @ brief Deallocate OutputControlDataType
170  !!
171  !! Deallocate members of this type
172  !!
173  !<
174  subroutine ocd_da(this)
175  ! -- modules
176  use constantsmodule, only: dzero
177  ! -- dummy
178  class(outputcontroldatatype) :: this
179  !
180  ! -- deallocate
181  deallocate (this%cname)
182  deallocate (this%cdatafmp)
183  deallocate (this%idataun)
184  deallocate (this%editdesc)
185  deallocate (this%nvaluesp)
186  deallocate (this%nwidthp)
187  deallocate (this%dnodata)
188  deallocate (this%inodata)
189  deallocate (this%psmobj)
190  !
191  ! -- return
192  return
193  end subroutine ocd_da
194 
195  !> @ brief Initialize this OutputControlDataType as double precision data
196  !!
197  !! Initialize this object as a double precision data type
198  !!
199  !<
200  subroutine init_dbl(this, cname, dblvec, dis, cdefpsm, cdeffmp, iout, &
201  dnodata)
202  ! -- dummy
203  class(outputcontroldatatype) :: this !< OutputControlDataType object
204  character(len=*), intent(in) :: cname !< Name of variable
205  real(DP), dimension(:), pointer, contiguous, intent(in) :: dblvec !< Data array that will be managed by this object
206  class(disbasetype), pointer, intent(in) :: dis !< Discretization package
207  character(len=*), intent(in) :: cdefpsm !< String for defining the print/save manager
208  character(len=*), intent(in) :: cdeffmp !< String for print format
209  integer(I4B), intent(in) :: iout !< Unit number for output
210  real(DP), intent(in) :: dnodata !< No data value
211  !
212  this%cname = cname
213  this%dblvec => dblvec
214  this%dis => dis
215  this%dnodata = dnodata
216  call this%psmobj%init()
217  if (cdefpsm /= '') call this%psmobj%rp(cdefpsm, iout)
218  call print_format(cdeffmp, this%cdatafmp, &
219  this%editdesc, this%nvaluesp, this%nwidthp, 0)
220  !
221  ! -- return
222  return
223  end subroutine init_dbl
224 
225  !> @ brief Initialize this OutputControlDataType as integer data
226  !!
227  !! Initialize this object as an integer data type
228  !!
229  !<
230  subroutine init_int(this, cname, intvec, dis, cdefpsm, cdeffmp, iout, &
231  inodata)
232  ! -- dummy
233  class(outputcontroldatatype) :: this !< OutputControlDataType object
234  character(len=*), intent(in) :: cname !< Name of variable
235  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: intvec !< Data array that will be managed by this object
236  class(disbasetype), pointer, intent(in) :: dis !< Discretization package
237  character(len=*), intent(in) :: cdefpsm !< String for defining the print/save manager
238  character(len=*), intent(in) :: cdeffmp !< String for print format
239  integer(I4B), intent(in) :: iout !< Unit number for output
240  integer(I4B), intent(in) :: inodata !< No data value
241  !
242  this%cname = cname
243  this%intvec => intvec
244  this%dis => dis
245  this%inodata = inodata
246  this%editdesc = 'I'
247  call this%psmobj%init()
248  if (cdefpsm /= '') call this%psmobj%rp(cdefpsm, iout)
249  call print_format(cdeffmp, this%cdatafmp, this%editdesc, this%nvaluesp, &
250  this%nwidthp, 0)
251  !
252  ! -- return
253  return
254  end subroutine init_int
255 
256  !> @ brief Allocate OutputControlDataType members
257  !!
258  !! Allocate and initialize member variables
259  !!
260  !<
261  subroutine allocate_scalars(this)
262  ! -- modules
263  use constantsmodule, only: dzero
264  ! -- dummy
265  class(outputcontroldatatype) :: this !< OutputControlDataType object
266  !
267  allocate (this%cname)
268  allocate (this%cdatafmp)
269  allocate (this%idataun)
270  allocate (this%editdesc)
271  allocate (this%nvaluesp)
272  allocate (this%nwidthp)
273  allocate (this%dnodata)
274  allocate (this%inodata)
275  allocate (this%psmobj)
276  !
277  this%cname = ''
278  this%cdatafmp = ''
279  this%idataun = 0
280  this%editdesc = ''
281  this%nvaluesp = 0
282  this%nwidthp = 0
283  this%dnodata = dzero
284  this%inodata = 0
285  !
286  ! -- return
287  return
288  end subroutine allocate_scalars
289 
290  !> @ brief Set options for this object based on an input string
291  !!
292  !! Set FILEOUT and PRINT_FORMAT options for this object.
293  !!
294  !<
295  subroutine set_option(this, linein, inunit, iout)
296  ! -- modules
297  use constantsmodule, only: mnormal
298  use openspecmodule, only: access, form
301  ! -- dummy
302  class(outputcontroldatatype) :: this !< OutputControlDataType object
303  character(len=*), intent(in) :: linein !< Character string with options
304  integer(I4B), intent(in) :: inunit !< Unit number for input
305  integer(I4B), intent(in) :: iout !< Unit number for output
306  ! -- local
307  character(len=len(linein)) :: line
308  integer(I4B) :: lloc, istart, istop, ival
309  real(DP) :: rval
310  ! -- format
311  character(len=*), parameter :: fmtocsave = &
312  "(4X,A,' INFORMATION WILL BE WRITTEN TO:', &
313  &/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
314  !
315  line(:) = linein(:)
316  lloc = 1
317  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
318  select case (line(istart:istop))
319  case ('FILEOUT')
320  call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
321  this%idataun = getunit()
322  write (iout, fmtocsave) trim(adjustl(this%cname)), this%idataun, &
323  line(istart:istop)
324  call openfile(this%idataun, iout, line(istart:istop), 'DATA(BINARY)', &
325  form, access, 'REPLACE', mnormal)
326  case ('PRINT_FORMAT')
327  call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
328  call print_format(line(istart:), this%cdatafmp, this%editdesc, &
329  this%nvaluesp, this%nwidthp, inunit)
330  case default
331  call store_error('Looking for FILEOUT or PRINT_FORMAT. Found:')
332  call store_error(trim(adjustl(line)))
333  call store_error_unit(inunit)
334  end select
335  !
336  ! -- return
337  return
338  end subroutine set_option
339 
340 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:44
@ mnormal
normal output mode
Definition: Constants.f90:205
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:64
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
This module contains the OutputControlDataModule.
subroutine init_dbl(this, cname, dblvec, dis, cdefpsm, cdeffmp, iout, dnodata)
@ brief Initialize this OutputControlDataType as double precision data
subroutine ocd_da(this)
@ brief Deallocate OutputControlDataType
subroutine ocd_rp_check(this, inunit)
@ brief Check OutputControlDataType object
subroutine ocd_ot(this, ipflg, kstp, endofperiod, iout, iprint_opt, isav_opt)
@ brief Output data
subroutine set_option(this, linein, inunit, iout)
@ brief Set options for this object based on an input string
subroutine init_int(this, cname, intvec, dis, cdefpsm, cdeffmp, iout, inodata)
@ brief Initialize this OutputControlDataType as integer data
subroutine allocate_scalars(this)
@ brief Allocate OutputControlDataType members
subroutine, public ocd_cr(ocdobj)
@ brief Create OutputControlDataType
This module contains the PrintSaveManagerModule.
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_unit(iunit, terminate)
Store the file unit number.
Definition: Sim.f90:168