private void buildDecelerationSequence() { //get the settings we need double voltage = (double)settings["voltage"]; int initspeed = (int)settings["initspeed"]; double onposition = (double)settings["onposition"] / 1000; double offposition = (double)settings["offposition"] / 1000; int numberOfStages = (int)settings["numberOfStages"]; int resonanceOrder = (int)settings["resonanceOrder"]; int jState = (int)settings["jState"]; int mState = (int)settings["mState"]; // make the FieldMap FieldMap map = new FieldMap((string)Environs.FileSystem.Paths["decelerationUtilitiesPath"] + (string)Environs.Hardware.GetInfo("deceleratorFieldMap"), (int)Environs.Hardware.GetInfo("mapPoints"), (double)Environs.Hardware.GetInfo("mapStartPoint"), (double)Environs.Hardware.GetInfo("mapResolution")); //make the molecule Molecule mol = new Molecule((string)Environs.Hardware.GetInfo("moleculeName"), (double)Environs.Hardware.GetInfo("moleculeMass"), (double)Environs.Hardware.GetInfo("moleculeRotationalConstant"), (double)Environs.Hardware.GetInfo("moleculeDipoleMoment")); //make the decelerator and the experiment Decelerator decel = new Decelerator(); DecelerationExperiment experiment = new DecelerationExperiment(); //assign a map and a lens spacing to the decelerator decel.Map = map; decel.LensSpacing = (double)Environs.Hardware.GetInfo("deceleratorLensSpacing"); //assign decelerator, molecule, quantum state and switch structure to the experiment experiment.Decelerator = decel; experiment.Molecule = mol; experiment.QuantumState = new int[] { jState, mState }; experiment.Structure = (DecelerationExperiment.SwitchStructure)Environs.Hardware.GetInfo("deceleratorStructure"); //get the timing sequence double[] timesdouble = experiment.GetTimingSequence(voltage, onposition, offposition, initspeed, numberOfStages, resonanceOrder); // The list of times is in seconds and is measured from the moment when the synchronous molecule // reaches the decelerator. Add on the amount of time it takes to reach this point. // Then convert to the units of the clockFrequency and round to the nearest unit. double nominalTimeToDecelerator = (double)Environs.Hardware.GetInfo("sourceToSoftwareDecelerator") / initspeed; int[] times = new int[timesdouble.Length]; for (int i = 0; i < timesdouble.Length; i++) { times[i] = (int)Math.Round((int)settings["clockFrequency"] * (nominalTimeToDecelerator + timesdouble[i])); } int[] structure = new int[times.Length]; // the last switch must send all electrodes to ground structure[structure.Length - 1] = 0; // build the rest of the structure int k = 0; switch (experiment.Structure) { case DecelerationExperiment.SwitchStructure.H_Off_V_Off: while (k < structure.Length - 1) { if (k < structure.Length - 1) { structure[k] = 2; k++; } if (k < structure.Length - 1) { structure[k] = 0; k++; } if (k < structure.Length - 1) { structure[k] = 1; k++; } if (k < structure.Length - 1) { structure[k] = 0; k++; } } break; case DecelerationExperiment.SwitchStructure.V_Off_H_Off: while (k < structure.Length - 1) { if (k < structure.Length - 1) { structure[k] = 1; k++; } if (k < structure.Length - 1) { structure[k] = 0; k++; } if (k < structure.Length - 1) { structure[k] = 2; k++; } if (k < structure.Length - 1) { structure[k] = 0; k++; } } break; case DecelerationExperiment.SwitchStructure.H_V: while (k < structure.Length - 1) { if (k < structure.Length - 1) { structure[k] = 2; k++; } if (k < structure.Length - 1) { structure[k] = 1; k++; } } break; case DecelerationExperiment.SwitchStructure.V_H: while (k < structure.Length - 1) { if (k < structure.Length - 1) { structure[k] = 1; k++; } if (k < structure.Length - 1) { structure[k] = 2; k++; } } break; } // keep track of the state of the horizontal and vertical electrodes bool[] states = { false, false }; //{horizontal, vertical} decelSequence = new TimingSequence(); // The timing sequence is built within this for loop. The structure of the decelerator is encoded // as follows: 0 means everything off, 1 means V on, H off, 2 means H on V off and 3 means both on. for (int i = 0; i < times.Length && i < structure.Length; i++) { if (structure[i] == 0) //horizontal = false, vertical = false { if (states[0] != false) { decelSequence.Add("decelhplus", times[i], false); decelSequence.Add("decelhminus", times[i], false); states[0] = false; } if (states[1] != false) { decelSequence.Add("decelvplus", times[i], false); decelSequence.Add("decelvminus", times[i], false); states[1] = false; } } if (structure[i] == 1) //horizontal = false, vertical = true { if (states[0] != false) { decelSequence.Add("decelhplus", times[i], false); decelSequence.Add("decelhminus", times[i], false); states[0] = false; } if (states[1] != true) { decelSequence.Add("decelvplus", times[i], true); decelSequence.Add("decelvminus", times[i], true); states[1] = true; } } if (structure[i] == 2) //horizontal = true, vertical = false { if (states[0] != true) { decelSequence.Add("decelhplus", times[i], true); decelSequence.Add("decelhminus", times[i], true); states[0] = true; } if (states[1] != false) { decelSequence.Add("decelvplus", times[i], false); decelSequence.Add("decelvminus", times[i], false); states[1] = false; } } if (structure[i] == 3) //horizontal = true, vertical = true { if (states[0] != true) { decelSequence.Add("decelhplus", times[i], true); decelSequence.Add("decelhminus", times[i], true); states[0] = true; } if (states[1] != true) { decelSequence.Add("decelvplus", times[i], true); decelSequence.Add("decelvminus", times[i], true); states[1] = true; } } } Console.WriteLine(decelSequence.ToString()); }