MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
meshdisvmodelmodule Module Reference

This module contains the MeshDisvModelModule. More...

Data Types

type  mesh2ddisvexporttype
 

Functions/Subroutines

subroutine disv_export_init (this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
 netcdf export disv init More...
 
subroutine disv_export_destroy (this)
 netcdf export disv destroy More...
 
subroutine df (this)
 netcdf export define More...
 
subroutine step (this)
 netcdf export step More...
 
subroutine package_step_ilayer (this, export_pkg, ilayer_varname, ilayer)
 netcdf export package dynamic input with ilayer index variable More...
 
subroutine package_step (this, export_pkg)
 netcdf export package dynamic input More...
 
subroutine export_layer_2d (this, export_pkg, idt, ilayer_read, ialayer, dbl1d, nc_varname, input_attr, iaux)
 export layer variable as full grid More...
 
subroutine export_input_array (this, pkgtype, pkgname, mempath, idt)
 netcdf export an input array More...
 
subroutine define_dim (this)
 netcdf export define dimensions More...
 
subroutine add_mesh_data (this)
 netcdf export add mesh information More...
 
subroutine nc_export_int1d (ncid, dim_ids, var_ids, dis, p_mem, nc_varname, pkgname, tagname, gridmap_name, shapestr, longname, nc_tag, deflate, shuffle, chunk_face, iper, nc_fname)
 netcdf export 1D integer array More...
 
subroutine nc_export_int2d (ncid, dim_ids, var_ids, disv, p_mem, nc_varname, pkgname, tagname, gridmap_name, shapestr, longname, nc_tag, deflate, shuffle, chunk_face, nc_fname)
 netcdf export 2D integer array More...
 
subroutine nc_export_dbl1d (ncid, dim_ids, var_ids, dis, p_mem, nc_varname, pkgname, tagname, gridmap_name, shapestr, longname, nc_tag, deflate, shuffle, chunk_face, nc_fname)
 netcdf export 1D double array More...
 
subroutine nc_export_dbl2d (ncid, dim_ids, var_ids, disv, p_mem, nc_varname, pkgname, tagname, gridmap_name, shapestr, longname, nc_tag, deflate, shuffle, chunk_face, iper, iaux, nc_fname)
 netcdf export 2D double array More...
 

Detailed Description

This module defines UGRID layered mesh compliant netcdf export type for DISV models. It is dependent on netcdf libraries.

Function/Subroutine Documentation

◆ add_mesh_data()

subroutine meshdisvmodelmodule::add_mesh_data ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 436 of file DisvNCMesh.f90.

437  class(Mesh2dDisvExportType), intent(inout) :: this
438  integer(I4B), dimension(:), contiguous, pointer :: icell2d => null()
439  integer(I4B), dimension(:), contiguous, pointer :: ncvert => null()
440  integer(I4B), dimension(:), contiguous, pointer :: icvert => null()
441  real(DP), dimension(:), contiguous, pointer :: cell_x => null()
442  real(DP), dimension(:), contiguous, pointer :: cell_y => null()
443  real(DP), dimension(:), contiguous, pointer :: vert_x => null()
444  real(DP), dimension(:), contiguous, pointer :: vert_y => null()
445  integer(I4B) :: n, m, idx, cnt, iv, maxvert
446  integer(I4B), dimension(:), allocatable :: verts
447  real(DP), dimension(:), allocatable :: bnds
448  integer(I4B) :: istop
449 
450  ! set pointers to input context
451  call mem_setptr(icell2d, 'ICELL2D', this%dis_mempath)
452  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
453  call mem_setptr(icvert, 'ICVERT', this%dis_mempath)
454  call mem_setptr(cell_x, 'XC', this%dis_mempath)
455  call mem_setptr(cell_y, 'YC', this%dis_mempath)
456  call mem_setptr(vert_x, 'XV', this%dis_mempath)
457  call mem_setptr(vert_y, 'YV', this%dis_mempath)
458 
459  ! initialize max vertices required to define cell
460  maxvert = maxval(ncvert)
461 
462  ! set mesh container variable value to 1
463  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
464  this%nc_fname)
465 
466  ! allocate temporary arrays
467  allocate (verts(maxvert))
468  allocate (bnds(maxvert))
469 
470  ! write node_x and node_y arrays to netcdf file
471  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, &
472  vert_x + this%disv%xorigin), this%nc_fname)
473  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, &
474  vert_y + this%disv%yorigin), this%nc_fname)
475 
476  ! write face_x and face_y arrays to netcdf file
477  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, &
478  cell_x + this%disv%xorigin), this%nc_fname)
479  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, &
480  cell_y + this%disv%yorigin), this%nc_fname)
481 
482  ! set face nodes array
483  cnt = 0
484  do n = 1, size(ncvert)
485  verts = nf90_fill_int
486  idx = cnt + ncvert(n)
487  iv = 0
488  istop = cnt + 1
489  do m = idx, istop, -1
490  cnt = cnt + 1
491  iv = iv + 1
492  verts(iv) = icvert(m)
493  end do
494 
495  ! write face nodes array to netcdf file
496  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
497  verts, start=(/1, n/), &
498  count=(/maxvert, 1/)), &
499  this%nc_fname)
500 
501  ! set face y bounds array
502  bnds = nf90_fill_double
503  do m = 1, size(bnds)
504  if (verts(m) /= nf90_fill_int) then
505  bnds(m) = vert_y(verts(m))
506  end if
507  ! write face y bounds array to netcdf file
508  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
509  bnds, start=(/1, n/), &
510  count=(/maxvert, 1/)), &
511  this%nc_fname)
512  end do
513 
514  ! set face x bounds array
515  bnds = nf90_fill_double
516  do m = 1, size(bnds)
517  if (verts(m) /= nf90_fill_int) then
518  bnds(m) = vert_x(verts(m))
519  end if
520  ! write face x bounds array to netcdf file
521  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
522  bnds, start=(/1, n/), &
523  count=(/maxvert, 1/)), &
524  this%nc_fname)
525  end do
526  end do
527 
528  ! cleanup
529  deallocate (bnds)
530  deallocate (verts)
Here is the call graph for this function:

