MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
disncstructuredmodule Module Reference

This module contains the DisNCStructuredModule. More...

Data Types

type  structuredncdimidtype
 
type  structuredncvaridtype
 
type  disncstructuredtype
 
interface  nc_export_array
 

Functions/Subroutines

subroutine dis_export_init (this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
 netcdf export dis init More...
 
subroutine dis_export_destroy (this)
 netcdf export dis destroy More...
 
subroutine df (this)
 netcdf export define More...
 
subroutine df_export (this)
 define timeseries input variables More...
 
subroutine step (this)
 netcdf export step More...
 
subroutine export_input_array (this, pkgtype, pkgname, mempath, idt)
 netcdf export an input array More...
 
subroutine export_df (this, export_pkg)
 define export package More...
 
subroutine create_timeseries (this, idt, iparam, iaux, export_pkg)
 create timeseries export variable More...
 
subroutine export_input_arrays (this, pkgtype, pkgname, mempath, param_dfns)
 write package gridded input data More...
 
subroutine package_step (this, export_pkg)
 netcdf export package dynamic input More...
 
subroutine add_pkg_data (this)
 determine packages to write gridded input More...
 
subroutine add_global_att (this)
 create file (group) attributes More...
 
subroutine define_dim (this)
 netcdf export define dimensions More...
 
subroutine define_dependent (this)
 create the model layer dependent variables More...
 
subroutine define_gridmap (this)
 create the file grid mapping container variable More...
 
subroutine define_geocoords (this)
 define grid projection variables More...
 
subroutine add_proj_data (this)
 add grid projection data More...
 
subroutine add_grid_data (this)
 add grid coordinates More...
 
subroutine ncvar_chunk2d (ncid, varid, chunk_x, chunk_y, nc_fname)
 define 2d variable chunking More...
 
subroutine ncvar_chunk3d (ncid, varid, chunk_x, chunk_y, chunk_z, nc_fname)
 define 3d variable chunking More...
 
subroutine ncvar_deflate (ncid, varid, deflate, shuffle, nc_fname)
 define variable compression More...
 
subroutine ncvar_gridmap (ncid, varid, gridmap_name, latlon, has_layer, nc_fname)
 put variable gridmap attributes More...
 
subroutine ncvar_mf6attr (ncid, varid, iaux, nc_tag, nc_fname)
 put variable internal modflow6 attributes More...
 
subroutine nc_export_int1d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, iper, nc_fname)
 netcdf export 1D integer More...
 
subroutine nc_export_int2d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, nc_fname)
 netcdf export 2D integer More...
 
subroutine nc_export_int3d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, nc_fname)
 netcdf export 3D integer More...
 
subroutine nc_export_dbl1d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, iper, iaux, nc_fname)
 netcdf export 1D double More...
 
subroutine nc_export_dbl2d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, nc_fname)
 netcdf export 2D double More...
 
subroutine nc_export_dbl3d (p_mem, ncid, dim_ids, var_ids, dis, idt, mempath, nc_tag, pkgname, gridmap_name, latlon, deflate, shuffle, chunk_z, chunk_y, chunk_x, nc_fname)
 netcdf export 3D double More...
 

Detailed Description

This module defines a STRUCTURED (non-ugrid) netcdf export type for DIS models. It is dependent on netcdf libraries.

Function/Subroutine Documentation

◆ add_global_att()

subroutine disncstructuredmodule::add_global_att ( class(disncstructuredtype), intent(inout)  this)

Definition at line 755 of file DisNCStructured.f90.

756  class(DisNCStructuredType), intent(inout) :: this
757  ! file scoped title
758  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'title', &
759  this%annotation%title), this%nc_fname)
760  ! source (MODFLOW 6)
761  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'source', &
762  this%annotation%source), this%nc_fname)
763  ! grid type (MODFLOW 6)
764  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'modflow_grid', &
765  this%annotation%grid), this%nc_fname)
766  ! MODFLOW 6 model type
767  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'modflow_model', &
768  this%annotation%model), this%nc_fname)
769  ! generation datetime
770  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'history', &
771  this%annotation%history), this%nc_fname)
772  ! supported conventions
773  call nf_verify(nf90_put_att(this%ncid, nf90_global, 'Conventions', &
774  this%annotation%conventions), &
775  this%nc_fname)
Here is the call graph for this function:

◆ add_grid_data()

subroutine disncstructuredmodule::add_grid_data ( class(disncstructuredtype), intent(inout)  this)
private

Definition at line 1219 of file DisNCStructured.f90.

1220  class(DisNCStructuredType), intent(inout) :: this
1221  integer(I4B) :: ibnd, n, k
1222  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
1223  real(DP), dimension(:), allocatable :: x, y
1224  real(DP), dimension(:, :, :), allocatable :: elev3d
1225  real(DP) :: xoff, yoff
1226 
1227  if (this%dis%angrot /= dzero) then
1228  xoff = dzero
1229  yoff = dzero
1230  else
1231  xoff = this%dis%xorigin
1232  yoff = this%dis%yorigin
1233  end if
1234 
1235  allocate (x(size(this%dis%cellx)))
1236  allocate (y(size(this%dis%celly)))
1237 
1238  do n = 1, size(this%dis%cellx)
1239  x(n) = this%dis%cellx(n) + xoff
1240  end do
1241 
1242  do n = 1, size(this%dis%celly)
1243  y(n) = this%dis%celly(n) + yoff
1244  end do
1245 
1246  call nf_verify(nf90_put_var(this%ncid, this%var_ids%x, x), &
1247  this%nc_fname)
1248  call nf_verify(nf90_put_var(this%ncid, this%var_ids%y, y), &
1249  this%nc_fname)
1250  ! TODO see cf-conventions 4.3.3. Parametric Vertical Coordinate
1251  call nf_verify(nf90_put_var(this%ncid, this%var_ids%layer, this%layers), &
1252  this%nc_fname)
1253 
1254  deallocate (x)
1255  deallocate (y)
1256 
1257  ! z: cell center elevation, layer 1 = midpoint of top/bot3d(1),
1258  ! layer k>1 = midpoint of bot3d(k-1)/bot3d(k)
1259  allocate (elev3d(this%dis%ncol, this%dis%nrow, this%nlay))
1260  do k = 1, this%nlay
1261  if (k == 1) then
1262  elev3d(:, :, k) = (this%dis%top2d(:, :) + this%dis%bot3d(:, :, k)) * &
1263  dhalf
1264  else
1265  elev3d(:, :, k) = (this%dis%bot3d(:, :, k - 1) + &
1266  this%dis%bot3d(:, :, k)) * dhalf
1267  end if
1268  end do
1269  call nf_verify(nf90_put_var(this%ncid, this%var_ids%elevation, elev3d), &
1270  this%nc_fname)
1271  deallocate (elev3d)
1272 
1273  ! bounds x
1274  allocate (dbl2d(2, size(this%dis%cellx)))
1275  ibnd = 1
1276  do n = 1, size(this%dis%cellx)
1277  if (ibnd == 1) then
1278  dbl2d(1, ibnd) = xoff
1279  dbl2d(2, ibnd) = xoff + this%dis%delr(ibnd)
1280  else
1281  dbl2d(1, ibnd) = dbl2d(1, ibnd - 1) + this%dis%delr(ibnd)
1282  dbl2d(2, ibnd) = dbl2d(2, ibnd - 1) + this%dis%delr(ibnd)
1283  end if
1284  ibnd = ibnd + 1
1285  end do
1286  call nf_verify(nf90_put_var(this%ncid, this%var_ids%x_bnds, dbl2d), &
1287  this%nc_fname)
1288  deallocate (dbl2d)
1289 
1290  ! bounds y
1291  allocate (dbl2d(2, size(this%dis%celly)))
1292  ibnd = 1
1293  do n = size(this%dis%celly), 1, -1
1294  if (ibnd == 1) then
1295  dbl2d(1, ibnd) = yoff + sum(this%dis%delc) - this%dis%delc(n)
1296  dbl2d(2, ibnd) = yoff + sum(this%dis%delc)
1297  else
1298  dbl2d(1, ibnd) = dbl2d(1, ibnd - 1) - this%dis%delc(n)
1299  dbl2d(2, ibnd) = dbl2d(2, ibnd - 1) - this%dis%delc(n)
1300  end if
1301  ibnd = ibnd + 1
1302  end do
1303  call nf_verify(nf90_put_var(this%ncid, this%var_ids%y_bnds, dbl2d), &
1304  this%nc_fname)
1305  deallocate (dbl2d)
Here is the call graph for this function:

◆ add_pkg_data()

subroutine disncstructuredmodule::add_pkg_data ( class(disncstructuredtype), intent(inout)  this)

Definition at line 698 of file DisNCStructured.f90.

704  class(DisNCStructuredType), intent(inout) :: this
705  character(LENCOMPONENTNAME) :: ptype, pname, pkgtype
706  type(CharacterStringType), dimension(:), contiguous, &
707  pointer :: pkgtypes => null()
708  type(CharacterStringType), dimension(:), contiguous, &
709  pointer :: pkgnames => null()
710  type(CharacterStringType), dimension(:), contiguous, &
711  pointer :: mempaths => null()
712  type(InputParamDefinitionType), dimension(:), pointer :: param_dfns
713  character(len=LENMEMPATH) :: input_mempath, mempath
714  integer(I4B) :: n
715  integer(I4B), pointer :: export_arrays
716  logical(LGP) :: found
717 
718  input_mempath = create_mem_path(component=this%modelname, context=idm_context)
719 
720  ! set pointers to model path package info
721  call mem_setptr(pkgtypes, 'PKGTYPES', input_mempath)
722  call mem_setptr(pkgnames, 'PKGNAMES', input_mempath)
723  call mem_setptr(mempaths, 'MEMPATHS', input_mempath)
724 
725  do n = 1, size(mempaths)
726  ! allocate export_arrays
727  allocate (export_arrays)
728  export_arrays = 0
729 
730  ! set package attributes
731  mempath = mempaths(n)
732  pname = pkgnames(n)
733  ptype = pkgtypes(n)
734 
735  ! export input arrays
736  if (mempath /= '') then
737  ! update export
738  call mem_set_value(export_arrays, 'EXPORT_NC', mempath, found, &
739  release=.false.)
740 
741  if (export_arrays > 0) then
742  pkgtype = idm_subcomponent_type(this%modeltype, ptype)
743  param_dfns => param_definitions(this%modeltype, pkgtype)
744  call this%export_input_arrays(ptype, pname, mempath, param_dfns)
745  end if
746  end if
747 
748  ! cleanup
749  deallocate (export_arrays)
750  end do
type(inputparamdefinitiontype) function, dimension(:), pointer, public param_definitions(component, subcomponent)
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=linelength) idm_context
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
character(len=lencomponentname) function, public idm_subcomponent_type(component, subcomponent)
component from package or model type
Here is the call graph for this function:

