MODFLOW 6  version 6.7.0.dev1
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.

438  class(Mesh2dDisvExportType), intent(inout) :: this
439  integer(I4B), dimension(:), contiguous, pointer :: icell2d => null()
440  integer(I4B), dimension(:), contiguous, pointer :: ncvert => null()
441  integer(I4B), dimension(:), contiguous, pointer :: icvert => null()
442  real(DP), dimension(:), contiguous, pointer :: cell_x => null()
443  real(DP), dimension(:), contiguous, pointer :: cell_y => null()
444  real(DP), dimension(:), contiguous, pointer :: vert_x => null()
445  real(DP), dimension(:), contiguous, pointer :: vert_y => null()
446  real(DP), dimension(:), contiguous, pointer :: cell_xt => null()
447  real(DP), dimension(:), contiguous, pointer :: cell_yt => null()
448  real(DP), dimension(:), contiguous, pointer :: vert_xt => null()
449  real(DP), dimension(:), contiguous, pointer :: vert_yt => null()
450  real(DP) :: x_transform, y_transform
451  integer(I4B) :: n, m, idx, cnt, iv, maxvert
452  integer(I4B), dimension(:), allocatable :: verts
453  real(DP), dimension(:), allocatable :: bnds
454  integer(I4B) :: istop
455 
456  ! set pointers to input context
457  call mem_setptr(icell2d, 'ICELL2D', this%dis_mempath)
458  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
459  call mem_setptr(icvert, 'ICVERT', this%dis_mempath)
460  call mem_setptr(cell_x, 'XC', this%dis_mempath)
461  call mem_setptr(cell_y, 'YC', this%dis_mempath)
462  call mem_setptr(vert_x, 'XV', this%dis_mempath)
463  call mem_setptr(vert_y, 'YV', this%dis_mempath)
464 
465  ! allocate x, y transform arrays
466  allocate (cell_xt(size(cell_x)))
467  allocate (cell_yt(size(cell_y)))
468  allocate (vert_xt(size(vert_x)))
469  allocate (vert_yt(size(vert_y)))
470 
471  ! set mesh container variable value to 1
472  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
473  this%nc_fname)
474 
475  ! transform vert x and y
476  do n = 1, size(vert_x)
477  call dis_transform_xy(vert_x(n), vert_y(n), &
478  this%disv%xorigin, &
479  this%disv%yorigin, &
480  this%disv%angrot, &
481  x_transform, y_transform)
482  vert_xt(n) = x_transform
483  vert_yt(n) = y_transform
484  end do
485 
486  ! transform cell x and y
487  do n = 1, size(cell_x)
488  call dis_transform_xy(cell_x(n), cell_y(n), &
489  this%disv%xorigin, &
490  this%disv%yorigin, &
491  this%disv%angrot, &
492  x_transform, y_transform)
493  cell_xt(n) = x_transform
494  cell_yt(n) = y_transform
495  end do
496 
497  ! write node_x and node_y arrays to netcdf file
498  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, &
499  vert_xt), this%nc_fname)
500  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, &
501  vert_yt), this%nc_fname)
502 
503  ! write face_x and face_y arrays to netcdf file
504  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, &
505  cell_xt), this%nc_fname)
506  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, &
507  cell_yt), this%nc_fname)
508 
509  ! initialize max vertices required to define cell
510  maxvert = maxval(ncvert)
511 
512  ! allocate temporary arrays
513  allocate (verts(maxvert))
514  allocate (bnds(maxvert))
515 
516  ! set face nodes array
517  cnt = 0
518  do n = 1, size(ncvert)
519  verts = nf90_fill_int
520  idx = cnt + ncvert(n)
521  iv = 0
522  istop = cnt + 1
523  do m = idx, istop, -1
524  cnt = cnt + 1
525  iv = iv + 1
526  verts(iv) = icvert(m)
527  end do
528 
529  ! write face nodes array to netcdf file
530  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
531  verts, start=(/1, n/), &
532  count=(/maxvert, 1/)), &
533  this%nc_fname)
534 
535  ! set face y bounds array
536  bnds = nf90_fill_double
537  do m = 1, size(bnds)
538  if (verts(m) /= nf90_fill_int) then
539  bnds(m) = vert_yt(verts(m))
540  end if
541  ! write face y bounds array to netcdf file
542  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
543  bnds, start=(/1, n/), &
544  count=(/maxvert, 1/)), &
545  this%nc_fname)
546  end do
547 
548  ! set face x bounds array
549  bnds = nf90_fill_double
550  do m = 1, size(bnds)
551  if (verts(m) /= nf90_fill_int) then
552  bnds(m) = vert_xt(verts(m))
553  end if
554  ! write face x bounds array to netcdf file
555  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
556  bnds, start=(/1, n/), &
557  count=(/maxvert, 1/)), &
558  this%nc_fname)
559  end do
560  end do
561 
562  ! cleanup
563  deallocate (bnds)
564  deallocate (verts)
565  deallocate (cell_xt)
566  deallocate (cell_yt)
567  deallocate (vert_xt)
568  deallocate (vert_yt)
subroutine, public dis_transform_xy(x, y, xorigin, yorigin, angrot, xglo, yglo)
Get global (x, y) coordinates from cell-local coordinates.
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, this%disv%lenuni, 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 746 of file DisvNCMesh.f90.

