MODFLOW 6  version 6.9.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  integer(I4B) :: k
393  character(len=LINELENGTH) :: varname
394  character(len=LINELENGTH) :: elev_longname
395 
396  if (isim_mode /= mvalidate .or. this%pkglist%Count() > 0) then
397  ! time
398  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
399  this%dim_ids%time), this%nc_fname)
400  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
401  this%dim_ids%time, this%var_ids%time), &
402  this%nc_fname)
403  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
404  'standard'), this%nc_fname)
405  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
406  this%datetime), this%nc_fname)
407  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
408  this%nc_fname)
409  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
410  'time'), this%nc_fname)
411  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
412  'time'), this%nc_fname)
413  end if
414 
415  ! mesh
416  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_node', &
417  ((this%dis%ncol + 1) * (this%dis%nrow + 1)), &
418  this%dim_ids%nmesh_node), this%nc_fname)
419  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_face', &
420  (this%dis%ncol * this%dis%nrow), &
421  this%dim_ids%nmesh_face), this%nc_fname)
422  call nf_verify(nf90_def_dim(this%ncid, 'max_nmesh_face_nodes', 4, &
423  this%dim_ids%max_nmesh_face_nodes), &
424  this%nc_fname)
425 
426  ! x, y
427  call nf_verify(nf90_def_dim(this%ncid, 'x', this%dis%ncol, &
428  this%x_dim), this%nc_fname)
429  call nf_verify(nf90_def_dim(this%ncid, 'y', this%dis%nrow, &
430  this%y_dim), this%nc_fname)
431 
432  ! layer
433  call nf_verify(nf90_def_dim(this%ncid, 'layer', this%nlay, &
434  this%dim_ids%layer), this%nc_fname)
435  call nf_verify(nf90_def_var(this%ncid, 'layer', nf90_int, &
436  this%dim_ids%layer, this%var_ids%layer), &
437  this%nc_fname)
438  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'units', '1'), &
439  this%nc_fname)
440  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'axis', 'Z'), &
441  this%nc_fname)
442  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'positive', &
443  'down'), this%nc_fname)
444  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'long_name', &
445  'model layer'), this%nc_fname)
446 
447  ! z_l1, z_l2, ... : per-layer cell center elevation auxiliary
448  ! coordinates -- real vertical position, unlike the discrete layer
449  ! index. Always written, independent of CRS/NCF configuration; split
450  ! per layer since face-indexed variables carry no layer dimension to
451  ! legally reference a combined z(layer, nmesh_face) coordinate
452  ! (CF-1.13 5.2).
453  allocate (this%var_ids%elevation(this%nlay))
454  do k = 1, this%nlay
455  write (varname, '(a,i0)') 'z_l', k
456  call nf_verify(nf90_def_var(this%ncid, trim(varname), nf90_double, &
457  (/this%dim_ids%nmesh_face/), &
458  this%var_ids%elevation(k)), this%nc_fname)
459  call ncvar_chunk(this%ncid, this%var_ids%elevation(k), this%chunk_face, &
460  this%nc_fname)
461  call ncvar_deflate(this%ncid, this%var_ids%elevation(k), this%deflate, &
462  this%shuffle, this%nc_fname)
463  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
464  'units', this%lenunits), this%nc_fname)
465  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
466  'standard_name', 'altitude'), this%nc_fname)
467  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
468  'positive', 'up'), this%nc_fname)
469  write (elev_longname, '(a,i0,a)') 'cell center elevation (layer ', &
470  k, ')'
471  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
472  'long_name', trim(elev_longname)), &
473  this%nc_fname)
474  call ncvar_layer(this%ncid, this%var_ids%elevation(k), k, this%nc_fname)
475  end do
476  end subroutine define_dim
477 
478  !> @brief netcdf export add mesh information
479  !<
480  subroutine add_mesh_data(this)
482  class(mesh2ddisexporttype), intent(inout) :: this
483  integer(I4B) :: cnt, maxvert, m, k
484  integer(I4B), dimension(:), allocatable :: verts, layers
485  real(DP), dimension(:), allocatable :: bnds
486  integer(I4B) :: i, j
487  real(DP) :: x, y, x_transform, y_transform
488  real(DP), dimension(:), allocatable :: node_x, node_y
489  real(DP), dimension(:), allocatable :: cell_x, cell_y
490  real(DP), dimension(:), allocatable :: elev_face
491 
492  ! initialize max vertices required to define cell
493  maxvert = 4
494 
495  ! set mesh container variable value to 1
496  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
497  this%nc_fname)
498 
499  ! write layer coordinate data
500  allocate (layers(this%nlay))
501  do k = 1, this%nlay
502  layers(k) = k
503  end do
504  call nf_verify(nf90_put_var(this%ncid, this%var_ids%layer, layers), &
505  this%nc_fname)
506  deallocate (layers)
507 
508  ! allocate temporary arrays
509  allocate (verts(maxvert))
510  allocate (bnds(maxvert))
511  allocate (node_x(((this%dis%ncol + 1) * (this%dis%nrow + 1))))
512  allocate (node_y(((this%dis%ncol + 1) * (this%dis%nrow + 1))))
513  allocate (cell_x((this%dis%ncol * this%dis%nrow)))
514  allocate (cell_y((this%dis%ncol * this%dis%nrow)))
515 
516  ! set node_x and node_y arrays
517  cnt = 0
518  node_x = nf90_fill_double
519  node_y = nf90_fill_double
520  y = sum(this%dis%delc)
521  do j = this%dis%nrow, 0, -1
522  x = 0
523  do i = this%dis%ncol, 0, -1
524  cnt = cnt + 1
525  call dis_transform_xy(x, y, &
526  this%dis%xorigin, &
527  this%dis%yorigin, &
528  this%dis%angrot, &
529  x_transform, y_transform)
530  node_x(cnt) = x_transform
531  node_y(cnt) = y_transform
532  if (i > 0) x = x + this%dis%delr(i)
533  end do
534  if (j > 0) y = y - this%dis%delc(j)
535  end do
536 
537  ! write node_x and node_y arrays to netcdf file
538  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, node_x), &
539  this%nc_fname)
540  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, node_y), &
541  this%nc_fname)
542 
543  ! set cell_x and cell_y arrays
544  cnt = 1
545  cell_x = nf90_fill_double
546  cell_y = nf90_fill_double
547  do j = 1, this%dis%nrow
548  y = this%dis%celly(j)
549  do i = 1, this%dis%ncol
550  x = this%dis%cellx(i)
551  call dis_transform_xy(x, y, &
552  this%dis%xorigin, &
553  this%dis%yorigin, &
554  this%dis%angrot, &
555  x_transform, y_transform)
556  cell_x(cnt) = x_transform
557  cell_y(cnt) = y_transform
558  cnt = cnt + 1
559  end do
560  end do
561 
562  ! write face_x and face_y arrays to netcdf file
563  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, cell_x), &
564  this%nc_fname)
565  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, cell_y), &
566  this%nc_fname)
567 
568  ! set and write z_l1, z_l2, ... face-flattened cell center elevation
569  ! arrays, reusing the same (row outer, col inner, cnt incrementing)
570  ! face-order convention as cell_x/cell_y above
571  allocate (elev_face((this%dis%ncol * this%dis%nrow)))
572  do k = 1, this%nlay
573  cnt = 1
574  do j = 1, this%dis%nrow
575  do i = 1, this%dis%ncol
576  if (k == 1) then
577  elev_face(cnt) = (this%dis%top2d(i, j) + &
578  this%dis%bot3d(i, j, k)) * dhalf
579  else
580  elev_face(cnt) = (this%dis%bot3d(i, j, k - 1) + &
581  this%dis%bot3d(i, j, k)) * dhalf
582  end if
583  cnt = cnt + 1
584  end do
585  end do
586  call nf_verify(nf90_put_var(this%ncid, this%var_ids%elevation(k), &
587  elev_face), this%nc_fname)
588  end do
589  deallocate (elev_face)
590 
591  ! set face nodes array
592  cnt = 0
593  do i = 1, this%dis%nrow
594  do j = 1, this%dis%ncol
595  cnt = cnt + 1
596  verts = nf90_fill_int
597  verts(1) = cnt + this%dis%ncol + i
598  verts(2) = cnt + this%dis%ncol + i + 1
599  if (i > 1) then
600  verts(3) = cnt + i
601  verts(4) = cnt + i - 1
602  else
603  verts(3) = cnt + 1
604  verts(4) = cnt
605  end if
606 
607  ! write face nodes array to netcdf file
608  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
609  verts, start=(/1, cnt/), &
610  count=(/maxvert, 1/)), &
611  this%nc_fname)
612 
613  ! set face y bounds array
614  bnds = nf90_fill_double
615  do m = 1, size(bnds)
616  if (verts(m) /= nf90_fill_int) then
617  bnds(m) = node_y(verts(m))
618  end if
619  ! write face y bounds array to netcdf file
620  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
621  bnds, start=(/1, cnt/), &
622  count=(/maxvert, 1/)), &
623  this%nc_fname)
624  end do
625 
626  ! set face x bounds array
627  bnds = nf90_fill_double
628  do m = 1, size(bnds)
629  if (verts(m) /= nf90_fill_int) then
630  bnds(m) = node_x(verts(m))
631  end if
632  ! write face x bounds array to netcdf file
633  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
634  bnds, start=(/1, cnt/), &
635  count=(/maxvert, 1/)), &
636  this%nc_fname)
637  end do
638  end do
639  end do
640 
641  ! cleanup
642  deallocate (bnds)
643  deallocate (verts)
644  deallocate (node_x)
645  deallocate (node_y)
646  deallocate (cell_x)
647  deallocate (cell_y)
648  end subroutine add_mesh_data
649 
650  !> @brief netcdf export 1D integer
651  !<
652  subroutine nc_export_int1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, &
653  idt, mempath, nc_tag, pkgname, gridmap_name, &
654  deflate, shuffle, chunk_face, iper, nc_fname)
655  use tdismodule, only: kper
656  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
657  integer(I4B), intent(in) :: ncid
658  type(meshncdimidtype), intent(inout) :: dim_ids
659  integer(I4B), intent(in) :: x_dim
660  integer(I4B), intent(in) :: y_dim
661  type(meshncvaridtype), intent(inout) :: var_ids
662  type(distype), pointer, intent(in) :: dis
663  type(inputparamdefinitiontype), pointer :: idt
664  character(len=*), intent(in) :: mempath
665  character(len=*), intent(in) :: nc_tag
666  character(len=*), intent(in) :: pkgname
667  character(len=*), intent(in) :: gridmap_name
668  integer(I4B), intent(in) :: deflate
669  integer(I4B), intent(in) :: shuffle
670  integer(I4B), intent(in) :: chunk_face
671  integer(I4B), intent(in) :: iper
672  character(len=*), intent(in) :: nc_fname
673  integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
674  integer(I4B), dimension(:), pointer, contiguous :: int1d
675  integer(I4B) :: axis_dim, nvals, k
676  integer(I4B), dimension(:), allocatable :: var_id
677  character(len=LINELENGTH) :: longname, varname
678 
679  if (idt%shape == 'NROW' .or. &
680  idt%shape == 'NCOL' .or. &
681  idt%shape == 'NCPL' .or. &
682  idt%shape == 'NAUX NCPL') then
683 
684  if (iper == 0) then
685 
686  select case (idt%shape)
687  case ('NROW')
688  axis_dim = y_dim
689  case ('NCOL')
690  axis_dim = x_dim
691  case ('NCPL', 'NAUX NCPL')
692  axis_dim = dim_ids%nmesh_face
693  end select
694 
695  ! set names
696  varname = export_varname(pkgname, idt%tagname, mempath)
697  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
698  component_type=idt%component_type, &
699  subcomponent_type=idt%subcomponent_type)
700 
701  allocate (var_id(1))
702 
703  ! reenter define mode and create variable
704  call nf_verify(nf90_redef(ncid), nc_fname)
705  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
706  (/axis_dim/), var_id(1)), &
707  nc_fname)
708 
709  ! apply chunking for face-indexed variables; NROW/NCOL use default
710  if (axis_dim == dim_ids%nmesh_face) then
711  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
712  end if
713  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
714 
715  ! put attr
716  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
717  (/nf90_fill_int/)), nc_fname)
718  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
719  longname), nc_fname)
720 
721  ! add grid mapping for face-indexed variables
722  if (axis_dim == dim_ids%nmesh_face) then
723  call ncvar_gridmap(ncid, var_id(1), gridmap_name, 0, nc_fname)
724  end if
725 
726  ! add mf6 attr
727  call ncvar_mf6attr(ncid, var_id(1), 0, 0, nc_tag, nc_fname)
728 
729  ! exit define mode and write data
730  call nf_verify(nf90_enddef(ncid), nc_fname)
731  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
732  nc_fname)
733  else
734  nvals = dis%nrow * dis%ncol
735  call nf_verify(nf90_put_var(ncid, &
736  var_ids%export(1), p_mem, &
737  start=(/1, kper/), &
738  count=(/nvals, 1/)), nc_fname)
739  end if
740 
741  else
742  ! reshape input
743  int3d(1:dis%ncol, 1:dis%nrow, 1:dis%nlay) => p_mem(1:dis%nodesuser)
744 
745  ! set nvals as ncpl
746  nvals = dis%nrow * dis%ncol
747 
748  if (iper == 0) then
749  ! not a timeseries, create variables and write griddata
750  allocate (var_id(dis%nlay))
751 
752  ! reenter define mode and create variable
753  call nf_verify(nf90_redef(ncid), nc_fname)
754  do k = 1, dis%nlay
755  ! set names
756  varname = export_varname(pkgname, idt%tagname, mempath, &
757  layer=k)
758  longname = export_longname(idt%longname, pkgname, idt%tagname, &
759  mempath, layer=k, &
760  component_type=idt%component_type, &
761  subcomponent_type=idt%subcomponent_type)
762 
763  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
764  (/dim_ids%nmesh_face/), var_id(k)), &
765  nc_fname)
766 
767  ! apply chunking parameters
768  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
769  ! deflate and shuffle
770  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
771 
772  ! put attr
773  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
774  (/nf90_fill_int/)), nc_fname)
775  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
776  longname), nc_fname)
777 
778  ! add grid mapping and mf6 attr
779  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
780  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
781  end do
782 
783  ! exit define mode and write data
784  call nf_verify(nf90_enddef(ncid), nc_fname)
785  do k = 1, dis%nlay
786  int1d(1:nvals) => int3d(:, :, k)
787  call nf_verify(nf90_put_var(ncid, var_id(k), int1d), nc_fname)
788  end do
789 
790  ! cleanup
791  deallocate (var_id)
792  else
793  ! timeseries, add period data
794  do k = 1, dis%nlay
795  int1d(1:nvals) => int3d(:, :, k)
796  call nf_verify(nf90_put_var(ncid, &
797  var_ids%export(k), int1d, &
798  start=(/1, kper/), &
799  count=(/nvals, 1/)), nc_fname)
800  end do
801  end if
802  end if
803  end subroutine nc_export_int1d
804 
805  !> @brief netcdf export 2D integer
806  !<
807  subroutine nc_export_int2d(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) :: var_id, nvals
825  integer(I4B), dimension(:), pointer, contiguous :: int1d
826  character(len=LINELENGTH) :: longname, varname
827 
828  ! set names
829  varname = export_varname(pkgname, idt%tagname, mempath)
830  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
831  component_type=idt%component_type, &
832  subcomponent_type=idt%subcomponent_type)
833 
834  ! reenter define mode and create variable
835  call nf_verify(nf90_redef(ncid), nc_fname)
836  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
837  (/dim_ids%nmesh_face/), var_id), &
838  nc_fname)
839 
840  ! apply chunking parameters
841  call ncvar_chunk(ncid, var_id, chunk_face, nc_fname)
842  ! deflate and shuffle
843  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
844 
845  ! put attr
846  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
847  (/nf90_fill_int/)), nc_fname)
848  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
849  longname), nc_fname)
850 
851  ! add grid mapping and mf6 attr
852  call ncvar_gridmap(ncid, var_id, gridmap_name, 0, nc_fname)
853  call ncvar_mf6attr(ncid, var_id, 0, 0, nc_tag, nc_fname)
854 
855  ! exit define mode and write data
856  call nf_verify(nf90_enddef(ncid), nc_fname)
857  nvals = dis%nrow * dis%ncol
858  int1d(1:nvals) => p_mem
859  call nf_verify(nf90_put_var(ncid, var_id, int1d), nc_fname)
860  end subroutine nc_export_int2d
861 
862  !> @brief netcdf export 3D integer
863  !<
864  subroutine nc_export_int3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
865  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
866  chunk_face, nc_fname)
867  integer(I4B), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
868  integer(I4B), intent(in) :: ncid
869  type(meshncdimidtype), intent(inout) :: dim_ids
870  type(meshncvaridtype), intent(inout) :: var_ids
871  type(distype), pointer, intent(in) :: dis
872  type(inputparamdefinitiontype), pointer :: idt
873  character(len=*), intent(in) :: mempath
874  character(len=*), intent(in) :: nc_tag
875  character(len=*), intent(in) :: pkgname
876  character(len=*), intent(in) :: gridmap_name
877  integer(I4B), intent(in) :: deflate
878  integer(I4B), intent(in) :: shuffle
879  integer(I4B), intent(in) :: chunk_face
880  character(len=*), intent(in) :: nc_fname
881  integer(I4B), dimension(:), allocatable :: var_id
882  integer(I4B), dimension(:), pointer, contiguous :: int1d
883  character(len=LINELENGTH) :: longname, varname
884  integer(I4B) :: k, nvals
885 
886  allocate (var_id(dis%nlay))
887 
888  ! reenter define mode and create variable
889  call nf_verify(nf90_redef(ncid), nc_fname)
890  do k = 1, dis%nlay
891  ! set names
892  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
893  longname = export_longname(idt%longname, pkgname, idt%tagname, &
894  mempath, layer=k, &
895  component_type=idt%component_type, &
896  subcomponent_type=idt%subcomponent_type)
897 
898  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
899  (/dim_ids%nmesh_face/), var_id(k)), &
900  nc_fname)
901 
902  ! apply chunking parameters
903  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
904  ! deflate and shuffle
905  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
906 
907  ! put attr
908  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
909  (/nf90_fill_int/)), nc_fname)
910  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
911  longname), nc_fname)
912 
913  ! add grid mapping and mf6 attr
914  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
915  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
916  end do
917 
918  ! exit define mode and write data
919  call nf_verify(nf90_enddef(ncid), nc_fname)
920  nvals = dis%nrow * dis%ncol
921  do k = 1, dis%nlay
922  int1d(1:nvals) => p_mem(:, :, k)
923  call nf_verify(nf90_put_var(ncid, var_id(k), int1d), nc_fname)
924  end do
925 
926  ! cleanup
927  deallocate (var_id)
928  end subroutine nc_export_int3d
929 
930  !> @brief netcdf export 1D double
931  !<
932  subroutine nc_export_dbl1d(p_mem, ncid, dim_ids, x_dim, y_dim, var_ids, dis, &
933  idt, mempath, nc_tag, pkgname, gridmap_name, &
934  deflate, shuffle, chunk_face, iper, iaux, nc_fname)
935  use tdismodule, only: kper
936  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
937  integer(I4B), intent(in) :: ncid
938  type(meshncdimidtype), intent(inout) :: dim_ids
939  integer(I4B), intent(in) :: x_dim
940  integer(I4B), intent(in) :: y_dim
941  type(meshncvaridtype), intent(in) :: var_ids
942  type(distype), pointer, intent(in) :: dis
943  type(inputparamdefinitiontype), pointer :: idt
944  character(len=*), intent(in) :: mempath
945  character(len=*), intent(in) :: nc_tag
946  character(len=*), intent(in) :: pkgname
947  character(len=*), intent(in) :: gridmap_name
948  integer(I4B), intent(in) :: deflate
949  integer(I4B), intent(in) :: shuffle
950  integer(I4B), intent(in) :: chunk_face
951  integer(I4B), intent(in) :: iper
952  integer(I4B), intent(in) :: iaux
953  character(len=*), intent(in) :: nc_fname
954  real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
955  real(DP), dimension(:), pointer, contiguous :: dbl1d
956  integer(I4B) :: axis_dim, nvals, k
957  integer(I4B), dimension(:), allocatable :: var_id
958  character(len=LINELENGTH) :: longname, varname
959 
960  if (idt%shape == 'NROW' .or. &
961  idt%shape == 'NCOL' .or. &
962  idt%shape == 'NCPL' .or. &
963  idt%shape == 'NAUX NCPL') then
964 
965  if (iper == 0) then
966 
967  select case (idt%shape)
968  case ('NROW')
969  axis_dim = y_dim
970  case ('NCOL')
971  axis_dim = x_dim
972  case ('NCPL', 'NAUX NCPL')
973  axis_dim = dim_ids%nmesh_face
974  end select
975 
976  ! set names
977  varname = export_varname(pkgname, idt%tagname, mempath, iaux=iaux)
978  longname = export_longname(idt%longname, pkgname, idt%tagname, &
979  mempath, iaux=iaux, &
980  component_type=idt%component_type, &
981  subcomponent_type=idt%subcomponent_type)
982 
983  allocate (var_id(1))
984 
985  ! reenter define mode and create variable
986  call nf_verify(nf90_redef(ncid), nc_fname)
987  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
988  (/axis_dim/), var_id(1)), &
989  nc_fname)
990 
991  ! apply chunking for face-indexed variables; NROW/NCOL use default
992  if (axis_dim == dim_ids%nmesh_face) then
993  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
994  end if
995  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
996 
997  ! put attr
998  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
999  (/nf90_fill_double/)), nc_fname)
1000  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
1001  longname), nc_fname)
1002 
1003  ! add grid mapping for face-indexed variables
1004  if (axis_dim == dim_ids%nmesh_face) then
1005  call ncvar_gridmap(ncid, var_id(1), gridmap_name, 0, nc_fname)
1006  end if
1007 
1008  ! add mf6 attr
1009  call ncvar_mf6attr(ncid, var_id(1), 0, iaux, nc_tag, nc_fname)
1010 
1011  ! exit define mode and write data
1012  call nf_verify(nf90_enddef(ncid), nc_fname)
1013  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
1014  nc_fname)
1015  else
1016  nvals = dis%nrow * dis%ncol
1017  call nf_verify(nf90_put_var(ncid, &
1018  var_ids%export(1), p_mem, &
1019  start=(/1, kper/), &
1020  count=(/nvals, 1/)), nc_fname)
1021  end if
1022 
1023  else
1024  ! reshape input
1025  dbl3d(1:dis%ncol, 1:dis%nrow, 1:dis%nlay) => p_mem(1:dis%nodesuser)
1026 
1027  ! set nvals as ncpl
1028  nvals = dis%nrow * dis%ncol
1029 
1030  if (iper == 0) then
1031  ! not a timeseries, create variables and write griddata
1032 
1033  ! allocate local variable id storage
1034  allocate (var_id(dis%nlay))
1035 
1036  ! reenter define mode and create layer variables
1037  call nf_verify(nf90_redef(ncid), nc_fname)
1038  do k = 1, dis%nlay
1039  ! set names
1040  varname = export_varname(pkgname, idt%tagname, mempath, layer=k, &
1041  iaux=iaux)
1042  longname = export_longname(idt%longname, pkgname, idt%tagname, &
1043  mempath, layer=k, iaux=iaux, &
1044  component_type=idt%component_type, &
1045  subcomponent_type=idt%subcomponent_type)
1046 
1047  ! create layer variable
1048  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1049  (/dim_ids%nmesh_face/), var_id(k)), &
1050  nc_fname)
1051 
1052  ! apply chunking parameters
1053  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
1054  ! deflate and shuffle
1055  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
1056 
1057  ! put attr
1058  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
1059  (/nf90_fill_double/)), nc_fname)
1060  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
1061  longname), nc_fname)
1062 
1063  ! add grid mapping and mf6 attr
1064  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
1065  call ncvar_mf6attr(ncid, var_id(k), k, iaux, nc_tag, nc_fname)
1066  end do
1067 
1068  ! exit define mode
1069  call nf_verify(nf90_enddef(ncid), nc_fname)
1070 
1071  ! write layer data
1072  do k = 1, dis%nlay
1073  dbl1d(1:nvals) => dbl3d(:, :, k)
1074  call nf_verify(nf90_put_var(ncid, var_id(k), dbl1d), nc_fname)
1075  end do
1076 
1077  ! cleanup
1078  deallocate (var_id)
1079  else
1080  ! timeseries, add period data
1081  do k = 1, dis%nlay
1082  dbl1d(1:nvals) => dbl3d(:, :, k)
1083  call nf_verify(nf90_put_var(ncid, &
1084  var_ids%export(k), dbl1d, &
1085  start=(/1, kper/), &
1086  count=(/nvals, 1/)), nc_fname)
1087  end do
1088  end if
1089  end if
1090  end subroutine nc_export_dbl1d
1091 
1092  !> @brief netcdf export 2D double
1093  !<
1094  subroutine nc_export_dbl2d(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) :: var_id, nvals
1112  character(len=LINELENGTH) :: longname, varname
1113  real(DP), dimension(:), pointer, contiguous :: dbl1d
1114 
1115  ! set names
1116  varname = export_varname(pkgname, idt%tagname, mempath)
1117  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1118  component_type=idt%component_type, &
1119  subcomponent_type=idt%subcomponent_type)
1120 
1121  ! reenter define mode and create variable
1122  call nf_verify(nf90_redef(ncid), nc_fname)
1123  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1124  (/dim_ids%nmesh_face/), var_id), &
1125  nc_fname)
1126 
1127  ! apply chunking parameters
1128  call ncvar_chunk(ncid, var_id, chunk_face, nc_fname)
1129  ! deflate and shuffle
1130  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1131 
1132  ! put attr
1133  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1134  (/nf90_fill_double/)), nc_fname)
1135  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1136  longname), nc_fname)
1137 
1138  ! add grid mapping and mf6 attr
1139  call ncvar_gridmap(ncid, var_id, gridmap_name, 0, nc_fname)
1140  call ncvar_mf6attr(ncid, var_id, 0, 0, nc_tag, nc_fname)
1141 
1142  ! exit define mode and write data
1143  call nf_verify(nf90_enddef(ncid), nc_fname)
1144  nvals = dis%nrow * dis%ncol
1145  dbl1d(1:nvals) => p_mem
1146  call nf_verify(nf90_put_var(ncid, var_id, dbl1d), nc_fname)
1147  end subroutine nc_export_dbl2d
1148 
1149  !> @brief netcdf export 3D double
1150  !<
1151  subroutine nc_export_dbl3d(p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, &
1152  nc_tag, pkgname, gridmap_name, deflate, shuffle, &
1153  chunk_face, nc_fname)
1154  real(DP), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
1155  integer(I4B), intent(in) :: ncid
1156  type(meshncdimidtype), intent(inout) :: dim_ids
1157  type(meshncvaridtype), intent(inout) :: var_ids
1158  type(distype), pointer, intent(in) :: dis
1159  type(inputparamdefinitiontype), pointer :: idt
1160  character(len=*), intent(in) :: mempath
1161  character(len=*), intent(in) :: nc_tag
1162  character(len=*), intent(in) :: pkgname
1163  character(len=*), intent(in) :: gridmap_name
1164  integer(I4B), intent(in) :: deflate
1165  integer(I4B), intent(in) :: shuffle
1166  integer(I4B), intent(in) :: chunk_face
1167  character(len=*), intent(in) :: nc_fname
1168  integer(I4B), dimension(:), allocatable :: var_id
1169  real(DP), dimension(:), pointer, contiguous :: dbl1d
1170  character(len=LINELENGTH) :: longname, varname
1171  integer(I4B) :: k, nvals
1172 
1173  ! set nvals as ncpl
1174  nvals = dis%nrow * dis%ncol
1175 
1176  allocate (var_id(dis%nlay))
1177 
1178  ! reenter define mode and create variable
1179  call nf_verify(nf90_redef(ncid), nc_fname)
1180  do k = 1, dis%nlay
1181  ! set names
1182  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
1183  longname = export_longname(idt%longname, pkgname, idt%tagname, &
1184  mempath, layer=k, &
1185  component_type=idt%component_type, &
1186  subcomponent_type=idt%subcomponent_type)
1187 
1188  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1189  (/dim_ids%nmesh_face/), var_id(k)), &
1190  nc_fname)
1191 
1192  ! apply chunking parameters
1193  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
1194  ! deflate and shuffle
1195  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
1196 
1197  ! put attr
1198  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
1199  (/nf90_fill_double/)), nc_fname)
1200  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
1201  longname), nc_fname)
1202 
1203  ! add grid mapping and mf6 attr
1204  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
1205  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
1206  end do
1207 
1208  ! exit define mode and write data
1209  call nf_verify(nf90_enddef(ncid), nc_fname)
1210  do k = 1, dis%nlay
1211  dbl1d(1:nvals) => p_mem(:, :, k)
1212  call nf_verify(nf90_put_var(ncid, var_id(k), dbl1d), nc_fname)
1213  end do
1214 
1215  ! cleanup
1216  deallocate (var_id)
1217  end subroutine nc_export_dbl3d
1218 
1219 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:206
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 dhalf
real constant 1/2
Definition: Constants.f90:68
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:1097
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:655
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:481
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:1154
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:810
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:867
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:935
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, layer, nc_fname)
put variable gridmap attributes
subroutine, public ncvar_chunk(ncid, varid, chunk_face, nc_fname)
define variable chunking
subroutine, public ncvar_layer(ncid, varid, layer, nc_fname)
put the layer attribute (only when layer > 0)
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:455
character(len=linelength) function, public export_longname(longname, pkgname, tagname, mempath, layer, iaux, component_type, subcomponent_type)
build netcdf variable longname
Definition: NCModel.f90:496
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:204
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:34
type for storing model export variable ids
Definition: MeshNCModel.f90:45