◆ define_dim()

subroutine meshdisvmodelmodule::define_dim ( class(mesh2ddisvexporttype), intent(inout)  this)
private

Definition at line 391 of file DisvNCMesh.f90.

392  use constantsmodule, only: mvalidate
393  use simvariablesmodule, only: isim_mode
394  class(Mesh2dDisvExportType), intent(inout) :: this
395  integer(I4B), dimension(:), contiguous, pointer :: ncvert
396 
397  ! set pointers to input context
398  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
399 
400  ! time
401  if (isim_mode /= mvalidate) then
402  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
403  this%dim_ids%time), this%nc_fname)
404  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
405  this%dim_ids%time, this%var_ids%time), &
406  this%nc_fname)
407  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
408  'standard'), this%nc_fname)
409  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
410  this%datetime), this%nc_fname)
411  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
412  this%nc_fname)
413  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
414  'time'), this%nc_fname)
415  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
416  'time'), this%nc_fname)
417  end if
418 
419  ! mesh
420  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_node', this%disv%nvert, &
421  this%dim_ids%nmesh_node), this%nc_fname)
422  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_face', this%disv%ncpl, &
423  this%dim_ids%nmesh_face), this%nc_fname)
424  call nf_verify(nf90_def_dim(this%ncid, 'max_nmesh_face_nodes', &
425  maxval(ncvert), &
426  this%dim_ids%max_nmesh_face_nodes), &
427  this%nc_fname)
428 
429  ! ncpl, nlay
430  call nf_verify(nf90_def_dim(this%ncid, 'nlay', this%disv%nlay, &
431  this%dim_ids%nlay), this%nc_fname)
This module contains simulation constants.
Definition: Constants.f90:9
@ mvalidate
validation mode - do not run time steps
Definition: Constants.f90:205
This module contains simulation variables.
Definition: SimVariables.f90:9
integer(i4b) isim_mode
simulation mode
Here is the call graph for this function:

◆ df()

subroutine meshdisvmodelmodule::df ( class(mesh2ddisvexporttype), intent(inout)  this)
private

Definition at line 85 of file DisvNCMesh.f90.

86  use constantsmodule, only: mvalidate
87  use simvariablesmodule, only: isim_mode
88  class(Mesh2dDisvExportType), intent(inout) :: this
89  ! put root group file scope attributes
90  call this%add_global_att()
91  ! define root group dimensions and coordinate variables
92  call this%define_dim()
93  ! define mesh variables
94  call this%create_mesh()
95  if (isim_mode /= mvalidate) then
96  ! define the dependent variable
97  call this%define_dependent()
98  end if
99  ! exit define mode
100  call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
101  ! create mesh
102  call this%add_mesh_data()
103  ! define and set package input griddata
104  call this%add_pkg_data()
105  ! define and set gridmap variable
106  call this%define_gridmap()
107  ! synchronize file
108  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
Here is the call graph for this function:

