MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
ObsOutput.f90
Go to the documentation of this file.
1 !> @brief This module defines the derived type ObsOutputType
2 !!
3 !! This module contains information and methods needed for writing
4 !! a line of simulated values for observations to an output file. Each
5 !! block of type continuous in an observation file is
6 !! associated with an ObsOutputType object. However, the methods are
7 !! needed only for continuous observations.
8 !!
9 !<
11 
12  use kindmodule, only: dp, i4b, lgp
14  use listmodule, only: listtype
15 
16  implicit none
17 
18  private
21 
22  type :: obsoutputtype
23  ! -- Public members
24  ! kind specified to ensure consistent binary output
25  integer(kind=4), public :: nobs = 0 !< number of observations
26  integer(I4B), public :: nunit = 0 !< observation output unit
27  character(len=500), public :: filename = '' !< observation output filename
28  logical(LGP), public :: empty_line = .true. !< logical indicating if the line for a time step is empty
29  character(len=LENOBSNAME), public :: header = '' !< observation header string
30  logical, public :: formattedoutput = .true. !< logical indicating if writing formatted output
31  contains
32  ! -- Public procedures
33  procedure, public :: resetobsemptyline
34  procedure, public :: writeobslinereturn
35  end type obsoutputtype
36 
37 contains
38 
39  ! Procedures bound to ObsOutputType
40 
41  !> @ brief Reset empty line logical
42  !!
43  !! Subroutine to reset the empty line logical.
44  !!
45  !<
46  subroutine resetobsemptyline(this)
47  ! -- dummy
48  class(obsoutputtype), intent(inout) :: this
49  !
50  this%empty_line = .true.
51  end subroutine resetobsemptyline
52 
53  !> @ brief Write line return for observation
54  !!
55  !! Subroutine to write a line return for a time step in an observation
56  !! output file.
57  !!
58  !<
59  subroutine writeobslinereturn(this)
60  ! -- dummy
61  class(obsoutputtype), intent(inout) :: this
62  ! -- write a line return to end of observation output line
63  ! for this totim
64  write (this%nunit, '(a)', advance='YES') ''
65  end subroutine writeobslinereturn
66 
67  ! Non-type-bound procedures
68 
69  !> @ brief Cast as ObsOutputType
70  !!
71  !! Cast an object as an ObsOutputType.
72  !!
73  !<
74  function castasobsoutputtype(obj) result(res)
75  ! -- dummy
76  class(*), pointer, intent(inout) :: obj !< input object
77  type(obsoutputtype), pointer :: res !< ObsOutputType
78  !
79  res => null()
80  if (.not. associated(obj)) return
81  !
82  select type (obj)
83  type is (obsoutputtype)
84  res => obj
85  class default
86  continue
87  end select
88  end function castasobsoutputtype
89 
90  !> @ brief Construct and assign ObsOutputType object
91  !!
92  !! Subroutine to construct an ObsOutputType object and assign
93  !! the observation output file name and unit number.
94  !!
95  !<
96  subroutine constructobsoutput(newObsOutput, fname, nunit)
97  ! -- dummy
98  type(obsoutputtype), pointer, intent(out) :: newobsoutput
99  character(len=*), intent(in) :: fname !< observation output file name
100  integer(I4B), intent(in) :: nunit !< observation output unit number
101  !
102  allocate (newobsoutput)
103  newobsoutput%filename = fname
104  newobsoutput%nunit = nunit
105  end subroutine constructobsoutput
106 
107  !> @ brief Add observation output to a list
108  !!
109  !! Subroutine to add observation output to a observation list.
110  !!
111  !<
112  subroutine addobsoutputtolist(list, obsOutput)
113  ! -- dummy
114  type(listtype), intent(inout) :: list !< observation list
115  type(obsoutputtype), pointer, intent(inout) :: obsoutput !< observation output
116  ! -- local
117  class(*), pointer :: obj
118  !
119  obj => obsoutput
120  call list%Add(obj)
121  end subroutine addobsoutputtolist
122 
123  !> @ brief Get observation output from a list
124  !!
125  !! Subroutine to get observation output from a observation list.
126  !!
127  !<
128  function getobsoutputfromlist(list, idx) result(res)
129  implicit none
130  ! -- dummy
131  type(listtype), intent(inout) :: list !< observation list
132  integer(I4B), intent(in) :: idx !< observation index
133  type(obsoutputtype), pointer :: res !< observation output
134  ! -- local
135  class(*), pointer :: obj
136  !
137  obj => list%GetItem(idx)
138  res => castasobsoutputtype(obj)
139  end function getobsoutputfromlist
140 
141 end module obsoutputmodule
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 defines the derived type ObsOutputType.
Definition: ObsOutput.f90:10
subroutine, public addobsoutputtolist(list, obsOutput)
@ brief Add observation output to a list
Definition: ObsOutput.f90:113
subroutine writeobslinereturn(this)
@ brief Write line return for observation
Definition: ObsOutput.f90:60
subroutine resetobsemptyline(this)
@ brief Reset empty line logical
Definition: ObsOutput.f90:47
type(obsoutputtype) function, pointer, public getobsoutputfromlist(list, idx)
@ brief Get observation output from a list
Definition: ObsOutput.f90:129
subroutine, public constructobsoutput(newObsOutput, fname, nunit)
@ brief Construct and assign ObsOutputType object
Definition: ObsOutput.f90:97
type(obsoutputtype) function, pointer castasobsoutputtype(obj)
@ brief Cast as ObsOutputType
Definition: ObsOutput.f90:75
A generic heterogeneous doubly-linked list.
Definition: List.f90:14