Skip to content

Commit

Permalink
update mem_write_usage to include context
Browse files Browse the repository at this point in the history
add get_mem_path_context character function
  • Loading branch information
jdhughes-usgs committed Dec 5, 2023
1 parent 0e627ce commit 6a6827b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
37 changes: 31 additions & 6 deletions src/Utilities/Memory/MemoryHelper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ subroutine split_mem_path(mem_path, component, subcomponent)

end subroutine split_mem_path

!> @brief Return the context from the memory path
!!
!! NB: when there is no context in the memory path, a
!! empty character string is returned.
!<
function get_mem_path_context(mem_path) result(res)
character(len=*), intent(in) :: mem_path !< path to the memory object
character(len=LENMEMPATH) :: res !< memory path context
! local
integer(I4B) :: idx

! initialize the memory path context
res = ' '

if (mem_path(1:2) == '__') then
idx = index(mem_path, memPathSeparator)
if (idx > 0) then
res = mem_path(:idx)
end if
end if

return

end function get_mem_path_context

!> @brief Remove the context from the memory path
!!
!! NB: when there is no context in the memory path, the
Expand All @@ -141,16 +166,16 @@ subroutine strip_context_mem_path(mem_path, mem_path_no_context)
character(len=LENMEMPATH), intent(inout) :: mem_path_no_context !< path to the memory object without the context
! local
integer(I4B) :: idx
character(len=LENMEMPATH) :: context

! initialize the local mem_path
mem_path_no_context = mem_path

if (mem_path(1:2) == '__') then
idx = index(mem_path, memPathSeparator)
if (idx > 0) then
mem_path_no_context = ' '
mem_path_no_context = mem_path(idx + 1:)
end if
context = get_mem_path_context(mem_path)

if (len_trim(context) > 0) then
idx = len_trim(context)
mem_path_no_context = mem_path(idx + 1:)
end if

end subroutine strip_context_mem_path
Expand Down
32 changes: 22 additions & 10 deletions src/Utilities/Memory/MemoryManager.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ module MemoryManagerModule
use ConstantsModule, only: DZERO, DONE, &
DEM3, DEM6, DEM9, DEP3, DEP6, DEP9, &
LENMEMPATH, LENMEMSEPARATOR, LENVARNAME, &
LENCOMPONENTNAME, LINELENGTH, LENMEMTYPE, &
LENMEMADDRESS, TABSTRING, TABUCSTRING, &
LENMEMADDRESS, LENCOMPONENTNAME, &
LENMEMTYPE, LINELENGTH, &
TABSTRING, TABUCSTRING, &
TABINTEGER, TABREAL, TABCENTER, TABLEFT, &
TABRIGHT
use SimVariablesModule, only: errmsg
use SimModule, only: store_error, count_errors
use MemoryTypeModule, only: MemoryType
use MemoryListModule, only: MemoryListType
use MemoryHelperModule, only: mem_check_length, split_mem_path, &
strip_context_mem_path
strip_context_mem_path, get_mem_path_context
use TableModule, only: TableType, table_cr
use CharacterStringModule, only: CharacterStringType

Expand Down Expand Up @@ -2829,8 +2830,12 @@ subroutine mem_write_usage(iout)
integer(I4B), intent(in) :: iout !< unit number for mfsim.lst
! -- local
class(MemoryType), pointer :: mt
character(len=LENMEMPATH), allocatable, dimension(:) :: cunique
character(len=LENMEMPATH) :: mem_path
character(len=LENMEMADDRESS), allocatable, dimension(:) :: cunique
! character(len=LENMEMPATH) :: mem_path
character(len=LENMEMPATH) :: context
character(len=LENCOMPONENTNAME) :: component
character(len=LENCOMPONENTNAME) :: subcomponent
character(len=LENMEMADDRESS) :: context_component
character(LEN=10) :: cunits
integer(I4B) :: ipos
integer(I4B) :: icomp
Expand Down Expand Up @@ -2874,8 +2879,10 @@ subroutine mem_write_usage(iout)
ilen = len_trim(cunique(icomp))
do ipos = 1, memorylist%count()
mt => memorylist%Get(ipos)
call strip_context_mem_path(mt%path, mem_path)
if (cunique(icomp) /= mem_path(1:ilen)) cycle
call split_mem_path(mt%path, component, subcomponent)
context = get_mem_path_context(mt%path)
context_component = trim(context)//component
if (cunique(icomp) /= context_component(1:ilen)) cycle
if (.not. mt%master) cycle
if (mt%memtype(1:6) == 'STRING') then
nchars = nchars + mt%isize * mt%element_size
Expand Down Expand Up @@ -3007,11 +3014,14 @@ subroutine mem_unique_origins(cunique)
! -- modules
use ArrayHandlersModule, only: ExpandArray, ifind
! -- dummy
character(len=LENMEMPATH), allocatable, dimension(:), intent(inout) :: cunique !< array with unique first components
character(len=LENMEMADDRESS), allocatable, dimension(:), intent(inout) :: &
cunique !< array with unique first components
! -- local
class(MemoryType), pointer :: mt
character(len=LENMEMPATH) :: context
character(len=LENCOMPONENTNAME) :: component
character(len=LENCOMPONENTNAME) :: subcomponent
character(len=LENMEMADDRESS) :: context_component
integer(I4B) :: ipos
integer(I4B) :: ipa
! -- code
Expand All @@ -3023,10 +3033,12 @@ subroutine mem_unique_origins(cunique)
do ipos = 1, memorylist%count()
mt => memorylist%Get(ipos)
call split_mem_path(mt%path, component, subcomponent)
ipa = ifind(cunique, component)
context = get_mem_path_context(mt%path)
context_component = trim(context)//component
ipa = ifind(cunique, context_component)
if (ipa < 1) then
call ExpandArray(cunique, 1)
cunique(size(cunique)) = component
cunique(size(cunique)) = context_component
end if
end do
!
Expand Down

0 comments on commit 6a6827b

Please sign in to comment.