◆ disv_export_destroy()

subroutine meshdisvmodelmodule::disv_export_destroy ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 75 of file DisvNCMesh.f90.

76  class(Mesh2dDisvExportType), intent(inout) :: this
77  deallocate (this%var_ids%dependent)
78  ! destroy base class
79  call this%mesh_destroy()
80  call this%NCModelExportType%destroy()

◆ disv_export_init()

subroutine meshdisvmodelmodule::disv_export_init ( class(mesh2ddisvexporttype), intent(inout)  this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelfname,
character(len=*), intent(in)  nc_fname,
integer(i4b), intent(in)  disenum,
integer(i4b), intent(in)  nctype,
integer(i4b), intent(in)  iout 
)
private

Definition at line 50 of file DisvNCMesh.f90.

53  class(Mesh2dDisvExportType), 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%disv%nlay
64 
65  ! allocate var_id arrays
66  allocate (this%var_ids%dependent(this%nlay))
67 
68  ! initialize base class
69  call this%mesh_init(modelname, modeltype, modelfname, nc_fname, disenum, &
70  nctype, iout)

◆ export_input_array()

subroutine meshdisvmodelmodule::export_input_array ( class(mesh2ddisvexporttype), intent(inout)  this,
character(len=*), intent(in)  pkgtype,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  mempath,
type(inputparamdefinitiontype), intent(in), pointer  idt 
)

Definition at line 334 of file DisvNCMesh.f90.

335  class(Mesh2dDisvExportType), intent(inout) :: this
336  character(len=*), intent(in) :: pkgtype
337  character(len=*), intent(in) :: pkgname
338  character(len=*), intent(in) :: mempath
339  type(InputParamDefinitionType), pointer, intent(in) :: idt
340  integer(I4B), dimension(:), pointer, contiguous :: int1d
341  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
342  real(DP), dimension(:), pointer, contiguous :: dbl1d
343  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
344  character(len=LINELENGTH) :: nc_varname, input_attr
345  integer(I4B) :: iper, iaux
346 
347  iper = 0
348  iaux = 0
349 
350  ! set package base name
351  nc_varname = trim(pkgname)//'_'//trim(idt%mf6varname)
352  ! put input attributes
353  input_attr = this%input_attribute(pkgname, idt)
354 
355  select case (idt%datatype)
356  case ('INTEGER1D')
357  call mem_setptr(int1d, idt%mf6varname, mempath)
358  call nc_export_int1d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
359  int1d, nc_varname, pkgname, idt%tagname, &
360  this%gridmap_name, idt%shape, idt%longname, &
361  input_attr, this%deflate, this%shuffle, &
362  this%chunk_face, iper, this%nc_fname)
363  case ('INTEGER2D')
364  call mem_setptr(int2d, idt%mf6varname, mempath)
365  call nc_export_int2d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
366  int2d, nc_varname, pkgname, idt%tagname, &
367  this%gridmap_name, idt%shape, idt%longname, &
368  input_attr, this%deflate, this%shuffle, &
369  this%chunk_face, this%nc_fname)
370  case ('DOUBLE1D')
371  call mem_setptr(dbl1d, idt%mf6varname, mempath)
372  call nc_export_dbl1d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
373  dbl1d, nc_varname, pkgname, idt%tagname, &
374  this%gridmap_name, idt%shape, idt%longname, &
375  input_attr, this%deflate, this%shuffle, &
376  this%chunk_face, this%nc_fname)
377  case ('DOUBLE2D')
378  call mem_setptr(dbl2d, idt%mf6varname, mempath)
379  call nc_export_dbl2d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
380  dbl2d, nc_varname, pkgname, idt%tagname, &
381  this%gridmap_name, idt%shape, idt%longname, &
382  input_attr, this%deflate, this%shuffle, &
383  this%chunk_face, iper, iaux, this%nc_fname)
384  case default
385  ! no-op, no other datatypes exported
386  end select
Here is the call graph for this function:

◆ export_layer_2d()

