subroutine track_sept1_end(lat,co, ix_essept, ix_magsept1,ix_magsept2, ix_extraction_fork) use bmad use ramp_parameters implicit none type (lat_struct) lat type (coord_struct), allocatable :: co(:),cob(:),coa(:) integer ix_essept, ix_magsept1,ix_magsept2, ix_extraction_fork integer track_state, lun integer i real(rp) s_ext_fork lun=lunget() open(unit=lun,file=trim(directory)//'/ext_line_traj.dat') call reallocate_coord(cob,lat%branch(1)%n_ele_track) call reallocate_coord(coa,size(co)) coa = co coa(ix_essept-1)%vec(1) = coa(ix_essept-1)%vec(1) + x_septum(0) coa(ix_essept-1)%vec(1) = x_septum(0) coa(ix_essept-1)%vec(2) = 0. call track_many(lat,coa,ix_essept-1,ix_extraction_fork,1, ix_branch=0, track_state=track_state) cob(0) = coa(ix_extraction_fork) call track_all(lat,cob,ix_branch=1) do i=1,lat%branch(0)%n_ele_track write(lun,'(a16,1x,8es12.4,1x,i10)')lat%branch(0)%ele(i)%name, lat%branch(0)%ele(i)%s, coa(i)%vec, lat%branch(0)%ele(i)%value(l$), lat%branch(0)%ele(i)%key end do write(lun,'(/,a1,/)')'#' s_ext_fork = lat%branch(0)%ele(ix_extraction_fork)%s do i=1,lat%branch(1)%n_ele_track write(lun,'(a16,1x,8es12.4,1x,i10)')lat%branch(1)%ele(i)%name, lat%branch(1)%ele(i)%s+s_ext_fork, cob(i)%vec, lat%branch(1)%ele(i)%value(l$), lat%branch(1)%ele(i)%key end do close(unit=lun) return end