subroutine focus_ele(ele,x,y,t,field) use bmad use parameters_bmad implicit none type(ele_struct) ele TYPE(em_field_struct) field real(rp) x,y,t real(rp) gradient,width,start, omega, phase integer:: save, lun logical :: first = .true. logical err !if(first)then ! lun=lunget() ! open(unit=lun,file='focus_ele_out.dat') ! first=.false. !endif width = value_of_attribute(ele, 'KICK_WIDTH', err) start = value_of_attribute (ele, 'X_ANGLE', err) ! for square pulse = start time in ns. For sinusoidal pulse, start = omega = width phase = start field%E(1:3) = 0. field%B(1:3) = 0. if(abs(value_of_attribute(ele, 'FIELD_INDEX')) > 100.) then !must be voltage gradient = value_of_attribute(ele, 'FIELD_INDEX')/(0.05)**2 * 2 * cos(omega * t + start) field%E(1) = -gradient * x field%E(2) = gradient * y else gradient = value_of_attribute(ele, 'FIELD_INDEX') * cos(omega * t + start) field%B(1) = gradient * y field%B(2) = gradient * x endif !if(t > start .and. t < start+width)then write(113, '(8(a13,1x,es12.4))')' gradient = ',gradient,' width=',width,'start=',start,'t=',t,' x =',x,' y =',y,' field%B(1) =', field%B(1),' field%B(2) =', field%B(2) !endif return end