subroutine meshdisvmodelmodule::export_layer_2d ( class(mesh2ddisvexporttype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg,
type(inputparamdefinitiontype), intent(in), pointer  idt,
logical(lgp), intent(in)  ilayer_read,
integer(i4b), dimension(:), intent(in), pointer, contiguous  ialayer,
real(dp), dimension(:), intent(in), pointer, contiguous  dbl1d,
character(len=*), intent(in)  nc_varname,
character(len=*), intent(in)  input_attr,
integer(i4b), intent(in), optional  iaux 
)

Definition at line 281 of file DisvNCMesh.f90.

283  use constantsmodule, only: dnodata, dzero
285  class(Mesh2dDisvExportType), intent(inout) :: this
286  class(ExportPackageType), pointer, intent(in) :: export_pkg
287  type(InputParamDefinitionType), pointer, intent(in) :: idt
288  logical(LGP), intent(in) :: ilayer_read
289  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: ialayer
290  real(DP), dimension(:), pointer, contiguous, intent(in) :: dbl1d
291  character(len=*), intent(in) :: nc_varname
292  character(len=*), intent(in) :: input_attr
293  integer(I4B), optional, intent(in) :: iaux
294  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
295  integer(I4B) :: n, j, k, idxaux
296 
297  ! initialize
298  idxaux = 0
299  if (present(iaux)) then
300  idxaux = iaux
301  end if
302 
303  allocate (dbl2d(export_pkg%mshape(2), export_pkg%mshape(1)))
304 
305  if (ilayer_read) then
306  do k = 1, size(dbl2d, dim=2)
307  n = 0
308  do j = 1, size(dbl2d, dim=1)
309  n = n + 1
310  if (ialayer(n) == k) then
311  dbl2d(j, k) = dbl1d(n)
312  else
313  dbl2d(j, k) = dnodata
314  end if
315  end do
316  end do
317  else
318  dbl2d = dnodata
319  dbl2d(:, 1) = dbl1d(:)
320  end if
321 
322  call nc_export_dbl2d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
323  dbl2d, nc_varname, &
324  export_pkg%mf6_input%subcomponent_name, idt%tagname, &
325  this%gridmap_name, idt%shape, idt%longname, input_attr, &
326  this%deflate, this%shuffle, this%chunk_face, &
327  export_pkg%iper, idxaux, this%nc_fname)
328 
329  deallocate (dbl2d)
real(dp), parameter dnodata
real no data constant
Definition: Constants.f90:95
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
Here is the call graph for this function:

◆ nc_export_dbl1d()

subroutine meshdisvmodelmodule::nc_export_dbl1d ( integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  dis,
real(dp), dimension(:), intent(in), pointer, contiguous  p_mem,
character(len=*), intent(in)  nc_varname,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  gridmap_name,
character(len=*), intent(in)  shapestr,
character(len=*), intent(in)  longname,
character(len=*), intent(in)  nc_tag,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 708 of file DisvNCMesh.f90.

711  integer(I4B), intent(in) :: ncid
712  type(MeshNCDimIdType), intent(inout) :: dim_ids
713  type(MeshNCVarIdType), intent(inout) :: var_ids
714  type(DisvType), pointer, intent(in) :: dis
715  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
716  character(len=*), intent(in) :: nc_varname
717  character(len=*), intent(in) :: pkgname
718  character(len=*), intent(in) :: tagname
719  character(len=*), intent(in) :: gridmap_name
720  character(len=*), intent(in) :: shapestr
721  character(len=*), intent(in) :: longname
722  character(len=*), intent(in) :: nc_tag
723  integer(I4B), intent(in) :: deflate
724  integer(I4B), intent(in) :: shuffle
725  integer(I4B), intent(in) :: chunk_face
726  character(len=*), intent(in) :: nc_fname
727  integer(I4B), dimension(2) :: dis_shape
728  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
729  integer(I4B) :: axis_sz, nvals, k
730  integer(I4B), dimension(:), allocatable :: var_id
731  character(len=LINELENGTH) :: longname_l, varname_l
732 
733  if (shapestr == 'NCPL') then
734  ! set names
735  varname_l = export_varname(nc_varname)
736  longname_l = export_longname(longname, pkgname, tagname, 0)
737 
738  allocate (var_id(1))
739  axis_sz = dim_ids%nmesh_face
740 
741  ! reenter define mode and create variable
742  call nf_verify(nf90_redef(ncid), nc_fname)
743  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
744  (/axis_sz/), var_id(1)), &
745  nc_fname)
746 
747  ! apply chunking parameters
748  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
749  ! deflate and shuffle
750  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
751 
752  ! put attr
753  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
754  (/nf90_fill_double/)), nc_fname)
755  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
756  longname_l), nc_fname)
757 
758  ! add grid mapping and mf6 attr
759  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
760  call ncvar_mf6attr(ncid, var_id(1), 0, 0, 0, nc_tag, nc_fname)
761 
762  ! exit define mode and write data
763  call nf_verify(nf90_enddef(ncid), nc_fname)
764  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
765  nc_fname)
766 
767  else
768  allocate (var_id(dis%nlay))
769 
770  ! reenter define mode and create variable
771  call nf_verify(nf90_redef(ncid), nc_fname)
772  do k = 1, dis%nlay
773  ! set names
774  varname_l = export_varname(nc_varname, layer=k)
775  longname_l = export_longname(longname, pkgname, tagname, k)
776 
777  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
778  (/dim_ids%nmesh_face/), var_id(k)), &
779  nc_fname)
780 
781  ! apply chunking parameters
782  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
783  ! deflate and shuffle
784  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
785 
786  ! put attr
787  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
788  (/nf90_fill_double/)), nc_fname)
789  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
790  longname_l), nc_fname)
791 
792  ! add grid mapping and mf6 attr
793  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
794  call ncvar_mf6attr(ncid, var_id(k), k, 0, 0, nc_tag, nc_fname)
795  end do
796 
797  ! reshape input
798  dis_shape(1) = dis%ncpl
799  dis_shape(2) = dis%nlay
800  nvals = product(dis_shape)
801  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => p_mem(1:nvals)
802 
803  ! exit define mode and write data
804  call nf_verify(nf90_enddef(ncid), nc_fname)
805  do k = 1, dis%nlay
806  call nf_verify(nf90_put_var(ncid, var_id(k), dbl2d(:, k)), nc_fname)
807  end do
808 
809  ! cleanup
810  deallocate (var_id)
811  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_dbl2d()

