subroutine target(q, en0, x0, y0, z0, thx0, thy0,txin1,txin2, & enp, x, y, z, thx, thy, xsig, thscat, & scflag, nRef, zt1, pl, totrot,scwgt) !bec implicit none include 'const.inc' integer scf, scflag, nRef integer i, j, n, k parameter(n=50) double precision q, en0, x0, y0, z0, thx0, thy0,scwgt double precision lam, thtestx, thtesty, zt1 ! zt1 starting pos of target 1 double precision txin1, txin2, zlm, pl, totrot, rotang double precision x, y, z, thx, thy, ep, enp double precision xi(n), yi(n), zi(n), thxi(n), thyi(n), eni(n) double precision xs(n), ys(n), zs(n) double precision xo(n), yo(n), zo(n), thxo(n), thyo(n), eno(n) double precision xsig,thscat double precision, external :: rsqrt,ratan logical rfailflg c lam = 2.*pi*h_par/rsqrt(2.*m_n*en0) ! Ang thtestx = gtindexx*lam thtesty = gtindexy*lam c rfailflg = .false. xsig = -1.d6 thscat = -1.d6 scf = 0 scflag = 0 nRef = 0 totrot = 0.d0 rotang = 0.d0 zlm = z0 + tarz if((x0.ge.txin1.and.x0.le.txin2).and. & (y0.ge.tary1.and.y0.le.tary2)) then xi(1) = x0 yi(1) = y0 zi(1) = z0 thxi(1) = thx0 thyi(1) = thy0 eni(1) = en0 pl = 0 do j=1, n ! loop through multiple scatterings if (j.ge.2) then xi(j) = xo(j-1) ! starting position now at last ending position yi(j) = yo(j-1) zi(j) = zo(j-1) thxi(j) = thxo(j-1) thyi(j) = thyo(j-1) eni(j) = eno(j-1) endif C load current position into scatt.f subroutine, check for scattering, do C reflections and return new positions, angles, energy call scatt(q, eni(j), xi(j), yi(j), zi(j),thxi(j), thyi(j), & txin1, txin2, tary1, tary2, zlm, & xs(j), ys(j), zs(j), scf, & eno(j), xo(j), yo(j), zo(j), thxo(j), thyo(j), & xsig,thscat,lam,rfailflg,scwgt) if (rfailflg) goto 110 ! neutron is lost through wall scflag = scflag + scf ! c scf is used in scatt,f to indicate if scatter position is inside c target (1) or outside target (0) c update rotation -- need begining and ending positions and energy if (scf.eq.1) then call rotation(eni(j),xi(j),yi(j),zi(j),xs(j),ys(j), & zs(j),zt1,rotang) pl=rsqrt((xs(j)-xi(j))**2+(ys(j)-yi(j))**2+(zs(j)-zi(j))**2)+pl totrot = totrot + rotang call rotation(eno(j),xs(j),ys(j),zs(j),xo(j),yo(j), & zo(j),zt1,rotang) pl=rsqrt((xo(j)-xs(j))**2+(yo(j)-ys(j))**2+(zo(j)-zs(j))**2)+pl totrot = totrot + rotang else if (eno(j).ne.eni(j)) write(6,*) ' no scat but Ei.ne.Eo ' call rotation(eno(j),xi(j),yi(j),zi(j),xo(j),yo(j), & zo(j),zt1,rotang) pl=rsqrt((xo(j)-xi(j))**2+(yo(j)-yi(j))**2+(zo(j)-zi(j))**2)+pl totrot = totrot + rotang end if c if (j.gt.1) then c write(6,*) ' target ', j, rotang, totrot c write(6,*) xo(j),yo(j),zo(j) c write(6,*) scf, rotang, totrot c write(6,*) ' pl ',pl c end if cccc end rotation update c below is somewhat redundant because of rflx,y in scatt.f, but if you set rflx,y=1 c in scatt.f, then this is needed. So leave in. if ((thxo(j).eq.-1*thxi(j)).and.(abs(thxo(j)).gt.thtestx)) then x = -1.d6 y = -1.d6 z = -1.d6 thx = -1.d6 thy = -1.d6 enp = -1.d6 exit endif if ((thyo(j).eq.-1*thyi(j)).and.(abs(thyo(j)).gt.thtesty)) then x = -1.d6 y = -1.d6 z = -1.d6 thx = -1.d6 thy = -1.d6 enp = -1.d6 exit endif c nRef = nRef + 1 if (j.gt.49) write(6,*) ' j,en, xsig ',j,eni(j), xsig if (j.gt.49) write(6,*) ' x,y,z ',xo(j),yo(j),zo(j) if(zo(j)-zlm.ge.0) then x = xo(j) y = yo(j) z = zo(j) thx = thxo(j) thy = thyo(j) enp = eno(j) exit ! Jump out of loop endif enddo else x = -1.d6 y = -1.d6 z = -1.d6 thx = -1.d6 thy = -1.d6 enp = -1.d6 endif goto 111 110 continue x = -1.d6 y = -1.d6 z = -1.d6 thx = -1.d6 thy = -1.d6 enp = -1.d6 c write(6,*) ' rfail ', thxi(j),thxo(j) c write(6,*) thyi(j),thyo(j) c write(6,*) thtestx,thtesty 111 return end