◆ add_proj_data()

subroutine disncstructuredmodule::add_proj_data ( class(disncstructuredtype), intent(inout)  this)
private

Definition at line 1200 of file DisNCStructured.f90.

1201  class(DisNCStructuredType), intent(inout) :: this
1202  if (this%latlon) then
1203  ! lat
1204  call nf_verify(nf90_put_var(this%ncid, this%var_ids%latitude, &
1205  this%latitude, start=(/1, 1/), &
1206  count=(/this%dis%ncol, this%dis%nrow/)), &
1207  this%nc_fname)
1208 
1209  ! lon
1210  call nf_verify(nf90_put_var(this%ncid, this%var_ids%longitude, &
1211  this%longitude, start=(/1, 1/), &
1212  count=(/this%dis%ncol, this%dis%nrow/)), &
1213  this%nc_fname)
1214  end if
Here is the call graph for this function:

◆ create_timeseries()

subroutine disncstructuredmodule::create_timeseries ( class(disncstructuredtype), intent(inout)  this,
type(inputparamdefinitiontype), intent(in), pointer  idt,
integer(i4b), intent(in)  iparam,
integer(i4b), intent(in)  iaux,
class(exportpackagetype), intent(in), pointer  export_pkg 
)

Definition at line 435 of file DisNCStructured.f90.

437  class(DisNCStructuredType), intent(inout) :: this
438  type(InputParamDefinitionType), pointer, intent(in) :: idt
439  integer(I4B), intent(in) :: iparam
440  integer(I4B), intent(in) :: iaux
441  class(ExportPackageType), pointer, intent(in) :: export_pkg
442  character(len=LINELENGTH) :: varname, longname, nc_tag
443  integer(I4B) :: varid
444  logical(LGP) :: has_layer
445 
446  has_layer = .not. (idt%shape == 'NCPL' .or. idt%shape == 'NAUX NCPL')
447 
448  ! set variable input tag
449  nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
450  idt)
451 
452  ! set names
453  varname = export_varname(export_pkg%mf6_input%subcomponent_name, &
454  idt%tagname, export_pkg%mf6_input%mempath, &
455  iaux=iaux)
456  longname = export_longname(idt%longname, &
457  export_pkg%mf6_input%subcomponent_name, &
458  idt%tagname, export_pkg%mf6_input%mempath, &
459  iaux=iaux, &
460  component_type=idt%component_type, &
461  subcomponent_type=idt%subcomponent_type)
462 
463  ! create the netcdf timeseries variable
464  select case (idt%datatype)
465  case ('DOUBLE1D', 'DOUBLE2D')
466  if (idt%shape == 'NCPL' .or. &
467  idt%shape == 'NAUX NCPL') then
468  call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
469  (/this%dim_ids%x, &
470  this%dim_ids%y, &
471  this%dim_ids%time/), varid), &
472  this%nc_fname)
473  else
474  call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
475  (/this%dim_ids%x, &
476  this%dim_ids%y, &
477  this%dim_ids%layer, &
478  this%dim_ids%time/), varid), &
479  this%nc_fname)
480  end if
481  call nf_verify(nf90_put_att(this%ncid, varid, &
482  '_FillValue', (/dnodata/)), &
483  this%nc_fname)
484  case ('INTEGER1D')
485  if (idt%shape == 'NCPL' .or. &
486  idt%shape == 'NAUX NCPL') then
487  call nf_verify(nf90_def_var(this%ncid, varname, nf90_int, &
488  (/this%dim_ids%x, &
489  this%dim_ids%y, &
490  this%dim_ids%time/), varid), &
491  this%nc_fname)
492  else
493  call nf_verify(nf90_def_var(this%ncid, varname, nf90_int, &
494  (/this%dim_ids%x, &
495  this%dim_ids%y, &
496  this%dim_ids%layer, &
497  this%dim_ids%time/), varid), &
498  this%nc_fname)
499  end if
500  call nf_verify(nf90_put_att(this%ncid, varid, &
501  '_FillValue', (/nf90_fill_int/)), &
502  this%nc_fname)
503  end select
504 
505  ! apply chunking parameters
506  if (this%chunking_active) then
507  call nf_verify(nf90_def_var_chunking(this%ncid, &
508  varid, &
509  nf90_chunked, &
510  (/this%chunk_x, this%chunk_y, &
511  this%chunk_z, this%chunk_time/)), &
512  this%nc_fname)
513  end if
514 
515  ! deflate and shuffle
516  call ncvar_deflate(this%ncid, varid, this%deflate, &
517  this%shuffle, this%nc_fname)
518 
519  ! variable attributes
520  call nf_verify(nf90_put_att(this%ncid, varid, &
521  'units', this%lenunits), this%nc_fname)
522  call nf_verify(nf90_put_att(this%ncid, varid, &
523  'long_name', longname), this%nc_fname)
524 
525  ! add grid mapping and mf6 attr
526  call ncvar_gridmap(this%ncid, varid, this%gridmap_name, this%latlon, &
527  has_layer, this%nc_fname)
528  call ncvar_mf6attr(this%ncid, varid, iaux, nc_tag, this%nc_fname)
529 
530  ! store variable id
531  if (idt%tagname == 'AUX') then
532  export_pkg%varids_aux(iaux, 1) = varid
533  else
534  export_pkg%varids_param(iparam, 1) = varid
535  end if
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
Here is the call graph for this function:

◆ define_dependent()

subroutine disncstructuredmodule::define_dependent ( class(disncstructuredtype), intent(inout)  this)

Definition at line 909 of file DisNCStructured.f90.

910  use constantsmodule, only: dhnoflo
911  class(DisNCStructuredType), intent(inout) :: this
912 
913  call nf_verify(nf90_def_var(this%ncid, this%xname, nf90_double, &
914  (/this%dim_ids%x, this%dim_ids%y, &
915  this%dim_ids%layer, this%dim_ids%time/), &
916  this%var_ids%dependent), &
917  this%nc_fname)
918 
919  ! apply chunking parameters
920  if (this%chunking_active) then
921  call nf_verify(nf90_def_var_chunking(this%ncid, &
922  this%var_ids%dependent, &
923  nf90_chunked, &
924  (/this%chunk_x, this%chunk_y, &
925  this%chunk_z, this%chunk_time/)), &
926  this%nc_fname)
927  end if
928 
929  ! deflate and shuffle
930  call ncvar_deflate(this%ncid, this%var_ids%dependent, this%deflate, &
931  this%shuffle, this%nc_fname)
932 
933  ! put attr
934  call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent, &
935  'units', this%lenunits), this%nc_fname)
936  call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent, 'long_name', &
937  this%annotation%longname), this%nc_fname)
938  call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent, '_FillValue', &
939  (/dhnoflo/)), this%nc_fname)
940  ! cell_methods (CF-1.13 7.3): dependent variable values are the
941  ! instantaneous simulated state at each output time, not a time
942  ! mean/accumulation over the interval -- an intensive quantity whose
943  ! default method is already "point" per CF's own Appendix E, stated
944  ! explicitly here per CF's recommendation to do so for every
945  ! spatio-temporal dimension.
946  call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent, &
947  'cell_methods', 'time: point'), this%nc_fname)
948 
949  ! add grid mapping
950  call ncvar_gridmap(this%ncid, this%var_ids%dependent, this%gridmap_name, &
951  this%latlon, .true., this%nc_fname)
This module contains simulation constants.
Definition: Constants.f90:9
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:93
Here is the call graph for this function:

◆ define_dim()

subroutine disncstructuredmodule::define_dim ( class(disncstructuredtype), intent(inout)  this)
private

Definition at line 780 of file DisNCStructured.f90.