subroutine meshdisvmodelmodule::nc_export_dbl2d ( integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
real(dp), dimension(:, :), intent(in), pointer, contiguous  p_mem,
character(len=*), intent(in)  nc_varname,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  gridmap_name,
character(len=*), intent(in)  shapestr,
character(len=*), intent(in)  longname,
character(len=*), intent(in)  nc_tag,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
integer(i4b), intent(in)  iper,
integer(i4b), intent(in)  iaux,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 816 of file DisvNCMesh.f90.

820  use constantsmodule, only: dnodata
821  integer(I4B), intent(in) :: ncid
822  type(MeshNCDimIdType), intent(inout) :: dim_ids
823  type(MeshNCVarIdType), intent(inout) :: var_ids
824  type(DisvType), pointer, intent(in) :: disv
825  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
826  character(len=*), intent(in) :: nc_varname
827  character(len=*), intent(in) :: pkgname
828  character(len=*), intent(in) :: tagname
829  character(len=*), intent(in) :: gridmap_name
830  character(len=*), intent(in) :: shapestr
831  character(len=*), intent(in) :: longname
832  character(len=*), intent(in) :: nc_tag
833  integer(I4B), intent(in) :: deflate
834  integer(I4B), intent(in) :: shuffle
835  integer(I4B), intent(in) :: chunk_face
836  integer(I4B), intent(in) :: iper
837  integer(I4B), intent(in) :: iaux
838  character(len=*), intent(in) :: nc_fname
839  integer(I4B), dimension(:), allocatable :: var_id
840  character(len=LINELENGTH) :: longname_l, varname_l
841  integer(I4B) :: k
842  real(DP) :: fill_value
843 
844  if (iper > 0) then
845  fill_value = dnodata
846  else
847  fill_value = nf90_fill_double
848  end if
849 
850  allocate (var_id(disv%nlay))
851 
852  ! reenter define mode and create variable
853  call nf_verify(nf90_redef(ncid), nc_fname)
854  do k = 1, disv%nlay
855  ! set names
856  varname_l = export_varname(nc_varname, layer=k, iper=iper, iaux=iaux)
857  longname_l = export_longname(longname, pkgname, tagname, layer=k, iper=iper)
858 
859  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
860  (/dim_ids%nmesh_face/), var_id(k)), &
861  nc_fname)
862 
863  ! apply chunking parameters
864  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
865  ! deflate and shuffle
866  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
867 
868  ! put attr
869  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
870  (/fill_value/)), nc_fname)
871  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
872  longname_l), nc_fname)
873 
874  ! add grid mapping and mf6 attr
875  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
876  call ncvar_mf6attr(ncid, var_id(k), k, iper, iaux, nc_tag, nc_fname)
877  end do
878 
879  ! exit define mode and write data
880  call nf_verify(nf90_enddef(ncid), nc_fname)
881  do k = 1, disv%nlay
882  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
883  end do
884 
885  deallocate (var_id)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_int1d()

