package se.lu.esss.ics.jels;

import java.io.IOException;

import org.junit.Test;

import se.lu.esss.ics.jels.model.elem.jels.JElsElementMapping;
import xal.model.ModelException;
import xal.model.alg.EnvelopeTracker;
import xal.model.alg.Tracker;
import xal.model.probe.EnvelopeProbe;
import xal.model.probe.Probe;
import xal.smf.Accelerator;
import xal.smf.AcceleratorSeq;

public class SpaceChargeTest {
	//@Test
	public void driftTest() throws ModelException, IOException
	{
		final double frequency = 4.025e8;
		EnvelopeProbe probe = TestCommon.setupOpenXALProbe2( 3e6, frequency, 30e-3); 
		((EnvelopeTracker)probe.getAlgorithm()).setProbeUpdatePolicy(Tracker.UPDATE_ALWAYS);
		AcceleratorSeq sequence = DriftTest.drift(500, 0., 0.);
		Accelerator acc = new Accelerator();
		acc.addNode(sequence);
		acc.setElementMapping(JElsElementMapping.getInstance());
		double dataOX[][] = GeneralTest.run(probe, sequence);
		GeneralTest.saveResults("openxal.drift500.txt", dataOX);
	}
	
	//@Test
	public void meterTest() throws ModelException, IOException
	{
		for (int i : new int[]{10,20,50,100,1000}) {
			final double frequency = 4.025e8;
			EnvelopeProbe probe = TestCommon.setupOpenXALProbe2( 3e6, frequency, 30e-3); 
			((EnvelopeTracker)probe.getAlgorithm()).setProbeUpdatePolicy(Tracker.UPDATE_ALWAYS);
			((EnvelopeTracker)probe.getAlgorithm()).setStepSize(1./i);
			double dataOX[][] = GeneralTest.run(probe);
			GeneralTest.saveResults("openxal.s"+i+".txt", dataOX);
		}
	}
	
	
	@Test
	public void dgdTest() throws ModelException, IOException
	{
		final double frequency = 4.025e8;
		EnvelopeProbe probe = TestCommon.setupOpenXALProbe2( 3e6, frequency, 30e-3); 
		((EnvelopeTracker)probe.getAlgorithm()).setProbeUpdatePolicy(Tracker.UPDATE_ALWAYS);
		((EnvelopeTracker)probe.getAlgorithm()).setStepSize(1./100.);
		
		//MEBT-DRFT-9: DRIFT 63 15
		//MEBT-RF_Cav-1: GAP 124000 -90 14.5 0
		//MEBT-DRFT-10: DRIFT 63 15
		
		Accelerator acc = new Accelerator();
		AcceleratorSeq seq = GapTest.gap(352.21e6, 124000, -90, 14.5, 0, 0, 0, 0, 0, 0, 0);
		seq.setPosition(0.063);
		acc.addNode(seq);
		acc.setLength(0.126);
		acc.setElementMapping(JElsElementMapping.getInstance());
		double dataOX[][] = GeneralTest.run(probe, acc);
		GeneralTest.saveResults("openxal.dgd6.txt", dataOX);
	}
}

@@ -42,21 +42,72 @@
 .io.
-IOException;%0A
+File;%0Aimport java.io.IOException;%0A%0Aimport org.junit.BeforeClass;
 %0Aimp
@@ -333,38 +333,8 @@
 be;%0A
-import xal.model.probe.Probe;%0A
 impo
@@ -420,16 +420,176 @@
 eTest %7B%0A
+%09%0A%09private static final String RESULTS_DIR = %22temp%22;%0A%09%0A%09@BeforeClass%0A%09public static void beforeClass() throws Exception %7B%0A%09%09new File(RESULTS_DIR).mkdir();%0A%09%7D%0A%09%0A
 %09//@Test
@@ -1110,33 +1110,48 @@
 est.saveResults(
-%22
+RESULTS_DIR + %22/
 openxal.drift500
@@ -1624,33 +1624,48 @@
 est.saveResults(
-%22
+RESULTS_DIR + %22/
 openxal.s%22+i+%22.t
@@ -2461,17 +2461,32 @@
 Results(
-%22
+RESULTS_DIR + %22/
 openxal.

Change SpaceChargeTest to write results to temp directory