! sddsplot      -column=x,y  run.da0   -graph=line,type=2  -legend=spec=IDEALDA
!sddsplot -layout=1,2     -column=x,y ilsf.aper    -graph=sym,vary=subtype,fill,scale=2,type=1 -order=spect   -column=x,y   run.da0   -graph=line,type=2  -legend=spec=IDEALDA   &  

&run_setup
    lattice = ilsfDA.lte,
    use_beamline = ring_rf,
    p_central_mev = 3e+3,
    magnets = %s.mag,
    centroid = %s.cen,
    semaphore_file = %s.done,
    default_order=3,
    parameters = %s.param,
    random_number_seed=0
&end

!&alter_elements name=*, type=ksext, item=K2, value=0.0 &end

&run_control
        n_steps = 20          !20
        n_passes = 100            !100
&end

&twiss_output 
filename = "%s.twi", 
 statistics=1, 
 radiation_integrals=1,
 output_at_each_step=1, 
      &end
        
        
&error_control clear_error_settings = 1,  &end

 !Misalignment errors on quadrupoles
&error_element name=*, element_type=*QUAD*, item=DX, amplitude=5e-6, cutoff=1 &end
&error_element name=*, element_type=*QUAD*, item=DY, amplitude=5e-5, cutoff=1 &end
&error_element name=*, element_type=*QUAD*, item=TILT, amplitude=1e-4, cutoff=1 &end
&error_element name=*, element_type=*QUAD*, item=FSE, amplitude=1e-4, cutoff=1 &end

! Misalignment errors on dipole
&error_element name=*, element_type=*CSBEN*, item=DX, amplitude=5e-6, cutoff=1 &end
&error_element name=*, element_type=*CSBEN*, item=DY, amplitude=5e-5, cutoff=1 &end
&error_element name=*, element_type=*CSBEN*, item=TILT, amplitude=1e-4, cutoff=1 &end
&error_element name=*, element_type=*CSBEN*, item=FSE, amplitude=1e-4, cutoff=1 &end

! Misalignment errors on sextupole
&error_element name=*, element_type=*KSEXT*, item=DX, amplitude=5e-6, cutoff=1 &end
&error_element name=*, element_type=*KSEXT*, item=DY, amplitude=5e-5, cutoff=1 &end
&error_element name=*, element_type=*KSEXT*, item=TILT, amplitude=1e-4, cutoff=1 &end
&error_element name=*, element_type=*KSEXT*, item=FSE, amplitude=1e-4, cutoff=1 &end

&twiss_output
        filename = %s.twi
        matched = 1,
        radiation_integrals = 1
        output_at_each_step = 1
&end

&closed_orbit
        output = %s.clo,
	output_monitors_only=0,
	closed_orbit_accuracy = 1e-10,
	closed_orbit_iterations = 500,
	iteration_fraction = 1e-2,
        verbosity = 1,
&end

!&error_control summarize_error_settings=1 &end

&correct
        mode = "orbit", method = "global",
        verbose = 1, n_iterations = 4, n_xy_cycles = 5,
        correction_fraction[0] = 0.5, 0.5,
        bpm_noise[0] = 0e-6, 0e-6,
        correction_accuracy[0] = 1e-9, 1e-9
        trajectory_output = "%s.orb",
        corrector_output = "%s.cor",
        statistics = "%s.scor",
        closed_orbit_iteration_fraction = 1e-2,
        closed_orbit_iterations = 500,
        closed_orbit_accuracy = 1e-9,
        closed_orbit_accuracy_requirement = 1e-6,
	minimum_SV_ratio[0] = 2*1e-4
	use_response_from_computed_orbits = 0,
&end
&twiss_output
        filename = %s.twi
        matched = 1,
        radiation_integrals = 1
        output_at_each_step = 1
&end

&bunched_beam n_particles_per_bunch = 1 &end


&find_aperture
        output = %s.aper,
        boundary = %s.abnd,
        xmin = -0.03, xmax=0.03,
        ymax = 0.01,
        mode = n-line,
        n_lines = 11,
        nx = 50,
        ny = 25,
        n_splits = 2,
        verbosity = 1,
&end
!!&track &end
