MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
ncmodelexportmodule Module Reference

This module contains the NCModelExportModule. More...

Data Types

type  exportpackagetype
 
type  ncexportannotation
 netcdf export attribute annotations More...
 
type  ncmodelexporttype
 base class for an export model More...
 
type  ncbasemodelexporttype
 abstract type for model netcdf export type More...
 
interface  model_define
 abstract interfaces for model netcdf export type More...
 
interface  model_step
 
interface  package_export
 
interface  package_export_ilayer
 

Enumerations

enum  
 netcdf export types enumerator More...
 

Functions/Subroutines

subroutine epkg_init (this, mf6_input, mshape, naux, param_names, nparam)
 initialize dynamic package export object More...
 
subroutine epkg_destroy (this)
 destroy dynamic package export object More...
 
subroutine set (this, modelname, modeltype, modelfname, nctype, disenum)
 set netcdf file scoped attributes More...
 
subroutine export_init (this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
 initialization of model netcdf export More...
 
class(exportpackagetype) function, pointer export_get (this, idx)
 retrieve dynamic export object from package list More...
 
character(len=linelength) function input_attribute (this, pkgname, idt)
 build modflow_input attribute string More...
 
integer(i4b) function istp (this)
 step index for timeseries data More...
 
character(len=linelength) function, public export_varname (pkgname, tagname, mempath, layer, iaux)
 build netcdf variable name More...
 
character(len=linelength) function, public export_longname (longname, pkgname, tagname, mempath, layer, iaux)
 build netcdf variable longname More...
 
subroutine export_input (this)
 netcdf dynamic package period export More...
 
subroutine export_destroy (this)
 destroy model netcdf export object More...
 

Variables

@, public netcdf_undef = 0
 undefined netcdf export type More...
 
@, public netcdf_structured = 1
 netcdf structrured export More...
 
@, public netcdf_mesh2d = 2
 netcdf ugrid layered mesh export More...
 

Detailed Description

This module defines a model export and base type for supported netcdf files and is not dependent on netcdf libraries.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
private

Definition at line 31 of file NCModel.f90.

Function/Subroutine Documentation

◆ epkg_destroy()

subroutine ncmodelexportmodule::epkg_destroy ( class(exportpackagetype), intent(inout)  this)

Definition at line 193 of file NCModel.f90.

195  class(ExportPackageType), intent(inout) :: this
196  if (allocated(this%param_names)) deallocate (this%param_names)
Input definition module.
Input parameter definition. Describes an input parameter.

◆ epkg_init()

subroutine ncmodelexportmodule::epkg_init ( class(exportpackagetype), intent(inout)  this,
type(modflowinputtype), intent(in)  mf6_input,
integer(i4b), dimension(:), intent(in), pointer, contiguous  mshape,
integer(i4b), intent(in)  naux,
character(len=linelength), dimension(:), intent(in), allocatable  param_names,
integer(i4b), intent(in)  nparam 
)
private
Parameters
[in]mshapemodel shape

Definition at line 145 of file NCModel.f90.

151  class(ExportPackageType), intent(inout) :: this
152  type(ModflowInputType), intent(in) :: mf6_input
153  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: mshape !< model shape
154  integer(I4B), intent(in) :: naux
155  character(len=LINELENGTH), dimension(:), allocatable, &
156  intent(in) :: param_names
157  integer(I4B), intent(in) :: nparam
158  integer(I4B) :: n
159  character(len=LENVARNAME) :: rs_varname
160  character(len=LENMEMPATH) :: input_mempath
161  integer(I4B), pointer :: rsvar
162 
163  this%mf6_input = mf6_input
164  this%mshape => mshape
165  this%nparam = nparam
166  this%naux = naux
167  this%eper = 0
168 
169  input_mempath = create_mem_path(component=mf6_input%component_name, &
170  subcomponent=mf6_input%subcomponent_name, &
171  context=idm_context)
172 
173  ! allocate param arrays
174  allocate (this%param_names(nparam))
175  allocate (this%param_reads(nparam))
176  allocate (this%varids_param(nparam, mshape(1)))
177  allocate (this%varids_aux(naux, mshape(1)))
178 
179  ! set param arrays
180  do n = 1, nparam
181  this%param_names(n) = param_names(n)
182  rs_varname = rsv_name(param_names(n))
183  call mem_setptr(rsvar, rs_varname, mf6_input%mempath)
184  this%param_reads(n)%invar => rsvar
185  end do
186 
187  ! set pointer to loaded input period
188  call mem_setptr(this%iper, 'IPER', mf6_input%mempath)
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
Here is the call graph for this function:

◆ export_destroy()

subroutine ncmodelexportmodule::export_destroy ( class(ncmodelexporttype), intent(inout)  this)

Definition at line 547 of file NCModel.f90.

550  class(NCModelExportType), intent(inout) :: this
551  ! override in derived class
552  deallocate (this%deflate)
553  deallocate (this%shuffle)
554  deallocate (this%input_attr)
555  deallocate (this%chunk_time)
556  ! Deallocate idm memory
557  if (this%ncf_mempath /= '') then
558  call memorystore_remove(this%modelname, 'NCF', idm_context)
559  end if
subroutine, public memorystore_remove(component, subcomponent, context)
Here is the call graph for this function:

◆ export_get()

class(exportpackagetype) function, pointer ncmodelexportmodule::export_get ( class(ncmodelexporttype), intent(inout)  this,
integer(i4b), intent(in)  idx 
)

Definition at line 393 of file NCModel.f90.

394  use listmodule, only: listtype
395  class(NCModelExportType), intent(inout) :: this
396  integer(I4B), intent(in) :: idx
397  class(ExportPackageType), pointer :: res
398  class(*), pointer :: obj
399  nullify (res)
400  obj => this%pkglist%GetItem(idx)
401  if (associated(obj)) then
402  select type (obj)
403  class is (exportpackagetype)
404  res => obj
405  end select
406  end if
A generic heterogeneous doubly-linked list.
Definition: List.f90:14

◆ export_init()

subroutine ncmodelexportmodule::export_init ( class(ncmodelexporttype), 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 
)

Definition at line 274 of file NCModel.f90.

276  use tdismodule, only: datetime0, nper, nstp
280  use inputoutputmodule, only: lowcase
283  class(NCModelExportType), intent(inout) :: this
284  character(len=*), intent(in) :: modelname
285  character(len=*), intent(in) :: modeltype
286  character(len=*), intent(in) :: modelfname
287  character(len=*), intent(in) :: nc_fname
288  integer(I4B), intent(in) :: disenum
289  integer(I4B), intent(in) :: nctype
290  integer(I4B), intent(in) :: iout
291  character(len=LENMEMPATH) :: model_mempath
292  type(UtlNcfParamFoundType) :: ncf_found
293 
294  ! allocate
295  allocate (this%deflate)
296  allocate (this%shuffle)
297  allocate (this%input_attr)
298  allocate (this%chunk_time)
299 
300  ! initialize
301  this%modelname = modelname
302  this%modeltype = modeltype
303  this%modelfname = modelfname
304  this%nc_fname = nc_fname
305  this%gridmap_name = ''
306  this%ncf_mempath = ''
307  this%wkt = ''
308  this%datetime = ''
309  this%xname = ''
310  this%lenunits = ''
311  this%disenum = disenum
312  this%ncid = 0
313  this%totnstp = 0
314  this%deflate = -1
315  this%shuffle = 0
316  this%input_attr = 1
317  this%chunk_time = -1
318  this%iout = iout
319  this%chunking_active = .false.
320 
321  ! set file scoped attributes
322  call this%annotation%set(modelname, modeltype, modelfname, nctype, disenum)
323 
324  ! set dependent variable basename
325  select case (modeltype)
326  case ('GWF')
327  this%xname = 'head'
328  case ('GWT')
329  this%xname = 'concentration'
330  case ('GWE')
331  this%xname = 'temperature'
332  case default
333  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
334  call store_error(errmsg)
335  call store_error_filename(modelfname)
336  end select
337 
338  ! set discretization input mempath
339  if (disenum == dis) then
340  this%dis_mempath = create_mem_path(modelname, 'DIS', idm_context)
341  else if (disenum == disu) then
342  this%dis_mempath = create_mem_path(modelname, 'DISU', idm_context)
343  else if (disenum == disv) then
344  this%dis_mempath = create_mem_path(modelname, 'DISV', idm_context)
345  end if
346 
347  ! set dependent variable pointer
348  model_mempath = create_mem_path(component=modelname)
349  call mem_setptr(this%x, 'X', model_mempath)
350 
351  ! set ncf_mempath if provided
352  if (filein_fname(this%ncf_mempath, 'NCF6_MEMPATH', this%dis_mempath, &
353  modelfname)) then
354  call mem_set_value(this%wkt, 'WKT', this%ncf_mempath, &
355  ncf_found%wkt)
356  call mem_set_value(this%deflate, 'DEFLATE', this%ncf_mempath, &
357  ncf_found%deflate)
358  call mem_set_value(this%shuffle, 'SHUFFLE', this%ncf_mempath, &
359  ncf_found%shuffle)
360  call mem_set_value(this%input_attr, 'ATTR_OFF', this%ncf_mempath, &
361  ncf_found%attr_off)
362  call mem_set_value(this%chunk_time, 'CHUNK_TIME', this%ncf_mempath, &
363  ncf_found%chunk_time)
364  end if
365 
366  if (ncf_found%wkt) then
367  this%gridmap_name = 'projection'
368  end if
369 
370  ! ATTR_OFF turns off modflow 6 input attributes
371  if (ncf_found%attr_off) then
372  this%input_attr = 0
373  end if
374 
375  ! set datetime string
376  if (datetime0 /= '') then
377  this%datetime = 'days since '//trim(datetime0)
378  else
379  ! January 1, 1970 at 00:00:00 UTC
380  this%datetime = 'days since 1970-01-01T00:00:00'
381  end if
382 
383  ! set total nstp
384  if (isim_mode == mvalidate) then
385  this%totnstp = nper
386  else
387  this%totnstp = sum(nstp)
388  end if
subroutine, public lowcase(word)
Convert to lower case.
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
logical(lgp) function, public filein_fname(filename, tagname, input_mempath, input_fname)
enforce and set a single input filename provided via FILEIN keyword
integer(i4b), dimension(:), pointer, public, contiguous nstp
number of time steps in each stress period
Definition: tdis.f90:39
character(len=lendatetime), pointer, public datetime0
starting date and time for the simulation
Definition: tdis.f90:41
integer(i4b), pointer, public nper
number of stress period
Definition: tdis.f90:21
Here is the call graph for this function:

◆ export_input()

subroutine ncmodelexportmodule::export_input ( class(ncbasemodelexporttype), intent(inout)  this)

Definition at line 529 of file NCModel.f90.

530  use tdismodule, only: kper
531  class(NCBaseModelExportType), intent(inout) :: this
532  integer(I4B) :: idx
533  class(ExportPackageType), pointer :: export_pkg
534  do idx = 1, this%pkglist%Count()
535  export_pkg => this%get(idx)
536  ! period input already exported
537  if (export_pkg%eper >= kper) cycle
538  ! update export package
539  call this%package_step(export_pkg)
540  ! update exported iper
541  export_pkg%eper = kper
542  end do
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23

◆ export_longname()

character(len=linelength) function, public ncmodelexportmodule::export_longname ( character(len=*), intent(in)  longname,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  mempath,
integer(i4b), intent(in), optional  layer,
integer(i4b), intent(in), optional  iaux 
)

Definition at line 483 of file NCModel.f90.

487  use inputoutputmodule, only: lowcase
488  character(len=*), intent(in) :: longname
489  character(len=*), intent(in) :: pkgname
490  character(len=*), intent(in) :: tagname
491  character(len=*), intent(in) :: mempath
492  integer(I4B), optional, intent(in) :: layer
493  integer(I4B), optional, intent(in) :: iaux
494  character(len=LINELENGTH) :: lname
495  type(CharacterStringType), dimension(:), pointer, &
496  contiguous :: auxnames
497  character(len=LINELENGTH) :: pname, vname, auxname
498  pname = pkgname
499  vname = tagname
500  call lowcase(pname)
501  call lowcase(vname)
502  if (longname == '') then
503  lname = trim(pname)//' '//trim(vname)
504  else
505  lname = longname
506  end if
507 
508  if (present(iaux)) then
509  if (iaux > 0) then
510  if (tagname == 'AUX') then
511  ! reset vname to auxiliary variable name
512  call mem_setptr(auxnames, 'AUXILIARY', mempath)
513  auxname = auxnames(iaux)
514  call lowcase(auxname)
515  lname = trim(lname)//' '//trim(auxname)
516  end if
517  end if
518  end if
519 
520  if (present(layer)) then
521  if (layer > 0) then
522  write (lname, '(a,i0)') trim(lname)//' layer ', layer
523  end if
524  end if
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_varname()

character(len=linelength) function, public ncmodelexportmodule::export_varname ( character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
character(len=*), intent(in)  mempath,
integer(i4b), intent(in), optional  layer,
integer(i4b), intent(in), optional  iaux 
)

Definition at line 442 of file NCModel.f90.

446  use inputoutputmodule, only: lowcase
447  character(len=*), intent(in) :: pkgname
448  character(len=*), intent(in) :: tagname
449  character(len=*), intent(in) :: mempath
450  integer(I4B), optional, intent(in) :: layer
451  integer(I4B), optional, intent(in) :: iaux
452  character(len=LINELENGTH) :: varname
453  type(CharacterStringType), dimension(:), pointer, &
454  contiguous :: auxnames
455  character(len=LINELENGTH) :: pname, vname
456  vname = tagname
457  pname = pkgname
458 
459  if (present(iaux)) then
460  if (iaux > 0) then
461  if (tagname == 'AUX') then
462  ! reset vname to auxiliary variable name
463  call mem_setptr(auxnames, 'AUXILIARY', mempath)
464  vname = auxnames(iaux)
465  end if
466  end if
467  end if
468 
469  call lowcase(vname)
470  call lowcase(pname)
471  varname = trim(pname)//'_'//trim(vname)
472 
473  if (present(layer)) then
474  if (layer > 0) then
475  !write (varname, '(a,i0)') trim(varname)//'_L', layer
476  write (varname, '(a,i0)') trim(varname)//'_l', layer
477  end if
478  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ input_attribute()

character(len=linelength) function ncmodelexportmodule::input_attribute ( class(ncmodelexporttype), intent(inout)  this,
character(len=*), intent(in)  pkgname,
type(inputparamdefinitiontype), intent(in), pointer  idt 
)

Definition at line 411 of file NCModel.f90.

412  use inputoutputmodule, only: lowcase
415  class(NCModelExportType), intent(inout) :: this
416  character(len=*), intent(in) :: pkgname
417  type(InputParamDefinitionType), pointer, intent(in) :: idt
418  character(len=LINELENGTH) :: attr
419  attr = ''
420  if (this%input_attr > 0) then
421  attr = trim(this%modelname)//mempathseparator//trim(pkgname)// &
422  mempathseparator//trim(idt%tagname)
423  end if
character(len=lenmemseparator), parameter mempathseparator
used to build up the memory address for the stored variables
Here is the call graph for this function:

◆ istp()

integer(i4b) function ncmodelexportmodule::istp ( class(ncmodelexporttype), intent(inout)  this)

Definition at line 428 of file NCModel.f90.

429  use tdismodule, only: kstp, kper, nstp
430  class(NCModelExportType), intent(inout) :: this
431  integer(I4B) :: n, istp
432  istp = kstp
433  if (kper > 1) then
434  do n = 1, kper - 1
435  istp = istp + nstp(n)
436  end do
437  end if
integer(i4b), pointer, public kstp
current time step number
Definition: tdis.f90:24

◆ set()

subroutine ncmodelexportmodule::set ( class(ncexportannotation), intent(inout)  this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelfname,
integer(i4b), intent(in)  nctype,
integer(i4b), intent(in)  disenum 
)

Definition at line 201 of file NCModel.f90.

202  use versionmodule, only: version
203  class(NCExportAnnotation), intent(inout) :: this
204  character(len=*), intent(in) :: modelname
205  character(len=*), intent(in) :: modeltype
206  character(len=*), intent(in) :: modelfname
207  integer(I4B), intent(in) :: nctype
208  integer(I4B), intent(in) :: disenum
209  integer :: values(8)
210 
211  this%title = ''
212  this%model = ''
213  this%mesh = ''
214  this%grid = ''
215  this%history = ''
216  this%source = ''
217  this%conventions = ''
218  this%stdname = ''
219  this%longname = ''
220 
221  ! set file conventions
222  this%conventions = 'CF-1.11'
223  if (nctype == netcdf_mesh2d) this%conventions = &
224  trim(this%conventions)//' UGRID-1.0'
225 
226  ! set model specific attributes
227  select case (modeltype)
228  case ('GWF')
229  this%title = trim(modelname)//' hydraulic head'
230  this%longname = 'head'
231  case ('GWT')
232  this%title = trim(modelname)//' concentration'
233  this%longname = 'concentration'
234  case ('GWE')
235  this%title = trim(modelname)//' temperature'
236  this%longname = 'temperature'
237  case default
238  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
239  call store_error(errmsg)
240  call store_error_filename(modelfname)
241  end select
242 
243  if (isim_mode == mvalidate) then
244  this%title = trim(this%title)//' array input'
245  end if
246 
247  ! set mesh type
248  if (nctype == netcdf_mesh2d) then
249  this%mesh = 'LAYERED'
250  end if
251 
252  ! set grid type
253  if (disenum == dis) then
254  this%grid = 'STRUCTURED'
255  else if (disenum == disv) then
256  this%grid = 'VERTEX'
257  end if
258 
259  ! model description string
260  this%model = trim(modeltype)//'6: '//trim(modelname)
261 
262  ! modflow6 version string
263  this%source = 'MODFLOW 6 '//trim(adjustl(version))
264 
265  ! create timestamp
266  call date_and_time(values=values)
267  write (this%history, '(a,i0,a,i0,a,i0,a,i0,a,i0,a,i0,a,i0)') &
268  'first created ', values(1), '/', values(2), '/', values(3), ' ', &
269  values(5), ':', values(6), ':', values(7), '.', values(8)
This module contains version information.
Definition: version.f90:7
character(len=40), parameter version
Definition: version.f90:22
Here is the call graph for this function:

Variable Documentation

◆ netcdf_mesh2d

@, public ncmodelexportmodule::netcdf_mesh2d = 2

Definition at line 34 of file NCModel.f90.

34  ENUMERATOR :: NETCDF_MESH2D = 2 !< netcdf ugrid layered mesh export

◆ netcdf_structured

@, public ncmodelexportmodule::netcdf_structured = 1

Definition at line 33 of file NCModel.f90.

33  ENUMERATOR :: NETCDF_STRUCTURED = 1 !< netcdf structrured export

◆ netcdf_undef

@, public ncmodelexportmodule::netcdf_undef = 0

Definition at line 32 of file NCModel.f90.

32  ENUMERATOR :: NETCDF_UNDEF = 0 !< undefined netcdf export type