781  use constantsmodule, only: mvalidate
782  use simvariablesmodule, only: isim_mode
783  class(DisNCStructuredType), intent(inout) :: this
784 
785  ! bound dim
786  call nf_verify(nf90_def_dim(this%ncid, 'bnd', 2, this%dim_ids%bnd), &
787  this%nc_fname)
788 
789  if (isim_mode /= mvalidate .or. this%pkglist%Count() > 0) then
790  ! Time
791  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
792  this%dim_ids%time), this%nc_fname)
793  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
794  this%dim_ids%time, this%var_ids%time), &
795  this%nc_fname)
796  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
797  'standard'), this%nc_fname)
798  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
799  this%datetime), this%nc_fname)
800  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
801  this%nc_fname)
802  !call nf_verify(nf90_put_att(ncid, var_ids%time, 'bounds', 'time_bnds'), this%nc_fname)
803  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
804  'time'), this%nc_fname)
805  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
806  'time'), this%nc_fname)
807  end if
808 
809  ! Z dimension
810  call nf_verify(nf90_def_dim(this%ncid, 'layer', this%dis%nlay, &
811  this%dim_ids%layer), this%nc_fname)
812  call nf_verify(nf90_def_var(this%ncid, 'layer', nf90_int, &
813  this%dim_ids%layer, this%var_ids%layer), &
814  this%nc_fname)
815  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'units', '1'), &
816  this%nc_fname)
817  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'axis', 'Z'), &
818  this%nc_fname)
819  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'positive', &
820  'down'), this%nc_fname)
821  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'long_name', &
822  'model layer'), this%nc_fname)
823 
824  ! Y dimension
825  call nf_verify(nf90_def_dim(this%ncid, 'y', this%dis%nrow, this%dim_ids%y), &
826  this%nc_fname)
827  call nf_verify(nf90_def_var(this%ncid, 'y', nf90_double, this%dim_ids%y, &
828  this%var_ids%y), this%nc_fname)
829  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'units', &
830  this%lenunits), this%nc_fname)
831  if (this%dis%angrot == dzero .or. &
832  wrap_rotated_crs(this%crs_wkt, this%dis%xorigin, this%dis%yorigin, &
833  this%dis%angrot) /= '') then
834  ! axis/standard_name assert that y holds the true projected
835  ! position. For a rotated grid this only holds once crs_wkt
836  ! encodes the rotation (see wrap_rotated_crs in define_gridmap);
837  ! otherwise y is grid-local (see add_grid_data) and asserting it
838  ! would cause GDAL's netCDF driver to derive an incorrect,
839  ! unrotated position directly from y's grid-local values.
840  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'axis', 'Y'), &
841  this%nc_fname)
842  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'standard_name', &
843  'projection_y_coordinate'), this%nc_fname)
844  end if
845  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'long_name', &
846  'Northing'), this%nc_fname)
847  if (this%gridmap_name /= '') then
848  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'grid_mapping', &
849  this%gridmap_name), this%nc_fname)
850  end if
851  call nf_verify(nf90_put_att(this%ncid, this%var_ids%y, 'bounds', 'y_bnds'), &
852  this%nc_fname)
853  call nf_verify(nf90_def_var(this%ncid, 'y_bnds', nf90_double, &
854  (/this%dim_ids%bnd, this%dim_ids%y/), &
855  this%var_ids%y_bnds), this%nc_fname)
856 
857  ! X dimension
858  call nf_verify(nf90_def_dim(this%ncid, 'x', this%dis%ncol, this%dim_ids%x), &
859  this%nc_fname)
860  call nf_verify(nf90_def_var(this%ncid, 'x', nf90_double, this%dim_ids%x, &
861  this%var_ids%x), this%nc_fname)
862  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'units', &
863  this%lenunits), this%nc_fname)
864  if (this%dis%angrot == dzero .or. &
865  wrap_rotated_crs(this%crs_wkt, this%dis%xorigin, this%dis%yorigin, &
866  this%dis%angrot) /= '') then
867  ! see matching comment on the Y dimension above
868  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'axis', 'X'), &
869  this%nc_fname)
870  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'standard_name', &
871  'projection_x_coordinate'), this%nc_fname)
872  end if
873  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'long_name', &
874  'Easting'), this%nc_fname)
875  if (this%gridmap_name /= '') then
876  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'grid_mapping', &
877  this%gridmap_name), this%nc_fname)
878  end if
879  call nf_verify(nf90_put_att(this%ncid, this%var_ids%x, 'bounds', 'x_bnds'), &
880  this%nc_fname)
881  call nf_verify(nf90_def_var(this%ncid, 'x_bnds', nf90_double, &
882  (/this%dim_ids%bnd, this%dim_ids%x/), &
883  this%var_ids%x_bnds), this%nc_fname)
884 
885  ! z: cell center elevation auxiliary coordinate -- a real vertical
886  ! position, unlike the discrete layer index. Always written,
887  ! independent of CRS/NCF configuration.
888  call nf_verify(nf90_def_var(this%ncid, 'z', nf90_double, &
889  (/this%dim_ids%x, this%dim_ids%y, &
890  this%dim_ids%layer/), &
891  this%var_ids%elevation), this%nc_fname)
892  call ncvar_chunk3d(this%ncid, this%var_ids%elevation, this%chunk_x, &
893  this%chunk_y, this%chunk_z, this%nc_fname)
894  call ncvar_deflate(this%ncid, this%var_ids%elevation, this%deflate, &
895  this%shuffle, this%nc_fname)
896  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation, 'units', &
897  this%lenunits), this%nc_fname)
898  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation, &
899  'standard_name', 'altitude'), this%nc_fname)
900  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation, &
901  'positive', 'up'), this%nc_fname)
902  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation, &
903  'long_name', 'cell center elevation'), &
904  this%nc_fname)
@ mvalidate
validation mode - do not run time steps
Definition: Constants.f90:206
integer(i4b) isim_mode
simulation mode
Here is the call graph for this function:

◆ define_geocoords()

subroutine disncstructuredmodule::define_geocoords ( class(disncstructuredtype), intent(inout)  this)
private

Definition at line 1171 of file DisNCStructured.f90.

1172  class(DisNCStructuredType), intent(inout) :: this
1173  if (this%latlon) then
1174  ! lat
1175  call nf_verify(nf90_def_var(this%ncid, 'lat', nf90_double, &
1176  (/this%dim_ids%x, this%dim_ids%y/), &
1177  this%var_ids%latitude), this%nc_fname)
1178  call nf_verify(nf90_put_att(this%ncid, this%var_ids%latitude, &
1179  'units', 'degrees_north'), this%nc_fname)
1180  call nf_verify(nf90_put_att(this%ncid, this%var_ids%latitude, &
1181  'standard_name', 'latitude'), this%nc_fname)
1182  call nf_verify(nf90_put_att(this%ncid, this%var_ids%latitude, &
1183  'long_name', 'latitude'), this%nc_fname)
1184 
1185  ! lon
1186  call nf_verify(nf90_def_var(this%ncid, 'lon', nf90_double, &
1187  (/this%dim_ids%x, this%dim_ids%y/), &
1188  this%var_ids%longitude), this%nc_fname)
1189  call nf_verify(nf90_put_att(this%ncid, this%var_ids%longitude, &
1190  'units', 'degrees_east'), this%nc_fname)
1191  call nf_verify(nf90_put_att(this%ncid, this%var_ids%longitude, &
1192  'standard_name', 'longitude'), this%nc_fname)
1193  call nf_verify(nf90_put_att(this%ncid, this%var_ids%longitude, &
1194  'long_name', 'longitude'), this%nc_fname)
1195  end if
Here is the call graph for this function:

◆ define_gridmap()

subroutine disncstructuredmodule::define_gridmap ( class(disncstructuredtype), intent(inout)  this)

Definition at line 956 of file DisNCStructured.f90.

957  class(DisNCStructuredType), intent(inout) :: this
958  integer(I4B) :: var_id
959  character(len=LINELENGTH) :: gmname
960  character(len=LENBIGLINE) :: effective_crs_wkt, derived_wkt
961  character(len=100) :: rotinfo
962  real(DP) :: longitude_of_central_meridian, latitude_of_projection_origin
963  real(DP) :: scale_factor_at_central_meridian, false_easting, false_northing
964  real(DP) :: semi_major_axis, inverse_flattening
965  real(DP) :: standard_parallel_1, standard_parallel_2
966  logical(LGP) :: params_found, is_2sp
967 
968  if (this%wkt /= '' .or. this%crs_wkt /= '') then
969  call nf_verify(nf90_redef(this%ncid), this%nc_fname)
970  call nf_verify(nf90_def_var(this%ncid, this%gridmap_name, nf90_int, &
971  var_id), this%nc_fname)
972  ! wkt (WKT1, OGC 01-009) -- for legacy/QGIS compatibility. WKT1
973  ! has no derived-CRS syntax, so it cannot encode grid rotation and
974  ! is always written unmodified.
975  if (this%wkt /= '') then
976  call nf_verify(nf90_put_att(this%ncid, var_id, 'wkt', this%wkt), &
977  this%nc_fname)
978  end if
979  ! crs_wkt (WKT2, ISO 19162:2019) -- required by CF-1.13
980  if (this%crs_wkt /= '') then
981  effective_crs_wkt = this%crs_wkt
982  else
983  effective_crs_wkt = this%wkt
984  end if
985  ! For a rotated structured grid, wrap crs_wkt in a derived CRS
986  ! encoding the rotation (see wrap_rotated_crs) so a CRS-aware
987  ! consumer resolves the correct real-world position and shape
988  ! via ordinary reprojection. Falls back to an unmodified
989  ! crs_wkt, with a warning, if CRS_WKT was not provided or is not
990  ! a recognized WKT2 PROJCRS.
991  if (this%dis%angrot /= dzero) then
992  if (this%crs_wkt == '') then
993  write (warnmsg, '(a)') 'Structured rotated grid with no CRS_WKT &
994  &input: no rotation-positioning information will be written &
995  &to the output CRS; x/y coordinate values will not reflect &
996  &the true rotated position. Applies to file "'// &
997  trim(this%nc_fname)//'".'
998  call store_warning(warnmsg)
999  else
1000  derived_wkt = wrap_rotated_crs(this%crs_wkt, this%dis%xorigin, &
1001  this%dis%yorigin, this%dis%angrot)
1002  if (derived_wkt /= '') then
1003  write (rotinfo, '(a,g0,a,g0,a,g0,a)') 'xorigin=', &
1004  this%dis%xorigin, ', yorigin=', this%dis%yorigin, &
1005  ', angrot=', this%dis%angrot, ' deg'
1006  write (warnmsg, '(a)') 'Structured rotated grid: wrapped &
1007  &CRS_WKT in a derived CRS to encode grid rotation ('// &
1008  trim(rotinfo)//'). Applies to file "'// &
1009  trim(this%nc_fname)//'".'
1010  call store_warning(warnmsg)
1011  effective_crs_wkt = derived_wkt
1012  else
1013  write (warnmsg, '(a)') 'Structured rotated grid: CRS_WKT is &
1014  &not a recognized WKT2 PROJCRS; no rotation-positioning &
1015  &information will be written to the output CRS; x/y &
1016  &coordinate values will not reflect the true rotated &
1017  &position. Applies to file "'//trim(this%nc_fname)//'".'
1018  call store_warning(warnmsg)
1019  end if
1020  end if
1021  end if
1022  call nf_verify(nf90_put_att(this%ncid, var_id, 'crs_wkt', &
1023  trim(effective_crs_wkt)), this%nc_fname)
1024  ! grid_mapping_name derived from WKT projection keyword
1025  gmname = wkt_to_cf_gridmapping(trim(effective_crs_wkt))
1026  if (gmname /= '') then
1027  call nf_verify(nf90_put_att(this%ncid, var_id, 'grid_mapping_name', &
1028  trim(gmname)), this%nc_fname)
1029  end if
1030  ! CF-standard numeric grid_mapping parameters (in addition to
1031  ! wkt/crs_wkt): some netCDF readers -- notably ArcGIS's classic
1032  ! netCDF connector -- position a projected grid using these
1033  ! individual attributes rather than parsing wkt/crs_wkt, and
1034  ! default every parameter to 0 if they are absent. Covers
1035  ! transverse_mercator, lambert_conformal_conic (2SP only -- CF has
1036  ! no scale_factor attribute for this method, so a 1SP/scale-factor
1037  ! WKT cannot be exactly represented), and albers_conical_equal_area;
1038  ! other grid_mapping_name values are unaffected. Best-effort
1039  ! extraction from effective_crs_wkt -- MF6 has no CRS parsing
1040  ! library, so this is skipped if any parameter cannot be located.
1041  if (trim(gmname) == 'transverse_mercator') then
1042  call wkt_transverse_mercator_params(trim(effective_crs_wkt), &
1043  longitude_of_central_meridian, &
1044  latitude_of_projection_origin, &
1045  scale_factor_at_central_meridian, &
1046  false_easting, false_northing, &
1047  semi_major_axis, inverse_flattening, &
1048  params_found)
1049  if (params_found) then
1050  call nf_verify(nf90_put_att(this%ncid, var_id, &
1051  'longitude_of_central_meridian', &
1052  longitude_of_central_meridian), &
1053  this%nc_fname)
1054  call nf_verify(nf90_put_att(this%ncid, var_id, &
1055  'latitude_of_projection_origin', &
1056  latitude_of_projection_origin), &
1057  this%nc_fname)
1058  call nf_verify(nf90_put_att(this%ncid, var_id, &
1059  'scale_factor_at_central_meridian', &
1060  scale_factor_at_central_meridian), &
1061  this%nc_fname)
1062  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1063  false_easting), this%nc_fname)
1064  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1065  false_northing), this%nc_fname)
1066  call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1067  semi_major_axis), this%nc_fname)
1068  call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1069  inverse_flattening), this%nc_fname)
1070  else
1071  write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1072  &transverse_mercator grid_mapping parameters from CRS_WKT; &
1073  &some netCDF readers may not correctly position this grid. &
1074  &Applies to file "'//trim(this%nc_fname)//'".'
1075  call store_warning(warnmsg)
1076  end if
1077  else if (trim(gmname) == 'lambert_conformal_conic') then
1078  call wkt_lambert_conformal_conic_params(trim(effective_crs_wkt), &
1079  standard_parallel_1, &
1080  standard_parallel_2, &
1081  longitude_of_central_meridian, &
1082  latitude_of_projection_origin, &
1083  false_easting, false_northing, &
1084  semi_major_axis, &
1085  inverse_flattening, is_2sp, &
1086  params_found)
1087  if (params_found) then
1088  call nf_verify(nf90_put_att(this%ncid, var_id, 'standard_parallel', &
1089  (/standard_parallel_1, &
1090  standard_parallel_2/)), this%nc_fname)
1091  call nf_verify(nf90_put_att(this%ncid, var_id, &
1092  'longitude_of_central_meridian', &
1093  longitude_of_central_meridian), &
1094  this%nc_fname)
1095  call nf_verify(nf90_put_att(this%ncid, var_id, &
1096  'latitude_of_projection_origin', &
1097  latitude_of_projection_origin), &
1098  this%nc_fname)
1099  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1100  false_easting), this%nc_fname)
1101  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1102  false_northing), this%nc_fname)
1103  call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1104  semi_major_axis), this%nc_fname)
1105  call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1106  inverse_flattening), this%nc_fname)
1107  else if (.not. is_2sp) then
1108  write (warnmsg, '(a)') 'Structured grid: 1SP lambert_conformal_conic &
1109  &variants are not supported for CF grid_mapping parameter &
1110  &extraction (CF has no scale_factor attribute for this method); &
1111  &some netCDF readers may not correctly position this grid. &
1112  &Applies to file "'//trim(this%nc_fname)//'".'
1113  call store_warning(warnmsg)
1114  else
1115  write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1116  &lambert_conformal_conic grid_mapping parameters from CRS_WKT; &
1117  &some netCDF readers may not correctly position this grid. &
1118  &Applies to file "'//trim(this%nc_fname)//'".'
1119  call store_warning(warnmsg)
1120  end if
1121  else if (trim(gmname) == 'albers_conical_equal_area') then
1122  call wkt_albers_conical_equal_area_params(trim(effective_crs_wkt), &
1123  standard_parallel_1, &
1124  standard_parallel_2, &
1125  longitude_of_central_meridian, &
1126  latitude_of_projection_origin, &
1127  false_easting, false_northing, &
1128  semi_major_axis, &
1129  inverse_flattening, &
1130  params_found)
1131  if (params_found) then
1132  call nf_verify(nf90_put_att(this%ncid, var_id, 'standard_parallel', &
1133  (/standard_parallel_1, &
1134  standard_parallel_2/)), this%nc_fname)
1135  call nf_verify(nf90_put_att(this%ncid, var_id, &
1136  'longitude_of_central_meridian', &
1137  longitude_of_central_meridian), &
1138  this%nc_fname)
1139  call nf_verify(nf90_put_att(this%ncid, var_id, &
1140  'latitude_of_projection_origin', &
1141  latitude_of_projection_origin), &
1142  this%nc_fname)
1143  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1144  false_easting), this%nc_fname)
1145  call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1146  false_northing), this%nc_fname)
1147  call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1148  semi_major_axis), this%nc_fname)
1149  call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1150  inverse_flattening), this%nc_fname)
1151  else
1152  write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1153  &albers_conical_equal_area grid_mapping parameters from &
1154  &CRS_WKT; some netCDF readers may not correctly position this &
1155  &grid. Applies to file "'//trim(this%nc_fname)//'".'
1156  call store_warning(warnmsg)
1157  end if
1158  end if
1159  ! GeoTransform/spatial_ref intentionally not written: a GDAL-only,
1160  ! non-CF extension ArcGIS does not read, superseded by crs_wkt's
1161  ! derived-CRS encoding above, which any CRS-aware consumer resolves
1162  ! via ordinary reprojection.
1163  call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
1164  call nf_verify(nf90_put_var(this%ncid, var_id, 1), &
1165  this%nc_fname)
1166  end if
Here is the call graph for this function:

◆ df()

subroutine disncstructuredmodule::df ( class(disncstructuredtype), intent(inout)  this)
private

Definition at line 233 of file DisNCStructured.f90.

234  use constantsmodule, only: mvalidate
235  use simvariablesmodule, only: isim_mode
236  class(DisNCStructuredType), intent(inout) :: this
237  ! put root group file scope attributes
238  call this%add_global_att()
239  ! define root group dimensions and coordinate variables
240  call this%define_dim()
241  ! define grid projection variables
242  call this%define_geocoords()
243  if (isim_mode == mvalidate) then
244  ! define period input arrays
245  call this%df_export()
246  else
247  ! define the dependent variable
248  call this%define_dependent()
249  end if
250  ! exit define mode
251  call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
252  ! add data locations
253  call this%add_grid_data()
254  ! add projection data
255  call this%add_proj_data()
256  if (isim_mode == mvalidate) then
257  ! define and set package input griddata
258  call this%add_pkg_data()
259  end if
260  ! define and set gridmap variable
261  call this%define_gridmap()
262  ! synchronize file
263  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
Here is the call graph for this function:

◆ df_export()

subroutine disncstructuredmodule::df_export ( class(disncstructuredtype), intent(inout)  this)

Definition at line 268 of file DisNCStructured.f90.

270  class(DisNCStructuredType), intent(inout) :: this
271  class(ExportPackageType), pointer :: export_pkg
272  integer(I4B) :: idx
273  do idx = 1, this%pkglist%Count()
274  export_pkg => this%get(idx)
275  call this%export_df(export_pkg)
276  end do

◆ dis_export_destroy()

subroutine disncstructuredmodule::dis_export_destroy ( class(disncstructuredtype), intent(inout)  this)

Definition at line 217 of file DisNCStructured.f90.

218  class(DisNCStructuredType), intent(inout) :: this
219  call nf_verify(nf90_close(this%ncid), this%nc_fname)
220  deallocate (this%chunk_z)
221  deallocate (this%chunk_y)
222  deallocate (this%chunk_x)
223  deallocate (this%layers)
224  nullify (this%chunk_z)
225  nullify (this%chunk_y)
226  nullify (this%chunk_x)
227  ! destroy base class
228  call this%NCModelExportType%destroy()
Here is the call graph for this function:

◆ dis_export_init()

