MODFLOW 6  version 6.7.0.dev2
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...
 
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 192 of file NCModel.f90.

194  class(ExportPackageType), intent(inout) :: this
195  if (allocated(this%param_names)) deallocate (this%param_names)
This module contains the InputDefinitionModule.

◆ 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 144 of file NCModel.f90.

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

548  class(NCModelExportType), intent(inout) :: this
549  ! override in derived class
550  deallocate (this%deflate)
551  deallocate (this%shuffle)
552  deallocate (this%input_attr)
553  deallocate (this%chunk_time)
554  ! Deallocate idm memory
555  if (this%ncf_mempath /= '') then
556  call memorystore_remove(this%modelname, 'NCF', idm_context)
557  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 403 of file NCModel.f90.

404  use listmodule, only: listtype
405  class(NCModelExportType), intent(inout) :: this
406  integer(I4B), intent(in) :: idx
407  class(ExportPackageType), pointer :: res
408  class(*), pointer :: obj
409  nullify (res)
410  obj => this%pkglist%GetItem(idx)
411  if (associated(obj)) then
412  select type (obj)
413  class is (exportpackagetype)
414  res => obj
415  end select
416  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 278 of file NCModel.f90.

280  use tdismodule, only: datetime0, nstp, inats
284  use inputoutputmodule, only: lowcase
286  class(NCModelExportType), intent(inout) :: this
287  character(len=*), intent(in) :: modelname
288  character(len=*), intent(in) :: modeltype
289  character(len=*), intent(in) :: modelfname
290  character(len=*), intent(in) :: nc_fname
291  integer(I4B), intent(in) :: disenum
292  integer(I4B), intent(in) :: nctype
293  integer(I4B), intent(in) :: iout
294  character(len=LENMEMPATH) :: model_mempath
295  type(UtlNcfParamFoundType) :: ncf_found
296  logical(LGP) :: found_mempath
297 
298  ! allocate
299  allocate (this%deflate)
300  allocate (this%shuffle)
301  allocate (this%input_attr)
302  allocate (this%chunk_time)
303 
304  ! initialize
305  this%modelname = modelname
306  this%modeltype = modeltype
307  this%modelfname = modelfname
308  this%nc_fname = nc_fname
309  this%gridmap_name = ''
310  this%ncf_mempath = ''
311  this%wkt = ''
312  this%datetime = ''
313  this%xname = ''
314  this%lenunits = ''
315  this%disenum = disenum
316  this%ncid = 0
317  this%totnstp = 0
318  this%deflate = -1
319  this%shuffle = 0
320  this%input_attr = 1
321  this%chunk_time = -1
322  this%iout = iout
323  this%chunking_active = .false.
324 
325  ! set file scoped attributes
326  call this%annotation%set(modelname, modeltype, modelfname, nctype, disenum)
327 
328  ! set dependent variable basename
329  select case (modeltype)
330  case ('GWF')
331  this%xname = 'head'
332  case ('GWT')
333  this%xname = 'concentration'
334  case ('GWE')
335  this%xname = 'temperature'
336  case default
337  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
338  call store_error(errmsg)
339  call store_error_filename(modelfname)
340  end select
341 
342  ! set discretization input mempath
343  if (disenum == dis) then
344  this%dis_mempath = create_mem_path(modelname, 'DIS', idm_context)
345  else if (disenum == disu) then
346  this%dis_mempath = create_mem_path(modelname, 'DISU', idm_context)
347  else if (disenum == disv) then
348  this%dis_mempath = create_mem_path(modelname, 'DISV', idm_context)
349  end if
350 
351  ! set dependent variable pointer
352  model_mempath = create_mem_path(component=modelname)
353  call mem_setptr(this%x, 'X', model_mempath)
354 
355  ! set ncf_mempath if provided
356  call mem_set_value(this%ncf_mempath, 'NCF6_MEMPATH', this%dis_mempath, &
357  found_mempath)
358 
359  if (found_mempath) then
360  call mem_set_value(this%wkt, 'WKT', this%ncf_mempath, &
361  ncf_found%wkt)
362  call mem_set_value(this%deflate, 'DEFLATE', this%ncf_mempath, &
363  ncf_found%deflate)
364  call mem_set_value(this%shuffle, 'SHUFFLE', this%ncf_mempath, &
365  ncf_found%shuffle)
366  call mem_set_value(this%input_attr, 'ATTR_OFF', this%ncf_mempath, &
367  ncf_found%attr_off)
368  call mem_set_value(this%chunk_time, 'CHUNK_TIME', this%ncf_mempath, &
369  ncf_found%chunk_time)
370  end if
371 
372  if (ncf_found%wkt) then
373  this%gridmap_name = 'projection'
374  end if
375 
376  ! ATTR_OFF turns off modflow 6 input attributes
377  if (ncf_found%attr_off) then
378  this%input_attr = 0
379  end if
380 
381  ! set datetime string
382  if (datetime0 /= '') then
383  this%datetime = 'days since '//trim(datetime0)
384  else
385  ! January 1, 1970 at 00:00:00 UTC
386  this%datetime = 'days since 1970-01-01T00:00:00'
387  end if
388 
389  ! Set error and exit if ATS is on
390  if (inats > 0) then
391  errmsg = 'Adaptive time stepping not currently supported &
392  &with NetCDF exports.'
393  call store_error(errmsg)
394  call store_error_filename(modelfname)
395  end if
396 
397  ! set total nstp
398  this%totnstp = sum(nstp)
subroutine, public lowcase(word)
Convert to lower case.
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 inats
flag indicating ats active for simulation
Definition: tdis.f90:25
Here is the call graph for this function:

◆ export_input()

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

Definition at line 525 of file NCModel.f90.

526  use tdismodule, only: kper
527  class(NCBaseModelExportType), intent(inout) :: this
528  integer(I4B) :: idx
529  class(ExportPackageType), pointer :: export_pkg
530  do idx = 1, this%pkglist%Count()
531  export_pkg => this%get(idx)
532  ! last loaded data is not current period
533  if (export_pkg%iper /= kper) cycle
534  ! period input already exported
535  if (export_pkg%iper_export >= export_pkg%iper) cycle
536  ! set exported iper
537  export_pkg%iper_export = export_pkg%iper
538  ! update export package
539  call this%package_step(export_pkg)
540  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 479 of file NCModel.f90.

483  use inputoutputmodule, only: lowcase
484  character(len=*), intent(in) :: longname
485  character(len=*), intent(in) :: pkgname
486  character(len=*), intent(in) :: tagname
487  character(len=*), intent(in) :: mempath
488  integer(I4B), optional, intent(in) :: layer
489  integer(I4B), optional, intent(in) :: iaux
490  character(len=LINELENGTH) :: lname
491  type(CharacterStringType), dimension(:), pointer, &
492  contiguous :: auxnames
493  character(len=LINELENGTH) :: pname, vname, auxname
494  pname = pkgname
495  vname = tagname
496  call lowcase(pname)
497  call lowcase(vname)
498  if (longname == '') then
499  lname = trim(pname)//' '//trim(vname)
500  else
501  lname = longname
502  end if
503 
504  if (present(iaux)) then
505  if (iaux > 0) then
506  if (tagname == 'AUX') then
507  ! reset vname to auxiliary variable name
508  call mem_setptr(auxnames, 'AUXILIARY', mempath)
509  auxname = auxnames(iaux)
510  call lowcase(auxname)
511  lname = trim(lname)//' '//trim(auxname)
512  end if
513  end if
514  end if
515 
516  if (present(layer)) then
517  if (layer > 0) then
518  write (lname, '(a,i0)') trim(lname)//' layer=', layer
519  end if
520  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 438 of file NCModel.f90.

442  use inputoutputmodule, only: lowcase
443  character(len=*), intent(in) :: pkgname
444  character(len=*), intent(in) :: tagname
445  character(len=*), intent(in) :: mempath
446  integer(I4B), optional, intent(in) :: layer
447  integer(I4B), optional, intent(in) :: iaux
448  character(len=LINELENGTH) :: varname
449  type(CharacterStringType), dimension(:), pointer, &
450  contiguous :: auxnames
451  character(len=LINELENGTH) :: pname, vname
452  vname = tagname
453  pname = pkgname
454 
455  if (present(iaux)) then
456  if (iaux > 0) then
457  if (tagname == 'AUX') then
458  ! reset vname to auxiliary variable name
459  call mem_setptr(auxnames, 'AUXILIARY', mempath)
460  vname = auxnames(iaux)
461  end if
462  end if
463  end if
464 
465  call lowcase(vname)
466  call lowcase(pname)
467  varname = trim(pname)//'_'//trim(vname)
468 
469  if (present(layer)) then
470  if (layer > 0) then
471  !write (varname, '(a,i0)') trim(varname)//'_L', layer
472  write (varname, '(a,i0)') trim(varname)//'_l', layer
473  end if
474  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 421 of file NCModel.f90.

422  use inputoutputmodule, only: lowcase
425  class(NCModelExportType), intent(inout) :: this
426  character(len=*), intent(in) :: pkgname
427  type(InputParamDefinitionType), pointer, intent(in) :: idt
428  character(len=LINELENGTH) :: attr
429  attr = ''
430  if (this%input_attr > 0) then
431  attr = trim(this%modelname)//mempathseparator//trim(pkgname)// &
432  mempathseparator//trim(idt%tagname)
433  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:

◆ 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 200 of file NCModel.f90.

201  use versionmodule, only: version
202  class(NCExportAnnotation), intent(inout) :: this
203  character(len=*), intent(in) :: modelname
204  character(len=*), intent(in) :: modeltype
205  character(len=*), intent(in) :: modelfname
206  integer(I4B), intent(in) :: nctype
207  integer(I4B), intent(in) :: disenum
208  character(len=LINELENGTH) :: fullname
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  fullname = 'Groundwater Flow'
230  this%title = trim(modelname)//' hydraulic head'
231  this%longname = 'head'
232  case ('GWT')
233  fullname = 'Groundwater Transport'
234  this%title = trim(modelname)//' concentration'
235  this%longname = 'concentration'
236  case ('GWE')
237  fullname = 'Groundwater Energy'
238  this%title = trim(modelname)//' temperature'
239  this%longname = 'temperature'
240  case default
241  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
242  call store_error(errmsg)
243  call store_error_filename(modelfname)
244  end select
245 
246  if (isim_mode == mvalidate) then
247  this%title = trim(this%title)//' array input'
248  end if
249 
250  ! set mesh type
251  if (nctype == netcdf_mesh2d) then
252  this%mesh = 'LAYERED'
253  end if
254 
255  ! set grid type
256  if (disenum == dis) then
257  this%grid = 'STRUCTURED'
258  else if (disenum == disv) then
259  this%grid = 'VERTEX'
260  end if
261 
262  ! model description string
263  this%model = trim(modelname)//': MODFLOW 6 '//trim(fullname)// &
264  ' ('//trim(modeltype)//') model'
265 
266  ! modflow6 version string
267  this%source = 'MODFLOW 6 '//trim(adjustl(version))
268 
269  ! create timestamp
270  call date_and_time(values=values)
271  write (this%history, '(a,i0,a,i0,a,i0,a,i0,a,i0,a,i0,a,i0)') &
272  'first created ', values(1), '/', values(2), '/', values(3), ' ', &
273  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