MODFLOW 6  version 6.7.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 51 of file NCContextBuild.f90.

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

150  use inputoutputmodule, only: lowcase, upcase
151  character(len=*), intent(in) :: modeltype
152  character(len=*), intent(in) :: modelname
153  character(len=*), intent(in) :: input_name
154  type(NCFileVarsType), intent(inout) :: nc_vars
155  character(len=*), intent(in) :: nc_fname
156  integer(I4B), intent(in) :: ncid
157  integer(I4B), intent(in) :: iout
158  integer(I4B) :: ndim, nvar, nattr, unlimDimID
159  integer(I4B), dimension(:), allocatable :: varids
160  character(len=LINELENGTH) :: grid
161  integer(I4B) :: iparam
162 
163  ! check global attributes
164  grid = verify_global_attr(modeltype, modelname, input_name, nc_fname, ncid)
165 
166  ! initialize netcdf input structure
167  call nc_vars%init(modelname, nc_fname, ncid, grid)
168 
169  ! inquire for root dataset info
170  call nf_verify(nf90_inquire(ncid, ndim, nvar, nattr, unlimdimid), &
171  nc_vars%nc_fname)
172 
173  ! allocate and set varids
174  allocate (varids(nvar))
175  call nf_verify(nf90_inq_varids(ncid, nvar, varids), nc_vars%nc_fname)
176  do iparam = 1, nvar
177  ! validate and add netcdf file input variable
178  call add_package_var(modeltype, modelname, nc_vars, input_name, &
179  varids(iparam), iout)
180  end do
181 
182  ! cleanup
183  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.

28  use netcdfcommonmodule, only: nc_fopen
29  character(len=*) :: nc_fname
30  integer(I4B) :: iout
31  integer(I4B) :: ncid
32  logical(LGP) :: exists
33 
34  ! initialize
35  ncid = 0
36 
37  ! check if NETCDF file exists
38  inquire (file=nc_fname, exist=exists)
39  if (.not. exists) then
40  write (errmsg, '(a,a,a)') 'Specified NetCDF input file does &
41  &not exist [file=', trim(nc_fname), '].'
42  call store_error(errmsg, .true.)
43  end if
44 
45  ! open
46  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 121 of file NCContextBuild.f90.

123  use inputoutputmodule, only: lowcase, upcase
124  character(len=*), intent(in) :: modeltype
125  character(len=*), intent(in) :: modelname
126  character(len=*), intent(in) :: input_name
127  character(len=*), intent(in) :: nc_fname
128  integer(I4B), intent(in) :: ncid
129  character(len=NETCDF_ATTR_STRLEN) :: grid
130 
131  ! initialize grid
132  grid = ''
133 
134  ! verify expected mf6_modeltype file attribute
135  if (nf90_get_att(ncid, nf90_global, "modflow6_grid", &
136  grid) == nf90_noerr) then
137  ! set grid to upper case
138  call upcase(grid)
139  else
140  errmsg = 'NetCDF input file global attribute "grid" not found.'
141  call store_error(errmsg)
142  call store_error_filename(nc_fname)
143  end if
Here is the call graph for this function:
Here is the caller graph for this function: