MODFLOW 6  version 6.7.0.dev2
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 modflow_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 50 of file NCContextBuild.f90.

52  use inputoutputmodule, only: lowcase, upcase
56  character(len=*), intent(in) :: modeltype
57  character(len=*), intent(in) :: modelname
58  type(NCFileVarsType), intent(inout) :: nc_vars
59  character(len=*), intent(in) :: input_name
60  integer(I4B), intent(in) :: varid
61  integer(I4B), intent(in) :: iout
62  character(len=NETCDF_ATTR_STRLEN) :: input_str
63  character(len=LENCOMPONENTNAME) :: c_name, sc_name
64  character(len=LINELENGTH) :: mempath, varname
65  integer(I4B) :: layer, iaux, mf6_layer, mf6_iaux
66  logical(LGP) :: success
67 
68  ! initialize
69  layer = -1
70  iaux = -1
71  varname = ''
72  c_name = ''
73  sc_name = ''
74 
75  ! process mf6_input attribute
76  if (nf90_get_att(nc_vars%ncid, varid, 'modflow_input', &
77  input_str) == nf90_noerr) then
78  ! mf6_input should provide a memory address
79  call split_mem_address(input_str, mempath, varname, success)
80 
81  if (success) then
82  ! split the mempath
83  call split_mem_path(mempath, c_name, sc_name)
84  ! set read tokens to upper case
85  call upcase(varname)
86  call upcase(c_name)
87  call upcase(sc_name)
88  ! check for optional layer attribute
89  if (nf90_get_att(nc_vars%ncid, varid, &
90  'layer', mf6_layer) == nf90_noerr) then
91  layer = mf6_layer
92  end if
93 
94  ! check for optional iaux attribute
95  if (nf90_get_att(nc_vars%ncid, varid, &
96  'modflow_iaux', mf6_iaux) == nf90_noerr) then
97  iaux = mf6_iaux
98  end if
99 
100  ! add the variable to netcdf description
101  call nc_vars%add(sc_name, varname, layer, iaux, varid)
102  else
103  errmsg = 'NetCDF variable invalid modflow_input attribute: "'// &
104  trim(input_str)//'".'
105  call store_error(errmsg)
106  call store_error_filename(nc_vars%nc_fname)
107  end if
108  end if
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 159 of file NCContextBuild.f90.

161  use inputoutputmodule, only: lowcase, upcase
162  character(len=*), intent(in) :: modeltype
163  character(len=*), intent(in) :: modelname
164  character(len=*), intent(in) :: input_name
165  type(NCFileVarsType), intent(inout) :: nc_vars
166  character(len=*), intent(in) :: nc_fname
167  integer(I4B), intent(in) :: ncid
168  integer(I4B), intent(in) :: iout
169  integer(I4B) :: ndim, nvar, nattr, unlimDimID
170  integer(I4B), dimension(:), allocatable :: varids
171  character(len=LINELENGTH) :: grid
172  integer(I4B) :: iparam
173 
174  ! check global attributes
175  grid = verify_global_attr(modeltype, modelname, input_name, nc_fname, ncid)
176 
177  ! initialize netcdf input structure
178  call nc_vars%init(modelname, nc_fname, ncid, grid)
179 
180  ! inquire for root dataset info
181  call nf_verify(nf90_inquire(ncid, ndim, nvar, nattr, unlimdimid), &
182  nc_vars%nc_fname)
183 
184  ! allocate and set varids
185  allocate (varids(nvar))
186  call nf_verify(nf90_inq_varids(ncid, nvar, varids), nc_vars%nc_fname)
187  do iparam = 1, nvar
188  ! validate and add netcdf file input variable
189  call add_package_var(modeltype, modelname, nc_vars, input_name, &
190  varids(iparam), iout)
191  end do
192 
193  ! cleanup
194  deallocate (varids)
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  use netcdfcommonmodule, only: nc_fopen
28  character(len=*) :: nc_fname
29  integer(I4B) :: iout
30  integer(I4B) :: ncid
31  logical(LGP) :: exists
32 
33  ! initialize
34  ncid = 0
35 
36  ! check if NETCDF file exists
37  inquire (file=nc_fname, exist=exists)
38  if (.not. exists) then
39  write (errmsg, '(a,a,a)') 'Specified NetCDF input file does &
40  &not exist [file=', trim(nc_fname), '].'
41  call store_error(errmsg, .true.)
42  end if
43 
44  ! open
45  ncid = nc_fopen(nc_fname, iout)
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 113 of file NCContextBuild.f90.

115  use inputoutputmodule, only: lowcase, upcase
116  character(len=*), intent(in) :: modeltype
117  character(len=*), intent(in) :: modelname
118  character(len=*), intent(in) :: input_name
119  character(len=*), intent(in) :: nc_fname
120  integer(I4B), intent(in) :: ncid
121  character(len=NETCDF_ATTR_STRLEN) :: grid, mesh, nctype
122 
123  ! initialize grid
124  grid = ''
125  mesh = ''
126  nctype = ''
127 
128  ! verify expected mf6_modeltype file attribute
129  if (nf90_get_att(ncid, nf90_global, "modflow_grid", &
130  grid) == nf90_noerr) then
131  call upcase(grid)
132  if (nf90_get_att(ncid, nf90_global, "mesh", &
133  mesh) == nf90_noerr) then
134  call upcase(mesh)
135  if (mesh == 'LAYERED') then
136  nctype = 'LAYERED MESH'
137  else
138  errmsg = 'NetCDF unsupported mesh type: "'//trim(mesh)//'".'
139  call store_error(errmsg)
140  call store_error_filename(nc_fname)
141  end if
142  else if (grid == 'STRUCTURED') then
143  nctype = 'STRUCTURED'
144  else if (grid == 'VERTEX' .or. grid == 'LAYERED MESH') then
145  warnmsg = 'Verify "modflow_grid" and "mesh" global &
146  &attributes in file: '//trim(nc_fname)
147  call store_warning(warnmsg)
148  nctype = 'LAYERED MESH'
149  end if
150  else
151  errmsg = 'NetCDF input file global attribute "modflow_grid" not found.'
152  call store_error(errmsg)
153  call store_error_filename(nc_fname)
154  end if
Here is the call graph for this function:
Here is the caller graph for this function: