MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
ncfilevarsmodule Module Reference

This module contains the NCFileVarsModule. More...

Data Types

type  ncpackagevarstype
 Type describing input variables for a package in NetCDF file. More...
 
type  ncfilemf6vartype
 Type which describes a modflow input variable in a netcdf file. More...
 
type  ncfilevarstype
 Type describing modflow6 input variables in model NetCDF file. More...
 

Functions/Subroutines

subroutine ncvars_init (this, modelname)
 create netcdf package variable lists More...
 
integer(i4b) function ncvars_varid (this, tagname, layer, iaux)
 return a netcdf variable id for a package tagname More...
 
subroutine ncvars_destroy (this)
 destroy netcdf package variable lists More...
 
subroutine fv_init (this, modelname, nc_fname, ncid, grid)
 initialize netcdf model variable description type More...
 
subroutine fv_add (this, pkgname, tagname, layer, iaux, varid)
 add netcdf modflow6 input variable to list More...
 
subroutine fv_destroy (this)
 destroy netcdf model variable description type More...
 
subroutine create_varlists (this, modelname, pkgname, nc_vars)
 create list of variables that correspond to a package More...
 
class(ncfilemf6vartype) function, pointer ncvar_get (nc_vars, idx)
 get modflow6 input variable description at position idx More...
 

Detailed Description

These data structures organize package input information associated with a single model netcdf input file.

Function/Subroutine Documentation

◆ create_varlists()