subroutine disncstructuredmodule::dis_export_init ( class(disncstructuredtype), 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 99 of file DisNCStructured.f90.

101  use memorymanagermodule, only: get_isize
103  class(DisNCStructuredType), intent(inout) :: this
104  character(len=*), intent(in) :: modelname
105  character(len=*), intent(in) :: modeltype
106  character(len=*), intent(in) :: modelfname
107  character(len=*), intent(in) :: nc_fname
108  integer(I4B), intent(in) :: disenum
109  integer(I4B), intent(in) :: nctype
110  integer(I4B), intent(in) :: iout
111  integer(I4B) :: k, latsz, lonsz
112  logical(LGP) :: found
113 
114  ! set nlay
115  this%nlay = this%dis%nlay
116 
117  ! allocate
118  allocate (this%chunk_z)
119  allocate (this%chunk_y)
120  allocate (this%chunk_x)
121  allocate (this%layers(this%nlay))
122 
123  ! initialize
124  this%chunk_z = -1
125  this%chunk_y = -1
126  this%chunk_x = -1
127  do k = 1, this%nlay
128  this%layers(k) = k
129  end do
130 
131  this%latlon = .false.
132 
133  ! initialize base class
134  call this%NCModelExportType%init(modelname, modeltype, modelfname, nc_fname, &
135  disenum, nctype, iout)
136 
137  ! update values from input context
138  if (this%ncf_mempath /= '') then
139  call mem_set_value(this%chunk_z, 'CHUNK_Z', this%ncf_mempath, found)
140  call mem_set_value(this%chunk_y, 'CHUNK_Y', this%ncf_mempath, found)
141  call mem_set_value(this%chunk_x, 'CHUNK_X', this%ncf_mempath, found)
142 
143  if (this%chunk_time > 0 .and. this%chunk_z > 0 .and. &
144  this%chunk_y > 0 .and. this%chunk_x > 0) then
145  this%chunking_active = .true.
146  else if (this%chunk_time > 0 .or. this%chunk_z > 0 .or. &
147  this%chunk_y > 0 .or. this%chunk_x > 0) then
148  this%chunk_time = -1
149  this%chunk_z = -1
150  this%chunk_y = -1
151  this%chunk_x = -1
152  write (warnmsg, '(a)') 'Ignoring user provided NetCDF chunking &
153  &parameters. Define chunk_time, chunk_x, chunk_y and chunk_z input &
154  &parameters to see an effect in file "'//trim(nc_fname)//'".'
155  call store_warning(warnmsg)
156  end if
157 
158  call get_isize('LATITUDE', this%ncf_mempath, latsz)
159  call get_isize('LONGITUDE', this%ncf_mempath, lonsz)
160 
161  if (latsz > 0 .and. lonsz > 0) then
162  this%latlon = .true.
163  if (this%wkt /= '' .or. this%crs_wkt /= '') then
164  write (warnmsg, '(a)') 'Ignoring user provided NetCDF wkt/crs_wkt &
165  &parameter(s) as longitude and latitude arrays have been provided. &
166  &Applies to file "'//trim(nc_fname)//'".'
167  call store_warning(warnmsg)
168  this%wkt = ''
169  this%crs_wkt = ''
170  this%gridmap_name = ''
171  end if
172  call mem_setptr(this%latitude, 'LATITUDE', this%ncf_mempath)
173  call mem_setptr(this%longitude, 'LONGITUDE', this%ncf_mempath)
174  if (this%dis%angrot /= dzero) then
175  write (warnmsg, '(a)') 'Structured rotated grid with &
176  &user-provided latitude/longitude: MF6 cannot verify these &
177  &values correctly account for grid rotation (angrot). They &
178  &must be computed from each cell''s true rotated position, &
179  &not from grid-local x/y. Applies to file "'// &
180  trim(nc_fname)//'".'
181  call store_warning(warnmsg)
182  end if
183  end if
184 
185  if (this%gridmap_name /= '') then
186  if (this%dis%angrot /= dzero) then
187  write (warnmsg, '(a)') 'CRS parameter set with structured rotated &
188  &grid. The x/y coordinate variables have grid-local, not &
189  &real-world, values. A CRS-aware consumer must apply the full &
190  &crs_wkt (which encodes rotation when a valid WKT2 PROJCRS was &
191  &supplied) via proper reprojection to resolve the true &
192  &position; deriving real longitude/latitude directly from x/y &
193  &and the flat/numeric CF grid_mapping parameters alone will be &
194  &incorrect, since those parameters never encode grid rotation. &
195  &Applies to file "'//trim(nc_fname)//'".'
196  call store_warning(warnmsg)
197  end if
198  end if
199  end if
200 
201  if (this%dis%lenuni == 1) then
202  this%lenunits = 'ft'
203  else if (this%dis%lenuni == 3) then
204  this%lenunits = 'cm'
205  else
206  this%lenunits = 'm'
207  end if
208 
209  ! create the netcdf file
210  call nf_verify(nf90_create(this%nc_fname, &
211  ior(nf90_clobber, nf90_netcdf4), this%ncid), &
212  this%nc_fname)
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
Here is the call graph for this function:

◆ export_df()

subroutine disncstructuredmodule::export_df ( class(disncstructuredtype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg 
)
private

Definition at line 403 of file DisNCStructured.f90.

406  class(DisNCStructuredType), intent(inout) :: this
407  class(ExportPackageType), pointer, intent(in) :: export_pkg
408  type(InputParamDefinitionType), pointer :: idt
409  integer(I4B) :: iparam, iaux
410 
411  ! export defined period input
412  do iparam = 1, export_pkg%nparam
413  ! initialize
414  iaux = 0
415  ! set input definition
416  idt => &
417  get_param_definition_type(export_pkg%mf6_input%param_dfns, &
418  export_pkg%mf6_input%component_type, &
419  export_pkg%mf6_input%subcomponent_type, &
420  'PERIOD', export_pkg%param_names(iparam), '')
421  select case (idt%shape)
422  case ('NCPL', 'NODES')
423  call this%create_timeseries(idt, iparam, iaux, export_pkg)
424  case ('NAUX NCPL', 'NAUX NODES')
425  do iaux = 1, export_pkg%naux
426  call this%create_timeseries(idt, iparam, iaux, export_pkg)
427  end do
428  case default
429  end select
430  end do
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.
Here is the call graph for this function:

◆ export_input_array()

subroutine disncstructuredmodule::export_input_array ( class(disncstructuredtype), 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 331 of file DisNCStructured.f90.

332  class(DisNCStructuredType), intent(inout) :: this
333  character(len=*), intent(in) :: pkgtype
334  character(len=*), intent(in) :: pkgname
335  character(len=*), intent(in) :: mempath
336  type(InputParamDefinitionType), pointer, intent(in) :: idt
337  integer(I4B), dimension(:), pointer, contiguous :: int1d
338  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
339  integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
340  real(DP), dimension(:), pointer, contiguous :: dbl1d
341  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
342  real(DP), dimension(:, :, :), pointer, contiguous :: dbl3d
343  character(len=LINELENGTH) :: nc_tag
344  integer(I4B) :: iper, iaux
345 
346  ! initialize
347  iper = 0
348  iaux = 0
349 
350  ! set variable name and input attribute string
351  nc_tag = this%input_attribute(pkgname, idt)
352 
353  select case (idt%datatype)
354  case ('INTEGER1D')
355  call mem_setptr(int1d, idt%mf6varname, mempath)
356  call nc_export_array(int1d, this%ncid, this%dim_ids, this%var_ids, &
357  this%dis, idt, mempath, nc_tag, pkgname, &
358  this%gridmap_name, this%latlon, this%deflate, &
359  this%shuffle, this%chunk_z, this%chunk_y, &
360  this%chunk_x, iper, this%nc_fname)
361  case ('INTEGER2D')
362  call mem_setptr(int2d, idt%mf6varname, mempath)
363  call nc_export_array(int2d, this%ncid, this%dim_ids, this%var_ids, &
364  this%dis, idt, mempath, nc_tag, pkgname, &
365  this%gridmap_name, this%latlon, this%deflate, &
366  this%shuffle, this%chunk_z, this%chunk_y, &
367  this%chunk_x, this%nc_fname)
368  case ('INTEGER3D')
369  call mem_setptr(int3d, idt%mf6varname, mempath)
370  call nc_export_array(int3d, this%ncid, this%dim_ids, this%var_ids, &
371  this%dis, idt, mempath, nc_tag, pkgname, &
372  this%gridmap_name, this%latlon, this%deflate, &
373  this%shuffle, this%chunk_z, this%chunk_y, &
374  this%chunk_x, this%nc_fname)
375  case ('DOUBLE1D')
376  call mem_setptr(dbl1d, idt%mf6varname, mempath)
377  call nc_export_array(dbl1d, this%ncid, this%dim_ids, this%var_ids, &
378  this%dis, idt, mempath, nc_tag, pkgname, &
379  this%gridmap_name, this%latlon, this%deflate, &
380  this%shuffle, this%chunk_z, this%chunk_y, &
381  this%chunk_x, iper, iaux, this%nc_fname)
382  case ('DOUBLE2D')
383  call mem_setptr(dbl2d, idt%mf6varname, mempath)
384  call nc_export_array(dbl2d, this%ncid, this%dim_ids, this%var_ids, &
385  this%dis, idt, mempath, nc_tag, pkgname, &
386  this%gridmap_name, this%latlon, this%deflate, &
387  this%shuffle, this%chunk_z, this%chunk_y, &
388  this%chunk_x, this%nc_fname)
389  case ('DOUBLE3D')
390  call mem_setptr(dbl3d, idt%mf6varname, mempath)
391  call nc_export_array(dbl3d, this%ncid, this%dim_ids, this%var_ids, &
392  this%dis, idt, mempath, nc_tag, pkgname, &
393  this%gridmap_name, this%latlon, this%deflate, &
394  this%shuffle, this%chunk_z, this%chunk_y, &
395  this%chunk_x, this%nc_fname)
396  case default
397  ! no-op, no other datatypes exported
398  end select

◆ export_input_arrays()

subroutine disncstructuredmodule::export_input_arrays ( class(disncstructuredtype), intent(inout)  this,
character(len=*), intent(in)  pkgtype,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  mempath,
type(inputparamdefinitiontype), dimension(:), intent(in), pointer  param_dfns 
)

Definition at line 540 of file DisNCStructured.f90.

541  use memorymanagermodule, only: get_isize
542  class(DisNCStructuredType), intent(inout) :: this
543  character(len=*), intent(in) :: pkgtype
544  character(len=*), intent(in) :: pkgname
545  character(len=*), intent(in) :: mempath
546  type(InputParamDefinitionType), dimension(:), pointer, &
547  intent(in) :: param_dfns
548  type(InputParamDefinitionType), pointer :: idt
549  integer(I4B) :: iparam, isize
550  do iparam = 1, size(param_dfns)
551  ! assign param definition pointer
552  idt => param_dfns(iparam)
553  ! for now only griddata is exported
554  if (idt%blockname == 'GRIDDATA') then
555  ! check if variable is already allocated
556  call get_isize(idt%mf6varname, mempath, isize)
557  if (isize > 0) then
558  call this%export_input_array(pkgtype, pkgname, mempath, idt)
559  end if
560  end if
561  end do
Here is the call graph for this function:

◆ nc_export_dbl1d()

subroutine disncstructuredmodule::nc_export_dbl1d ( real(dp), dimension(:), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
integer(i4b), intent(in)  iper,
integer(i4b), intent(in)  iaux,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1646 of file DisNCStructured.f90.

1650  use tdismodule, only: kper
1651  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
1652  integer(I4B), intent(in) :: ncid
1653  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1654  type(StructuredNCVarIdType), intent(inout) :: var_ids
1655  type(DisType), pointer, intent(in) :: dis
1656  type(InputParamDefinitionType), pointer, intent(in) :: idt
1657  character(len=*), intent(in) :: mempath
1658  character(len=*), intent(in) :: nc_tag
1659  character(len=*), intent(in) :: pkgname
1660  character(len=*), intent(in) :: gridmap_name
1661  logical(LGP), intent(in) :: latlon
1662  integer(I4B), intent(in) :: deflate
1663  integer(I4B), intent(in) :: shuffle
1664  integer(I4B), intent(in) :: chunk_z
1665  integer(I4B), intent(in) :: chunk_y
1666  integer(I4B), intent(in) :: chunk_x
1667  integer(I4B), intent(in) :: iper
1668  integer(I4B), intent(in) :: iaux
1669  character(len=*), intent(in) :: nc_fname
1670  integer(I4B) :: var_id, axis_sz
1671  character(len=LINELENGTH) :: varname, longname
1672 
1673  if (idt%shape == 'NROW' .or. &
1674  idt%shape == 'NCOL' .or. &
1675  idt%shape == 'NCPL' .or. &
1676  idt%shape == 'NAUX NCPL') then
1677 
1678  if (iper == 0) then
1679  select case (idt%shape)
1680  case ('NROW')
1681  axis_sz = dim_ids%y
1682  case ('NCOL')
1683  axis_sz = dim_ids%x
1684  end select
1685 
1686  varname = export_varname(pkgname, idt%tagname, mempath)
1687  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1688  iaux=iaux, &
1689  component_type=idt%component_type, &
1690  subcomponent_type=idt%subcomponent_type)
1691 
1692  ! reenter define mode and create variable
1693  call nf_verify(nf90_redef(ncid), nc_fname)
1694  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1695  (/axis_sz/), var_id), &
1696  nc_fname)
1697 
1698  ! NROW/NCOL shapes use default chunking
1699  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1700 
1701  ! put attr
1702  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1703  (/nf90_fill_double/)), nc_fname)
1704  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1705  longname), nc_fname)
1706 
1707  ! add mf6 attr
1708  call ncvar_mf6attr(ncid, var_id, iaux, nc_tag, nc_fname)
1709 
1710  ! exit define mode and write data
1711  call nf_verify(nf90_enddef(ncid), nc_fname)
1712  call nf_verify(nf90_put_var(ncid, var_id, p_mem), &
1713  nc_fname)
1714  else
1715  ! timeseries
1716  call nf_verify(nf90_put_var(ncid, &
1717  var_ids%export, p_mem, &
1718  start=(/1, 1, kper/), &
1719  count=(/dis%ncol, dis%nrow, 1/)), nc_fname)
1720  end if
1721 
1722  else
1723 
1724  if (iper == 0) then
1725  varname = export_varname(pkgname, idt%tagname, mempath, iaux=iaux)
1726  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1727  iaux=iaux, &
1728  component_type=idt%component_type, &
1729  subcomponent_type=idt%subcomponent_type)
1730 
1731  ! reenter define mode and create variable
1732  call nf_verify(nf90_redef(ncid), nc_fname)
1733  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1734  (/dim_ids%x, dim_ids%y, dim_ids%layer/), &
1735  var_id), nc_fname)
1736 
1737  ! apply chunking parameters
1738  call ncvar_chunk3d(ncid, var_id, chunk_x, chunk_y, chunk_z, nc_fname)
1739  ! deflate and shuffle
1740  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1741 
1742  ! put attr
1743  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1744  (/nf90_fill_double/)), nc_fname)
1745  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1746  longname), nc_fname)
1747 
1748  ! add grid mapping and mf6 attr
1749  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .true., &
1750  nc_fname)
1751  call ncvar_mf6attr(ncid, var_id, iaux, nc_tag, nc_fname)
1752 
1753  ! exit define mode and write data
1754  call nf_verify(nf90_enddef(ncid), nc_fname)
1755  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1, 1/), &
1756  count=(/dis%ncol, dis%nrow, dis%nlay/)), &
1757  nc_fname)
1758  else
1759  ! timeseries
1760  call nf_verify(nf90_put_var(ncid, &
1761  var_ids%export, p_mem, &
1762  start=(/1, 1, 1, kper/), &
1763  count=(/dis%ncol, dis%nrow, dis%nlay, 1/)), &
1764  nc_fname)
1765  end if
1766  end if
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:26

