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  character(len=LINELENGTH) :: nc_fname !< name of netcdf export file
42  class(ncbasemodelexporttype), pointer :: nc_export => null() !< netcdf export object pointer
43  integer(I4B) :: nctype !< type of netcdf export
44  integer(I4B) :: disenum !< type of discretization
45  integer(I4B) :: iout !< lst file descriptor
46  contains
47  procedure :: init
48  procedure :: post_prepare
49  procedure :: post_step
50  procedure :: destroy
51  end type exportmodeltype
52 
53 contains
54 
55  !> @brief is netcdf export configured for any model
56  !!
57  function nc_export_active() result(active)
59  logical(LGP) :: active
60  integer(I4B) :: n
61  type(exportmodeltype), pointer :: export_model
62  active = .false.
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  integer(I4B) :: n
88  logical(LGP) :: found
89 
90  do n = 1, model_dynamic_pkgs%Count()
91  ! allocate and initialize
92  allocate (export_model)
93 
94  ! set pointer to dynamic input model instance
95  model_dynamic_input => getdynamicmodelfromlist(model_dynamic_pkgs, n)
96 
97  ! set input mempaths
98  modelnam_mempath = &
99  create_mem_path(component=model_dynamic_input%modelname, &
100  subcomponent='NAM', context=idm_context)
101  model_mempath = create_mem_path(component=model_dynamic_input%modelname, &
102  context=idm_context)
103  ! set pointer to dis enum type
104  call mem_setptr(disenum, 'DISENUM', model_mempath)
105 
106  ! initialize model
107  call export_model%init(model_dynamic_input, disenum, iout)
108 
109  ! update NetCDF fileout name if provided
110  call mem_set_value(export_model%nc_fname, 'NCMESH2DFILE', &
111  modelnam_mempath, found)
112  if (found) then
113  export_model%nctype = netcdf_mesh2d
114  else
115  call mem_set_value(export_model%nc_fname, 'NCSTRUCTFILE', &
116  modelnam_mempath, found)
117  if (found) then
118  export_model%nctype = netcdf_structured
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  class(*), pointer :: obj
131  class(exportmodeltype), pointer :: export_model
132  integer(I4B) :: n
133  do n = 1, export_models%Count()
134  obj => export_models%GetItem(n)
135  if (associated(obj)) then
136  select type (obj)
137  class is (exportmodeltype)
138  export_model => obj
139  call export_model%post_prepare()
140  end select
141  end if
142  end do
143  end subroutine modelexports_post_prepare
144 
145  !> @brief export model list post step
146  !!
148  class(*), pointer :: obj
149  class(exportmodeltype), pointer :: export_model
150  integer(I4B) :: n
151  do n = 1, export_models%Count()
152  obj => export_models%GetItem(n)
153  if (associated(obj)) then
154  select type (obj)
155  class is (exportmodeltype)
156  export_model => obj
157  call export_model%post_step()
158  end select
159  end if
160  end do
161  end subroutine modelexports_post_step
162 
163  !> @brief destroy export model list
164  !!
165  subroutine modelexports_destroy()
166  class(*), pointer :: obj
167  class(exportmodeltype), pointer :: export_model
168  integer(I4B) :: n
169  do n = 1, export_models%Count()
170  obj => export_models%GetItem(n)
171  if (associated(obj)) then
172  select type (obj)
173  class is (exportmodeltype)
174  export_model => obj
175  call export_model%destroy()
176  deallocate (export_model)
177  nullify (export_model)
178  end select
179  end if
180  end do
181  !
182  call export_models%clear()
183  end subroutine modelexports_destroy
184 
185  !> @brief initialize model export container variable
186  !!
187  !<
188  subroutine init(this, loaders, disenum, iout)
190  class(exportmodeltype), intent(inout) :: this
191  type(modeldynamicpkgstype), pointer, intent(in) :: loaders
192  integer(I4B), intent(in) :: disenum
193  integer(I4B), intent(in) :: iout
194  this%loaders => loaders
195  this%modelname = loaders%modelname
196  this%modeltype = loaders%modeltype
197  this%modelfname = loaders%modelfname
198  this%nc_fname = ''
199  this%nctype = netcdf_undef
200  this%disenum = disenum
201  this%iout = iout
202  nullify (this%nc_export)
203  end subroutine init
204 
205  !> @brief model export container post prepare step actions
206  !!
207  !<
208  subroutine post_prepare(this)
209  class(exportmodeltype), intent(inout) :: this
210  if (associated(this%nc_export)) then
211  call this%nc_export%export_input()
212  end if
213  end subroutine post_prepare
214 
215  !> @brief model export container post step actions
216  !!
217  !<
218  subroutine post_step(this)
219  class(exportmodeltype), intent(inout) :: this
220  if (associated(this%nc_export)) then
221  call this%nc_export%step()
222  end if
223  end subroutine post_step
224 
225  !> @brief destroy model export container
226  !!
227  !<
228  subroutine destroy(this)
229  class(exportmodeltype), intent(inout) :: this
230  if (associated(this%nc_export)) then
231  call this%nc_export%destroy()
232  deallocate (this%nc_export)
233  nullify (this%nc_export)
234  end if
235  end subroutine destroy
236 
237  !> @brief add model export object to list
238  !!
239  !<
240  subroutine add_export_model(export_model)
241  type(exportmodeltype), pointer, intent(inout) :: export_model
242  class(*), pointer :: obj
243  obj => export_model
244  call export_models%Add(obj)
245  end subroutine add_export_model
246 
247  !> @brief get model export object by index
248  !!
249  !<
250  function get_export_model(idx) result(res)
251  integer(I4B), intent(in) :: idx !< package number
252  class(exportmodeltype), pointer :: res
253  class(*), pointer :: obj
254  ! initialize res
255  nullify (res)
256  ! get the object from the list
257  obj => export_models%GetItem(idx)
258  if (associated(obj)) then
259  select type (obj)
260  class is (exportmodeltype)
261  res => obj
262  end select
263  end if
264  end function get_export_model
265 
266 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:58
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
@, public netcdf_structured
netcdf structrured export
Definition: NCModel.f90:33
@, public netcdf_mesh2d
netcdf ugrid layered mesh export
Definition: NCModel.f90:34
@, public netcdf_undef
undefined netcdf export type
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:101