MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
nccontextbuildmodule Module Reference

This module contains the NCContextBuildModule. More...

Functions/Subroutines

integer(i4b) function, public open_ncfile (nc_fname, iout)
 open netcdf file More...
 
subroutine add_package_var (modeltype, modelname, nc_vars, input_name, varid, iout)
 add a package input variable to nc_vars structure More...
 
character(len=netcdf_attr_strlen) function verify_global_attr (modeltype, modelname, input_name, nc_fname, ncid)
 verify global attribute modflow6_grid is present and return value More...
 
subroutine, public create_netcdf_context (modeltype, modelname, input_name, nc_vars, nc_fname, ncid, iout)
 create internal description of modflow6 input variables in netcdf file More...
 

Detailed Description

Read NetCDF input file and add modflow6 input variables

Function/Subroutine Documentation

◆ add_package_var()

subroutine nccontextbuildmodule::add_package_var ( character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelname,
type(ncfilevarstype), intent(inout)  nc_vars,
character(len=*), intent(in)  input_name,
integer(i4b), intent(in)  varid,
integer(i4b), intent(in)  iout 
)

Definition at line 58 of file NCContextBuild.f90.

60  ! -- modules
61  use inputoutputmodule, only: lowcase, upcase
65  ! -- dummy
66  character(len=*), intent(in) :: modeltype
67  character(len=*), intent(in) :: modelname
68  type(NCFileVarsType), intent(inout) :: nc_vars
69  character(len=*), intent(in) :: input_name
70  integer(I4B), intent(in) :: varid
71  integer(I4B), intent(in) :: iout
72  ! -- local
73  character(len=NETCDF_ATTR_STRLEN) :: input_str
74  character(len=LENCOMPONENTNAME) :: c_name, sc_name
75  character(len=LINELENGTH) :: mempath, varname
76  integer(I4B) :: layer, period, iaux, mf6_layer, mf6_period, mf6_iaux
77  logical(LGP) :: success
78  !
79  ! -- initialize
80  layer = -1
81  period = -1
82  iaux = -1
83  varname = ''
84  c_name = ''
85  sc_name = ''
86  !
87  ! -- process mf6_input attribute
88  if (nf90_get_att(nc_vars%ncid, varid, 'modflow6_input', &
89  input_str) == nf90_noerr) then
90  !
91  ! -- mf6_input should provide a memory address
92  call split_mem_address(input_str, mempath, varname, success)
93  !
94  if (success) then
95  ! -- split the mempath
96  call split_mem_path(mempath, c_name, sc_name)
97  !
98  ! -- set read tokens to upper case
99  call upcase(varname)
100  call upcase(c_name)
101  call upcase(sc_name)
102  !
103  ! -- check for optional layer attribute
104  if (nf90_get_att(nc_vars%ncid, varid, &
105  'modflow6_layer', mf6_layer) == nf90_noerr) then
106  layer = mf6_layer
107  end if
108  !
109  ! -- check for optional period attribute
110  if (nf90_get_att(nc_vars%ncid, varid, &
111  'modflow6_iper', mf6_period) == nf90_noerr) then
112  period = mf6_period
113  end if
114  !
115  ! -- check for optional period attribute
116  if (nf90_get_att(nc_vars%ncid, varid, &
117  'modflow6_iaux', mf6_iaux) == nf90_noerr) then
118  iaux = mf6_iaux
119  end if
120  !
121  ! -- add the variable to netcdf description
122  call nc_vars%add(sc_name, varname, layer, period, iaux, varid)
123  else
124  errmsg = 'NetCDF variable invalid modflow6_input attribute: "'// &
125  trim(input_str)//'".'
126  call store_error(errmsg)
127  call store_error_filename(nc_vars%nc_fname)
128  end if
129  end if
130  !
131  ! -- return
132  return
subroutine, public lowcase(word)
Convert to lower case.
subroutine, public upcase(word)
Convert to upper case.
subroutine split_mem_address(mem_address, mem_path, var_name, success)
Split a memory address string into memory path and variable name.
subroutine split_mem_path(mem_path, component, subcomponent)
Split the memory path into component(s)
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
character(len=lencomponentname) function, public idm_subcomponent_type(component, subcomponent)
component from package or model type
character(len=lenpackagename) function, public idm_subcomponent_name(component_type, subcomponent_type, sc_name)
model package subcomponent name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_netcdf_context()

