MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
NCExportCreate.f90
Go to the documentation of this file.
1 !> @brief This module contains the NCExportCreateModule
2 !!
3 !! This module creates derived model netcdf export
4 !! objects. It is dependent on netcdf libraries.
5 !!
6 !<
8 
9  use kindmodule, only: dp, i4b, lgp
10  use simvariablesmodule, only: errmsg
11  use constantsmodule, only: dis, disu, disv
14  use basedismodule, only: disbasetype
15  use dismodule, only: distype
16  use disvmodule, only: disvtype
17  use disumodule, only: disutype
21 
22  implicit none
23  private
24  public :: nc_export_create
25 
26 contains
27 
28  !> @brief create model netcdf export type
29  !!
30  subroutine create_nc_export(export_model, num_model)
36  type(exportmodeltype), pointer, intent(inout) :: export_model
37  class(numericalmodeltype), pointer, intent(in) :: num_model
38  class(mesh2ddisexporttype), pointer :: ugrid_dis
39  class(mesh2ddisvexporttype), pointer :: ugrid_disv
40  class(disncstructuredtype), pointer :: structured_dis
41  class(disbasetype), pointer :: disbase
42  !
43  select case (export_model%disenum)
44  case (dis)
45  ! -- allocate nc structured grid export object
46  if (export_model%nctype == netcdf_ugrid) then
47  !
48  ! -- allocate nc structured grid export object
49  allocate (ugrid_dis)
50  !
51  ! -- set dis base type
52  disbase => num_model%dis
53  select type (disbase)
54  type is (distype)
55  ugrid_dis%dis => disbase
56  end select
57  !
58  ! -- set dynamic loaders
59  call create_export_pkglist(ugrid_dis%pkglist, export_model%loaders, &
60  export_model%iout)
61  !
62  ! -- initialize export object
63  call ugrid_dis%init(export_model%modelname, export_model%modeltype, &
64  export_model%modelfname, export_model%disenum, &
65  netcdf_ugrid, export_model%iout)
66  !
67  ! -- define export object
68  call ugrid_dis%df()
69  !
70  ! -- set base pointer
71  export_model%nc_export => ugrid_dis
72  else if (export_model%nctype == netcdf_structured) then
73  !
74  ! -- allocate nc structured grid export object
75  allocate (structured_dis)
76  !
77  ! -- set dis base type
78  disbase => num_model%dis
79  select type (disbase)
80  type is (distype)
81  structured_dis%dis => disbase
82  end select
83  !
84  ! -- set dynamic loaders
85  call create_export_pkglist(structured_dis%pkglist, export_model%loaders, &
86  export_model%iout)
87  !
88  ! -- initialize export object
89  call structured_dis%init(export_model%modelname, export_model%modeltype, &
90  export_model%modelfname, export_model%disenum, &
91  netcdf_structured, export_model%iout)
92  !
93  ! -- define export object
94  call structured_dis%df()
95  !
96  ! -- set base pointer
97  export_model%nc_export => structured_dis
98  end if
99  case (disv)
100  if (export_model%nctype == netcdf_ugrid) then
101  ! -- allocate nc structured grid export object
102  allocate (ugrid_disv)
103  !
104  ! -- set dis base type
105  disbase => num_model%dis
106  select type (disbase)
107  type is (disvtype)
108  ugrid_disv%disv => disbase
109  end select
110  !
111  ! -- set dynamic loaders
112  call create_export_pkglist(ugrid_disv%pkglist, export_model%loaders, &
113  export_model%iout)
114  !
115  ! -- initialize export object
116  call ugrid_disv%init(export_model%modelname, export_model%modeltype, &
117  export_model%modelfname, export_model%disenum, &
118  netcdf_ugrid, export_model%iout)
119  !
120  ! -- define export object
121  call ugrid_disv%df()
122  !
123  ! -- set base pointer
124  export_model%nc_export => ugrid_disv
125  else
126  errmsg = 'DISV model discretization only &
127  &supported as UGRID NetCDF export. &
128  &Model='//trim(export_model%modelname)//'.'
129  call store_error(errmsg)
130  call store_error_filename(export_model%modelfname)
131  end if
132  case default
133  errmsg = 'Unsupported discretization for NetCDF model export. &
134  &Model='//trim(export_model%modelname)//'.'
135  call store_error(errmsg)
136  call store_error_filename(export_model%modelfname)
137  end select
138  end subroutine create_nc_export
139 
140  subroutine create_export_pkglist(pkglist, loaders, iout)
141  use listmodule, only: listtype
148  type(listtype), intent(inout) :: pkglist
149  type(modeldynamicpkgstype), pointer, intent(in) :: loaders
150  integer(I4B), intent(in) :: iout
151  class(dynamicpkgloadbasetype), pointer :: dynamic_pkg
152  class(asciidynamicpkgloadbasetype), pointer :: rp_loader
153  type(exportpackagetype), pointer :: export_pkg
154  integer(I4B), pointer :: export_arrays
155  class(*), pointer :: obj
156  logical(LGP) :: found
157  integer(I4B) :: n
158  !
159  ! -- create list of in scope loaders
160  allocate (export_arrays)
161  !
162  do n = 1, loaders%pkglist%Count()
163  !
164  ! -- initialize export arrays option
165  export_arrays = 0
166  !
167  dynamic_pkg => loaders%get(n)
168  !
169  ! -- update export arrays option
170  call mem_set_value(export_arrays, 'EXPORT_NC', &
171  dynamic_pkg%mf6_input%mempath, found)
172  !
173  if (export_arrays > 0 .and. dynamic_pkg%readasarrays) then
174  select type (dynamic_pkg)
175  type is (mf6filedynamicpkgloadtype)
176  !
177  rp_loader => dynamic_pkg%rp_loader
178  !
179  select type (rp_loader)
180  type is (boundgridinputtype)
181  ! -- create the export object
182  allocate (export_pkg)
183  call export_pkg%init(rp_loader%mf6_input, &
184  rp_loader%bound_context%mshape, &
185  rp_loader%param_names, rp_loader%nparam)
186  obj => export_pkg
187  call pkglist%add(obj)
188  !
189  end select
190  end select
191  end if
192  end do
193  !
194  ! -- cleanup
195  deallocate (export_arrays)
196  end subroutine create_export_pkglist
197 
198  !> @brief initialize netcdf model export type
199  !!
200  subroutine nc_export_create()
202  use listsmodule, only: basemodellist
204  integer(I4B) :: n
205  type(exportmodeltype), pointer :: export_model
206  class(numericalmodeltype), pointer :: num_model
207  integer(I4B) :: im
208  !
209  do n = 1, export_models%Count()
210  ! -- set pointer to export model
211  export_model => get_export_model(n)
212  if (export_model%nctype /= netcdf_undef) then
213  !
214  ! -- netcdf export is active identify model
215  do im = 1, basemodellist%Count()
216  !
217  ! -- set model pointer
218  num_model => getnumericalmodelfromlist(basemodellist, im)
219  if (num_model%name == export_model%modelname .and. &
220  num_model%macronym == export_model%modeltype) then
221  !
222  ! -- allocate and initialize nc export model
223  call create_nc_export(export_model, num_model)
224  exit
225  !
226  end if
227  end do
228  end if
229  end do
230  end subroutine nc_export_create
231 
232 end module ncexportcreatemodule
This module contains the AsciiInputLoadTypeModule.
This module contains simulation constants.
Definition: Constants.f90:9
@ disu
DISV6 discretization.
Definition: Constants.f90:157
@ dis
DIS6 discretization.
Definition: Constants.f90:155
@ disv
DISU6 discretization.
Definition: Constants.f90:156
Definition: Dis.f90:1
This module contains the DisNCStructuredModule.
This module contains the IdmMf6FileModule.
Definition: IdmMf6File.f90:10
This module contains the InputLoadTypeModule.
This module defines variable data types.
Definition: kind.f90:8
type(listtype), public basemodellist
Definition: mf6lists.f90:16
This module contains the MeshDisModelModule.
Definition: DisNCMesh.f90:8
This module contains the MeshDisvModelModule.
Definition: DisvNCMesh.f90:8
This module contains the Mf6FileGridInputModule.
This module contains the ModelExportModule.
Definition: ModelExport.f90:8
type(listtype), public export_models
Definition: ModelExport.f90:28
class(exportmodeltype) function, pointer, public get_export_model(idx)
get model export object by index
This module contains the NCExportCreateModule.
subroutine create_nc_export(export_model, num_model)
create model netcdf export type
subroutine, public nc_export_create()
initialize netcdf model export type
subroutine create_export_pkglist(pkglist, loaders, iout)
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
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
base abstract type for ascii source dynamic load
Structured grid discretization.
Definition: Dis.f90:23
Unstructured grid discretization.
Definition: Disu.f90:28
Vertex grid discretization.
Definition: Disv.f90:24
MF6File dynamic loader type.
Definition: IdmMf6File.f90:39
Base abstract type for dynamic input loader.
type for storing a dynamic package load list
A generic heterogeneous doubly-linked list.
Definition: List.f90:14
Ascii grid based dynamic loader type.