11! +
2- ! Function pointer_to_next_ele (this_ele, offset, skip_beginning, follow_fork) result (next_ele)
2+ ! Function pointer_to_next_ele (this_ele, offset, skip_beginning, follow_fork, ix_multipass ) result (next_ele)
33!
44! Function to return a pointer to the next (if offset = 1) tracking element relative to this_ele.
55!
6- ! If the this_ele is a super_lord element , the appropriate element in the tracking
6+ ! If the this_ele is a super_lord or girder_lord , the appropriate element in the tracking
77! part of the lattice is returned.
88!
9- ! If this_ele is a lord element but not a super_lord then this is an error since
9+ ! If this_ele is a lord element but not a super_lord nor a girder_lord then this is an error since
1010! it is not clear what to do in this case.
1111!
1212! This routine will always wrap around between branch end and branch beginning
2626! when wrapping around. Default is False.
2727! follow_fork -- logical, optional: If True then fork at any fork element.
2828! Default is False.
29- !
29+ ! ix_multipass -- integer, optional: Default = 1. Used to select the multipass branch if
30+ ! this_ele is a multipass_lord.
31+ !
32+ ! Output:
3033! next_ele -- ele_struct, pointer: Element after this_ele (if offset = 1).
3134! Nullified if there is an error. EG bad this_ele.
3235!-
3336
34- function pointer_to_next_ele (this_ele , offset , skip_beginning , follow_fork ) result (next_ele)
37+ function pointer_to_next_ele (this_ele , offset , skip_beginning , follow_fork , ix_multipass ) result (next_ele)
3538
3639use bmad_routine_interface, dummy = > pointer_to_next_ele
3740
@@ -42,7 +45,7 @@ function pointer_to_next_ele (this_ele, offset, skip_beginning, follow_fork) res
4245type (ele_struct), pointer :: an_ele
4346type (branch_struct), pointer :: branch
4447
45- integer , optional :: offset
48+ integer , optional :: offset, ix_multipass
4649integer i, ix_ele, n_off
4750logical , optional :: skip_beginning, follow_fork
4851
@@ -65,16 +68,26 @@ function pointer_to_next_ele (this_ele, offset, skip_beginning, follow_fork) res
6568! Initially point to the first or last slave element so that this routine
6669! will return a pointer to an element that is not a slave of this_ele.
6770
68- if (this_ele% ix_ele > this_ele% branch% n_ele_track) then ! Is a lord
69- if (this_ele% lord_status /= super_lord$) return ! Error
70- if (n_off > 0 ) then
71- an_ele = > pointer_to_slave(this_ele, this_ele% n_slave)
72- else
73- an_ele = > pointer_to_slave(this_ele, 1 )
74- endif
75- else
76- an_ele = > this_ele
77- endif
71+ an_ele = > this_ele
72+
73+ do
74+ if (an_ele% ix_ele <= an_ele% branch% n_ele_track) exit ! Is not a lord
75+
76+ select case (an_ele% lord_status)
77+ case (multipass_lord$)
78+ an_ele = > pointer_to_slave(an_ele, integer_option(1 , ix_multipass))
79+
80+ case (super_lord$, girder_lord$)
81+ if (n_off > 0 ) then
82+ an_ele = > pointer_to_slave(an_ele, an_ele% n_slave)
83+ else
84+ an_ele = > pointer_to_slave(an_ele, 1 )
85+ endif
86+
87+ case default
88+ return ! Error
89+ end select
90+ enddo
7891
7992! Apply offset.
8093! If follow_fork = True then must check all elements in between for a possible fork element.
0 commit comments