◆ nc_export_dbl2d()

subroutine disncstructuredmodule::nc_export_dbl2d ( real(dp), dimension(:, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
character(len=*), intent(in)  nc_fname 
)

Definition at line 1771 of file DisNCStructured.f90.

1774  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
1775  integer(I4B), intent(in) :: ncid
1776  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1777  type(StructuredNCVarIdType), intent(inout) :: var_ids
1778  type(DisType), pointer, intent(in) :: dis
1779  type(InputParamDefinitionType), pointer, intent(in) :: idt
1780  character(len=*), intent(in) :: mempath
1781  character(len=*), intent(in) :: nc_tag
1782  character(len=*), intent(in) :: pkgname
1783  character(len=*), intent(in) :: gridmap_name
1784  logical(LGP), intent(in) :: latlon
1785  integer(I4B), intent(in) :: deflate
1786  integer(I4B), intent(in) :: shuffle
1787  integer(I4B), intent(in) :: chunk_z
1788  integer(I4B), intent(in) :: chunk_y
1789  integer(I4B), intent(in) :: chunk_x
1790  character(len=*), intent(in) :: nc_fname
1791  character(len=LINELENGTH) :: varname
1792  integer(I4B) :: var_id
1793 
1794  varname = export_varname(pkgname, idt%tagname, mempath)
1795 
1796  ! reenter define mode and create variable
1797  call nf_verify(nf90_redef(ncid), nc_fname)
1798  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1799  (/dim_ids%x, dim_ids%y/), var_id), &
1800  nc_fname)
1801 
1802  ! apply chunking parameters
1803  call ncvar_chunk2d(ncid, var_id, chunk_x, chunk_y, nc_fname)
1804  ! deflate and shuffle
1805  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1806 
1807  ! put attr
1808  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1809  (/nf90_fill_double/)), nc_fname)
1810  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1811  idt%longname), nc_fname)
1812 
1813  ! add grid mapping and mf6 attr
1814  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .false., &
1815  nc_fname)
1816  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1817 
1818  ! exit define mode and write data
1819  call nf_verify(nf90_enddef(ncid), nc_fname)
1820  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1/), &
1821  count=(/dis%ncol, dis%nrow/)), &
1822  nc_fname)

◆ nc_export_dbl3d()

subroutine disncstructuredmodule::nc_export_dbl3d ( real(dp), dimension(:, :, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1827 of file DisNCStructured.f90.

1830  real(DP), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
1831  integer(I4B), intent(in) :: ncid
1832  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1833  type(StructuredNCVarIdType), intent(inout) :: var_ids
1834  type(DisType), pointer, intent(in) :: dis
1835  type(InputParamDefinitionType), pointer, intent(in) :: idt
1836  character(len=*), intent(in) :: mempath
1837  character(len=*), intent(in) :: nc_tag
1838  character(len=*), intent(in) :: pkgname
1839  character(len=*), intent(in) :: gridmap_name
1840  logical(LGP), intent(in) :: latlon
1841  integer(I4B), intent(in) :: deflate
1842  integer(I4B), intent(in) :: shuffle
1843  integer(I4B), intent(in) :: chunk_z
1844  integer(I4B), intent(in) :: chunk_y
1845  integer(I4B), intent(in) :: chunk_x
1846  character(len=*), intent(in) :: nc_fname
1847  integer(I4B) :: var_id
1848  character(len=LINELENGTH) :: varname, longname
1849 
1850  varname = export_varname(pkgname, idt%tagname, mempath)
1851  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1852  component_type=idt%component_type, &
1853  subcomponent_type=idt%subcomponent_type)
1854 
1855  ! reenter define mode and create variable
1856  call nf_verify(nf90_redef(ncid), nc_fname)
1857  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
1858  (/dim_ids%x, dim_ids%y, dim_ids%layer/), &
1859  var_id), nc_fname)
1860 
1861  ! apply chunking parameters
1862  call ncvar_chunk3d(ncid, var_id, chunk_x, chunk_y, chunk_z, nc_fname)
1863  ! deflate and shuffle
1864  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1865 
1866  ! put attr
1867  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1868  (/nf90_fill_double/)), nc_fname)
1869  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1870  longname), nc_fname)
1871 
1872  ! add grid mapping and mf6 attr
1873  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .true., &
1874  nc_fname)
1875  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1876 
1877  ! exit define mode and write data
1878  call nf_verify(nf90_enddef(ncid), nc_fname)
1879  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1, 1/), &
1880  count=(/dis%ncol, dis%nrow, dis%nlay/)), &
1881  nc_fname)

◆ nc_export_int1d()