subroutine ncfilevarsmodule::create_varlists ( class(ncfilevarstype this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  pkgname,
type(ncpackagevarstype), intent(inout), pointer  nc_vars 
)
private

Definition at line 215 of file NCFileVars.f90.

216  class(NCFileVarsType) :: this
217  character(len=*), intent(in) :: modelname
218  character(len=*), intent(in) :: pkgname
219  type(NCPackageVarsType), pointer, intent(inout) :: nc_vars
220  integer(I4B) :: n
221  class(NCFileMf6VarType), pointer :: invar, nc_var
222  class(*), pointer :: obj
223 
224  do n = 1, this%mf6invar%count()
225  invar => ncvar_get(this%mf6invar, n)
226  if (invar%pkgname == pkgname) then
227  ! create package variable description
228  allocate (nc_var)
229  nc_var%pkgname = invar%pkgname
230  nc_var%tagname = invar%tagname
231  nc_var%layer = invar%layer
232  nc_var%iaux = invar%iaux
233  nc_var%varid = invar%varid
234  obj => nc_var
235  call nc_vars%nc_vars%Add(obj)
236  end if
237  end do
238 
239  ! set modelname
240  nc_vars%modelname = modelname
241 
242  ! set file attribute pointers
243  nc_vars%ncid => this%ncid
244  nc_vars%nc_fname => this%nc_fname
245  nc_vars%grid => this%grid
Here is the call graph for this function:

◆ fv_add()

subroutine ncfilevarsmodule::fv_add ( class(ncfilevarstype this,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  tagname,
integer(i4b), intent(in)  layer,
integer(i4b), intent(in)  iaux,
integer(i4b), intent(in)  varid 
)

Definition at line 178 of file NCFileVars.f90.

180  class(NCFileVarsType) :: this
181  character(len=*), intent(in) :: pkgname
182  character(len=*), intent(in) :: tagname
183  integer(I4B), intent(in) :: layer
184  integer(I4B), intent(in) :: iaux
185  integer(I4B), intent(in) :: varid
186  class(NCFileMf6VarType), pointer :: invar
187  class(*), pointer :: obj
188  ! add mf6 variable to file list
189  allocate (invar)
190  invar%pkgname = pkgname
191  invar%tagname = tagname
192  invar%layer = layer
193  invar%iaux = iaux
194  invar%varid = varid
195  obj => invar
196  call this%mf6invar%Add(obj)

◆ fv_destroy()

subroutine ncfilevarsmodule::fv_destroy ( class(ncfilevarstype this)

Definition at line 201 of file NCFileVars.f90.

202  class(NCFileVarsType) :: this
203  class(NCFileMf6VarType), pointer :: invar
204  integer(I4B) :: n
205  do n = 1, this%mf6invar%Count()
206  invar => ncvar_get(this%mf6invar, n)
207  deallocate (invar)
208  nullify (invar)
209  end do
210  call this%mf6invar%Clear()
Here is the call graph for this function:

◆ fv_init()

subroutine ncfilevarsmodule::fv_init ( class(ncfilevarstype this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  nc_fname,
integer(i4b), intent(in)  ncid,
character(len=*), intent(in)  grid 
)
private

Definition at line 146 of file NCFileVars.f90.

147  use constantsmodule, only: lenmempath
151  class(NCFileVarsType) :: this
152  character(len=*), intent(in) :: modelname
153  character(len=*), intent(in) :: nc_fname
154  integer(I4B), intent(in) :: ncid
155  character(len=*), intent(in) :: grid
156  character(len=LENMEMPATH) :: mempath
157  integer(I4B) :: ilen
158 
159  ! set mempath
160  mempath = create_mem_path(component=modelname, &
161  context=idm_context)
162  ! initialize strlen
163  ilen = linelength
164 
165  ! allocate managed memory
166  call mem_allocate(this%grid, ilen, 'NETCDF_GRID', mempath)
167  call mem_allocate(this%nc_fname, ilen, 'NETCDF_FNAME', mempath)
168  call mem_allocate(this%ncid, 'NCID', mempath)
169 
170  ! set
171  this%grid = grid
172  this%nc_fname = nc_fname
173  this%ncid = ncid
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
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:

◆ ncvar_get()

class(ncfilemf6vartype) function, pointer ncfilevarsmodule::ncvar_get ( type(listtype nc_vars,
integer(i4b), intent(in)  idx 
)
private
Parameters
[in]idxpackage number

Definition at line 250 of file NCFileVars.f90.

251  type(ListType) :: nc_vars
252  integer(I4B), intent(in) :: idx !< package number
253  class(NCFileMf6VarType), pointer :: res
254  class(*), pointer :: obj
255 
256  ! initialize res
257  res => null()
258 
259  ! get the package from the list
260  obj => nc_vars%GetItem(idx)
261  if (associated(obj)) then
262  select type (obj)
263  class is (ncfilemf6vartype)
264  res => obj
265  end select
266  end if
Here is the caller graph for this function:

◆ ncvars_destroy()

subroutine ncfilevarsmodule::ncvars_destroy ( class(ncpackagevarstype this)
private

Definition at line 131 of file NCFileVars.f90.

132  class(NCPackageVarsType) :: this
133  class(NCFileMf6VarType), pointer :: nc_var
134  integer(I4B) :: n
135  ! deallocate allocated memory
136  do n = 1, this%nc_vars%Count()
137  nc_var => ncvar_get(this%nc_vars, n)
138  deallocate (nc_var)
139  nullify (nc_var)
140  end do
141  call this%nc_vars%Clear()
Here is the call graph for this function:

◆ ncvars_init()

subroutine ncfilevarsmodule::ncvars_init ( class(ncpackagevarstype this,
character(len=*), intent(in)  modelname 
)
private

Definition at line 63 of file NCFileVars.f90.

64  class(NCPackageVarsType) :: this
65  character(len=*), intent(in) :: modelname
66  ! set modelname
67  this%modelname = modelname

◆ ncvars_varid()

integer(i4b) function ncfilevarsmodule::ncvars_varid ( class(ncpackagevarstype this,
character(len=*), intent(in)  tagname,
integer(i4b), optional  layer,
integer(i4b), optional  iaux 
)
private

Definition at line 72 of file NCFileVars.f90.

73  class(NCPackageVarsType) :: this
74  character(len=*), intent(in) :: tagname
75  integer(I4B), optional :: layer
76  integer(I4B), optional :: iaux
77  integer(I4B) :: varid
78  integer(I4B) :: n, l, p, a
79  class(NCFileMf6VarType), pointer :: nc_var
80 
81  ! initialize
82  varid = -1
83  l = -1
84  p = -1
85  a = -1
86 
87  ! set search layer if provided
88  if (present(layer)) then
89  l = layer
90  end if
91 
92  ! set search iaux if provided
93  if (present(iaux)) then
94  a = iaux
95  end if
96 
97  do n = 1, this%nc_vars%Count()
98  nc_var => ncvar_get(this%nc_vars, n)
99  if (nc_var%tagname == tagname .and. &
100  nc_var%layer == l .and. &
101  nc_var%iaux == a) then
102  varid = nc_var%varid
103  end if
104  end do
105 
106  ! set error and exit if variable not in NetCDF input
107  if (varid == -1) then
108  if (this%nc_fname /= '') then
109  write (errmsg, '(a)') &
110  'NetCDF variable not found, tagname="'//trim(tagname)//'"'
111  if (present(layer)) then
112  write (errmsg, '(a,i0)') trim(errmsg)//', layer=', layer
113  end if
114  if (present(iaux)) then
115  write (errmsg, '(a,i0)') trim(errmsg)//', iaux=', iaux
116  end if
117  write (errmsg, '(a)') trim(errmsg)//'.'
118  call store_error(errmsg)
119  call store_error_filename(this%nc_fname)
120  else
121  write (errmsg, '(a)') &
122  'NetCDF variable not found, tagname="'//trim(tagname)// &
123  '". NetCDF input not provided for model "'//trim(this%modelname)//'".'
124  call store_error(errmsg, .true.)
125  end if
126  end if
Here is the call graph for this function: