MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
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  end subroutine write_fmtd_obs
67 
68  !> @ brief Write unformatted observation
69  !!
70  !! Subroutine to write observation data for the end of a time step to
71  !! a unformatted file. If the simulation time has not been written for
72  !! the current time step, totim is written. The simulated value is
73  !! written using the precision specified in the iprec argument.
74  !!
75  !! iprec = 1: real32 specifies 32-bit real = 4 bytes = single precision.
76  !! iprec = 2: real64 specifies 64-bit real = 8 bytes = double precision.
77  !!
78  !<
79  subroutine write_unfmtd_obs(obsrv, iprec, obsOutputList, value)
80  use iso_fortran_env, only: real32, real64
81  ! -- dummy
82  type(observetype), intent(inout) :: obsrv !< observation type
83  integer(I4B), intent(in) :: iprec !< observation precision
84  type(obsoutputlisttype), pointer, intent(inout) :: obsoutputlist !< observation list
85  real(dp), intent(in) :: value !< observation
86  ! -- local
87  integer(I4B) :: indx, nunit
88  real(real32) :: totimsngl, valsngl
89  real(real64) :: totimdbl, valdbl
90  type(obsoutputtype), pointer :: obsoutput => null()
91  !
92  ! -- output unit
93  nunit = obsrv%UnitNumber
94  ! -- continuous observation
95  indx = obsrv%indxObsOutput
96  obsoutput => obsoutputlist%Get(indx)
97  if (obsoutput%empty_line) then
98  obsoutput%empty_line = .false.
99  if (iprec == 1) then
100  totimsngl = real(totim, real32)
101  write (nunit) totimsngl
102  elseif (iprec == 2) then
103  totimdbl = totim
104  write (nunit) totimdbl
105  end if
106  end if
107  ! -- write value to unformatted output
108  if (iprec == 1) then
109  valsngl = real(value, real32)
110  write (nunit) valsngl
111  elseif (iprec == 2) then
112  valdbl = value
113  write (nunit) valdbl
114  end if
115  end subroutine write_unfmtd_obs
116 
117 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:40
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:80
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:32