MODFLOW 6  version 6.7.0.dev3
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)
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 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 549 of file NCModel.f90.

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

396  use listmodule, only: listtype
397  class(NCModelExportType), intent(inout) :: this
398  integer(I4B), intent(in) :: idx
399  class(ExportPackageType), pointer :: res
400  class(*), pointer :: obj
401  nullify (res)
402  obj => this%pkglist%GetItem(idx)
403  if (associated(obj)) then
404  select type (obj)
405  class is (exportpackagetype)
406  res => obj
407  end select
408  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
282  class(NCModelExportType), intent(inout) :: this
283  character(len=*), intent(in) :: modelname
284  character(len=*), intent(in) :: modeltype
285  character(len=*), intent(in) :: modelfname
286  character(len=*), intent(in) :: nc_fname
287  integer(I4B), intent(in) :: disenum
288  integer(I4B), intent(in) :: nctype
289  integer(I4B), intent(in) :: iout
290  character(len=LENMEMPATH) :: model_mempath
291  type(UtlNcfParamFoundType) :: ncf_found
292  logical(LGP) :: found_mempath
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  call mem_set_value(this%ncf_mempath, 'NCF6_MEMPATH', this%dis_mempath, &
353  found_mempath)
354 
355  if (found_mempath) then
356  call mem_set_value(this%wkt, 'WKT', this%ncf_mempath, &
357  ncf_found%wkt)
358  call mem_set_value(this%deflate, 'DEFLATE', this%ncf_mempath, &
359  ncf_found%deflate)
360  call mem_set_value(this%shuffle, 'SHUFFLE', this%ncf_mempath, &
361  ncf_found%shuffle)
362  call mem_set_value(this%input_attr, 'ATTR_OFF', this%ncf_mempath, &
363  ncf_found%attr_off)
364  call mem_set_value(this%chunk_time, 'CHUNK_TIME', this%ncf_mempath, &
365  ncf_found%chunk_time)
366  end if
367 
368  if (ncf_found%wkt) then
369  this%gridmap_name = 'projection'
370  end if
371 
372  ! ATTR_OFF turns off modflow 6 input attributes
373  if (ncf_found%attr_off) then
374  this%input_attr = 0
375  end if
376 
377  ! set datetime string
378  if (datetime0 /= '') then
379  this%datetime = 'days since '//trim(datetime0)
380  else
381  ! January 1, 1970 at 00:00:00 UTC
382  this%datetime = 'days since 1970-01-01T00:00:00'
383  end if
384 
385  ! set total nstp
386  if (isim_mode == mvalidate) then
387  this%totnstp = nper
388  else
389  this%totnstp = sum(nstp)
390  end if
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 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 531 of file NCModel.f90.

532  use tdismodule, only: kper
533  class(NCBaseModelExportType), intent(inout) :: this
534  integer(I4B) :: idx
535  class(ExportPackageType), pointer :: export_pkg
536  do idx = 1, this%pkglist%Count()
537  export_pkg => this%get(idx)
538  ! period input already exported
539  if (export_pkg%eper >= kper) cycle
540  ! update export package
541  call this%package_step(export_pkg)
542  ! update exported iper
543  export_pkg%eper = kper
544  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 485 of file NCModel.f90.

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

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

414  use inputoutputmodule, only: lowcase
417  class(NCModelExportType), intent(inout) :: this
418  character(len=*), intent(in) :: pkgname
419  type(InputParamDefinitionType), pointer, intent(in) :: idt
420  character(len=LINELENGTH) :: attr
421  attr = ''
422  if (this%input_attr > 0) then
423  attr = trim(this%modelname)//mempathseparator//trim(pkgname)// &
424  mempathseparator//trim(idt%tagname)
425  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 430 of file NCModel.f90.

431  use tdismodule, only: kstp, kper, nstp
432  class(NCModelExportType), intent(inout) :: this
433  integer(I4B) :: n, istp
434  istp = kstp
435  if (kper > 1) then
436  do n = 1, kper - 1
437  istp = istp + nstp(n)
438  end do
439  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