subroutine meshdisvmodelmodule::nc_export_int1d ( integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  dis,
integer(i4b), dimension(:), intent(in), pointer, contiguous  p_mem,
character(len=*), intent(in)  nc_varname,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  gridmap_name,
character(len=*), intent(in)  shapestr,
character(len=*), intent(in)  longname,
character(len=*), intent(in)  nc_tag,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
integer(i4b), intent(in)  iper,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 535 of file DisvNCMesh.f90.

538  integer(I4B), intent(in) :: ncid
539  type(MeshNCDimIdType), intent(inout) :: dim_ids
540  type(MeshNCVarIdType), intent(inout) :: var_ids
541  type(DisvType), pointer, intent(in) :: dis
542  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
543  character(len=*), intent(in) :: nc_varname
544  character(len=*), intent(in) :: pkgname
545  character(len=*), intent(in) :: tagname
546  character(len=*), intent(in) :: gridmap_name
547  character(len=*), intent(in) :: shapestr
548  character(len=*), intent(in) :: longname
549  character(len=*), intent(in) :: nc_tag
550  integer(I4B), intent(in) :: deflate
551  integer(I4B), intent(in) :: shuffle
552  integer(I4B), intent(in) :: chunk_face
553  integer(I4B), intent(in) :: iper
554  character(len=*), intent(in) :: nc_fname
555  integer(I4B), dimension(2) :: dis_shape
556  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
557  integer(I4B) :: axis_sz, nvals, k
558  integer(I4B), dimension(:), allocatable :: var_id
559  character(len=LINELENGTH) :: longname_l, varname_l
560 
561  if (shapestr == 'NCPL') then
562  ! set names
563  varname_l = export_varname(nc_varname)
564  longname_l = export_longname(longname, pkgname, tagname, layer=0, iper=iper)
565 
566  allocate (var_id(1))
567  axis_sz = dim_ids%nmesh_face
568 
569  ! reenter define mode and create variable
570  call nf_verify(nf90_redef(ncid), nc_fname)
571  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
572  (/axis_sz/), var_id(1)), &
573  nc_fname)
574 
575  ! apply chunking parameters
576  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
577  ! deflate and shuffle
578  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
579 
580  ! put attr
581  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
582  (/nf90_fill_int/)), nc_fname)
583  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
584  longname_l), nc_fname)
585 
586  ! add grid mapping and mf6 attr
587  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
588  call ncvar_mf6attr(ncid, var_id(1), 0, iper, 0, nc_tag, nc_fname)
589 
590  ! exit define mode and write data
591  call nf_verify(nf90_enddef(ncid), nc_fname)
592  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
593  nc_fname)
594 
595  else
596  allocate (var_id(dis%nlay))
597 
598  ! reenter define mode and create variable
599  call nf_verify(nf90_redef(ncid), nc_fname)
600  do k = 1, dis%nlay
601  ! set names
602  varname_l = export_varname(nc_varname, layer=k, iper=iper)
603  longname_l = export_longname(longname, pkgname, tagname, layer=k, &
604  iper=iper)
605 
606  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
607  (/dim_ids%nmesh_face/), var_id(k)), &
608  nc_fname)
609 
610  ! apply chunking parameters
611  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
612  ! defalte and shuffle
613  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
614 
615  ! put attr
616  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
617  (/nf90_fill_int/)), nc_fname)
618  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
619  longname_l), nc_fname)
620 
621  ! add grid mapping and mf6 attr
622  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
623  call ncvar_mf6attr(ncid, var_id(k), k, iper, 0, nc_tag, nc_fname)
624  end do
625 
626  ! reshape input
627  dis_shape(1) = dis%ncpl
628  dis_shape(2) = dis%nlay
629  nvals = product(dis_shape)
630  int2d(1:dis_shape(1), 1:dis_shape(2)) => p_mem(1:nvals)
631 
632  ! exit define mode and write data
633  call nf_verify(nf90_enddef(ncid), nc_fname)
634  do k = 1, dis%nlay
635  call nf_verify(nf90_put_var(ncid, var_id(k), int2d(:, k)), nc_fname)
636  end do
637 
638  ! cleanup
639  deallocate (var_id)
640  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_int2d()