subroutine disncstructuredmodule::nc_export_int1d ( integer(i4b), dimension(:), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
integer(i4b), intent(in)  iper,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1417 of file DisNCStructured.f90.

1420  use tdismodule, only: kper
1421  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
1422  integer(I4B), intent(in) :: ncid
1423  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1424  type(StructuredNCVarIdType), intent(inout) :: var_ids
1425  type(DisType), pointer, intent(in) :: dis
1426  type(InputParamDefinitionType), pointer, intent(in) :: idt
1427  character(len=*), intent(in) :: mempath
1428  character(len=*), intent(in) :: nc_tag
1429  character(len=*), intent(in) :: pkgname
1430  character(len=*), intent(in) :: gridmap_name
1431  logical(LGP), intent(in) :: latlon
1432  integer(I4B), intent(in) :: deflate
1433  integer(I4B), intent(in) :: shuffle
1434  integer(I4B), intent(in) :: chunk_z
1435  integer(I4B), intent(in) :: chunk_y
1436  integer(I4B), intent(in) :: chunk_x
1437  integer(I4B), intent(in) :: iper
1438  character(len=*), intent(in) :: nc_fname
1439  integer(I4B) :: var_id, axis_sz
1440  character(len=LINELENGTH) :: varname, longname
1441 
1442  varname = export_varname(pkgname, idt%tagname, mempath)
1443 
1444  if (idt%shape == 'NROW' .or. &
1445  idt%shape == 'NCOL' .or. &
1446  idt%shape == 'NCPL' .or. &
1447  idt%shape == 'NAUX NCPL') then
1448 
1449  if (iper == 0) then
1450  select case (idt%shape)
1451  case ('NROW')
1452  axis_sz = dim_ids%y
1453  case ('NCOL')
1454  axis_sz = dim_ids%x
1455  end select
1456 
1457  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
1458  component_type=idt%component_type, &
1459  subcomponent_type=idt%subcomponent_type)
1460 
1461  ! reenter define mode and create variable
1462  call nf_verify(nf90_redef(ncid), nc_fname)
1463  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
1464  (/axis_sz/), var_id), &
1465  nc_fname)
1466 
1467  ! NROW/NCOL shapes use default chunking
1468  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1469 
1470  ! put attr
1471  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1472  (/nf90_fill_int/)), nc_fname)
1473  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1474  longname), nc_fname)
1475 
1476  ! add mf6 attr
1477  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1478 
1479  ! exit define mode and write data
1480  call nf_verify(nf90_enddef(ncid), nc_fname)
1481  call nf_verify(nf90_put_var(ncid, var_id, p_mem), &
1482  nc_fname)
1483  else
1484  ! timeseries
1485  call nf_verify(nf90_put_var(ncid, &
1486  var_ids%export, p_mem, &
1487  start=(/1, 1, kper/), &
1488  count=(/dis%ncol, dis%nrow, 1/)), nc_fname)
1489  end if
1490 
1491  else
1492 
1493  if (iper == 0) then
1494  ! reenter define mode and create variable
1495  call nf_verify(nf90_redef(ncid), nc_fname)
1496  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
1497  (/dim_ids%x, dim_ids%y, dim_ids%layer/), &
1498  var_id), nc_fname)
1499 
1500  ! apply chunking parameters
1501  call ncvar_chunk3d(ncid, var_id, chunk_x, chunk_y, chunk_z, nc_fname)
1502  ! deflate and shuffle
1503  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1504 
1505  ! put attr
1506  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1507  (/nf90_fill_int/)), nc_fname)
1508  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1509  idt%longname), nc_fname)
1510 
1511  ! add grid mapping and mf6 attr
1512  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .true., &
1513  nc_fname)
1514  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1515 
1516  ! exit define mode and write data
1517  call nf_verify(nf90_enddef(ncid), nc_fname)
1518  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1, 1/), &
1519  count=(/dis%ncol, dis%nrow, dis%nlay/)), &
1520  nc_fname)
1521  else
1522  ! timeseries
1523  call nf_verify(nf90_put_var(ncid, &
1524  var_ids%export, p_mem, &
1525  start=(/1, 1, 1, kper/), &
1526  count=(/dis%ncol, dis%nrow, dis%nlay, 1/)), &
1527  nc_fname)
1528  end if
1529  end if

◆ nc_export_int2d()

subroutine disncstructuredmodule::nc_export_int2d ( integer(i4b), dimension(:, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
character(len=*), intent(in)  nc_fname 
)

Definition at line 1534 of file DisNCStructured.f90.

1537  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
1538  integer(I4B), intent(in) :: ncid
1539  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1540  type(StructuredNCVarIdType), intent(inout) :: var_ids
1541  type(DisType), pointer, intent(in) :: dis
1542  type(InputParamDefinitionType), pointer, intent(in) :: idt
1543  character(len=*), intent(in) :: mempath
1544  character(len=*), intent(in) :: nc_tag
1545  character(len=*), intent(in) :: pkgname
1546  character(len=*), intent(in) :: gridmap_name
1547  logical(LGP), intent(in) :: latlon
1548  integer(I4B), intent(in) :: deflate
1549  integer(I4B), intent(in) :: shuffle
1550  integer(I4B), intent(in) :: chunk_z
1551  integer(I4B), intent(in) :: chunk_y
1552  integer(I4B), intent(in) :: chunk_x
1553  character(len=*), intent(in) :: nc_fname
1554  character(len=LINELENGTH) :: varname
1555  integer(I4B) :: var_id
1556 
1557  varname = export_varname(pkgname, idt%tagname, mempath)
1558 
1559  ! reenter define mode and create variable
1560  call nf_verify(nf90_redef(ncid), nc_fname)
1561  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
1562  (/dim_ids%x, dim_ids%y/), var_id), &
1563  nc_fname)
1564 
1565  ! apply chunking parameters
1566  call ncvar_chunk2d(ncid, var_id, chunk_x, chunk_y, nc_fname)
1567  ! deflate and shuffle
1568  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1569 
1570  ! put attr
1571  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1572  (/nf90_fill_int/)), nc_fname)
1573  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1574  idt%longname), nc_fname)
1575 
1576  ! add grid mapping and mf6 attr
1577  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .false., &
1578  nc_fname)
1579  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1580 
1581  ! exit define mode and write data
1582  call nf_verify(nf90_enddef(ncid), nc_fname)
1583  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1/), &
1584  count=(/dis%ncol, dis%nrow/)), &
1585  nc_fname)

◆ nc_export_int3d()

subroutine disncstructuredmodule::nc_export_int3d ( integer(i4b), dimension(:, :, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(structuredncdimidtype), intent(inout)  dim_ids,
type(structuredncvaridtype), intent(inout)  var_ids,
type(distype), intent(in), pointer  dis,
type(inputparamdefinitiontype), intent(in), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_z,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_x,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1590 of file DisNCStructured.f90.

1593  integer(I4B), dimension(:, :, :), pointer, contiguous, intent(in) :: p_mem
1594  integer(I4B), intent(in) :: ncid
1595  type(StructuredNCDimIdType), intent(inout) :: dim_ids
1596  type(StructuredNCVarIdType), intent(inout) :: var_ids
1597  type(DisType), pointer, intent(in) :: dis
1598  type(InputParamDefinitionType), pointer, intent(in) :: idt
1599  character(len=*), intent(in) :: mempath
1600  character(len=*), intent(in) :: nc_tag
1601  character(len=*), intent(in) :: pkgname
1602  character(len=*), intent(in) :: gridmap_name
1603  logical(LGP), intent(in) :: latlon
1604  integer(I4B), intent(in) :: deflate
1605  integer(I4B), intent(in) :: shuffle
1606  integer(I4B), intent(in) :: chunk_z
1607  integer(I4B), intent(in) :: chunk_y
1608  integer(I4B), intent(in) :: chunk_x
1609  character(len=*), intent(in) :: nc_fname
1610  character(len=LINELENGTH) :: varname
1611  integer(I4B) :: var_id
1612 
1613  varname = export_varname(pkgname, idt%tagname, mempath)
1614 
1615  ! reenter define mode and create variable
1616  call nf_verify(nf90_redef(ncid), nc_fname)
1617  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
1618  (/dim_ids%x, dim_ids%y, dim_ids%layer/), &
1619  var_id), nc_fname)
1620 
1621  ! apply chunking parameters
1622  call ncvar_chunk3d(ncid, var_id, chunk_x, chunk_y, chunk_z, nc_fname)
1623  ! deflate and shuffle
1624  call ncvar_deflate(ncid, var_id, deflate, shuffle, nc_fname)
1625 
1626  ! put attr
1627  call nf_verify(nf90_put_att(ncid, var_id, '_FillValue', &
1628  (/nf90_fill_int/)), nc_fname)
1629  call nf_verify(nf90_put_att(ncid, var_id, 'long_name', &
1630  idt%longname), nc_fname)
1631 
1632  ! add grid mapping and mf6 attr
1633  call ncvar_gridmap(ncid, var_id, gridmap_name, latlon, .true., &
1634  nc_fname)
1635  call ncvar_mf6attr(ncid, var_id, 0, nc_tag, nc_fname)
1636 
1637  ! exit define mode and write data
1638  call nf_verify(nf90_enddef(ncid), nc_fname)
1639  call nf_verify(nf90_put_var(ncid, var_id, p_mem, start=(/1, 1, 1/), &
1640  count=(/dis%ncol, dis%nrow, dis%nlay/)), &
1641  nc_fname)

◆ ncvar_chunk2d()

