MODFLOW 6  version 6.7.0.dev1
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, 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)
 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 modflow6_input attribute string More...
 
character(len=linelength) function, public export_longname (longname, pkgname, tagname, layer, iper)
 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 185 of file NCModel.f90.

187  class(ExportPackageType), intent(inout) :: this
188  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,
character(len=linelength), dimension(:), intent(in), allocatable  param_names,
integer(i4b), intent(in)  nparam 
)
private
Parameters
[in]mshapemodel shape

Definition at line 141 of file NCModel.f90.

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

487  class(NCModelExportType), intent(inout) :: this
488  ! override in derived class
489  deallocate (this%deflate)
490  deallocate (this%shuffle)
491  deallocate (this%input_attr)
492  deallocate (this%chunk_time)
493  ! Deallocate idm memory
494  if (this%ncf_mempath /= '') then
495  call memorystore_remove(this%modelname, 'NCF', idm_context)
496  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 382 of file NCModel.f90.

383  use listmodule, only: listtype
384  class(NCModelExportType), intent(inout) :: this
385  integer(I4B), intent(in) :: idx
386  class(ExportPackageType), pointer :: res
387  class(*), pointer :: obj
388  nullify (res)
389  obj => this%pkglist%GetItem(idx)
390  if (associated(obj)) then
391  select type (obj)
392  class is (exportpackagetype)
393  res => obj
394  end select
395  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 264 of file NCModel.f90.

266  use tdismodule, only: datetime0, nstp
270  use inputoutputmodule, only: lowcase
272  class(NCModelExportType), intent(inout) :: this
273  character(len=*), intent(in) :: modelname
274  character(len=*), intent(in) :: modeltype
275  character(len=*), intent(in) :: modelfname
276  character(len=*), intent(in) :: nc_fname
277  integer(I4B), intent(in) :: disenum
278  integer(I4B), intent(in) :: nctype
279  integer(I4B), intent(in) :: iout
280  character(len=LENMEMPATH) :: model_mempath
281  type(UtlNcfParamFoundType) :: ncf_found
282  logical(LGP) :: found_mempath
283 
284  ! allocate
285  allocate (this%deflate)
286  allocate (this%shuffle)
287  allocate (this%input_attr)
288  allocate (this%chunk_time)
289 
290  ! initialize
291  this%modelname = modelname
292  this%modeltype = modeltype
293  this%modelfname = modelfname
294  this%nc_fname = nc_fname
295  this%gridmap_name = ''
296  this%ncf_mempath = ''
297  this%wkt = ''
298  this%datetime = ''
299  this%xname = ''
300  this%lenunits = ''
301  this%disenum = disenum
302  this%ncid = 0
303  this%stepcnt = 0
304  this%totnstp = 0
305  this%deflate = -1
306  this%shuffle = 0
307  this%input_attr = 1
308  this%chunk_time = -1
309  this%iout = iout
310  this%chunking_active = .false.
311 
312  ! set file scoped attributes
313  call this%annotation%set(modelname, modeltype, modelfname, nctype)
314 
315  ! set dependent variable basename
316  select case (modeltype)
317  case ('GWF')
318  this%xname = 'head'
319  case ('GWT')
320  this%xname = 'concentration'
321  case ('GWE')
322  this%xname = 'temperature'
323  case default
324  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
325  call store_error(errmsg)
326  call store_error_filename(modelfname)
327  end select
328 
329  ! set discretization input mempath
330  if (disenum == dis) then
331  this%dis_mempath = create_mem_path(modelname, 'DIS', idm_context)
332  else if (disenum == disu) then
333  this%dis_mempath = create_mem_path(modelname, 'DISU', idm_context)
334  else if (disenum == disv) then
335  this%dis_mempath = create_mem_path(modelname, 'DISV', idm_context)
336  end if
337 
338  ! set dependent variable pointer
339  model_mempath = create_mem_path(component=modelname)
340  call mem_setptr(this%x, 'X', model_mempath)
341 
342  ! set ncf_mempath if provided
343  call mem_set_value(this%ncf_mempath, 'NCF6_MEMPATH', this%dis_mempath, &
344  found_mempath)
345 
346  if (found_mempath) then
347  call mem_set_value(this%wkt, 'WKT', this%ncf_mempath, &
348  ncf_found%wkt)
349  call mem_set_value(this%deflate, 'DEFLATE', this%ncf_mempath, &
350  ncf_found%deflate)
351  call mem_set_value(this%shuffle, 'SHUFFLE', this%ncf_mempath, &
352  ncf_found%shuffle)
353  call mem_set_value(this%input_attr, 'ATTR_OFF', this%ncf_mempath, &
354  ncf_found%attr_off)
355  call mem_set_value(this%chunk_time, 'CHUNK_TIME', this%ncf_mempath, &
356  ncf_found%chunk_time)
357  end if
358 
359  if (ncf_found%wkt) then
360  this%gridmap_name = 'projection'
361  end if
362 
363  ! ATTR_OFF turns off modflow 6 input attributes
364  if (ncf_found%attr_off) then
365  this%input_attr = 0
366  end if
367 
368  ! set datetime string
369  if (datetime0 /= '') then
370  this%datetime = 'days since '//trim(datetime0)
371  else
372  ! January 1, 1970 at 00:00:00 UTC
373  this%datetime = 'days since 1970-01-01T00:00:00'
374  end if
375 
376  ! set total nstp
377  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
Here is the call graph for this function:

◆ export_input()

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

Definition at line 447 of file NCModel.f90.

448  use tdismodule, only: kper
449  use arrayhandlersmodule, only: ifind
450  class(NCBaseModelExportType), intent(inout) :: this
451  integer(I4B) :: idx, ilayer
452  class(ExportPackageType), pointer :: export_pkg
453  character(len=LENVARNAME) :: ilayer_varname
454 
455  do idx = 1, this%pkglist%Count()
456  export_pkg => this%get(idx)
457  ! last loaded data is not current period
458  if (export_pkg%iper /= kper) cycle
459  ! period input already exported
460  if (export_pkg%iper_export >= export_pkg%iper) cycle
461  ! set exported iper
462  export_pkg%iper_export = export_pkg%iper
463 
464  ! initialize ilayer
465  ilayer = 0
466 
467  ! set expected ilayer index variable name
468  ilayer_varname = 'I'//trim(export_pkg%mf6_input%subcomponent_type(1:3))
469 
470  ! is ilayer variable in param name list
471  ilayer = ifind(export_pkg%param_names, ilayer_varname)
472 
473  ! layer index variable is required to be first defined in period block
474  if (ilayer == 1) then
475  call this%package_step_ilayer(export_pkg, ilayer_varname, ilayer)
476  else
477  call this%package_step(export_pkg)
478  end if
479  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,
integer(i4b), intent(in)  layer,
integer(i4b), intent(in), optional  iper 
)

Definition at line 417 of file NCModel.f90.

418  use inputoutputmodule, only: lowcase
419  character(len=*), intent(in) :: longname
420  character(len=*), intent(in) :: pkgname
421  character(len=*), intent(in) :: tagname
422  integer(I4B), intent(in) :: layer
423  integer(I4B), optional, intent(in) :: iper
424  character(len=LINELENGTH) :: lname
425  character(len=LINELENGTH) :: pname, vname
426  pname = pkgname
427  vname = tagname
428  call lowcase(pname)
429  call lowcase(vname)
430  if (longname == '') then
431  lname = trim(pname)//' '//trim(vname)
432  else
433  lname = longname
434  end if
435  if (layer > 0) then
436  write (lname, '(a,i0)') trim(lname)//' layer=', layer
437  end if
438  if (present(iper)) then
439  if (iper > 0) then
440  write (lname, '(a,i0)') trim(lname)//' period=', iper
441  end if
442  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 400 of file NCModel.f90.

401  use inputoutputmodule, only: lowcase
404  class(NCModelExportType), intent(inout) :: this
405  character(len=*), intent(in) :: pkgname
406  type(InputParamDefinitionType), pointer, intent(in) :: idt
407  character(len=LINELENGTH) :: attr
408  attr = ''
409  if (this%input_attr > 0) then
410  attr = trim(this%modelname)//mempathseparator//trim(pkgname)// &
411  mempathseparator//trim(idt%mf6varname)
412  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 
)

Definition at line 193 of file NCModel.f90.

194  use versionmodule, only: version
195  class(NCExportAnnotation), intent(inout) :: this
196  character(len=*), intent(in) :: modelname
197  character(len=*), intent(in) :: modeltype
198  character(len=*), intent(in) :: modelfname
199  integer(I4B), intent(in) :: nctype
200  character(len=LINELENGTH) :: fullname
201  integer :: values(8)
202 
203  this%title = ''
204  this%model = ''
205  this%grid = ''
206  this%history = ''
207  this%source = ''
208  this%conventions = ''
209  this%stdname = ''
210  this%longname = ''
211 
212  ! set file conventions
213  this%conventions = 'CF-1.11'
214  if (nctype == netcdf_mesh2d) this%conventions = &
215  trim(this%conventions)//' UGRID-1.0'
216 
217  ! set model specific attributes
218  select case (modeltype)
219  case ('GWF')
220  fullname = 'Groundwater Flow'
221  this%title = trim(modelname)//' hydraulic head'
222  this%longname = 'head'
223  case ('GWT')
224  fullname = 'Groundwater Transport'
225  this%title = trim(modelname)//' concentration'
226  this%longname = 'concentration'
227  case ('GWE')
228  fullname = 'Groundwater Energy'
229  this%title = trim(modelname)//' temperature'
230  this%longname = 'temperature'
231  case default
232  errmsg = trim(modeltype)//' models not supported for NetCDF export.'
233  call store_error(errmsg)
234  call store_error_filename(modelfname)
235  end select
236 
237  if (isim_mode == mvalidate) then
238  this%title = trim(this%title)//' array input'
239  end if
240 
241  ! set export type
242  if (nctype == netcdf_mesh2d) then
243  this%grid = 'LAYERED MESH'
244  else if (nctype == netcdf_structured) then
245  this%grid = 'STRUCTURED'
246  end if
247 
248  ! model description string
249  this%model = trim(modelname)//': MODFLOW 6 '//trim(fullname)// &
250  ' ('//trim(modeltype)//') model'
251 
252  ! modflow6 version string
253  this%source = 'MODFLOW 6 '//trim(adjustl(version))
254 
255  ! create timestamp
256  call date_and_time(values=values)
257  write (this%history, '(a,i0,a,i0,a,i0,a,i0,a,i0,a,i0,a,i0)') &
258  'first created ', values(1), '/', values(2), '/', values(3), ' ', &
259  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