subroutine meshdisvmodelmodule::nc_export_int2d ( integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
integer(i4b), dimension(:, :), intent(in), pointer, contiguous  p_mem,
character(len=*), intent(in)  nc_varname,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  gridmap_name,
character(len=*), intent(in)  shapestr,
character(len=*), intent(in)  longname,
character(len=*), intent(in)  nc_tag,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 645 of file DisvNCMesh.f90.

648  integer(I4B), intent(in) :: ncid
649  type(MeshNCDimIdType), intent(inout) :: dim_ids
650  type(MeshNCVarIdType), intent(inout) :: var_ids
651  type(DisvType), pointer, intent(in) :: disv
652  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
653  character(len=*), intent(in) :: nc_varname
654  character(len=*), intent(in) :: pkgname
655  character(len=*), intent(in) :: tagname
656  character(len=*), intent(in) :: gridmap_name
657  character(len=*), intent(in) :: shapestr
658  character(len=*), intent(in) :: longname
659  character(len=*), intent(in) :: nc_tag
660  integer(I4B), intent(in) :: deflate
661  integer(I4B), intent(in) :: shuffle
662  integer(I4B), intent(in) :: chunk_face
663  character(len=*), intent(in) :: nc_fname
664  integer(I4B), dimension(:), allocatable :: var_id
665  character(len=LINELENGTH) :: longname_l, varname_l
666  integer(I4B) :: k
667 
668  allocate (var_id(disv%nlay))
669 
670  ! reenter define mode and create variable
671  call nf_verify(nf90_redef(ncid), nc_fname)
672  do k = 1, disv%nlay
673  ! set names
674  varname_l = export_varname(nc_varname, layer=k)
675  longname_l = export_longname(longname, pkgname, tagname, k)
676 
677  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
678  (/dim_ids%nmesh_face/), var_id(k)), &
679  nc_fname)
680 
681  ! apply chunking parameters
682  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
683  ! deflate and shuffle
684  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
685 
686  ! put attr
687  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
688  (/nf90_fill_int/)), nc_fname)
689  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
690  longname_l), nc_fname)
691 
692  ! add grid mapping and mf6 attr
693  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
694  call ncvar_mf6attr(ncid, var_id(k), k, 0, 0, nc_tag, nc_fname)
695  end do
696 
697  ! exit define mode and write data
698  call nf_verify(nf90_enddef(ncid), nc_fname)
699  do k = 1, disv%nlay
700  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
701  end do
702 
703  deallocate (var_id)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ package_step()