749  integer(I4B), intent(in) :: ncid
750  type(MeshNCDimIdType), intent(inout) :: dim_ids
751  type(MeshNCVarIdType), intent(inout) :: var_ids
752  type(DisvType), pointer, intent(in) :: dis
753  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
754  character(len=*), intent(in) :: nc_varname
755  character(len=*), intent(in) :: pkgname
756  character(len=*), intent(in) :: tagname
757  character(len=*), intent(in) :: gridmap_name
758  character(len=*), intent(in) :: shapestr
759  character(len=*), intent(in) :: longname
760  character(len=*), intent(in) :: nc_tag
761  integer(I4B), intent(in) :: deflate
762  integer(I4B), intent(in) :: shuffle
763  integer(I4B), intent(in) :: chunk_face
764  character(len=*), intent(in) :: nc_fname
765  integer(I4B), dimension(2) :: dis_shape
766  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
767  integer(I4B) :: axis_sz, nvals, k
768  integer(I4B), dimension(:), allocatable :: var_id
769  character(len=LINELENGTH) :: longname_l, varname_l
770 
771  if (shapestr == 'NCPL') then
772  ! set names
773  varname_l = export_varname(nc_varname)
774  longname_l = export_longname(longname, pkgname, tagname, 0)
775 
776  allocate (var_id(1))
777  axis_sz = dim_ids%nmesh_face
778 
779  ! reenter define mode and create variable
780  call nf_verify(nf90_redef(ncid), nc_fname)
781  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
782  (/axis_sz/), var_id(1)), &
783  nc_fname)
784 
785  ! apply chunking parameters
786  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
787  ! deflate and shuffle
788  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
789 
790  ! put attr
791  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
792  (/nf90_fill_double/)), nc_fname)
793  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
794  longname_l), nc_fname)
795 
796  ! add grid mapping and mf6 attr
797  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
798  call ncvar_mf6attr(ncid, var_id(1), 0, 0, 0, nc_tag, nc_fname)
799 
800  ! exit define mode and write data
801  call nf_verify(nf90_enddef(ncid), nc_fname)
802  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
803  nc_fname)
804 
805  else
806  allocate (var_id(dis%nlay))
807 
808  ! reenter define mode and create variable
809  call nf_verify(nf90_redef(ncid), nc_fname)
810  do k = 1, dis%nlay
811  ! set names
812  varname_l = export_varname(nc_varname, layer=k)
813  longname_l = export_longname(longname, pkgname, tagname, k)
814 
815  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
816  (/dim_ids%nmesh_face/), var_id(k)), &
817  nc_fname)
818 
819  ! apply chunking parameters
820  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
821  ! deflate and shuffle
822  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
823 
824  ! put attr
825  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
826  (/nf90_fill_double/)), nc_fname)
827  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
828  longname_l), nc_fname)
829 
830  ! add grid mapping and mf6 attr
831  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
832  call ncvar_mf6attr(ncid, var_id(k), k, 0, 0, nc_tag, nc_fname)
833  end do
834 
835  ! reshape input
836  dis_shape(1) = dis%ncpl
837  dis_shape(2) = dis%nlay
838  nvals = product(dis_shape)
839  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => p_mem(1:nvals)
840 
841  ! exit define mode and write data
842  call nf_verify(nf90_enddef(ncid), nc_fname)
843  do k = 1, dis%nlay
844  call nf_verify(nf90_put_var(ncid, var_id(k), dbl2d(:, k)), nc_fname)
845  end do
846 
847  ! cleanup
848  deallocate (var_id)
849  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 854 of file DisvNCMesh.f90.

