MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
ModelExport.f90
Go to the documentation of this file.
1 !> @brief This module contains the ModelExportModule
2 !!
3 !! This modeule defines the local list of model exports.
4 !! It is not dependent on netcdf or other external
5 !! libraries.
6 !!
7 !<
9 
10  use kindmodule, only: dp, i4b, lgp
13  use listmodule, only: listtype
16 
17  implicit none
18  private
19  public :: modelexports_create
21  public :: modelexports_post_step
22  public :: modelexports_destroy
23  public :: nc_export_active
24  public :: export_models
25  public :: get_export_model
26  public :: exportmodeltype
27 
29 
30  !> @brief export model type
31  !!
32  !! This is a container variable which holds
33  !! model export objects.
34  !!
35  !<
37  type(modeldynamicpkgstype), pointer :: loaders => null()
38  character(len=LENMODELNAME) :: modelname !< name of model
39  character(len=LENCOMPONENTNAME) :: modeltype !< type of model
40  character(len=LINELENGTH) :: modelfname !< name of model input file
41  class(ncbasemodelexporttype), pointer :: nc_export => null() !< netcdf export object pointer
42  integer(I4B) :: nctype !< type of netcdf export
43  integer(I4B) :: disenum !< type of discretization
44  integer(I4B) :: iout !< lst file descriptor
45  contains
46  procedure :: init
47  procedure :: post_prepare
48  procedure :: post_step
49  procedure :: destroy
50  end type exportmodeltype
51 
52 contains
53 
54  !> @brief is netcdf export configured for any model
55  !!
56  function nc_export_active() result(active)
58  logical(LGP) :: active
59  integer(I4B) :: n
60  type(exportmodeltype), pointer :: export_model
61  active = .false.
62  !
63  do n = 1, export_models%Count()
64  export_model => get_export_model(n)
65  if (export_model%nctype /= netcdf_undef) then
66  active = .true.
67  exit
68  end if
69  end do
70  end function nc_export_active
71 
72  !> @brief create export container variable for all local models
73  !!
74  subroutine modelexports_create(iout)
82  integer(I4B), intent(in) :: iout
83  type(modeldynamicpkgstype), pointer :: model_dynamic_input
84  type(exportmodeltype), pointer :: export_model
85  character(len=LENMEMPATH) :: modelnam_mempath, model_mempath
86  integer(I4B), pointer :: disenum
87  character(len=LINELENGTH) :: exportstr
88  integer(I4B) :: n
89  logical(LGP) :: found
90  !
91  do n = 1, model_dynamic_pkgs%Count()
92  !
93  ! -- allocate and initialize
94  allocate (export_model)
95  !
96  ! -- set pointer to dynamic input model instance
97  model_dynamic_input => getdynamicmodelfromlist(model_dynamic_pkgs, n)
98  !
99  ! --set input mempaths
100  modelnam_mempath = &
101  create_mem_path(component=model_dynamic_input%modelname, &
102  subcomponent='NAM', context=idm_context)
103  model_mempath = create_mem_path(component=model_dynamic_input%modelname, &
104  context=idm_context)
105  ! -- set pointer to dis enum type
106  call mem_setptr(disenum, 'DISENUM', model_mempath)
107  !
108  ! -- initialize model
109  call export_model%init(model_dynamic_input, disenum, iout)
110  !
111  ! -- update EXPORT_NETCDF string if provided
112  call mem_set_value(exportstr, 'EXPORT_NETCDF', modelnam_mempath, found)
113  if (found) then
114  if (exportstr == 'STRUCTURED') then
115  export_model%nctype = netcdf_structured
116  else
117  ! -- mesh export is default
118  export_model%nctype = netcdf_ugrid
119  end if
120  end if
121  !
122  ! -- add model to list
123  call add_export_model(export_model)
124  end do
125  end subroutine modelexports_create
126 
127  !> @brief export model list post prepare step
128  !!
130  ! -- local variables
131  class(*), pointer :: obj
132  class(exportmodeltype), pointer :: export_model
133  integer(I4B) :: n
134  !
135  do n = 1, export_models%Count()
136  obj => export_models%GetItem(n)
137  if (associated(obj)) then
138  select type (obj)
139  class is (exportmodeltype)
140  export_model => obj
141  call export_model%post_prepare()
142  end select
143  end if
144  end do
145  end subroutine modelexports_post_prepare
146 
147  !> @brief export model list post step
148  !!
150  ! -- local variables
151  class(*), pointer :: obj
152  class(exportmodeltype), pointer :: export_model
153  integer(I4B) :: n
154  !
155  do n = 1, export_models%Count()
156  obj => export_models%GetItem(n)
157  if (associated(obj)) then
158  select type (obj)
159  class is (exportmodeltype)
160  export_model => obj
161  call export_model%post_step()
162  end select
163  end if
164  end do
165  end subroutine modelexports_post_step
166 
167  !> @brief destroy export model list
168  !!
169  subroutine modelexports_destroy()
170  ! -- local variables
171  class(*), pointer :: obj
172  class(exportmodeltype), pointer :: export_model
173  integer(I4B) :: n
174  !
175  do n = 1, export_models%Count()
176  obj => export_models%GetItem(n)
177  if (associated(obj)) then
178  select type (obj)
179  class is (exportmodeltype)
180  export_model => obj
181  call export_model%destroy()
182  deallocate (export_model)
183  nullify (export_model)
184  end select
185  end if
186  end do
187  !
188  call export_models%clear()
189  end subroutine modelexports_destroy
190 
191  !> @brief initialize model export container variable
192  !!
193  !<
194  subroutine init(this, loaders, disenum, iout)
196  class(exportmodeltype), intent(inout) :: this
197  type(modeldynamicpkgstype), pointer, intent(in) :: loaders
198  integer(I4B), intent(in) :: disenum
199  integer(I4B), intent(in) :: iout
200  !
201  this%loaders => loaders
202  this%modelname = loaders%modelname
203  this%modeltype = loaders%modeltype
204  this%modelfname = loaders%modelfname
205  this%nctype = netcdf_undef
206  this%disenum = disenum
207  this%iout = iout
208  !
209  nullify (this%nc_export)
210  end subroutine init
211 
212  !> @brief model export container post prepare step actions
213  !!
214  !<
215  subroutine post_prepare(this)
216  class(exportmodeltype), intent(inout) :: this
217  !
218  if (associated(this%nc_export)) then
219  call this%nc_export%export_input()
220  end if
221  end subroutine post_prepare
222 
223  !> @brief model export container post step actions
224  !!
225  !<
226  subroutine post_step(this)
227  class(exportmodeltype), intent(inout) :: this
228  !
229  if (associated(this%nc_export)) then
230  call this%nc_export%step()
231  end if
232  end subroutine post_step
233 
234  !> @brief destroy model export container
235  !!
236  !<
237  subroutine destroy(this)
238  class(exportmodeltype), intent(inout) :: this
239  !
240  if (associated(this%nc_export)) then
241  call this%nc_export%destroy()
242  deallocate (this%nc_export)
243  nullify (this%nc_export)
244  end if
245  end subroutine destroy
246 
247  !> @brief add model export object to list
248  !!
249  !<
250  subroutine add_export_model(export_model)
251  ! -- dummy variables
252  type(exportmodeltype), pointer, intent(inout) :: export_model
253  ! -- local variables
254  class(*), pointer :: obj
255  !
256  obj => export_model
257  call export_models%Add(obj)
258  end subroutine add_export_model
259 
260  !> @brief get model export object by index
261  !!
262  !<
263  function get_export_model(idx) result(res)
264  ! -- dummy variables
265  integer(I4B), intent(in) :: idx !< package number
266  ! -- local variables
267  class(exportmodeltype), pointer :: res
268  class(*), pointer :: obj
269  !
270  ! -- initialize res
271  nullify (res)
272  !
273  ! -- get the object from the list
274  obj => export_models%GetItem(idx)
275  if (associated(obj)) then
276  select type (obj)
277  class is (exportmodeltype)
278  res => obj
279  end select
280  end if
281  end function get_export_model
282 
283 end module modelexportmodule
subroutine init()
Definition: GridSorting.f90:24
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 lencomponentname
maximum length of a component name
Definition: Constants.f90:18
integer(i4b), parameter lenmodelname
maximum length of the model name
Definition: Constants.f90:22
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
This module contains the InputLoadTypeModule.
class(modeldynamicpkgstype) function, pointer, public getdynamicmodelfromlist(list, idx)
get model dynamic packages object from list
type(listtype), public model_dynamic_pkgs
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the ModelExportModule.
Definition: ModelExport.f90:8
subroutine post_step(this)
model export container post step actions
subroutine, public modelexports_post_prepare()
export model list post prepare step
subroutine destroy(this)
destroy model export container
subroutine, public modelexports_destroy()
destroy export model list
subroutine, public modelexports_post_step()
export model list post step
type(listtype), public export_models
Definition: ModelExport.f90:28
subroutine post_prepare(this)
model export container post prepare step actions
class(exportmodeltype) function, pointer, public get_export_model(idx)
get model export object by index
subroutine add_export_model(export_model)
add model export object to list
subroutine, public modelexports_create(iout)
create export container variable for all local models
Definition: ModelExport.f90:75
logical(lgp) function, public nc_export_active()
is netcdf export configured for any model
Definition: ModelExport.f90:57
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
@, public netcdf_structured
netcdf structrured export
Definition: NCModel.f90:33
@, public netcdf_undef
undefined netcdf export type
Definition: NCModel.f90:31
@, public netcdf_ugrid
netcdf mesh export
Definition: NCModel.f90:32
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=linelength) idm_context
type for storing a dynamic package load list
A generic heterogeneous doubly-linked list.
Definition: List.f90:14
abstract type for model netcdf export type
Definition: NCModel.f90:100