subroutine meshdisvmodelmodule::package_step ( class(mesh2ddisvexporttype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg 
)

Definition at line 267 of file DisvNCMesh.f90.

269  class(Mesh2dDisvExportType), intent(inout) :: this
270  class(ExportPackageType), pointer, intent(in) :: export_pkg
271  errmsg = 'NetCDF period export not supported for model='// &
272  trim(this%modelname)//', package='// &
273  trim(export_pkg%mf6_input%subcomponent_name)
274  call store_error(errmsg, .true.)
275  ! synchronize file
276  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
Here is the call graph for this function:

◆ package_step_ilayer()

subroutine meshdisvmodelmodule::package_step_ilayer ( class(mesh2ddisvexporttype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg,
character(len=*), intent(in)  ilayer_varname,
integer(i4b), intent(in)  ilayer 
)

Definition at line 180 of file DisvNCMesh.f90.

181  use constantsmodule, only: dnodata, dzero
182  use tdismodule, only: kper
185  class(Mesh2dDisvExportType), intent(inout) :: this
186  class(ExportPackageType), pointer, intent(in) :: export_pkg
187  character(len=*), intent(in) :: ilayer_varname
188  integer(I4B), intent(in) :: ilayer
189  type(InputParamDefinitionType), pointer :: idt
190  integer(I4B), dimension(:), pointer, contiguous :: int1d
191  real(DP), dimension(:), pointer, contiguous :: dbl1d
192  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
193  integer(I4B), dimension(:), pointer, contiguous :: ialayer
194  real(DP), dimension(:), contiguous, pointer :: dbl1d_ptr
195  character(len=LINELENGTH) :: nc_varname, input_attr
196  integer(I4B) :: n, iparam, nvals
197  logical(LGP) :: ilayer_read
198 
199  ! initialize
200  nullify (ialayer)
201  ilayer_read = .false.
202 
203  ! set pointer to ilayer variable
204  call mem_setptr(ialayer, export_pkg%param_names(ilayer), &
205  export_pkg%mf6_input%mempath)
206 
207  ! check if layer index variable was read
208  if (export_pkg%param_reads(ilayer)%invar == 1) then
209  ilayer_read = .true.
210  end if
211 
212  ! export defined period input
213  do iparam = 1, export_pkg%nparam
214  ! check if variable was read this period
215  if (export_pkg%param_reads(iparam)%invar < 1) cycle
216 
217  ! set input definition
218  idt => &
219  get_param_definition_type(export_pkg%mf6_input%param_dfns, &
220  export_pkg%mf6_input%component_type, &
221  export_pkg%mf6_input%subcomponent_type, &
222  'PERIOD', export_pkg%param_names(iparam), '')
223 
224  ! set variable name and input string
225  nc_varname = trim(export_pkg%mf6_input%subcomponent_name)//'_'// &
226  trim(idt%mf6varname)
227  input_attr = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
228  idt)
229 
230  ! export arrays
231  select case (idt%datatype)
232  case ('INTEGER1D')
233  call mem_setptr(int1d, idt%mf6varname, export_pkg%mf6_input%mempath)
234  call nc_export_int1d(this%ncid, this%dim_ids, this%var_ids, this%disv, &
235  int1d, nc_varname, &
236  export_pkg%mf6_input%subcomponent_name, &
237  idt%tagname, this%gridmap_name, idt%shape, &
238  idt%longname, input_attr, this%deflate, &
239  this%shuffle, this%chunk_face, kper, this%nc_fname)
240  case ('DOUBLE1D')
241  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
242  call this%export_layer_2d(export_pkg, idt, ilayer_read, ialayer, &
243  dbl1d, nc_varname, input_attr)
244  case ('DOUBLE2D')
245  call mem_setptr(dbl2d, idt%mf6varname, export_pkg%mf6_input%mempath)
246  nvals = this%disv%ncpl
247  do n = 1, size(dbl2d, dim=1) !naux
248  dbl1d_ptr(1:nvals) => dbl2d(n, :)
249  if (all(dbl1d_ptr == dzero)) then
250  else
251  call this%export_layer_2d(export_pkg, idt, ilayer_read, ialayer, &
252  dbl1d_ptr, nc_varname, input_attr, n)
253  end if
254  end do
255  case default
256  errmsg = 'EXPORT ilayer unsupported datatype='//trim(idt%datatype)
257  call store_error(errmsg, .true.)
258  end select
259  end do
260 
261  ! synchronize file
262  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename)
Return parameter definition.
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23
Here is the call graph for this function:

◆ step()

subroutine meshdisvmodelmodule::step ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 113 of file DisvNCMesh.f90.

114  use constantsmodule, only: dhnoflo
115  use tdismodule, only: totim
116  class(Mesh2dDisvExportType), intent(inout) :: this
117  real(DP), dimension(:), pointer, contiguous :: dbl1d
118  integer(I4B) :: n, k, nvals
119  integer(I4B), dimension(2) :: dis_shape
120  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
121 
122  ! initialize
123  nullify (dbl1d)
124  nullify (dbl2d)
125 
126  ! increment step
127  this%stepcnt = this%stepcnt + 1
128 
129  dis_shape(1) = this%disv%ncpl
130  dis_shape(2) = this%disv%nlay
131 
132  nvals = product(dis_shape)
133 
134  ! add data to dependent variable
135  if (size(this%disv%nodeuser) < &
136  size(this%disv%nodereduced)) then
137  ! allocate nodereduced size 1d array
138  allocate (dbl1d(size(this%disv%nodereduced)))
139 
140  ! initialize DHNOFLO for non-active cells
141  dbl1d = dhnoflo
142 
143  ! update active cells
144  do n = 1, size(this%disv%nodereduced)
145  if (this%disv%nodereduced(n) > 0) then
146  dbl1d(n) = this%x(this%disv%nodereduced(n))
147  end if
148  end do
149 
150  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => dbl1d(1:nvals)
151  else
152  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => this%x(1:nvals)
153  end if
154 
155  do k = 1, this%disv%nlay
156  ! extend array with step data
157  call nf_verify(nf90_put_var(this%ncid, &
158  this%var_ids%dependent(k), dbl2d(:, k), &
159  start=(/1, this%stepcnt/), &
160  count=(/this%disv%ncpl, 1/)), &
161  this%nc_fname)
162  end do
163 
164  ! write to time coordinate variable
165  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
166  totim, start=(/this%stepcnt/)), &
167  this%nc_fname)
168 
169  ! update file
170  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
171 
172  ! cleanup
173  if (associated(dbl1d)) deallocate (dbl1d)
174  nullify (dbl1d)
175  nullify (dbl2d)
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:93
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:32
Here is the call graph for this function: