SUBROUTINE BUNCHCROSS common /zquad/totcir,tloc(300),circ(300) common /crospnt/d(1000),ncross,ntrains,nbunches,nspace,angle & ,ncb(100,300),istart,l3,ncb1b2(100,100),last,nfind(1000) dimension e(1000),mcb1b2(100,100),mfind(1000),mcb(100,300) real*8 amat,xpel,ypel,expel,eldat,tleng,aleng,acleng include 'elements.inc' c d(i) is distance from IP to i crossing point c ncross is the number of parasitic crossing points c ntrains is the number of bunch trains c nspace=the bunch separation in units of 7 RF wavelengths c ncb(i,j) is true if bunch i has a close encounter at the j crossing point data lcd/7/ !lcd=least common denominator of RF wavelengths data mcb/30000*0/ if(totcir.eq.0.)totcir=tleng/2 ntotcir=183 !number of lcds in circumference wavelength=2*totcir/(ntotcir*lcd) !totcir=1/2 total circumference d(1)=0. n=1 do 20 nt1=1,ntrains ntrain1=INT(183*(nt1-1)/ntrains) do 20 nb1=1,nbunches nzb1=ntrain1+nspace*(nb1-1) do 20 nt2=1,ntrains ntrain2=INT(183*(nt2-1)/ntrains) do 20 nb2=1,nbunches nzb2=ntrain2+nspace*(nb2-1) marg1=ntotcir+nzb1-nzb2 s=0.5*MOD(marg1,ntotcir)*lcd*wavelength c eliminate duplicates do j=1,n !see if s is the same as any previous s if(s.eq.0.)s=totcir if(s.eq.0.)goto 20 index=(nt1-1)*nbunches+nb1 if(s.eq.d(j))then mcb(index,j)=1 n1=(nt1-1)*nbunches+nb1 n2=(nt2-1)*nbunches+nb2 mcb1b2(n1,n2)=j goto 20 endif end do d(n)=s n1=(nt1-1)*nbunches+nb1 n2=(nt2-1)*nbunches+nb2 mcb1b2(n1,n2)=n mcb(index,n)=1 n=n+1 20 continue ncross=n-1 c sort the list of crossing points do j=1,ncross e(j)=d(j) mfind(j)=j end do do jj=1,ncross do kk=jj+1,ncross j=mfind(jj) k=mfind(kk) if(e(k).lt.e(j))then mfind(jj)=k mfind(kk)=j endif end do end do c do j=1,ncross d(j)=e(mfind(j)) nfind(mfind(j))=j end do c nbuntot=ntrains*nbunches c do j=1,ncross do n1=1,nbuntot ncb(n1,j)=0 end do end do c do n1=1,nbuntot do n2=1,nbuntot n=mcb1b2(n1,n2) ncb1b2(n1,n2)=nfind(n) if(mcb(n1,n).eq.1)ncb(n1,nfind(n))=1 end do end do c return end