private ReturnCode ParseCycles(BinaryReader readBinary) { ushort nCycles = readBinary.ReadUInt16(); Cycles = new List <NCCWriter.Cycle>(nCycles); NCCWriter.Cycle cycle; ushort nMultiplicityBins; for (int c = 0; c < nCycles; ++c) { cycle = new NCCWriter.Cycle(); string dateTimeString = new string(readBinary.ReadChars(16)); cycle.DateAndTime = new DateTime(2000 + int.Parse(dateTimeString.Substring(0, 2)), int.Parse(dateTimeString.Substring(3, 2)), int.Parse(dateTimeString.Substring(6, 2)), int.Parse(dateTimeString.Substring(8, 2)), int.Parse(dateTimeString.Substring(11, 2)), int.Parse(dateTimeString.Substring(14, 2))); cycle.CountSeconds = readBinary.ReadUInt16(); cycle.Totals = readBinary.ReadDouble(); cycle.RPlusA = readBinary.ReadDouble(); cycle.A = readBinary.ReadDouble(); cycle.Scaler1 = readBinary.ReadDouble(); cycle.Scaler2 = readBinary.ReadDouble(); nMultiplicityBins = readBinary.ReadUInt16(); cycle.MultiplicityRPlusA = new UInt32[nMultiplicityBins]; for (int m = 0; m < nMultiplicityBins; ++m) { cycle.MultiplicityRPlusA[m] = readBinary.ReadUInt32(); } cycle.MultiplicityA = new UInt32[nMultiplicityBins]; for (int m = 0; m < nMultiplicityBins; ++m) { cycle.MultiplicityA[m] = readBinary.ReadUInt32(); } Cycles.Add(cycle); } return(ReturnCode.SUCCESS); }
private void ExportNCC(string fileName, List <Channel> selectedChannels, DateTime start, DateTime end) { // Validate detector ID if (DetectorIDTextBox.Text.Length > 11) { MessageBox.Show("Detector ID must be 11 or fewer characters"); return; } while (DetectorIDTextBox.Text.Length < 11) { DetectorIDTextBox.Text += " "; } // Validate item ID if (ItemIDTextBox.Text.Length > 12) { MessageBox.Show("Item ID must be 12 or fewer characters"); return; } while (ItemIDTextBox.Text.Length < 12) { ItemIDTextBox.Text += " "; } NCCWriter writer = new NCCWriter(); if (MeasurementTypeComboBox.SelectedIndex == MeasurementTypeComboBox.FindStringExact("Background")) { writer.NCCMode = NCCWriter.NCCType.BACKGROUND; } else if (MeasurementTypeComboBox.SelectedIndex == MeasurementTypeComboBox.FindStringExact("Normalization")) { writer.NCCMode = NCCWriter.NCCType.NORMALIZATION; } if (MeasurementTypeComboBox.SelectedIndex == MeasurementTypeComboBox.FindStringExact("Verification")) { writer.NCCMode = NCCWriter.NCCType.VERIFICATION; } writer.SetDetectorID(DetectorIDTextBox.Text); writer.SetItemID(ItemIDTextBox.Text); writer.Cycles = new List <NCCWriter.Cycle>(); foreach (Channel chan in selectedChannels) { chan.GetInstrument().LoadData(ChannelCompartment.Process, start, end); } List <DateTime> dates = selectedChannels[0].GetTimeStamps(ChannelCompartment.Process); for (int i = 0; i < dates.Count; i++) { if (dates[i] >= start && dates[i] <= end) { NCCWriter.Cycle cycle = new NCCWriter.Cycle(); cycle.DateAndTime = dates[i]; if (i < dates.Count - 1) { cycle.CountSeconds = (ushort)(dates[i + 1] - dates[i]).TotalSeconds; } else { cycle.CountSeconds = (ushort)(dates[i] - dates[i - 1]).TotalSeconds; } cycle.Totals = selectedChannels[0].GetValues(ChannelCompartment.Process)[i]; switch (selectedChannels.Count) { case 1: cycle.RPlusA = 0; cycle.A = 0; cycle.Scaler1 = 0; cycle.Scaler2 = 0; break; case 2: cycle.RPlusA = selectedChannels[1].GetValues(ChannelCompartment.Process)[i]; cycle.A = 0; cycle.Scaler1 = 0; cycle.Scaler2 = 0; break; case 3: cycle.RPlusA = selectedChannels[1].GetValues(ChannelCompartment.Process)[i]; cycle.A = selectedChannels[2].GetValues(ChannelCompartment.Process)[i]; cycle.Scaler1 = 0; cycle.Scaler2 = 0; break; case 4: cycle.RPlusA = selectedChannels[1].GetValues(ChannelCompartment.Process)[i]; cycle.A = selectedChannels[2].GetValues(ChannelCompartment.Process)[i]; cycle.Scaler1 = selectedChannels[3].GetValues(ChannelCompartment.Process)[i]; cycle.Scaler2 = 0; break; default: cycle.RPlusA = selectedChannels[1].GetValues(ChannelCompartment.Process)[i]; cycle.A = selectedChannels[2].GetValues(ChannelCompartment.Process)[i]; cycle.Scaler1 = selectedChannels[3].GetValues(ChannelCompartment.Process)[i]; cycle.Scaler2 = selectedChannels[4].GetValues(ChannelCompartment.Process)[i]; break; } writer.Cycles.Add(cycle); } } try { writer.WriteNeutronCyclesFile(FileTextBox.Text); } catch (Exception ex) { MessageBox.Show("Export Error\n" + ex.Message); System.Windows.Forms.Cursor.Current = Cursors.Default; return; } MessageBox.Show("Export complete!"); DialogResult = DialogResult.OK; Dispose(); }