MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
ObsUtility.f90
Go to the documentation of this file.
1 !> @brief This module contains the ObsUtilityModule module
2 !!
3 !! This module contains subroutines for writing simulated values stored
4 !! in objects of ObserveType to output files. The subroutines handle
5 !! continuous observations, and can write values to either formatted or
6 !! unformatted files.
7 !!
8 !<
10 
11  use kindmodule, only: dp, i4b
13  use observemodule, only: observetype
16  use tdismodule, only: totim
17 
18  implicit none
19 
20  private
22 
23 contains
24 
25  !> @ brief Write formatted observation
26  !!
27  !! Subroutine to write observation data for the end of a time step to
28  !! a formatted file. If the simulation time has not been written to
29  !! for the current time step, totim is written. The simulated value is
30  !! written in the format specified in the fmtc argument.
31  !!
32  !<
33  subroutine write_fmtd_obs(fmtc, obsrv, obsOutputList, value)
34  ! -- dummy
35  character(len=*), intent(in) :: fmtc !< observation format
36  type(observetype), intent(inout) :: obsrv !< observation type
37  type(obsoutputlisttype), pointer, intent(inout) :: obsoutputlist !< observation list
38  real(dp), intent(in) :: value !< observation
39  ! -- local
40  integer(I4B) :: indx
41  integer(I4B) :: nunit
42  character(len=20) :: ctotim
43  character(len=50) :: cval
44  type(obsoutputtype), pointer :: obsoutput => null()
45  ! -- output unit
46  nunit = obsrv%UnitNumber
47  !
48  indx = obsrv%indxObsOutput
49  obsoutput => obsoutputlist%Get(indx)
50  if (obsoutput%empty_line) then
51  obsoutput%empty_line = .false.
52  write (ctotim, '(G20.13)') totim
53  else
54  ctotim = ''
55  end if
56  ! -- append value to output line
57  write (cval, fmtc) value
58  write (nunit, '(3a)', advance='NO') &
59  trim(adjustl(ctotim)), ',', trim(adjustl(cval))
60  !
61  ! -- flush the file
62  ! Added flush after each non-advancing write to resolve
63  ! issue with ifort (IFORT) 19.1.0.166 20191121 for Linux
64  ! that occurred on some Linux systems.
65  flush (nunit)
66  !
67  ! -- return
68  return
69  end subroutine write_fmtd_obs
70 
71  !> @ brief Write unformatted observation
72  !!
73  !! Subroutine to write observation data for the end of a time step to
74  !! a unformatted file. If the simulation time has not been written for
75  !! the current time step, totim is written. The simulated value is
76  !! written using the precision specified in the iprec argument.
77  !!
78  !! iprec = 1: real32 specifies 32-bit real = 4 bytes = single precision.
79  !! iprec = 2: real64 specifies 64-bit real = 8 bytes = double precision.
80  !!
81  !<
82  subroutine write_unfmtd_obs(obsrv, iprec, obsOutputList, value)
83  use iso_fortran_env, only: real32, real64
84  ! -- dummy
85  type(observetype), intent(inout) :: obsrv !< observation type
86  integer(I4B), intent(in) :: iprec !< observation precision
87  type(obsoutputlisttype), pointer, intent(inout) :: obsoutputlist !< observation list
88  real(dp), intent(in) :: value !< observation
89  ! -- local
90  integer(I4B) :: indx, nunit
91  real(real32) :: totimsngl, valsngl
92  real(real64) :: totimdbl, valdbl
93  type(obsoutputtype), pointer :: obsoutput => null()
94  !
95  ! -- output unit
96  nunit = obsrv%UnitNumber
97  ! -- continuous observation
98  indx = obsrv%indxObsOutput
99  obsoutput => obsoutputlist%Get(indx)
100  if (obsoutput%empty_line) then
101  obsoutput%empty_line = .false.
102  if (iprec == 1) then
103  totimsngl = real(totim, real32)
104  write (nunit) totimsngl
105  elseif (iprec == 2) then
106  totimdbl = totim
107  write (nunit) totimdbl
108  end if
109  end if
110  ! -- write value to unformatted output
111  if (iprec == 1) then
112  valsngl = real(value, real32)
113  write (nunit) valsngl
114  elseif (iprec == 2) then
115  valdbl = value
116  write (nunit) valdbl
117  end if
118  !
119  ! -- return
120  return
121  end subroutine write_unfmtd_obs
122 
123 end module obsutilitymodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenbigline
maximum length of a big line
Definition: Constants.f90:15
integer(i4b), parameter lenobsname
maximum length of a observation name
Definition: Constants.f90:39
This module defines variable data types.
Definition: kind.f90:8
This module contains the derived types ObserveType and ObsDataType.
Definition: Observe.f90:15
This module defines the derived type ObsOutputListType.
This module defines the derived type ObsOutputType.
Definition: ObsOutput.f90:10
This module contains the ObsUtilityModule module.
Definition: ObsUtility.f90:9
subroutine, public write_fmtd_obs(fmtc, obsrv, obsOutputList, value)
@ brief Write formatted observation
Definition: ObsUtility.f90:34
subroutine, public write_unfmtd_obs(obsrv, iprec, obsOutputList, value)
@ brief Write unformatted observation
Definition: ObsUtility.f90:83
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:32