subroutine disncstructuredmodule::ncvar_chunk2d ( integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  varid,
integer(i4b), intent(in)  chunk_x,
integer(i4b), intent(in)  chunk_y,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1310 of file DisNCStructured.f90.

1311  integer(I4B), intent(in) :: ncid
1312  integer(I4B), intent(in) :: varid
1313  integer(I4B), intent(in) :: chunk_x
1314  integer(I4B), intent(in) :: chunk_y
1315  character(len=*), intent(in) :: nc_fname
1316  if (chunk_y > 0 .and. chunk_x > 0) then
1317  call nf_verify(nf90_def_var_chunking(ncid, varid, nf90_chunked, &
1318  (/chunk_x, chunk_y/)), nc_fname)
1319  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvar_chunk3d()

subroutine disncstructuredmodule::ncvar_chunk3d ( integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  varid,
integer(i4b), intent(in)  chunk_x,
integer(i4b), intent(in)  chunk_y,
integer(i4b), intent(in)  chunk_z,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1324 of file DisNCStructured.f90.

1325  integer(I4B), intent(in) :: ncid
1326  integer(I4B), intent(in) :: varid
1327  integer(I4B), intent(in) :: chunk_x
1328  integer(I4B), intent(in) :: chunk_y
1329  integer(I4B), intent(in) :: chunk_z
1330  character(len=*), intent(in) :: nc_fname
1331  if (chunk_z > 0 .and. chunk_y > 0 .and. chunk_x > 0) then
1332  call nf_verify(nf90_def_var_chunking(ncid, varid, nf90_chunked, &
1333  (/chunk_x, chunk_y, chunk_z/)), &
1334  nc_fname)
1335  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvar_deflate()

subroutine disncstructuredmodule::ncvar_deflate ( integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  varid,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1340 of file DisNCStructured.f90.

1341  integer(I4B), intent(in) :: ncid
1342  integer(I4B), intent(in) :: varid
1343  integer(I4B), intent(in) :: deflate
1344  integer(I4B), intent(in) :: shuffle
1345  character(len=*), intent(in) :: nc_fname
1346  ! deflate and shuffle
1347  if (deflate >= 0) then
1348  call nf_verify(nf90_def_var_deflate(ncid, varid, shuffle=shuffle, &
1349  deflate=1, deflate_level=deflate), &
1350  nc_fname)
1351  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvar_gridmap()

subroutine disncstructuredmodule::ncvar_gridmap ( integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  varid,
character(len=*), intent(in)  gridmap_name,
logical(lgp), intent(in)  latlon,
logical(lgp), intent(in)  has_layer,
character(len=*), intent(in)  nc_fname 
)
private

has_layer must be true only for variables carrying the layer, y, and x dimensions – z(layer, y, x) can only be legally referenced via coordinates from a variable whose dimensions are a superset of its own (CF-1.13 5.2). 2D (y, x)-only variables such as dis_top must pass has_layer=.false. z is written unconditionally, independent of gridmap_name/latlon.

Definition at line 1363 of file DisNCStructured.f90.

1365  integer(I4B), intent(in) :: ncid
1366  integer(I4B), intent(in) :: varid
1367  character(len=*), intent(in) :: gridmap_name
1368  logical(LGP), intent(in) :: latlon
1369  logical(LGP), intent(in) :: has_layer
1370  character(len=*), intent(in) :: nc_fname
1371  character(len=LINELENGTH) :: coords
1372  coords = ''
1373  ! NOTE: x/y are not listed here even when gridmap_name is set -- unlike
1374  ! lon/lat (real 2D auxiliary coordinates), x/y are true CF dimension
1375  ! coordinates already discoverable by dimension-name matching alone, so
1376  ! listing them in 'coordinates' is redundant (CF-1.13 Ch.5 preamble).
1377  if (latlon) then
1378  coords = 'lon lat'
1379  end if
1380  if (has_layer) then
1381  if (len_trim(coords) > 0) then
1382  coords = trim(coords)//' z'
1383  else
1384  coords = 'z'
1385  end if
1386  end if
1387  if (len_trim(coords) > 0) then
1388  call nf_verify(nf90_put_att(ncid, varid, 'coordinates', trim(coords)), &
1389  nc_fname)
1390  end if
1391  if (gridmap_name /= '') then
1392  call nf_verify(nf90_put_att(ncid, varid, 'grid_mapping', gridmap_name), &
1393  nc_fname)
1394  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncvar_mf6attr()

subroutine disncstructuredmodule::ncvar_mf6attr ( integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  varid,
integer(i4b), intent(in)  iaux,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 1399 of file DisNCStructured.f90.

1400  integer(I4B), intent(in) :: ncid
1401  integer(I4B), intent(in) :: varid
1402  integer(I4B), intent(in) :: iaux
1403  character(len=*), intent(in) :: nc_tag
1404  character(len=*), intent(in) :: nc_fname
1405  if (nc_tag /= '') then
1406  call nf_verify(nf90_put_att(ncid, varid, 'modflow_input', &
1407  nc_tag), nc_fname)
1408  if (iaux > 0) then
1409  call nf_verify(nf90_put_att(ncid, varid, 'modflow_iaux', &
1410  iaux), nc_fname)
1411  end if
1412  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ package_step()

subroutine disncstructuredmodule::package_step ( class(disncstructuredtype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg 
)

Definition at line 566 of file DisNCStructured.f90.

567  use tdismodule, only: totim, kper
570  class(DisNCStructuredType), intent(inout) :: this
571  class(ExportPackageType), pointer, intent(in) :: export_pkg
572  type(InputParamDefinitionType), pointer :: idt
573  integer(I4B), dimension(:), pointer, contiguous :: int1d
574  real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
575  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
576  character(len=LINELENGTH) :: nc_tag
577  integer(I4B) :: iaux, iparam, nvals, n
578  integer(I4B), pointer :: nbound
579 
580  ! initialize
581  iaux = 0
582 
583  ! export defined period input
584  do iparam = 1, export_pkg%nparam
585  if (export_pkg%iper /= kper) cycle
586  ! check if variable was read this period
587  if (export_pkg%param_reads(iparam)%invar < 1) cycle
588 
589  ! set input definition
590  idt => &
591  get_param_definition_type(export_pkg%mf6_input%param_dfns, &
592  export_pkg%mf6_input%component_type, &
593  export_pkg%mf6_input%subcomponent_type, &
594  'PERIOD', export_pkg%param_names(iparam), '')
595 
596  ! set variable input tag
597  nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
598  idt)
599 
600  ! export arrays
601  select case (idt%datatype)
602  case ('INTEGER1D')
603  call mem_setptr(int1d, idt%mf6varname, export_pkg%mf6_input%mempath)
604  this%var_ids%export = export_pkg%varids_param(iparam, 1)
605  call nc_export_array(int1d, this%ncid, this%dim_ids, this%var_ids, &
606  this%dis, idt, export_pkg%mf6_input%mempath, &
607  nc_tag, export_pkg%mf6_input%subcomponent_name, &
608  this%gridmap_name, this%latlon, this%deflate, &
609  this%shuffle, this%chunk_z, this%chunk_y, &
610  this%chunk_x, kper, this%nc_fname)
611  case ('DOUBLE1D')
612  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
613  this%var_ids%export = export_pkg%varids_param(iparam, 1)
614  select case (idt%shape)
615  case ('NCPL')
616  call nc_export_array(dbl1d, this%ncid, this%dim_ids, this%var_ids, &
617  this%dis, idt, export_pkg%mf6_input%mempath, &
618  nc_tag, export_pkg%mf6_input%subcomponent_name, &
619  this%gridmap_name, this%latlon, this%deflate, &
620  this%shuffle, this%chunk_z, this%chunk_y, &
621  this%chunk_x, kper, iaux, this%nc_fname)
622  case ('NODES')
623  nvals = this%dis%nodesuser
624  allocate (nodes(nvals))
625  nodes = dnodata
626  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
627  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
628  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
629  do n = 1, nbound
630  nodes(int1d(n)) = dbl1d(n)
631  end do
632  call nc_export_array(nodes, this%ncid, this%dim_ids, this%var_ids, &
633  this%dis, idt, export_pkg%mf6_input%mempath, &
634  nc_tag, export_pkg%mf6_input%subcomponent_name, &
635  this%gridmap_name, this%latlon, this%deflate, &
636  this%shuffle, this%chunk_z, this%chunk_y, &
637  this%chunk_x, kper, iaux, this%nc_fname)
638  deallocate (nodes)
639  case default
640  end select
641  case ('DOUBLE2D')
642  call mem_setptr(dbl2d, idt%mf6varname, export_pkg%mf6_input%mempath)
643  select case (idt%shape)
644  case ('NAUX NCPL')
645  nvals = this%dis%nrow * this%dis%ncol
646  allocate (nodes(nvals))
647  do iaux = 1, size(dbl2d, dim=1) !naux
648  this%var_ids%export = export_pkg%varids_aux(iaux, 1)
649  do n = 1, nvals
650  nodes(n) = dbl2d(iaux, n)
651  end do
652  call nc_export_array(nodes, this%ncid, this%dim_ids, this%var_ids, &
653  this%dis, idt, export_pkg%mf6_input%mempath, &
654  nc_tag, export_pkg%mf6_input%subcomponent_name, &
655  this%gridmap_name, this%latlon, this%deflate, &
656  this%shuffle, this%chunk_z, this%chunk_y, &
657  this%chunk_x, kper, iaux, this%nc_fname)
658  end do
659  deallocate (nodes)
660  case ('NAUX NODES')
661  nvals = this%dis%nodesuser
662  allocate (nodes(nvals))
663  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
664  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
665  do iaux = 1, size(dbl2d, dim=1) ! naux
666  nodes = dnodata
667  this%var_ids%export = export_pkg%varids_aux(iaux, 1)
668  do n = 1, nbound
669  nodes(int1d(n)) = dbl2d(iaux, n)
670  end do
671  call nc_export_array(nodes, this%ncid, this%dim_ids, this%var_ids, &
672  this%dis, idt, export_pkg%mf6_input%mempath, &
673  nc_tag, export_pkg%mf6_input%subcomponent_name, &
674  this%gridmap_name, this%latlon, this%deflate, &
675  this%shuffle, this%chunk_z, this%chunk_y, &
676  this%chunk_x, kper, iaux, this%nc_fname)
677 
678  end do
679  deallocate (nodes)
680  case default
681  end select
682  case default
683  ! no-op, no other datatypes exported
684  end select
685  end do
686 
687  ! write to time coordinate variable
688  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
689  totim, start=(/kper/)), &
690  this%nc_fname)
691 
692  ! synchronize file
693  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:35
Here is the call graph for this function:

◆ step()

subroutine disncstructuredmodule::step ( class(disncstructuredtype), intent(inout)  this)

Definition at line 281 of file DisNCStructured.f90.

282  use constantsmodule, only: dhnoflo
283  use tdismodule, only: totim
284  class(DisNCStructuredType), intent(inout) :: this
285  real(DP), dimension(:), pointer, contiguous :: dbl1d
286  integer(I4B) :: n, istp
287 
288  ! set global step index
289  istp = this%istp()
290 
291  if (size(this%dis%nodeuser) < &
292  size(this%dis%nodereduced)) then
293  allocate (dbl1d(size(this%dis%nodereduced)))
294  dbl1d = dhnoflo
295  do n = 1, size(this%dis%nodereduced)
296  if (this%dis%nodereduced(n) > 0) then
297  dbl1d(n) = this%x(this%dis%nodereduced(n))
298  end if
299  end do
300  ! write step data to dependent variable
301  call nf_verify(nf90_put_var(this%ncid, &
302  this%var_ids%dependent, dbl1d, &
303  start=(/1, 1, 1, istp/), &
304  count=(/this%dis%ncol, &
305  this%dis%nrow, &
306  this%dis%nlay, 1/)), &
307  this%nc_fname)
308  deallocate (dbl1d)
309  else
310  ! write step data to dependent variable
311  call nf_verify(nf90_put_var(this%ncid, &
312  this%var_ids%dependent, this%x, &
313  start=(/1, 1, 1, istp/), &
314  count=(/this%dis%ncol, &
315  this%dis%nrow, &
316  this%dis%nlay, 1/)), &
317  this%nc_fname)
318  end if
319 
320  ! write to time coordinate variable
321  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
322  totim, start=(/istp/)), &
323  this%nc_fname)
324 
325  ! synchronize file
326  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
Here is the call graph for this function: