Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Generalized the merger text append code to get rid of hard-coded cons…
Browse files Browse the repository at this point in the history
…tants and make it more maintainable
  • Loading branch information
daminton committed Jan 9, 2023
1 parent 2a409ed commit 19b957b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/collision/collision_resolve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ module subroutine collision_resolve_mergeaddsub(nbody_system, param, t, status)
logical, dimension(:), allocatable :: lmask
class(swiftest_pl), allocatable :: plnew, plsub
character(*), parameter :: FRAGFMT = '("Newbody",I0.7)'
character(*), parameter :: MERGEFMT = '(A,"_MERGE",I0.7)'
integer(I4B), parameter :: merge_text_length = 12
character(*), parameter :: MERGEFMT = '(A,I0.7)'
character(*), parameter :: MERGE_PREPEND_TEXT = "_MERGE"
integer(I4B) :: merge_text_length
character(len=NAMELEN) :: merge_text
character(len=NAMELEN) :: newname, origin_type
real(DP) :: volume

Expand Down Expand Up @@ -417,9 +419,11 @@ module subroutine collision_resolve_mergeaddsub(nbody_system, param, t, status)

! Appends an index number to the end of the original name to make it unique, but still identifiable as the original.
! If there is already an index number appended, replace it
nameidx = index(plnew%info(1)%name, "_MERGE") - 1
write(merge_text,MERGEFMT) MERGE_PREPEND_TEXT,plnew%id(1)
merge_text_length = len(trim(adjustl(merge_text)))
nameidx = index(plnew%info(1)%name, MERGE_PREPEND_TEXT) - 1
if (nameidx < 0) nameidx = min(len(trim(adjustl(plnew%info(1)%name))), NAMELEN - merge_text_length)
write(newname,MERGEFMT) trim(adjustl(plnew%info(1)%name(1:nameidx))),plnew%id(1)
write(newname,*) trim(adjustl(plnew%info(1)%name(1:nameidx))) // trim(adjustl(merge_text))
plnew%status(1) = NEW_PARTICLE
call plnew%info(1)%set_value(origin_type=origin_type, origin_time=t, name=newname, &
origin_rh=plnew%rh(:,1), origin_vh=plnew%vh(:,1), &
Expand Down

0 comments on commit 19b957b

Please sign in to comment.