Skip to content

Commit

Permalink
check input length of model,exg,pacakge names
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed May 6, 2024
1 parent 4bfb27a commit c0b0a62
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src/Utilities/Idm/IdmLoad.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module IdmLoadModule
use SimVariablesModule, only: errmsg
use ConstantsModule, only: LINELENGTH, LENMEMPATH, LENMODELNAME, &
LENEXCHANGENAME, LENCOMPONENTNAME
use SimModule, only: store_error, store_error_filename
use SimModule, only: store_error, count_errors, store_error_filename
use ListModule, only: ListType
use InputLoadTypeModule, only: StaticPkgLoadBaseType, &
DynamicPkgLoadBaseType, &
Expand Down Expand Up @@ -212,9 +212,9 @@ subroutine load_models(model_loadmask, iout)
use MemoryHelperModule, only: create_mem_path
use MemoryManagerModule, only: mem_setptr
use CharacterStringModule, only: CharacterStringType
use SimVariablesModule, only: idm_context
use SimVariablesModule, only: idm_context, simfile
use ModelPackageInputsModule, only: ModelPackageInputsType
use SourceCommonModule, only: idm_component_type
use SourceCommonModule, only: idm_component_type, inlen_check
use SourceLoadModule, only: load_modelnam
! -- dummy
integer(I4B), dimension(:), intent(in) :: model_loadmask
Expand Down Expand Up @@ -245,7 +245,12 @@ subroutine load_models(model_loadmask, iout)
! -- attributes for this model
mtype = mtypes(n)
mfname = mfnames(n)
mname = mnames(n)
call inlen_check(mnames(n), mname, LENMODELNAME, 'MODELNAME')
!
! -- terminate if errors were detected
if (count_errors() > 0) then
call store_error_filename(simfile)
end if
!
! -- load specified model inputs
if (model_loadmask(n) > 0) then
Expand Down Expand Up @@ -282,7 +287,8 @@ subroutine load_exchanges(model_loadmask, iout)
mem_deallocate, get_isize
use CharacterStringModule, only: CharacterStringType
use SimVariablesModule, only: idm_context, simfile
use SourceCommonModule, only: idm_subcomponent_type, ifind_charstr
use SourceCommonModule, only: idm_subcomponent_type, ifind_charstr, &
inlen_check
use SourceLoadModule, only: create_input_loader, remote_model_ndim
! -- dummy
integer(I4B), dimension(:), intent(in) :: model_loadmask
Expand Down Expand Up @@ -335,8 +341,8 @@ subroutine load_exchanges(model_loadmask, iout)
! -- attributes for this exchange
exgtype = etypes(n)
efname = efiles(n)
mname1 = emnames_a(n)
mname2 = emnames_b(n)
call inlen_check(emnames_a(n), mname1, LENMODELNAME, 'MODELNAME')
call inlen_check(emnames_b(n), mname2, LENMODELNAME, 'MODELNAME')
!
! initialize mempath as no path
emempaths(n) = ''
Expand All @@ -351,6 +357,10 @@ subroutine load_exchanges(model_loadmask, iout)
if (m1_idx <= 0) errmsg = trim(errmsg)//' '//trim(mname1)
if (m2_idx <= 0) errmsg = trim(errmsg)//' '//trim(mname2)
call store_error(errmsg)
end if
!
! -- terminate if errors were detected
if (count_errors() > 0) then
call store_error_filename(simfile)
end if
!
Expand Down
10 changes: 8 additions & 2 deletions src/Utilities/Idm/ModelPackageInputs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module ModelPackageInputsModule
use SimVariablesModule, only: errmsg
use ConstantsModule, only: LINELENGTH, LENMEMPATH, LENMODELNAME, LENFTYPE, &
LENPACKAGETYPE, LENPACKAGENAME, LENCOMPONENTNAME
use SimModule, only: store_error, store_error_filename
use SimModule, only: store_error, count_errors, store_error_filename
use SimVariablesModule, only: iout
use ArrayHandlersModule, only: expandarray
use CharacterStringModule, only: CharacterStringType
Expand Down Expand Up @@ -384,6 +384,7 @@ end subroutine modelpkgs_add
subroutine modelpkgs_addpkgs(this)
! -- modules
use MemoryManagerModule, only: mem_setptr
use SourceCommonModule, only: inlen_check
! -- dummy
class(ModelPackageInputsType) :: this
! -- local
Expand All @@ -410,7 +411,12 @@ subroutine modelpkgs_addpkgs(this)
! -- attributes for this package
ftype = ftypes(n)
fname = fnames(n)
pname = pnames(n)
call inlen_check(pnames(n), pname, LENPACKAGENAME, 'PACKAGENAME')
!
! -- terminate if errors were detected
if (count_errors() > 0) then
call store_error_filename(this%modelfname)
end if
!
! -- add this instance to package list
call this%add(ftype, fname, pname)
Expand Down
31 changes: 30 additions & 1 deletion src/Utilities/Idm/SourceCommon.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module SourceCommonModule
public :: file_ext
public :: ifind_charstr
public :: filein_fname
public :: inlen_check

contains

Expand Down Expand Up @@ -466,7 +467,6 @@ end function ifind_charstr
!<
function filein_fname(filename, tagname, input_mempath, input_fname) &
result(found)
use SimModule, only: store_error, store_error_filename
use MemoryManagerModule, only: mem_setptr, get_isize
use CharacterStringModule, only: CharacterStringType
character(len=*), intent(inout) :: filename
Expand Down Expand Up @@ -504,4 +504,33 @@ function filein_fname(filename, tagname, input_mempath, input_fname) &
return
end function filein_fname

!> @brief store an error for input exceeding internal name length
!<
subroutine inlen_check(input_name, mf6_name, maxlen, name_type)
use CharacterStringModule, only: CharacterStringType
type(CharacterStringType), intent(in) :: input_name
character(len=*), intent(inout) :: mf6_name
integer(I4B), intent(in) :: maxlen
character(len=*), intent(in) :: name_type
character(len=LINELENGTH) :: input_str
integer(I4B) :: ilen
!
! -- initialize
mf6_name = ''
input_str = input_name
ilen = len_trim(input_str)
if (ilen > maxlen) then
write (errmsg, '(a,i0,a)') &
'Input name "'//trim(input_str)//'" exceeds maximum allowed length (', &
maxlen, ') for '//trim(name_type)//'.'
call store_error(errmsg)
end if
!
! -- set truncated name
mf6_name = trim(input_str)
!
! -- return
return
end subroutine inlen_check

end module SourceCommonModule

0 comments on commit c0b0a62

Please sign in to comment.