858  use constantsmodule, only: dnodata
859  integer(I4B), intent(in) :: ncid
860  type(MeshNCDimIdType), intent(inout) :: dim_ids
861  type(MeshNCVarIdType), intent(inout) :: var_ids
862  type(DisvType), pointer, intent(in) :: disv
863  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
864  character(len=*), intent(in) :: nc_varname
865  character(len=*), intent(in) :: pkgname
866  character(len=*), intent(in) :: tagname
867  character(len=*), intent(in) :: gridmap_name
868  character(len=*), intent(in) :: shapestr
869  character(len=*), intent(in) :: longname
870  character(len=*), intent(in) :: nc_tag
871  integer(I4B), intent(in) :: deflate
872  integer(I4B), intent(in) :: shuffle
873  integer(I4B), intent(in) :: chunk_face
874  integer(I4B), intent(in) :: iper
875  integer(I4B), intent(in) :: iaux
876  character(len=*), intent(in) :: nc_fname
877  integer(I4B), dimension(:), allocatable :: var_id
878  character(len=LINELENGTH) :: longname_l, varname_l
879  integer(I4B) :: k
880  real(DP) :: fill_value
881 
882  if (iper > 0) then
883  fill_value = dnodata
884  else
885  fill_value = nf90_fill_double
886  end if
887 
888  allocate (var_id(disv%nlay))
889 
890  ! reenter define mode and create variable
891  call nf_verify(nf90_redef(ncid), nc_fname)
892  do k = 1, disv%nlay
893  ! set names
894  varname_l = export_varname(nc_varname, layer=k, iper=iper, iaux=iaux)
895  longname_l = export_longname(longname, pkgname, tagname, layer=k, iper=iper)
896 
897  call nf_verify(nf90_def_var(ncid, varname_l, nf90_double, &
898  (/dim_ids%nmesh_face/), var_id(k)), &
899  nc_fname)
900 
901  ! apply chunking parameters
902  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
903  ! deflate and shuffle
904  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
905 
906  ! put attr
907  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
908  (/fill_value/)), nc_fname)
909  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
910  longname_l), nc_fname)
911 
912  ! add grid mapping and mf6 attr
913  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
914  call ncvar_mf6attr(ncid, var_id(k), k, iper, iaux, nc_tag, nc_fname)
915  end do
916 
917  ! exit define mode and write data
918  call nf_verify(nf90_enddef(ncid), nc_fname)
919  do k = 1, disv%nlay
920  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
921  end do
922 
923  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 
)

Definition at line 573 of file DisvNCMesh.f90.

576  integer(I4B), intent(in) :: ncid
577  type(MeshNCDimIdType), intent(inout) :: dim_ids
578  type(MeshNCVarIdType), intent(inout) :: var_ids
579  type(DisvType), pointer, intent(in) :: dis
580  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
581  character(len=*), intent(in) :: nc_varname
582  character(len=*), intent(in) :: pkgname
583  character(len=*), intent(in) :: tagname
584  character(len=*), intent(in) :: gridmap_name
585  character(len=*), intent(in) :: shapestr
586  character(len=*), intent(in) :: longname
587  character(len=*), intent(in) :: nc_tag
588  integer(I4B), intent(in) :: deflate
589  integer(I4B), intent(in) :: shuffle
590  integer(I4B), intent(in) :: chunk_face
591  integer(I4B), intent(in) :: iper
592  character(len=*), intent(in) :: nc_fname
593  integer(I4B), dimension(2) :: dis_shape
594  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
595  integer(I4B) :: axis_sz, nvals, k
596  integer(I4B), dimension(:), allocatable :: var_id
597  character(len=LINELENGTH) :: longname_l, varname_l
598 
599  if (shapestr == 'NCPL') then
600  ! set names
601  varname_l = export_varname(nc_varname)
602  longname_l = export_longname(longname, pkgname, tagname, layer=0, iper=iper)
603 
604  allocate (var_id(1))
605  axis_sz = dim_ids%nmesh_face
606 
607  ! reenter define mode and create variable
608  call nf_verify(nf90_redef(ncid), nc_fname)
609  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
610  (/axis_sz/), var_id(1)), &
611  nc_fname)
612 
613  ! apply chunking parameters
614  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
615  ! deflate and shuffle
616  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
617 
618  ! put attr
619  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
620  (/nf90_fill_int/)), nc_fname)
621  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
622  longname_l), nc_fname)
623 
624  ! add grid mapping and mf6 attr
625  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
626  call ncvar_mf6attr(ncid, var_id(1), 0, iper, 0, nc_tag, nc_fname)
627 
628  ! exit define mode and write data
629  call nf_verify(nf90_enddef(ncid), nc_fname)
630  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
631  nc_fname)
632 
633  else
634  allocate (var_id(dis%nlay))
635 
636  ! reenter define mode and create variable
637  call nf_verify(nf90_redef(ncid), nc_fname)
638  do k = 1, dis%nlay
639  ! set names
640  varname_l = export_varname(nc_varname, layer=k, iper=iper)
641  longname_l = export_longname(longname, pkgname, tagname, layer=k, &
642  iper=iper)
643 
644  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
645  (/dim_ids%nmesh_face/), var_id(k)), &
646  nc_fname)
647 
648  ! apply chunking parameters
649  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
650  ! defalte and shuffle
651  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
652 
653  ! put attr
654  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
655  (/nf90_fill_int/)), nc_fname)
656  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
657  longname_l), nc_fname)
658 
659  ! add grid mapping and mf6 attr
660  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
661  call ncvar_mf6attr(ncid, var_id(k), k, iper, 0, nc_tag, nc_fname)
662  end do
663 
664  ! reshape input
665  dis_shape(1) = dis%ncpl
666  dis_shape(2) = dis%nlay
667  nvals = product(dis_shape)
668  int2d(1:dis_shape(1), 1:dis_shape(2)) => p_mem(1:nvals)
669 
670  ! exit define mode and write data
671  call nf_verify(nf90_enddef(ncid), nc_fname)
672  do k = 1, dis%nlay
673  call nf_verify(nf90_put_var(ncid, var_id(k), int2d(:, k)), nc_fname)
674  end do
675 
676  ! cleanup
677  deallocate (var_id)
678  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 683 of file DisvNCMesh.f90.

686  integer(I4B), intent(in) :: ncid
687  type(MeshNCDimIdType), intent(inout) :: dim_ids
688  type(MeshNCVarIdType), intent(inout) :: var_ids
689  type(DisvType), pointer, intent(in) :: disv
690  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
691  character(len=*), intent(in) :: nc_varname
692  character(len=*), intent(in) :: pkgname
693  character(len=*), intent(in) :: tagname
694  character(len=*), intent(in) :: gridmap_name
695  character(len=*), intent(in) :: shapestr
696  character(len=*), intent(in) :: longname
697  character(len=*), intent(in) :: nc_tag
698  integer(I4B), intent(in) :: deflate
699  integer(I4B), intent(in) :: shuffle
700  integer(I4B), intent(in) :: chunk_face
701  character(len=*), intent(in) :: nc_fname
702  integer(I4B), dimension(:), allocatable :: var_id
703  character(len=LINELENGTH) :: longname_l, varname_l
704  integer(I4B) :: k
705 
706  allocate (var_id(disv%nlay))
707 
708  ! reenter define mode and create variable
709  call nf_verify(nf90_redef(ncid), nc_fname)
710  do k = 1, disv%nlay
711  ! set names
712  varname_l = export_varname(nc_varname, layer=k)
713  longname_l = export_longname(longname, pkgname, tagname, k)
714 
715  call nf_verify(nf90_def_var(ncid, varname_l, nf90_int, &
716  (/dim_ids%nmesh_face/), var_id(k)), &
717  nc_fname)
718 
719  ! apply chunking parameters
720  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
721  ! deflate and shuffle
722  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
723 
724  ! put attr
725  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
726  (/nf90_fill_int/)), nc_fname)
727  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
728  longname_l), nc_fname)
729 
730  ! add grid mapping and mf6 attr
731  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
732  call ncvar_mf6attr(ncid, var_id(k), k, 0, 0, nc_tag, nc_fname)
733  end do
734 
735  ! exit define mode and write data
736  call nf_verify(nf90_enddef(ncid), nc_fname)
737  do k = 1, disv%nlay
738  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
739  end do
740 
741  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: