MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
tsp-obs.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, i4b
5  use basedismodule, only: disbasetype
6  use tspicmodule, only: tspictype
7  use observemodule, only: observetype
8  use obsmodule, only: obstype
9  use simmodule, only: count_errors, store_error, &
11 
12  implicit none
13 
14  private
15  public :: tspobstype, tsp_obs_cr
16 
17  type, extends(obstype) :: tspobstype
18  ! -- Private members
19  type(tspictype), pointer, private :: ic => null() ! initial conditions
20  real(dp), dimension(:), pointer, contiguous, private :: x => null() ! concentration or temperature
21  real(dp), dimension(:), pointer, contiguous, private :: flowja => null() ! intercell flows
22  character(len=LENVARNAME) :: depvartype = '' !< "concentration" or "temperature"
23  contains
24  ! -- Public procedures
25  procedure, public :: tsp_obs_ar
26  procedure, public :: obs_bd => tsp_obs_bd
27  procedure, public :: obs_df => tsp_obs_df
28  procedure, public :: obs_rp => tsp_obs_rp
29  procedure, public :: obs_da => tsp_obs_da
30  ! -- Private procedures
31  procedure, private :: set_pointers
32  end type tspobstype
33 
34 contains
35 
36  !> @brief Create a new TspObsType object
37  !!
38  !! This routine:
39  !! - creates an observation object
40  !! - allocates pointers
41  !! - initializes values
42  !<
43  subroutine tsp_obs_cr(obs, inobs, dvt)
44  ! -- dummy
45  type(tspobstype), pointer, intent(out) :: obs
46  integer(I4B), pointer, intent(in) :: inobs
47  character(len=LENVARNAME), intent(in) :: dvt !< "concentration" or "temperature"
48  !
49  allocate (obs)
50  call obs%allocate_scalars()
51  obs%active = .false.
52  obs%inputFilename = ''
53  obs%inUnitObs => inobs
54  obs%depvartype = dvt
55  end subroutine tsp_obs_cr
56 
57  !> @brief Allocate and read method for package
58  !!
59  !! Method to allocate and read static data for the package.
60  !<
61  subroutine tsp_obs_ar(this, ic, x, flowja)
62  ! -- dummy
63  class(tspobstype), intent(inout) :: this
64  type(tspictype), pointer, intent(in) :: ic
65  real(DP), dimension(:), pointer, contiguous, intent(in) :: x
66  real(DP), dimension(:), pointer, contiguous, intent(in) :: flowja
67  !
68  ! -- Call ar method of parent class
69  call this%obs_ar()
70  !
71  ! -- set pointers
72  call this%set_pointers(ic, x, flowja)
73  end subroutine tsp_obs_ar
74 
75  !> @brief Define observation object
76  !<
77  subroutine tsp_obs_df(this, iout, pkgname, filtyp, dis)
78  ! -- dummy
79  class(tspobstype), intent(inout) :: this
80  integer(I4B), intent(in) :: iout
81  character(len=*), intent(in) :: pkgname
82  character(len=*), intent(in) :: filtyp
83  class(disbasetype), pointer :: dis
84  ! -- local
85  integer(I4B) :: indx
86  !
87  ! -- Call overridden method of parent class
88  call this%ObsType%obs_df(iout, pkgname, filtyp, dis)
89  !
90  ! -- StoreObsType arguments are: (ObserveType, cumulative, indx);
91  ! indx is returned.
92  !
93  ! -- Store obs type and assign procedure pointer for head observation type
94  call this%StoreObsType(trim(adjustl(this%depvartype)), .false., indx)
95  this%obsData(indx)%ProcessIdPtr => tsp_process_obs_id
96  !
97  ! -- Store obs type and assign procedure pointer for flow-ja-face observation type
98  call this%StoreObsType('flow-ja-face', .true., indx)
99  this%obsData(indx)%ProcessIdPtr => tsp_process_intercell_obs_id
100  end subroutine tsp_obs_df
101 
102  !> @brief Save observations
103  !<
104  subroutine tsp_obs_bd(this)
105  ! -- dummy
106  class(tspobstype), intent(inout) :: this
107  ! -- local
108  integer(I4B) :: i, jaindex, nodenumber
109  character(len=100) :: msg
110  class(observetype), pointer :: obsrv => null()
111  !
112  call this%obs_bd_clear()
113  !
114  ! -- iterate through all GWT observations
115  if (this%npakobs > 0) then
116  do i = 1, this%npakobs
117  obsrv => this%pakobs(i)%obsrv
118  nodenumber = obsrv%NodeNumber
119  jaindex = obsrv%JaIndex
120  select case (obsrv%ObsTypeId)
121  case ('CONCENTRATION', 'TEMPERATURE')
122  call this%SaveOneSimval(obsrv, this%x(nodenumber))
123  case ('FLOW-JA-FACE')
124  call this%SaveOneSimval(obsrv, this%flowja(jaindex))
125  case default
126  msg = ' Unrecognized observation type: '//trim(obsrv%ObsTypeId)
127  call store_error(msg)
128  call store_error_unit(this%inUnitObs)
129  end select
130  end do
131  end if
132  end subroutine tsp_obs_bd
133 
134  !> @brief If transport model observations need checks, add them here
135  !<
136  subroutine tsp_obs_rp(this)
137  ! -- dummy
138  class(tspobstype), intent(inout) :: this
139  !
140  ! Do GWT (or GWE) observations need any checking? If so, add checks here
141  end subroutine tsp_obs_rp
142 
143  !> Deallocate memory
144  !!
145  !! Deallocate memory associated with transport model
146  !<
147  subroutine tsp_obs_da(this)
148  ! -- dummy
149  class(tspobstype), intent(inout) :: this
150  !
151  nullify (this%ic)
152  nullify (this%x)
153  nullify (this%flowja)
154  call this%ObsType%obs_da()
155  end subroutine tsp_obs_da
156 
157  !> @brief Set pointers needed by the transport OBS package
158  !<
159  subroutine set_pointers(this, ic, x, flowja)
160  ! -- dummy
161  class(tspobstype), intent(inout) :: this
162  type(tspictype), pointer, intent(in) :: ic
163  real(DP), dimension(:), pointer, contiguous, intent(in) :: x
164  real(DP), dimension(:), pointer, contiguous, intent(in) :: flowja
165  !
166  this%ic => ic
167  this%x => x
168  this%flowja => flowja
169  end subroutine set_pointers
170 
171  !> @brief Procedure related to Tsp observations (NOT type-bound)
172  !!
173  !! Process a specific observation ID
174  !<
175  subroutine tsp_process_obs_id(obsrv, dis, inunitobs, iout)
176  ! -- dummy
177  type(observetype), intent(inout) :: obsrv
178  class(disbasetype), intent(in) :: dis
179  integer(I4B), intent(in) :: inunitobs
180  integer(I4B), intent(in) :: iout
181  ! -- local
182  integer(I4B) :: nn1
183  integer(I4B) :: icol, istart, istop
184  character(len=LINELENGTH) :: ermsg, string
185  !
186  ! -- Initialize variables
187  string = obsrv%IDstring
188  icol = 1
189  !
190  ! Get node number, with option for ID string to be either node
191  ! number or lay, row, column (when dis is structured).
192  nn1 = dis%noder_from_string(icol, istart, istop, inunitobs, &
193  iout, string, .false.)
194  !
195  if (nn1 > 0) then
196  obsrv%NodeNumber = nn1
197  else
198  ermsg = 'Error reading data from ID string'
199  call store_error(ermsg)
200  call store_error_unit(inunitobs)
201  end if
202  end subroutine tsp_process_obs_id
203 
204  !> @brief Procedure related to Tsp observations (NOT type-bound)
205  !!
206  !! Process an intercell observation requested by the user
207  !<
208  subroutine tsp_process_intercell_obs_id(obsrv, dis, inunitobs, iout)
209  ! -- dummy
210  type(observetype), intent(inout) :: obsrv
211  class(disbasetype), intent(in) :: dis
212  integer(I4B), intent(in) :: inunitobs
213  integer(I4B), intent(in) :: iout
214  ! -- local
215  integer(I4B) :: nn1, nn2
216  integer(I4B) :: icol, istart, istop, jaidx
217  character(len=LINELENGTH) :: ermsg, string
218  ! formats
219 70 format('Error: No connection exists between cells identified in text: ', a)
220  !
221  ! -- Initialize variables
222  string = obsrv%IDstring
223  icol = 1
224  !
225  ! Get node number, with option for ID string to be either node
226  ! number or lay, row, column (when dis is structured).
227  nn1 = dis%noder_from_string(icol, istart, istop, inunitobs, &
228  iout, string, .false.)
229  !
230  if (nn1 > 0) then
231  obsrv%NodeNumber = nn1
232  else
233  ermsg = 'Error reading data from ID string: '//string(istart:istop)
234  call store_error(ermsg)
235  end if
236  !
237  ! Get node number, with option for ID string to be either node
238  ! number or lay, row, column (when dis is structured).
239  nn2 = dis%noder_from_string(icol, istart, istop, inunitobs, &
240  iout, string, .false.)
241  if (nn2 > 0) then
242  obsrv%NodeNumber2 = nn2
243  else
244  ermsg = 'Error reading data from ID string: '//string(istart:istop)
245  call store_error(ermsg)
246  end if
247  !
248  ! -- store JA index
249  jaidx = dis%con%getjaindex(nn1, nn2)
250  if (jaidx == 0) then
251  write (ermsg, 70) trim(string)
252  call store_error(ermsg)
253  end if
254  obsrv%JaIndex = jaidx
255  !
256  if (count_errors() > 0) then
257  call store_error_unit(inunitobs)
258  end if
259  end subroutine tsp_process_intercell_obs_id
260 
261 end module tspobsmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
integer(i4b), parameter maxobstypes
maximum number of observation types
Definition: Constants.f90:48
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
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 contains the derived type ObsType.
Definition: Obs.f90:127
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
subroutine tsp_process_intercell_obs_id(obsrv, dis, inunitobs, iout)
Procedure related to Tsp observations (NOT type-bound)
Definition: tsp-obs.f90:209
subroutine tsp_obs_da(this)
Deallocate memory.
Definition: tsp-obs.f90:148
subroutine set_pointers(this, ic, x, flowja)
Set pointers needed by the transport OBS package.
Definition: tsp-obs.f90:160
subroutine tsp_obs_rp(this)
If transport model observations need checks, add them here.
Definition: tsp-obs.f90:137
subroutine tsp_process_obs_id(obsrv, dis, inunitobs, iout)
Procedure related to Tsp observations (NOT type-bound)
Definition: tsp-obs.f90:176
subroutine tsp_obs_ar(this, ic, x, flowja)
Allocate and read method for package.
Definition: tsp-obs.f90:62
subroutine tsp_obs_bd(this)
Save observations.
Definition: tsp-obs.f90:105
subroutine, public tsp_obs_cr(obs, inobs, dvt)
Create a new TspObsType object.
Definition: tsp-obs.f90:44
subroutine tsp_obs_df(this, iout, pkgname, filtyp, dis)
Define observation object.
Definition: tsp-obs.f90:78