MODFLOW 6  version 6.7.0.dev0
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, period, 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, period, 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 227 of file NCFileVars.f90.

228  class(NCFileVarsType) :: this
229  character(len=*), intent(in) :: modelname
230  character(len=*), intent(in) :: pkgname
231  type(NCPackageVarsType), pointer, intent(inout) :: nc_vars
232  integer(I4B) :: n
233  class(NCFileMf6VarType), pointer :: invar, nc_var
234  class(*), pointer :: obj
235 
236  do n = 1, this%mf6invar%count()
237  invar => ncvar_get(this%mf6invar, n)
238  if (invar%pkgname == pkgname) then
239  ! create package variable description
240  allocate (nc_var)
241  nc_var%pkgname = invar%pkgname
242  nc_var%tagname = invar%tagname
243  nc_var%layer = invar%layer
244  nc_var%period = invar%period
245  nc_var%iaux = invar%iaux
246  nc_var%varid = invar%varid
247  obj => nc_var
248  call nc_vars%nc_vars%Add(obj)
249  end if
250  end do
251 
252  ! set modelname
253  nc_vars%modelname = modelname
254 
255  ! set file attribute pointers
256  nc_vars%ncid => this%ncid
257  nc_vars%nc_fname => this%nc_fname
258  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)  period,
integer(i4b), intent(in)  iaux,
integer(i4b), intent(in)  varid 
)

Definition at line 188 of file NCFileVars.f90.

190  class(NCFileVarsType) :: this
191  character(len=*), intent(in) :: pkgname
192  character(len=*), intent(in) :: tagname
193  integer(I4B), intent(in) :: layer
194  integer(I4B), intent(in) :: period
195  integer(I4B), intent(in) :: iaux
196  integer(I4B), intent(in) :: varid
197  class(NCFileMf6VarType), pointer :: invar
198  class(*), pointer :: obj
199  ! add mf6 variable to file list
200  allocate (invar)
201  invar%pkgname = pkgname
202  invar%tagname = tagname
203  invar%layer = layer
204  invar%period = period
205  invar%iaux = iaux
206  invar%varid = varid
207  obj => invar
208  call this%mf6invar%Add(obj)

◆ fv_destroy()

subroutine ncfilevarsmodule::fv_destroy ( class(ncfilevarstype this)

Definition at line 213 of file NCFileVars.f90.

214  class(NCFileVarsType) :: this
215  class(NCFileMf6VarType), pointer :: invar
216  integer(I4B) :: n
217  do n = 1, this%mf6invar%Count()
218  invar => ncvar_get(this%mf6invar, n)
219  deallocate (invar)
220  nullify (invar)
221  end do
222  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 156 of file NCFileVars.f90.

157  use constantsmodule, only: lenmempath
161  class(NCFileVarsType) :: this
162  character(len=*), intent(in) :: modelname
163  character(len=*), intent(in) :: nc_fname
164  integer(I4B), intent(in) :: ncid
165  character(len=*), intent(in) :: grid
166  character(len=LENMEMPATH) :: mempath
167  integer(I4B) :: ilen
168 
169  ! set mempath
170  mempath = create_mem_path(component=modelname, &
171  context=idm_context)
172  ! initialize strlen
173  ilen = linelength
174 
175  ! allocate managed memory
176  call mem_allocate(this%grid, ilen, 'NETCDF_GRID', mempath)
177  call mem_allocate(this%nc_fname, ilen, 'NETCDF_FNAME', mempath)
178  call mem_allocate(this%ncid, 'NCID', mempath)
179 
180  ! set
181  this%grid = grid
182  this%nc_fname = nc_fname
183  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 263 of file NCFileVars.f90.

264  type(ListType) :: nc_vars
265  integer(I4B), intent(in) :: idx !< package number
266  class(NCFileMf6VarType), pointer :: res
267  class(*), pointer :: obj
268 
269  ! initialize res
270  res => null()
271 
272  ! get the package from the list
273  obj => nc_vars%GetItem(idx)
274  if (associated(obj)) then
275  select type (obj)
276  class is (ncfilemf6vartype)
277  res => obj
278  end select
279  end if
Here is the caller graph for this function:

◆ ncvars_destroy()

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

Definition at line 141 of file NCFileVars.f90.

142  class(NCPackageVarsType) :: this
143  class(NCFileMf6VarType), pointer :: nc_var
144  integer(I4B) :: n
145  ! deallocate allocated memory
146  do n = 1, this%nc_vars%Count()
147  nc_var => ncvar_get(this%nc_vars, n)
148  deallocate (nc_var)
149  nullify (nc_var)
150  end do
151  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 64 of file NCFileVars.f90.

65  class(NCPackageVarsType) :: this
66  character(len=*), intent(in) :: modelname
67  ! set modelname
68  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  period,
integer(i4b), optional  iaux 
)
private

Definition at line 73 of file NCFileVars.f90.

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