MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
DisNCMesh.f90
Go to the documentation of this file.
1 !> @brief This module contains the MeshDisModelModule
2 !!
3 !! This module defines UGRID layered mesh compliant netcdf
4 !! export type for DIS models. It is dependent on netcdf
5 !! libraries.
6 !!
7 !<
9 
10  use kindmodule, only: dp, i4b, lgp
13  use simvariablesmodule, only: errmsg
22  use dismodule, only: distype
23  use netcdfcommonmodule, only: nf_verify
24  use netcdf
25 
26  implicit none
27  private
28  public :: mesh2ddisexporttype
29 
30  ! UGRID layered mesh (ULM) DIS
32  type(distype), pointer :: dis => null() !< pointer to model dis package
33  integer(I4B) :: x_dim !< ncol dimension id
34  integer(I4B) :: y_dim !< nrow dimension id
35  contains
36  procedure :: init => dis_export_init
37  procedure :: destroy => dis_export_destroy
38  procedure :: df
39  procedure :: step
40  procedure :: export_input_array
41  procedure :: package_step
42  procedure :: define_dim
43  procedure :: add_mesh_data
44  end type mesh2ddisexporttype
45 
46 contains
47 
48  !> @brief netcdf export dis init
49  !<
50  subroutine dis_export_init(this, modelname, modeltype, modelfname, nc_fname, &
51  disenum, nctype, iout)
53  class(mesh2ddisexporttype), intent(inout) :: this
54  character(len=*), intent(in) :: modelname
55  character(len=*), intent(in) :: modeltype
56  character(len=*), intent(in) :: modelfname
57  character(len=*), intent(in) :: nc_fname
58  integer(I4B), intent(in) :: disenum
59  integer(I4B), intent(in) :: nctype
60  integer(I4B), intent(in) :: iout
61 
62  ! set nlay
63  this%nlay = this%dis%nlay
64 
65  ! allocate var_id arrays
66  allocate (this%var_ids%dependent(this%nlay))
67  allocate (this%var_ids%export(this%nlay))
68 
69  ! initialize base class
70  call this%mesh_init(modelname, modeltype, modelfname, nc_fname, disenum, &
71  nctype, this%dis%lenuni, iout)
72  end subroutine dis_export_init
73 
74  !> @brief netcdf export dis destroy
75  !<
76  subroutine dis_export_destroy(this)
77  class(mesh2ddisexporttype), intent(inout) :: this
78  deallocate (this%var_ids%dependent)
79  ! destroy base class
80  call this%mesh_destroy()
81  call this%NCModelExportType%destroy()
82  end subroutine dis_export_destroy
83 
84  !> @brief netcdf export define
85  !<
86  subroutine df(this)
87  use constantsmodule, only: mvalidate
88  use simvariablesmodule, only: isim_mode
89  class(mesh2ddisexporttype), intent(inout) :: this
90  ! put root group file scope attributes
91  call this%add_global_att()
92  ! define root group dimensions and coordinate variables
93  call this%define_dim()
94  ! define mesh variables
95  call this%create_mesh()
96  if (isim_mode == mvalidate) then
97  ! define period input arrays
98  call this%df_export()
99  else
100  ! define the dependent variable
101  call this%define_dependent()
102  end if
103  ! exit define mode
104  call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
105  ! create mesh
106  call this%add_mesh_data()
107  if (isim_mode == mvalidate) then
108  ! define and set package input griddata
109  call this%add_pkg_data()
110  end if
111  ! define and set gridmap variable
112  call this%define_gridmap()
113  ! synchronize file
114  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
115  end subroutine df
116 
117  !> @brief netcdf export step
118  !<
119  subroutine step(this)
120  use constantsmodule, only: dhnoflo
121  use tdismodule, only: totim
122  class(mesh2ddisexporttype), intent(inout) :: this
123  real(DP), dimension(:), pointer, contiguous :: dbl1d
124  integer(I4B) :: n, k, nvals, istp
125  integer(I4B), dimension(2) :: dis_shape
126  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
127 
128  ! initialize
129  nullify (dbl1d)
130  nullify (dbl2d)
131 
132  ! set global step index
133  istp = this%istp()
134 
135  dis_shape(1) = this%dis%ncol * this%dis%nrow
136  dis_shape(2) = this%dis%nlay
137 
138  nvals = product(dis_shape)
139 
140  ! add data to dependent variable
141  if (size(this%dis%nodeuser) < &
142  size(this%dis%nodereduced)) then
143  ! allocate nodereduced size 1d array
144  allocate (dbl1d(size(this%dis%nodereduced)))
145 
146  ! initialize DHNOFLO for non-active cells
147  dbl1d = dhnoflo
148 
149  ! update active cells
150  do n = 1, size(this%dis%nodereduced)
151  if (this%dis%nodereduced(n) > 0) then
152  dbl1d(n) = this%x(this%dis%nodereduced(n))
153  end if
154  end do
155 
156  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => dbl1d(1:nvals)
157  else
158  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => this%x(1:nvals)
159  end if
160 
161  do k = 1, this%dis%nlay
162  ! extend array with step data
163  call nf_verify(nf90_put_var(this%ncid, &
164  this%var_ids%dependent(k), dbl2d(:, k), &
165  start=(/1, istp/), &
166  count=(/(this%dis%ncol * this%dis%nrow), 1/)), &
167  this%nc_fname)
168  end do
169 
170  ! write to time coordinate variable
171  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
172  totim, start=(/istp/)), &
173  this%nc_fname)
174  ! update file
175  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
176 
177  ! cleanup
178  if (associated(dbl1d)) deallocate (dbl1d)
179  nullify (dbl1d)
180  nullify (dbl2d)
181  end subroutine step
182 
183  !> @brief netcdf export package dynamic input
184  !<
185  subroutine package_step(this, export_pkg)
186  use tdismodule, only: totim, kper
189  class(mesh2ddisexporttype), intent(inout) :: this
190  class(exportpackagetype), pointer, intent(in) :: export_pkg
191  type(inputparamdefinitiontype), pointer :: idt
192  integer(I4B), dimension(:), pointer, contiguous :: int1d
193  real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
194  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
195  character(len=LINELENGTH) :: nc_tag
196  integer(I4B) :: iaux, iparam, nvals
197  integer(I4B) :: k, n
198  integer(I4B), pointer :: nbound
199 
200  ! initialize
201  iaux = 0
202 
203  ! export defined period input
204  do iparam = 1, export_pkg%nparam
205  ! check if variable was read this period
206  if (export_pkg%param_reads(iparam)%invar < 1) cycle
207 
208  ! set input definition
209  idt => &
210  get_param_definition_type(export_pkg%mf6_input%param_dfns, &
211  export_pkg%mf6_input%component_type, &
212  export_pkg%mf6_input%subcomponent_type, &
213  'PERIOD', export_pkg%param_names(iparam), '')
214 
215  ! set variable input tag
216  nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
217  idt)
218 
219  ! export arrays
220  select case (idt%datatype)
221  case ('INTEGER1D')
222  call mem_setptr(int1d, idt%mf6varname, export_pkg%mf6_input%mempath)
223  this%var_ids%export(1) = export_pkg%varids_param(iparam, 1)
224  call nc_export_int1d(int1d, this%ncid, this%dim_ids, this%x_dim, &
225  this%y_dim, this%var_ids, this%dis, idt, &
226  export_pkg%mf6_input%mempath, nc_tag, &
227  export_pkg%mf6_input%subcomponent_name, &
228  this%gridmap_name, this%deflate, this%shuffle, &
229  this%chunk_face, kper, this%nc_fname)
230  case ('DOUBLE1D')
231  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
232  select case (idt%shape)
233  case ('NCPL')
234  this%var_ids%export(1) = export_pkg%varids_param(iparam, 1)
235  call nc_export_dbl1d(dbl1d, this%ncid, this%dim_ids, this%x_dim, &
236  this%y_dim, this%var_ids, this%dis, idt, &
237  export_pkg%mf6_input%mempath, nc_tag, &
238  export_pkg%mf6_input%subcomponent_name, &
239  this%gridmap_name, this%deflate, this%shuffle, &
240  this%chunk_face, kper, iaux, this%nc_fname)
241  case ('NODES')
242  nvals = this%dis%nodesuser
243  allocate (nodes(nvals))
244  nodes = dnodata
245  do k = 1, this%dis%nlay
246  this%var_ids%export(k) = export_pkg%varids_param(iparam, k)
247  end do
248  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
249  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
250  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
251  do n = 1, nbound
252  nodes(int1d(n)) = dbl1d(n)
253  end do
254  call nc_export_dbl1d(nodes, this%ncid, this%dim_ids, this%x_dim, &
255  this%y_dim, this%var_ids, this%dis, idt, &
256  export_pkg%mf6_input%mempath, nc_tag, &
257  export_pkg%mf6_input%subcomponent_name, &
258  this%gridmap_name, this%deflate, this%shuffle, &
259  this%chunk_face, kper, iaux, this%nc_fname)
260  deallocate (nodes)
261  case default
262  end select
263  case ('DOUBLE2D')
264  call mem_setptr(dbl2d, idt%mf6varname, export_pkg%mf6_input%mempath)
265  select case (idt%shape)
266  case ('NAUX NCPL')
267  nvals = this%dis%nrow * this%dis%ncol
268  allocate (nodes(nvals))
269  do iaux = 1, size(dbl2d, dim=1) !naux
270  this%var_ids%export(1) = export_pkg%varids_aux(iaux, 1)
271  do n = 1, nvals
272  nodes(n) = dbl2d(iaux, n)
273  end do
274  call nc_export_dbl1d(nodes, this%ncid, this%dim_ids, this%x_dim, &
275  this%y_dim, this%var_ids, this%dis, idt, &
276  export_pkg%mf6_input%mempath, nc_tag, &
277  export_pkg%mf6_input%subcomponent_name, &
278  this%gridmap_name, this%deflate, this%shuffle, &
279  this%chunk_face, kper, iaux, this%nc_fname)
280  end do
281  deallocate (nodes)
282  case ('NAUX NODES')
283  nvals = this%dis%nodesuser
284  allocate (nodes(nvals))
285  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
286  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
287  do iaux = 1, size(dbl2d, dim=1) ! naux
288  nodes = dnodata
289  do k = 1, this%dis%nlay
290  this%var_ids%export(k) = export_pkg%varids_aux(iaux, k)
291  end do
292  do n = 1, nbound
293  nodes(int1d(n)) = dbl2d(iaux, n)
294  end do
295  call nc_export_dbl1d(nodes, this%ncid, this%dim_ids, this%x_dim, &
296  this%y_dim, this%var_ids, this%dis, idt, &
297  export_pkg%mf6_input%mempath, nc_tag, &
298  export_pkg%mf6_input%subcomponent_name, &
299  this%gridmap_name, this%deflate, this%shuffle, &
300  this%chunk_face, kper, iaux, this%nc_fname)
301 
302  end do
303  deallocate (nodes)
304  case default
305  end select
306  case default
307  ! no-op, no other datatypes exported
308  end select
309  end do
310 
311  ! write to time coordinate variable
312  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
313  totim, start=(/kper/)), &
314  this%nc_fname)
315 
316  ! synchronize file
317  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
318  end subroutine package_step
319 
320  !> @brief netcdf export an input array
321  !<
322  subroutine export_input_array(this, pkgtype, pkgname, mempath, idt)
323  class(mesh2ddisexporttype), intent(inout) :: this
324  character(len=*), intent(in) :: pkgtype
325  character(len=*), intent(in) :: pkgname
326  character(len=*), intent(in) :: mempath
327  type(inputparamdefinitiontype), pointer, intent(in) :: idt
328  integer(I4B), dimension(:), pointer, contiguous :: int1d
329  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
330  integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
331  real(DP), dimension(:), pointer, contiguous :: dbl1d
332  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
333  real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
334  character(len=LINELENGTH) :: nc_tag
335  integer(I4B) :: iper, iaux
336 
337  iper = 0
338  iaux = 0
339 
340  ! set package input tag
341  nc_tag = this%input_attribute(pkgname, idt)
342 
343  select case (idt%datatype)
344  case ('INTEGER1D')
345  call mem_setptr(int1d, idt%mf6varname, mempath)
346  call nc_export_int1d(int1d, this%ncid, this%dim_ids, this%x_dim, &
347  this%y_dim, this%var_ids, this%dis, idt, mempath, &
348  nc_tag, pkgname, this%gridmap_name, this%deflate, &
349  this%shuffle, this%chunk_face, iper, this%nc_fname)
350  case ('INTEGER2D')
351  call mem_setptr(int2d, idt%mf6varname, mempath)
352  call nc_export_int2d(int2d, this%ncid, this%dim_ids, this%var_ids, &
353  this%dis, idt, mempath, nc_tag, pkgname, &
354  this%gridmap_name, this%deflate, this%shuffle, &
355  this%chunk_face, this%nc_fname)
356  case ('INTEGER3D')
357  call mem_setptr(int3d, idt%mf6varname, mempath)
358  call nc_export_int3d(int3d, this%ncid, this%dim_ids, this%var_ids, &
359  this%dis, idt, mempath, nc_tag, pkgname, &
360  this%gridmap_name, this%deflate, this%shuffle, &
361  this%chunk_face, this%nc_fname)
362  case ('DOUBLE1D')
363  call mem_setptr(dbl1d, idt%mf6varname, mempath)
364  call nc_export_dbl1d(dbl1d, this%ncid, this%dim_ids, this%x_dim, &
365  this%y_dim, this%var_ids, this%dis, idt, mempath, &
366  nc_tag, pkgname, this%gridmap_name, this%deflate, &
367  this%shuffle, this%chunk_face, iper, iaux, &
368  this%nc_fname)
369  case ('DOUBLE2D')
370  call mem_setptr(dbl2d, idt%mf6varname, mempath)
371  call nc_export_dbl2d(dbl2d, this%ncid, this%dim_ids, this%var_ids, &
372  this%dis, idt, mempath, nc_tag, pkgname, &
373  this%gridmap_name, this%deflate, this%shuffle, &
374  this%chunk_face, this%nc_fname)
375  case ('DOUBLE3D')
376  call mem_setptr(dbl3d, idt%mf6varname, mempath)
377  call nc_export_dbl3d(dbl3d, this%ncid, this%dim_ids, this%var_ids, &
378  this%dis, idt, mempath, nc_tag, pkgname, &
379  this%gridmap_name, this%deflate, this%shuffle, &
380  this%chunk_face, this%nc_fname)
381  case default
382  ! no-op, no other datatypes exported
383  end select
384  end subroutine export_input_array
385 
386  !> @brief netcdf export define dimensions
387  !<
388  subroutine define_dim(this)
389  use constantsmodule, only: mvalidate
390  use simvariablesmodule, only: isim_mode
391  class(mesh2ddisexporttype), intent(inout) :: this
392 
393  if (isim_mode /= mvalidate .or. this%pkglist%Count() > 0) then
394  ! time
395  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
396  this%dim_ids%time), this%nc_fname)
397  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
398  this%dim_ids%time, this%var_ids%time), &
399  this%nc_fname)
400  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
401  'standard'), this%nc_fname)
402  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
403  this%datetime), this%nc_fname)
404  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
405  this%nc_fname)
406  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
407  'time'), this%nc_fname)
408  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
409  'time'), this%nc_fname)
410  end if
411 
412  ! mesh
413  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_node', &
414  ((this%dis%ncol + 1) * (this%dis%nrow + 1)), &
415  this%dim_ids%nmesh_node), this%nc_fname)
416  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_face', &
417  (this%dis%ncol * this%dis%nrow), &
418  this%dim_ids%nmesh_face), this%nc_fname)
419  call nf_verify(nf90_def_dim(this%ncid, 'max_nmesh_face_nodes', 4, &
420  this%dim_ids%max_nmesh_face_nodes), &
421  this%nc_fname)
422 
423  ! x, y
424  call nf_verify(nf90_def_dim(this%ncid, 'x', this%dis%ncol, &
425  this%x_dim), this%nc_fname)
426  call nf_verify(nf90_def_dim(this%ncid, 'y', this%dis%nrow, &
427  this%y_dim), this%nc_fname)
428 
429  ! layer
430  call nf_verify(nf90_def_dim(this%ncid, 'layer', this%nlay, &
431  this%dim_ids%layer), this%nc_fname)
432  call nf_verify(nf90_def_var(this%ncid, 'layer', nf90_int, &
433  this%dim_ids%layer, this%var_ids%layer), &
434  this%nc_fname)
435  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'units', '1'), &
436  this%nc_fname)
437  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'axis', 'Z'), &
438  this%nc_fname)
439  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'positive', &
440  'down'), this%nc_fname)
441  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'long_name', &
442  'model layer'), this%nc_fname)
443  end subroutine define_dim
444 
445  !> @brief netcdf export add mesh information
446  !<
447  subroutine add_mesh_data(this)
449  class(mesh2ddisexporttype), intent(inout) :: this
450  integer(I4B) :: cnt, maxvert, m, k
451  integer(I4B), dimension(:), allocatable :: verts, layers
452  real(DP), dimension(:), allocatable :: bnds
453  integer(I4B) :: i, j
454  real(DP) :: x, y, x_transform, y_transform
455  real(DP), dimension(:), allocatable :: node_x, node_y
456  real(DP), dimension(:), allocatable :: cell_x, cell_y
457 
458  ! initialize max vertices required to define cell
459  maxvert = 4
460 
461  ! set mesh container variable value to 1
462  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
463  this%nc_fname)
464 
465  ! write layer coordinate data
466  allocate (layers(this%nlay))
467  do k = 1, this%nlay
468  layers(k) = k
469  end do
470  call nf_verify(nf90_put_var(this%ncid, this%var_ids%layer, layers), &
471  this%nc_fname)
472  deallocate (layers)
473 
474  ! allocate temporary arrays
475  allocate (verts(maxvert))
476  allocate (bnds(maxvert))
477  allocate (node_x(((this%dis%ncol + 1) * (this%dis%nrow + 1))))
478  allocate (node_y(((this%dis%ncol + 1) * (this%dis%nrow + 1))))
479  allocate (cell_x((this%dis%ncol * this%dis%nrow)))
480  allocate (cell_y((this%dis%ncol * this%dis%nrow)))
481 
482  ! set node_x and node_y arrays
483  cnt = 0
484  node_x = nf90_fill_double
485  node_y = nf90_fill_double
486  y = sum(this%dis%delc)
487  do j = this%dis%nrow, 0, -1
488  x = 0
489  do i = this%dis%ncol, 0, -1
490  cnt = cnt + 1
491  call dis_transform_xy(x, y, &
492  this%dis%xorigin, &
493  this%dis%yorigin, &
494  this%dis%angrot, &
495  x_transform, y_transform)
496  node_x(cnt) = x_transform
497  node_y(cnt) = y_transform
498  if (i > 0) x = x + this%dis%delr(i)
499  end do
500  if (j > 0) y = y - this%dis%delc(j)
501  end do
502 
503  ! write node_x and node_y arrays to netcdf file
504  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, node_x), &
505  this%nc_fname)
506  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, node_y), &
507  this%nc_fname)
508 
509  ! set cell_x and cell_y arrays
510  cnt = 1
511  cell_x = nf90_fill_double
512  cell_y = nf90_fill_double
513  do j = 1, this%dis%nrow
514  y = this%dis%celly(j)
515  do i = 1, this%dis%ncol
516  x = this%dis%cellx(i)
517  call dis_transform_xy(x, y, &
518  this%dis%xorigin, &
519  this%dis%yorigin, &
520  this%dis%angrot, &
521  x_transform, y_transform)
522  cell_x(cnt) = x_transform
523  cell_y(cnt) = y_transform
524  cnt = cnt + 1
525  end do
526  end do
527 
528  ! write face_x and face_y arrays to netcdf file
529  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, cell_x), &
530  this%nc_fname)
531  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, cell_y), &
532  this%nc_fname)
533 
534  ! set face nodes array
535  cnt = 0
536  do i = 1, this%dis%nrow
537  do j = 1, this%dis%ncol
538  cnt = cnt + 1
539  verts = nf90_fill_int
540  verts(1) = cnt + this%dis%ncol + i
541  verts(2) = cnt + this%dis%ncol + i + 1
542  if (i > 1) then
543  verts(3) = cnt + i
544  verts(4) = cnt + i - 1
545  else
546  verts(3) = cnt + 1
547  verts(4) = cnt
548  end if
549 
550  ! write face nodes array to netcdf file
551  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
552  verts, start=(/1, cnt/), &
553  count=(/maxvert, 1/)), &
554  this%nc_fname)
555 
556  ! set face y bounds array
557  bnds = nf90_fill_double
558  do m = 1, size(bnds)
559  if (verts(m) /= nf90_fill_int) then
560  bnds(m) = node_y(verts(m))
561  end if
562  ! write face y bounds array to netcdf file
563  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
564  bnds, start=(/1, cnt/), &
565  count=(/maxvert, 1/)), &
566  this%nc_fname)
567  end do
568 
569  ! set face x bounds array
570  bnds = nf90_fill_double
571  do m = 1, size(bnds)
572  if (verts(m) /= nf90_fill_int) then
573  bnds(m) = node_x(verts(m))
574  end if
575  ! write face x bounds array to netcdf file
576  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
577  bnds, start=(/1, cnt/), &
578  count=(/maxvert, 1/)), &
579  this%nc_fname)
580  end do
581  end do
582  end do
583 
584  ! cleanup
585  deallocate (bnds)
586  deallocate (verts)
587  deallocate (node_x)
588  deallocate (node_y)
589  deallocate (cell_x)
590  deallocate (cell_y)
591  end subroutine add_mesh_data
592 
593  !> @brief netcdf export 1D integer
594  !<
595  subroutine nc_export_int1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, &
596  idt, mempath, nc_tag, pkgname, gridmap_name, &
597  deflate, shuffle, chunk_face, iper, nc_fname)
598  use tdismodule, only: kper
599  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
600  integer(I4B), intent(in) :: ncid
601  type(meshncdimidtype), intent(inout) :: dim_ids
602  integer(I4B), intent(in) :: x_dim
603  integer(I4B), intent(in) :: y_dim
604  type(meshncvaridtype), intent(inout) :: var_ids
605  type(distype), pointer, intent(in) :: dis
606  type(inputparamdefinitiontype), pointer :: idt
607  character(len=*), intent(in) :: mempath
608  character(len=*), intent(in) :: nc_tag
609  character(len=*), intent(in) :: pkgname
610  character(len=*), intent(in) :: gridmap_name
611  integer(I4B), intent(in) :: deflate
612  integer(I4B), intent(in) :: shuffle
613  integer(I4B), intent(in) :: chunk_face
614  integer(I4B), intent(in) :: iper
615  character(len=*), intent(in) :: nc_fname
616  integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
617  integer(I4B), dimension(:), pointer, contiguous :: int1d
618  integer(I4B) :: axis_dim, nvals, k
619  integer(I4B), dimension(:), allocatable :: var_id
620  character(len=LINELENGTH) :: longname, varname
621 
622  if (idt%shape == 'NROW' .or. &
623  idt%shape == 'NCOL' .or. &
624  idt%shape == 'NCPL' .or. &
625  idt%shape == 'NAUX NCPL') then
626 
627  if (iper == 0) then
628 
629  select case (idt%shape)
630  case ('NROW')
631  axis_dim = y_dim
632  case ('NCOL')
633  axis_dim = x_dim
634  case ('NCPL', 'NAUX NCPL')
635  axis_dim = dim_ids%nmesh_face
636  end select
637 
638  ! set names
639  varname = export_varname(pkgname, idt%tagname, mempath)
640  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
641  component_type=idt%component_type, &
642  subcomponent_type=idt%subcomponent_type)
643 
644  allocate (var_id(1))
645 
646  ! reenter define mode and create variable
647  call nf_verify(nf90_redef(ncid), nc_fname)
648  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
649  (/axis_dim/), var_id(1)), &
650  nc_fname)
651 
652  ! apply chunking for face-indexed variables; NROW/NCOL use default
653  if (axis_dim == dim_ids%nmesh_face) then
654  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
655  end if
656  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
657 
658  ! put attr
659  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
660  (/nf90_fill_int/)), nc_fname)
661  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
662  longname), nc_fname)
663 
664  ! add grid mapping for face-indexed variables
665  if (axis_dim == dim_ids%nmesh_face) then
666  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
667  end if
668 
669  ! add mf6 attr
670  call ncvar_mf6attr(ncid, var_id(1), 0, 0, nc_tag, nc_fname)
671 
672  ! exit define mode and write data
673  call nf_verify(nf90_enddef(ncid), nc_fname)
674  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
675  nc_fname)
676  else
677  nvals = dis%nrow * dis%ncol
678  call nf_verify(nf90_put_var(ncid, &
679  var_ids%export(1), p_mem, &
680  start=(/1, kper/), &
681  count=(/nvals, 1/)), nc_fname)
682  end if
683 
684  else
685  ! reshape input
686  int3d(1:dis%ncol, 1:dis%nrow, 1:dis%nlay) => p_mem(1:dis%nodesuser)
687 
688  ! set nvals as ncpl
689  nvals = dis%nrow * dis%ncol
690 
691  if (iper == 0) then
692  ! not a timeseries, create variables and write griddata
693  allocate (var_id(dis%nlay))
694 
695  ! reenter define mode and create variable
696  call nf_verify(nf90_redef(ncid), nc_fname)
697  do k = 1, dis%nlay
698  ! set names
699  varname = export_varname(pkgname, idt%tagname, mempath, &
700  layer=k)
701  longname = export_longname(idt%longname, pkgname, idt%tagname, &
702  mempath, layer=k, &
703  component_type=idt%component_type, &
704  subcomponent_type=idt%subcomponent_type)
705 
706  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
707  (/dim_ids%nmesh_face/), var_id(k)), &
708  nc_fname)
709 
710  ! apply chunking parameters
711  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
712  ! deflate and shuffle
713  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
714 
715  ! put attr
716  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
717  (/nf90_fill_int/)), nc_fname)
718  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
719  longname), nc_fname)
720 
721  ! add grid mapping and mf6 attr
722  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
723  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
724  end do
725 
726  ! exit define mode and write data
727  call nf_verify(nf90_enddef(ncid), nc_fname)
728  do k = 1, dis%nlay
729  int1d(1:nvals) => int3d(:, :, k)
730  call nf_verify(nf90_put_var(ncid, var_id(k), int1d), nc_fname)
731  end do
732 
733  ! cleanup
734  deallocate (var_id)
735  else
736  ! timeseries, add period data
737  do k = 1, dis%nlay
738  int1d(1:nvals) => int3d(:, :, k)
739  call nf_verify(nf90_put_var(ncid, &
740  var_ids%export(k), int1d, &
741  start=(/1, kper/), &
742  count=(/nvals, 1/)), nc_fname)
743  end do
744  end if
745  end if
746  end subroutine nc_export_int1d
747 
748  !> @brief netcdf export 2D integer
749  !<
750  subroutine nc_export_int2d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
751  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
752  chunk_face, nc_fname)
753  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
754  integer(I4B), intent(in) :: ncid
755  type(meshncdimidtype), intent(inout) :: dim_ids
756  type(meshncvaridtype), intent(inout) :: var_ids
757  type(distype), pointer, intent(in) :: dis
758  type(inputparamdefinitiontype), pointer :: idt
759  character(len=*), intent(in) :: mempath
760  character(len=*), intent(in) :: nc_tag
761  character(len=*), intent(in) :: pkgname
762  character(len=*), intent(in) :: gridmap_name
763  integer(I4B), intent(in) :: deflate
764  integer(I4B), intent(in) :: shuffle
765  integer(I4B), intent(in) :: chunk_face
766  character(len=*), intent(in) :: nc_fname
767  integer(I4B) :: var_id, nvals
768  integer(I4B), dimension(:), pointer, contiguous :: int1d
769  character(len=LINELENGTH) :: longname, varname
770 
771  ! set names
772  varname = export_varname(pkgname, idt%tagname, mempath)
773  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
774  component_type=idt%component_type, &
775  subcomponent_type=idt%subcomponent_type)
776 
777  ! reenter define mode and create variable
778  call nf_verify(nf90_redef(ncid), nc_fname)
779  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
780  (/dim_ids%nmesh_face/), var_id), &
781  nc_fname)
782 
783  ! apply chunking parameters
784  call ncvar_chunk(ncid, var_id, chunk_face, nc_fname)
785  ! deflate and shuffle
786  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
787 
788  ! put attr
789  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
790  (/nf90_fill_int/)), nc_fname)
791  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
792  longname), nc_fname)
793 
794  ! add grid mapping and mf6 attr
795  call ncvar_gridmap(ncid, var_id, gridmap_name, nc_fname)
796  call ncvar_mf6attr(ncid, var_id, 0, 0, nc_tag, nc_fname)
797 
798  ! exit define mode and write data
799  call nf_verify(nf90_enddef(ncid), nc_fname)
800  nvals = dis%nrow * dis%ncol
801  int1d(1:nvals) => p_mem
802  call nf_verify(nf90_put_var(ncid, var_id, int1d), nc_fname)
803  end subroutine nc_export_int2d
804 
805  !> @brief netcdf export 3D integer
806  !<
807  subroutine nc_export_int3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
808  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
809  chunk_face, nc_fname)
810  integer(I4B), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
811  integer(I4B), intent(in) :: ncid
812  type(meshncdimidtype), intent(inout) :: dim_ids
813  type(meshncvaridtype), intent(inout) :: var_ids
814  type(distype), pointer, intent(in) :: dis
815  type(inputparamdefinitiontype), pointer :: idt
816  character(len=*), intent(in) :: mempath
817  character(len=*), intent(in) :: nc_tag
818  character(len=*), intent(in) :: pkgname
819  character(len=*), intent(in) :: gridmap_name
820  integer(I4B), intent(in) :: deflate
821  integer(I4B), intent(in) :: shuffle
822  integer(I4B), intent(in) :: chunk_face
823  character(len=*), intent(in) :: nc_fname
824  integer(I4B), dimension(:), allocatable :: var_id
825  integer(I4B), dimension(:), pointer, contiguous :: int1d
826  character(len=LINELENGTH) :: longname, varname
827  integer(I4B) :: k, nvals
828 
829  allocate (var_id(dis%nlay))
830 
831  ! reenter define mode and create variable
832  call nf_verify(nf90_redef(ncid), nc_fname)
833  do k = 1, dis%nlay
834  ! set names
835  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
836  longname = export_longname(idt%longname, pkgname, idt%tagname, &
837  mempath, layer=k, &
838  component_type=idt%component_type, &
839  subcomponent_type=idt%subcomponent_type)
840 
841  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
842  (/dim_ids%nmesh_face/), var_id(k)), &
843  nc_fname)
844 
845  ! apply chunking parameters
846  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
847  ! deflate and shuffle
848  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
849 
850  ! put attr
851  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
852  (/nf90_fill_int/)), nc_fname)
853  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
854  longname), nc_fname)
855 
856  ! add grid mapping and mf6 attr
857  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
858  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
859  end do
860 
861  ! exit define mode and write data
862  call nf_verify(nf90_enddef(ncid), nc_fname)
863  nvals = dis%nrow * dis%ncol
864  do k = 1, dis%nlay
865  int1d(1:nvals) => p_mem(:, :, k)
866  call nf_verify(nf90_put_var(ncid, var_id(k), int1d), nc_fname)
867  end do
868 
869  ! cleanup
870  deallocate (var_id)
871  end subroutine nc_export_int3d
872 
873  !> @brief netcdf export 1D double
874  !<
875  subroutine nc_export_dbl1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, &
876  idt, mempath, nc_tag, pkgname, gridmap_name, &
877  deflate, shuffle, chunk_face, iper, iaux, nc_fname)
878  use tdismodule, only: kper
879  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
880  integer(I4B), intent(in) :: ncid
881  type(meshncdimidtype), intent(inout) :: dim_ids
882  integer(I4B), intent(in) :: x_dim
883  integer(I4B), intent(in) :: y_dim
884  type(meshncvaridtype), intent(in) :: var_ids
885  type(distype), pointer, intent(in) :: dis
886  type(inputparamdefinitiontype), pointer :: idt
887  character(len=*), intent(in) :: mempath
888  character(len=*), intent(in) :: nc_tag
889  character(len=*), intent(in) :: pkgname
890  character(len=*), intent(in) :: gridmap_name
891  integer(I4B), intent(in) :: deflate
892  integer(I4B), intent(in) :: shuffle
893  integer(I4B), intent(in) :: chunk_face
894  integer(I4B), intent(in) :: iper
895  integer(I4B), intent(in) :: iaux
896  character(len=*), intent(in) :: nc_fname
897  real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
898  real(DP), dimension(:), pointer, contiguous :: dbl1d
899  integer(I4B) :: axis_dim, nvals, k
900  integer(I4B), dimension(:), allocatable :: var_id
901  character(len=LINELENGTH) :: longname, varname
902 
903  if (idt%shape == 'NROW' .or. &
904  idt%shape == 'NCOL' .or. &
905  idt%shape == 'NCPL' .or. &
906  idt%shape == 'NAUX NCPL') then
907 
908  if (iper == 0) then
909 
910  select case (idt%shape)
911  case ('NROW')
912  axis_dim = y_dim
913  case ('NCOL')
914  axis_dim = x_dim
915  case ('NCPL', 'NAUX NCPL')
916  axis_dim = dim_ids%nmesh_face
917  end select
918 
919  ! set names
920  varname = export_varname(pkgname, idt%tagname, mempath, iaux=iaux)
921  longname = export_longname(idt%longname, pkgname, idt%tagname, &
922  mempath, iaux=iaux, &
923  component_type=idt%component_type, &
924  subcomponent_type=idt%subcomponent_type)
925 
926  allocate (var_id(1))
927 
928  ! reenter define mode and create variable
929  call nf_verify(nf90_redef(ncid), nc_fname)
930  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
931  (/axis_dim/), var_id(1)), &
932  nc_fname)
933 
934  ! apply chunking for face-indexed variables; NROW/NCOL use default
935  if (axis_dim == dim_ids%nmesh_face) then
936  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
937  end if
938  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
939 
940  ! put attr
941  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
942  (/nf90_fill_double/)), nc_fname)
943  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
944  longname), nc_fname)
945 
946  ! add grid mapping for face-indexed variables
947  if (axis_dim == dim_ids%nmesh_face) then
948  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
949  end if
950 
951  ! add mf6 attr
952  call ncvar_mf6attr(ncid, var_id(1), 0, iaux, nc_tag, nc_fname)
953 
954  ! exit define mode and write data
955  call nf_verify(nf90_enddef(ncid), nc_fname)
956  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
957  nc_fname)
958  else
959  nvals = dis%nrow * dis%ncol
960  call nf_verify(nf90_put_var(ncid, &
961  var_ids%export(1), p_mem, &
962  start=(/1, kper/), &
963  count=(/nvals, 1/)), nc_fname)
964  end if
965 
966  else
967  ! reshape input
968  dbl3d(1:dis%ncol, 1:dis%nrow, 1:dis%nlay) => p_mem(1:dis%nodesuser)
969 
970  ! set nvals as ncpl
971  nvals = dis%nrow * dis%ncol
972 
973  if (iper == 0) then
974  ! not a timeseries, create variables and write griddata
975 
976  ! allocate local variable id storage
977  allocate (var_id(dis%nlay))
978 
979  ! reenter define mode and create layer variables
980  call nf_verify(nf90_redef(ncid), nc_fname)
981  do k = 1, dis%nlay
982  ! set names
983  varname = export_varname(pkgname, idt%tagname, mempath, layer=k, &
984  iaux=iaux)
985  longname = export_longname(idt%longname, pkgname, idt%tagname, &
986  mempath, layer=k, iaux=iaux, &
987  component_type=idt%component_type, &
988  subcomponent_type=idt%subcomponent_type)
989 
990  ! create layer variable
991  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
992  (/dim_ids%nmesh_face/), var_id(k)), &
993  nc_fname)
994 
995  ! apply chunking parameters
996  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
997  ! deflate and shuffle
998  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
999 
1000  ! put attr
1001  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
1002  (/nf90_fill_double/)), nc_fname)
1003  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
1004  longname), nc_fname)
1005 
1006  ! add grid mapping and mf6 attr
1007  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
1008  call ncvar_mf6attr(ncid, var_id(k), k, iaux, nc_tag, nc_fname)
1009  end do
1010 
1011  ! exit define mode
1012  call nf_verify(nf90_enddef(ncid), nc_fname)
1013 
1014  ! write layer data
1015  do k = 1, dis%nlay
1016  dbl1d(1:nvals) => dbl3d(:, :, k)
1017  call nf_verify(nf90_put_var(ncid, var_id(k), dbl1d), nc_fname)
1018  end do
1019 
1020  ! cleanup
1021  deallocate (var_id)
1022  else
1023  ! timeseries, add period data
1024  do k = 1, dis%nlay
1025  dbl1d(1:nvals) => dbl3d(:, :, k)
1026  call nf_verify(nf90_put_var(ncid, &
1027  var_ids%export(k), dbl1d, &
1028  start=(/1, kper/), &
1029  count=(/nvals, 1/)), nc_fname)
1030  end do
1031  end if
1032  end if
1033  end subroutine nc_export_dbl1d
1034 
1035  !> @brief netcdf export 2D double
1036  !<
1037  subroutine nc_export_dbl2d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
1038  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
1039  chunk_face, nc_fname)
1040  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
1041  integer(I4B), intent(in) :: ncid
1042  type(meshncdimidtype), intent(inout) :: dim_ids
1043  type(meshncvaridtype), intent(inout) :: var_ids
1044  type(distype), pointer, intent(in) :: dis
1045  type(inputparamdefinitiontype), pointer :: idt
1046  character(len=*), intent(in) :: mempath
1047  character(len=*), intent(in) :: nc_tag
1048  character(len=*), intent(in) :: pkgname
1049  character(len=*), intent(in) :: gridmap_name
1050  integer(I4B), intent(in) :: deflate
1051  integer(I4B), intent(in) :: shuffle
1052  integer(I4B), intent(in) :: chunk_face
1053  character(len=*), intent(in) :: nc_fname
1054  integer(I4B) :: var_id, nvals
1055  character(len=LINELENGTH) :: longname, varname
1056  real(DP), dimension(:), pointer, contiguous :: dbl1d
1057 
1058  ! set names
1059  varname = export_varname(pkgname, idt%tagname, mempath)
1060  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1061  component_type=idt%component_type, &
1062  subcomponent_type=idt%subcomponent_type)
1063 
1064  ! reenter define mode and create variable
1065  call nf_verify(nf90_redef(ncid), nc_fname)
1066  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1067  (/dim_ids%nmesh_face/), var_id), &
1068  nc_fname)
1069 
1070  ! apply chunking parameters
1071  call ncvar_chunk(ncid, var_id, chunk_face, nc_fname)
1072  ! deflate and shuffle
1073  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1074 
1075  ! put attr
1076  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1077  (/nf90_fill_double/)), nc_fname)
1078  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1079  longname), nc_fname)
1080 
1081  ! add grid mapping and mf6 attr
1082  call ncvar_gridmap(ncid, var_id, gridmap_name, nc_fname)
1083  call ncvar_mf6attr(ncid, var_id, 0, 0, nc_tag, nc_fname)
1084 
1085  ! exit define mode and write data
1086  call nf_verify(nf90_enddef(ncid), nc_fname)
1087  nvals = dis%nrow * dis%ncol
1088  dbl1d(1:nvals) => p_mem
1089  call nf_verify(nf90_put_var(ncid, var_id, dbl1d), nc_fname)
1090  end subroutine nc_export_dbl2d
1091 
1092  !> @brief netcdf export 3D double
1093  !<
1094  subroutine nc_export_dbl3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
1095  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
1096  chunk_face, nc_fname)
1097  real(DP), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
1098  integer(I4B), intent(in) :: ncid
1099  type(meshncdimidtype), intent(inout) :: dim_ids
1100  type(meshncvaridtype), intent(inout) :: var_ids
1101  type(distype), pointer, intent(in) :: dis
1102  type(inputparamdefinitiontype), pointer :: idt
1103  character(len=*), intent(in) :: mempath
1104  character(len=*), intent(in) :: nc_tag
1105  character(len=*), intent(in) :: pkgname
1106  character(len=*), intent(in) :: gridmap_name
1107  integer(I4B), intent(in) :: deflate
1108  integer(I4B), intent(in) :: shuffle
1109  integer(I4B), intent(in) :: chunk_face
1110  character(len=*), intent(in) :: nc_fname
1111  integer(I4B), dimension(:), allocatable :: var_id
1112  real(DP), dimension(:), pointer, contiguous :: dbl1d
1113  character(len=LINELENGTH) :: longname, varname
1114  integer(I4B) :: k, nvals
1115 
1116  ! set nvals as ncpl
1117  nvals = dis%nrow * dis%ncol
1118 
1119  allocate (var_id(dis%nlay))
1120 
1121  ! reenter define mode and create variable
1122  call nf_verify(nf90_redef(ncid), nc_fname)
1123  do k = 1, dis%nlay
1124  ! set names
1125  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
1126  longname = export_longname(idt%longname, pkgname, idt%tagname, &
1127  mempath, layer=k, &
1128  component_type=idt%component_type, &
1129  subcomponent_type=idt%subcomponent_type)
1130 
1131  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1132  (/dim_ids%nmesh_face/), var_id(k)), &
1133  nc_fname)
1134 
1135  ! apply chunking parameters
1136  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
1137  ! deflate and shuffle
1138  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
1139 
1140  ! put attr
1141  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
1142  (/nf90_fill_double/)), nc_fname)
1143  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
1144  longname), nc_fname)
1145 
1146  ! add grid mapping and mf6 attr
1147  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
1148  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
1149  end do
1150 
1151  ! exit define mode and write data
1152  call nf_verify(nf90_enddef(ncid), nc_fname)
1153  do k = 1, dis%nlay
1154  dbl1d(1:nvals) => p_mem(:, :, k)
1155  call nf_verify(nf90_put_var(ncid, var_id(k), dbl1d), nc_fname)
1156  end do
1157 
1158  ! cleanup
1159  deallocate (var_id)
1160  end subroutine nc_export_dbl3d
1161 
1162 end module meshdismodelmodule
subroutine init()
Definition: GridSorting.f90:25
subroutine, public dis_transform_xy(x, y, xorigin, yorigin, angrot, xglo, yglo)
Get global (x, y) coordinates from cell-local coordinates.
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
@ mvalidate
validation mode - do not run time steps
Definition: Constants.f90:205
real(dp), parameter dnodata
real no data constant
Definition: Constants.f90:95
integer(i4b), parameter lenbigline
maximum length of a big line
Definition: Constants.f90:15
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:93
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename, found)
Return parameter definition.
Definition: Dis.f90:1
Input definition module.
This module defines variable data types.
Definition: kind.f90:8
This module contains the MeshDisModelModule.
Definition: DisNCMesh.f90:8
subroutine nc_export_dbl2d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
netcdf export 2D double
Definition: DisNCMesh.f90:1040
subroutine nc_export_int1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, iper, nc_fname)
netcdf export 1D integer
Definition: DisNCMesh.f90:598
subroutine define_dim(this)
netcdf export define dimensions
Definition: DisNCMesh.f90:389
subroutine add_mesh_data(this)
netcdf export add mesh information
Definition: DisNCMesh.f90:448
subroutine nc_export_dbl3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
netcdf export 3D double
Definition: DisNCMesh.f90:1097
subroutine nc_export_int2d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
netcdf export 2D integer
Definition: DisNCMesh.f90:753
subroutine dis_export_init(this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
netcdf export dis init
Definition: DisNCMesh.f90:52
subroutine step(this)
netcdf export step
Definition: DisNCMesh.f90:120
subroutine package_step(this, export_pkg)
netcdf export package dynamic input
Definition: DisNCMesh.f90:186
subroutine dis_export_destroy(this)
netcdf export dis destroy
Definition: DisNCMesh.f90:77
subroutine nc_export_int3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
netcdf export 3D integer
Definition: DisNCMesh.f90:810
subroutine nc_export_dbl1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, iper, iaux, nc_fname)
netcdf export 1D double
Definition: DisNCMesh.f90:878
subroutine export_input_array(this, pkgtype, pkgname, mempath, idt)
netcdf export an input array
Definition: DisNCMesh.f90:323
subroutine df(this)
netcdf export define
Definition: DisNCMesh.f90:87
This module contains the MeshModelModule.
Definition: MeshNCModel.f90:7
subroutine, public ncvar_mf6attr(ncid, varid, layer, iaux, nc_tag, nc_fname)
put variable internal attributes
subroutine, public ncvar_gridmap(ncid, varid, gridmap_name, nc_fname)
put variable gridmap attributes
subroutine, public ncvar_chunk(ncid, varid, chunk_face, nc_fname)
define variable chunking
subroutine, public ncvar_deflate(ncid, varid, deflate, shuffle, nc_fname)
define variable compression
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
character(len=linelength) function, public export_varname(pkgname, tagname, mempath, layer, iaux)
build netcdf variable name
Definition: NCModel.f90:452
character(len=linelength) function, public export_longname(longname, pkgname, tagname, mempath, layer, iaux, component_type, subcomponent_type)
build netcdf variable longname
Definition: NCModel.f90:493
This module contains the NetCDFCommonModule.
Definition: NetCDFCommon.f90:6
subroutine, public nf_verify(res, nc_fname)
error check a netcdf-fortran interface call
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
integer(i4b) isim_mode
simulation mode
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:35
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:26
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
Structured grid discretization.
Definition: Dis.f90:23
Input parameter definition. Describes an input parameter.
type for storing model export dimension ids
Definition: MeshNCModel.f90:33
type for storing model export variable ids
Definition: MeshNCModel.f90:44