Skip to content

Commit

Permalink
extend idm framework with netcdf4 loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Nov 5, 2023
1 parent 2e3db7a commit 2519249
Show file tree
Hide file tree
Showing 9 changed files with 3,503 additions and 20 deletions.
48 changes: 48 additions & 0 deletions src/Utilities/Idm/DefinitionSelect.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module DefinitionSelectModule
implicit none
private
public :: get_param_definition_type
public :: package_scoped_param_dfn
public :: get_aggregate_definition_type
public :: split_record_definition

Expand Down Expand Up @@ -63,6 +64,53 @@ function get_param_definition_type(input_definition_types, &
return
end function get_param_definition_type

!> @brief Return parameter definition without checking blockname
!<
function package_scoped_param_dfn(input_definition_types, &
component_type, subcomponent_type, &
tagname, filename) &
result(idt)
type(InputParamDefinitionType), dimension(:), intent(in), target :: &
input_definition_types
character(len=*), intent(in) :: component_type !< component type, such as GWF or GWT
character(len=*), intent(in) :: subcomponent_type !< subcomponent type, such as DIS or NPF
character(len=*), intent(in) :: tagname !< name of the input tag
character(len=*), intent(in) :: filename !< input filename
type(InputParamDefinitionType), pointer :: idt !< corresponding InputParameterDefinitionType for this tag
type(InputParamDefinitionType), pointer :: tmp_ptr
integer(I4B) :: i
!
idt => null()
!
do i = 1, size(input_definition_types)
tmp_ptr => input_definition_types(i)
if (tmp_ptr%component_type == component_type .and. &
tmp_ptr%subcomponent_type == subcomponent_type .and. &
tmp_ptr%tagname == tagname) then
if (associated(idt)) then
write (errmsg, '(a,a,a)') &
'Input file tag name "', trim(tagname), &
'" is not unique (file scope) in package definition set.'
call store_error(errmsg)
call store_error_filename(filename)
else
idt => input_definition_types(i)
end if
end if
end do
!
if (.not. associated(idt)) then
write (errmsg, '(a,a,a)') &
'Input file tag not found: "', trim(tagname), &
'".'
call store_error(errmsg)
call store_error_filename(filename)
end if
!
! -- return
return
end function package_scoped_param_dfn

!> @brief Return aggregate definition
!<
function get_aggregate_definition_type(input_definition_types, component_type, &
Expand Down
12 changes: 11 additions & 1 deletion src/Utilities/Idm/IdmLoad.f90
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ end subroutine idm_ad
!> @brief idm deallocate routine
!<
subroutine idm_da(iout)
use InputModelContextModule, only: ModelContextDestroy
integer(I4B), intent(in) :: iout
!
call dynamic_da(iout)
!
call ModelContextDestroy()
!
! -- return
return
end subroutine idm_da
Expand Down Expand Up @@ -189,12 +192,19 @@ end subroutine model_pkg_load
!<
subroutine load_model_pkgs(model_pkg_inputs, iout)
use ModelPackageInputsModule, only: ModelPackageInputsType
use SourceLoadModule, only: open_source_file
use SourceLoadModule, only: open_source_file, create_context
use IdmDfnSelectorModule, only: idm_integrated
type(ModelPackageInputsType), intent(inout) :: model_pkg_inputs
integer(i4B), intent(in) :: iout
integer(I4B) :: itype, ipkg
!
! -- create package context object
call create_context(model_pkg_inputs%modeltype, &
model_pkg_inputs%component_type, &
model_pkg_inputs%modelname, &
model_pkg_inputs%modelfname, &
model_pkg_inputs%pkglist, iout)
!
! -- load package instances by type
do itype = 1, size(model_pkg_inputs%pkglist)
!
Expand Down
50 changes: 37 additions & 13 deletions src/Utilities/Idm/ModflowInput.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module ModflowInputModule

use KindModule, only: I4B, LGP
use ConstantsModule, only: LENMEMPATH, LENCOMPONENTNAME, &
LENPACKAGETYPE
LENPACKAGETYPE, LENPACKAGENAME, &
LINELENGTH
use MemoryHelperModule, only: create_mem_path
use InputDefinitionModule, only: InputParamDefinitionType, &
InputBlockDefinitionType
Expand All @@ -23,9 +24,9 @@ module ModflowInputModule
private
public :: ModflowInputType, getModflowInput

!> @brief derived type for storing input definition for a file
!> @brief type for storing input definition for a file
!!
!! This derived type contains the information needed to read
!! This type contains the information needed to read
!! a specific modflow input file, including block definitions,
!! aggregate definitions (structarrays), and individual
!! parameter definitions.
Expand Down Expand Up @@ -63,7 +64,8 @@ function getModflowInput(pkgtype, component_type, subcomponent_type, &
! -- set subcomponent type
if (present(filename)) then
dfn_subcomponent_type = update_sc_type(pkgtype, filename, component_type, &
subcomponent_type)
subcomponent_type, component_name, &
subcomponent_name)
else
dfn_subcomponent_type = trim(subcomponent_type)
end if
Expand All @@ -90,23 +92,45 @@ function getModflowInput(pkgtype, component_type, subcomponent_type, &
mf6_input%subcomponent_type)
end function getModflowInput

function update_sc_type(filetype, filename, component_type, subcomponent_type) &
function update_sc_type(filetype, filename, component_type, subcomponent_type, &
component_name, subcomponent_name) &
result(sc_type)
character(len=*), intent(in) :: component_type
character(len=*), intent(in) :: subcomponent_type
use SourceCommonModule, only: package_source_type
use InputModelContextModule, only: GetModelNC4Context
use NC4ModelInputsModule, only: NC4ModelInputsType, NC4ModelPackageInputType
character(len=*), intent(in) :: filetype
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: component_type
character(len=*), intent(in) :: subcomponent_type
character(len=*), intent(in) :: component_name
character(len=*), intent(in) :: subcomponent_name
! -- result
character(len=LENPACKAGETYPE) :: sc_type
! -- local
character(len=LENPACKAGENAME) :: source_type
type(NC4ModelInputsType), pointer :: nc4_context
type(NC4ModelPackageInputType), pointer :: ncpkg
!
sc_type = subcomponent_type
source_type = package_source_type(filename)
!
select case (subcomponent_type)
case ('RCH', 'EVT', 'SCP')
sc_type = read_as_arrays(filetype, filename, component_type, &
subcomponent_type)
case default
end select
if (source_type == 'MF6FILE') then
select case (subcomponent_type)
case ('RCH', 'EVT', 'SCP')
sc_type = read_as_arrays(filetype, filename, component_type, &
subcomponent_type)
case default
end select
else if (source_type == 'NETCDF4') then
select case (subcomponent_type)
case ('RCH', 'EVT', 'SCP')
nc4_context => GetModelNC4Context(component_name)
ncpkg => nc4_context%get_package(component_name, &
subcomponent_name)
sc_type = trim(ncpkg%subcomponent_type)
case default
end select
end if
!
! -- return
return
Expand Down
Loading

0 comments on commit 2519249

Please sign in to comment.