MODFLOW 6  version 6.7.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, 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 184 of file NCModel.f90.

186  class(ExportPackageType), intent(inout) :: this
187  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 140 of file NCModel.f90.

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

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

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

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

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

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

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

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