!+ subroutine ramp_function (t,frac_ref, extract_qv, extract_qh, extract_s, extract_octk3, bump) use bmad use ramp_parameters use multibunch_interface implicit none logical err_flag character(*), parameter :: r_name = 'track1_preprocess' real(rp) t, frac_ref, f_AC/60./, extract_qv, extract_qh, extract_s, extract_octk3 real(rp) sint,w real(rp) tau/2.52131e-6/ real(rp) turn_on real(rp) bump ! integer n, j, jmax, i, ix_corner(0:100) integer turn logical first/.true./ frac_ref = (-cos(twopi*f_ac * t) + 1.)/2. sint=0. if(t>t_ext .and. t < 3*t_ext)then w = twopi*60. ! do n=1,59,2 ! sint = sint + 1/float(n) * sin(n*w*(t-t_ext)) ! end do ! turn_on_time (time to turn on) in fractions of t_ext. If turn_on_time = 1/4, then sint goes from 0 to 1 in 1/4 t_ext after t_ext if(t>t_ext .and. t< (1.+turn_on_time*t_ext))sint = (t-t_ext)/(turn_on_time*t_ext) if(t>=(1.+turn_on_time)*t_ext)sint = 1. endif if(first)then ! assemble function for octupole print *,' size(oct_ramp) = ', size(oct_ramp) call create_profile(oct_ramp) call create_profile(quad_ramp) call create_profile(bump_ramp) call create_profile(sext_ramp) first=.false. endif turn = min(size(oct_ramp)-1,int((t-t0)/tau)) turn_on = 0. if(t>t_ext)turn_on=1 ! extract_qv = qv*sint ! extract_qh = qh*sint extract_qv = qv*quad_ramp(turn) extract_qh = qh*quad_ramp(turn) ! extract_octk3 = octk3 * ext_param * max(0._rp, min(t,t1)-t_ext) !+octk3*frac_ref * turn_on extract_octk3 = octk3 * oct_ramp(turn) ! bump = frac_ref * bump_ramp(turn) bump = bump_ramp(turn) extract_s = sextk2 * sext_ramp(turn) ! if(t>t_ext)write(19,'(4es12.4)')t,t/tau,extract_s, extract_octk3 err_flag = .false. end subroutine !subroutine to create ramp profile P(turn) based on P specified at a few points subroutine create_profile(Q) use bmad implicit none real(rp) Q(0:7000) logical err_flag real(rp) P_corner(0:100), slope ! integer n, j, jmax/1/, i, ix_corner(0:100) integer turn character(len=32):: fmt !populate array P(1:nturns) based on corner values Q(0) = 0 P_corner(0) = 0 ix_corner(0) = 0 j=0 do i=1,size(Q)-1 if(Q(i)>=0)then j=j+1 P_corner(j) = Q(i) ix_corner(j) = i jmax = j endif end do print '(a,1x,10es12.4)',' P_corner', P_corner(1:min(10,jmax)) if(jmax > 10)then write(fmt,'(a6,i2,a7)')'(a,1x,',jmax-10,'es12.4)' ! print *, 'fmt = ', fmt print fmt,' ',P_corner(11:jmax) endif print '(a,1x,10i10)', ' ix_corner ',ix_corner(1:min(10,jmax)) if(jmax > 10)then write(fmt,'(a6,i2,a4)')'(a,1x,',jmax-10,'i10)' print fmt, ' ',ix_corner(11:jmax) endif do j=0,jmax-1 slope = (Q(ix_corner(j+1)) - Q(ix_corner(j)))/(ix_corner(j+1)-ix_corner(j)) do i = ix_corner(j)+1,ix_corner(j+1)-1 Q(i) = slope * (i-ix_corner(j)) + Q(ix_corner(j)) end do end do ! do i=0,size(Q)-1 ! print '(i10,1x,es12.4)', i,Q(i) ! end do return end