subroutine, public nccontextbuildmodule::create_netcdf_context ( character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  input_name,
type(ncfilevarstype), intent(inout)  nc_vars,
character(len=*), intent(in)  nc_fname,
integer(i4b), intent(in)  ncid,
integer(i4b), intent(in)  iout 
)

Definition at line 172 of file NCContextBuild.f90.

174  use inputoutputmodule, only: lowcase, upcase
175  character(len=*), intent(in) :: modeltype
176  character(len=*), intent(in) :: modelname
177  character(len=*), intent(in) :: input_name
178  type(NCFileVarsType), intent(inout) :: nc_vars
179  character(len=*), intent(in) :: nc_fname
180  integer(I4B), intent(in) :: ncid
181  integer(I4B), intent(in) :: iout
182  integer(I4B) :: ndim, nvar, nattr, unlimDimID
183  integer(I4B), dimension(:), allocatable :: varids
184  ! -- local
185  character(len=LINELENGTH) :: grid
186  integer(I4B) :: iparam
187  !
188  ! -- check global attributes
189  grid = verify_global_attr(modeltype, modelname, input_name, nc_fname, ncid)
190  !
191  ! -- initialize netcdf input structure
192  call nc_vars%init(modelname, nc_fname, ncid, grid)
193  !
194  ! -- inquire for root dataset info
195  call nf_verify(nf90_inquire(ncid, ndim, nvar, nattr, unlimdimid), &
196  nc_vars%nc_fname)
197  !
198  ! -- allocate and set varids
199  allocate (varids(nvar))
200  call nf_verify(nf90_inq_varids(ncid, nvar, varids), nc_vars%nc_fname)
201  !
202  do iparam = 1, nvar
203  !
204  ! -- validate and add netcdf file input variable
205  call add_package_var(modeltype, modelname, nc_vars, input_name, &
206  varids(iparam), iout)
207  !
208  end do
209  !
210  ! -- cleanup
211  deallocate (varids)
212  !
213  ! -- return
214  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_ncfile()

integer(i4b) function, public nccontextbuildmodule::open_ncfile ( character(len=*)  nc_fname,
integer(i4b)  iout 
)

Definition at line 26 of file NCContextBuild.f90.

27  ! -- modules
29  use netcdfcommonmodule, only: nc_fopen
30  ! -- dummy
31  character(len=*) :: nc_fname
32  integer(I4B) :: iout
33  ! -- result
34  integer(I4B) :: ncid
35  ! -- local
36  logical(LGP) :: exists
37  !
38  ! -- initialize
39  ncid = 0
40  !
41  ! -- check if NETCDF file exists
42  inquire (file=nc_fname, exist=exists)
43  if (.not. exists) then
44  write (errmsg, '(a,a,a)') 'Specified NetCDF input file does &
45  &not exist [file=', trim(nc_fname), '].'
46  call store_error(errmsg, .true.)
47  end if
48  !
49  ! -- open
50  ncid = nc_fopen(nc_fname, iout)
51  !
52  ! -- return
53  return
This module contains the NetCDFCommonModule.
Definition: NetCDFCommon.f90:6
integer(i4b) function, public nc_fopen(nc_fname, iout)
Open netcdf file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_global_attr()

character(len=netcdf_attr_strlen) function nccontextbuildmodule::verify_global_attr ( character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  input_name,
character(len=*), intent(in)  nc_fname,
integer(i4b), intent(in)  ncid 
)

Definition at line 137 of file NCContextBuild.f90.

139  use inputoutputmodule, only: lowcase, upcase
140  ! -- dummy
141  character(len=*), intent(in) :: modeltype
142  character(len=*), intent(in) :: modelname
143  character(len=*), intent(in) :: input_name
144  character(len=*), intent(in) :: nc_fname
145  integer(I4B), intent(in) :: ncid
146  ! -- result
147  character(len=NETCDF_ATTR_STRLEN) :: grid
148  !
149  ! -- initialize grid
150  grid = ''
151  !
152  ! -- verify expected mf6_modeltype file attribute
153  if (nf90_get_att(ncid, nf90_global, "modflow6_grid", &
154  grid) == nf90_noerr) then
155  !
156  ! -- set grid to upper case
157  call upcase(grid)
158  !
159  else
160  errmsg = 'NetCDF input file global attribute "grid" not found.'
161  call store_error(errmsg)
162  call store_error_filename(nc_fname)
163  !
164  end if
165  !
166  ! -- return
167  return
Here is the call graph for this function:
Here is the caller graph for this function: