// This restores the last Study/probe used public void RegisterQuickStart(object sender, EventArgs e) { string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); path = System.IO.Path.Combine(path, "LastSettings.xml"); // Read the Config.xml file XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNodeList elemList; elemList = doc.GetElementsByTagName("Investigator"); string investigator = elemList[0].InnerXml.Trim(); elemList = doc.GetElementsByTagName("Study"); string study = elemList[0].InnerXml.Trim(); elemList = doc.GetElementsByTagName("probefile"); string probefile = elemList[0].InnerXml.Trim(); int[] lambda = MainClass.win.settings.system_Info.wavelengths; nirs.core.Probe probe = nirs.io.LoadProbe(probefile, lambda); // Add channels for Optical Density, HbO2, and HbR int cnt = probe.ChannelMap.Length; nirs.ChannelMap[] ChannelMap = new nirs.ChannelMap[cnt * 2 + 2 * cnt / probe.numWavelengths]; for (int ii = 0; ii < cnt; ii++) { ChannelMap[ii] = probe.ChannelMap[ii]; } for (int ii = 0; ii < cnt; ii++) { ChannelMap[ii + cnt] = probe.ChannelMap[ii]; ChannelMap[ii + cnt].datasubtype = string.Format("ΔOD {0}nm", ChannelMap[ii].wavelength); } for (int ii = 0; ii < cnt / probe.numWavelengths; ii++) { ChannelMap[ii + 2 * cnt] = probe.ChannelMap[ii]; ChannelMap[ii + 2 * cnt].datasubtype = "HbO2"; } for (int ii = cnt / probe.numWavelengths; ii < cnt; ii++) { ChannelMap[ii + 2 * cnt] = probe.ChannelMap[ii]; ChannelMap[ii + 2 * cnt].datasubtype = "Hb"; } probe.ChannelMap = ChannelMap; probe.measlistAct = new bool[probe.ChannelMap.Length]; for (int ii = 0; ii < probe.ChannelMap.Length; ii++) { probe.measlistAct[ii] = true; } Gdk.Color[] cmap = new Gdk.Color[probe.ChannelMap.Length]; for (int ii = 0; ii < probe.numChannels; ii++) { cmap[ii] = probe.colormap[ii]; cmap[probe.numChannels + ii] = probe.colormap[ii]; cmap[probe.numChannels * 2 + ii] = probe.colormap[ii]; } probe.colormap = cmap; nirsdata = new List <nirs.core.Data>(); for (int i = 0; i < MainClass.devices.Length; i++) { nirs.core.Data data = new nirs.core.Data { demographics = new nirs.Dictionary() }; data.demographics.set("SubjID", ""); data.demographics.set("Investigator", investigator); data.demographics.set("Study", study); data.demographics.set("Gender", ""); data.demographics.set("Group", ""); data.demographics.set("Age", ""); data.demographics.set("Instrument", MainClass.win.settings.SYSTEM); data.demographics.set("head_circumference", ""); data.demographics.set("Technician", ""); data.demographics.set("comments", ""); DateTime now = DateTime.Now; data.demographics.set("scan_date", now.ToString("F")); data.probe = probe.Clone(); nirsdata.Add(data); } ListStore ClearList = new ListStore(typeof(string)); MainClass.win._handles.whichdata.Model = ClearList; List <string> datatypes = new List <string>(); for (int ii = 0; ii < probe.ChannelMap.Length; ii++) { datatypes.Add(probe.ChannelMap[ii].datasubtype); } datatypes = datatypes.Distinct().ToList(); foreach (string s in datatypes) { MainClass.win._handles.whichdata.AppendText(s); } for (int dI = probe.numDet; dI < MainClass.win._handles.detectors.Count; dI++) { MainClass.win._handles.detectors[dI].frame.Sensitive = false; MainClass.win._handles.detectors[dI].vScale.Sensitive = false; MainClass.win._handles.detectors[dI].vScale.Value = 0; MainClass.win._handles.detectors[dI].led.Color = new Gdk.Color(93, 93, 93); } for (int sI = probe.numSrc; sI < MainClass.win._handles.lasers.Count; sI++) { MainClass.win._handles.lasers[sI].frame.Sensitive = false; for (int wI = 0; wI < MainClass.win._handles.lasers[sI].buttons.Length; wI++) { MainClass.win._handles.lasers[sI].spinButtons[wI].Sensitive = false; MainClass.win._handles.lasers[sI].buttons[wI].Sensitive = false; } } #if ADDLSL MainClass.win.dataLSL = new LSL.liblsl.StreamOutlet[MainClass.devices.Length]; for (int ii = 0; ii < MainClass.devices.Length; ii++) { int fs = MainClass.devices[ii].GetSampleRate(); string name = string.Format("NIRSRecordIRData_{0}", ii + 1); LSL.liblsl.StreamInfo info = new LSL.liblsl.StreamInfo(name, "NIRS", MainClass.win.nirsdata[ii].probe.numChannels, (double)fs, LSL.liblsl.channel_format_t.cf_int32); MainClass.win.dataLSL[ii] = new LSL.liblsl.StreamOutlet(info); } #endif comboboxdeviceDemo.Active = 0; MainClass.win._handles.whichdata.Active = 0; MainClass.win.EnableControls(true); MainClass.win._handles.SDGplot.QueueDraw(); }
private static nirs.core.Probe loadSDprobe(string file, int[] lambda) { nirs.core.Probe probe = new core.Probe(); MatFileReader mfr = new MatFileReader(file); MLStructure SD = (mfr.Content["SD"] as MLStructure); MLDouble MLsrcpos = null; if (SD.Keys.Contains("SrcPos")) { MLsrcpos = (SD["SrcPos"] as MLDouble); } else if (SD.Keys.Contains("srcpos")) { MLsrcpos = (SD["srcpos"] as MLDouble); } MLDouble MLdetpos = null; if (SD.Keys.Contains("DetPos")) { MLdetpos = (SD["DetPos"] as MLDouble); } else if (SD.Keys.Contains("detpos")) { MLdetpos = (SD["detpos"] as MLDouble); } if (MLdetpos != null) { double[][] detpos = MLdetpos.GetArray(); probe.DetPos = new double[detpos.Length, 3]; probe.DetectorLabels = new string[detpos.Length]; for (int i = 0; i < detpos.Length; i++) { probe.DetPos[i, 0] = (float)detpos[i][0]; probe.DetPos[i, 1] = (float)detpos[i][1]; probe.DetPos[i, 2] = (float)detpos[i][2]; probe.DetectorLabels[i] = String.Format("Detector-{0}", +1); } probe.numDet = detpos.Length; } if (MLsrcpos != null) { double[][] srcpos = MLsrcpos.GetArray(); probe.SrcPos = new double[srcpos.Length, 3]; probe.SourceLabels = new string[srcpos.Length]; for (int i = 0; i < srcpos.Length; i++) { probe.SrcPos[i, 0] = (float)srcpos[i][0]; probe.SrcPos[i, 1] = (float)srcpos[i][1]; probe.SrcPos[i, 2] = (float)srcpos[i][2]; probe.SourceLabels[i] = String.Format("Source-{0}", i + 1); } probe.numSrc = srcpos.Length; } MLDouble mlMeasList = null; if (mfr.Content.ContainsKey("ml")) { mlMeasList = (mfr.Content["ml"] as MLDouble); } else { mlMeasList = (SD["MeasList"] as MLDouble); } if (mlMeasList != null) { double[][] ml = mlMeasList.GetArray(); probe.ChannelMap = new ChannelMap[ml.Length]; for (int i = 0; i < ml.Length; i++) { probe.ChannelMap[i] = new ChannelMap(); probe.ChannelMap[i].sourceindex = (int)ml[i][0] - 1; probe.ChannelMap[i].detectorindex = (int)ml[i][1] - 1; probe.ChannelMap[i].channelname = String.Format("Src{0}-Det{1}", probe.ChannelMap[i].sourceindex + 1, probe.ChannelMap[i].detectorindex + 1); probe.ChannelMap[i].wavelength = lambda[(int)ml[i][3] - 1]; probe.ChannelMap[i].datasubtype = String.Format("{0}nm", probe.ChannelMap[i].wavelength); } } probe.numChannels = probe.ChannelMap.Length; probe.measlistAct = new bool[probe.numChannels]; for (int i = 0; i < probe.numChannels; i++) { probe.measlistAct[i] = false; } probe.measlistAct[0] = true; probe.numWavelengths = lambda.Length; return(probe); }
{ // methods devoted to file I/O public static core.Data[] readSNIRF(string filename) { List <nirs.HDF5info> info = nirs.io.SNIRFinfo(filename); hid_t fileId = H5F.open(filename, H5F.ACC_RDONLY); string formatVersion = nirs.io.ReadDataString(fileId, "/formatVersion"); List <string> dataLst = new List <string>(); List <string> nirsLst = new List <string>(); for (int i = 0; i < info.Count; i++) { if (info[i].field.Contains("/nirs") & info[i].field.Contains("/data")) { int cnt = info[i].field.IndexOf("/"); cnt = info[i].field.IndexOf("/", cnt + 1); int cnt2 = cnt; cnt = info[i].field.IndexOf("/", cnt + 1); // find the third instance string str = info[i].field.Substring(0, cnt); string str2 = info[i].field.Substring(0, cnt2); if (str.Contains("/nirs") & str.Contains("/data")) { if (!dataLst.Contains(str)) { dataLst.Add(str); } } if (str2.Contains("/nirs")) { if (!nirsLst.Contains(str2)) { nirsLst.Add(str2); } } } } core.Probe[] probes = new core.Probe[nirsLst.Count]; Dictionary[] demographics = new Dictionary[nirsLst.Count]; core.Data[] data = new core.Data[dataLst.Count]; List <Stimulus>[] stimuli = new List <Stimulus> [nirsLst.Count]; auxillary[][] aux = new auxillary[nirsLst.Count][]; for (int i = 0; i < nirsLst.Count; i++) { demographics[i] = new Dictionary(); for (int j = 0; j < info.Count; j++) { if (info[j].field.Contains(string.Format("{0}/metaDataTags", nirsLst[i]))) { string fld = info[j].field.Substring(string.Format("{0}/metaDataTags", nirsLst[i]).Length + 1); if (nirs.io.IsHDF5String(fileId, info[j].field)) { string val = nirs.io.ReadDataString(fileId, info[j].field); demographics[i].set(fld, val); } else { double val = nirs.io.ReadDataValue(fileId, info[j].field); demographics[i].set(fld, val); } } } //aux events List <string> auxList = new List <string>(); for (int j = 0; j < info.Count; j++) { if (info[j].field.Contains(string.Format("{0}/aux", nirsLst[i])) & info[j].field.Contains("/name")) { string str = info[j].field.Substring(0, info[j].field.LastIndexOf("/")); auxList.Add(str); } } aux[i] = new auxillary[auxList.Count]; for (int j = 0; j < auxList.Count; j++) { double[] daux = nirs.io.ReadDataVector(fileId, string.Format("{0}/dataTimeSeries", auxList[j])); double[] taux = nirs.io.ReadDataVector(fileId, string.Format("{0}/time", auxList[j])); aux[i][j] = new auxillary(); aux[i][j].name = nirs.io.ReadDataString(fileId, string.Format("{0}/name", auxList[j])); aux[i][j].timeOffset = nirs.io.ReadDataValue(fileId, string.Format("{0}/timeOffset", auxList[j])); aux[i][j].data = new List <double>(); aux[i][j].time = new List <double>(); for (int k = 0; k < daux.Length; k++) { aux[i][j].data.Add(daux[k]); aux[i][j].time.Add(taux[k]); } } // stim events stimuli[i] = new List <Stimulus>(); for (int j = 0; j < info.Count; j++) { if (info[j].field.Contains(string.Format("{0}/stim", nirsLst[i])) & info[j].field.Contains("/name")) { string str = info[j].field.Substring(0, info[j].field.LastIndexOf("/")); string stimname = nirs.io.ReadDataString(fileId, string.Format("{0}/name", str)); double[,] times = nirs.io.ReadDataArray(fileId, string.Format("{0}/data", str)); if (times.GetLength(0) == 3 & times.GetLength(1) != 3) { times = nirs.io.ReadDataArray(fileId, string.Format("{0}/data", str), true); } Stimulus stim = new Stimulus(); stim.name = stimname; stim.onsets = new List <double>(); stim.duration = new List <double>(); stim.amplitude = new List <double>(); for (int ii = 0; ii < times.GetLength(0); ii++) { stim.onsets.Add(times[ii, 0]); stim.duration.Add(times[ii, 1]); stim.amplitude.Add(times[ii, 2]); } stimuli[i].Add(stim); } } // read the probe probes[i] = new core.Probe(); double[] wav; if (nirs.io.groupexists(fileId, String.Format("{0}/probe/wavelengths", nirsLst[i]))) { wav = nirs.io.ReadDataVector(fileId, String.Format("{0}/probe/wavelengths", nirsLst[i])); } else { wav = new double[0]; } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/sourcePos2D", nirsLst[i]))) { probes[i].SrcPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos2D", nirsLst[i])); if (probes[i].SrcPos.GetLength(0) == 3 & probes[i].SrcPos.GetLength(1) != 3) { probes[i].SrcPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos2D", nirsLst[i]), true); } } else { probes[i].SrcPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos", nirsLst[i])); if (probes[i].SrcPos.GetLength(0) == 3 & probes[i].SrcPos.GetLength(1) != 3) { probes[i].SrcPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos", nirsLst[i]), true); } } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/detectorPos2D", nirsLst[i]))) { probes[i].DetPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos2D", nirsLst[i])); if (probes[i].DetPos.GetLength(0) == 3 & probes[i].SrcPos.GetLength(1) != 3) { probes[i].DetPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos2D", nirsLst[i]), true); } } else { probes[i].DetPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos", nirsLst[i])); if (probes[i].DetPos.GetLength(0) == 3 & probes[i].DetPos.GetLength(1) != 3) { probes[i].DetPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos", nirsLst[i]), true); } } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/landmarkPos2D", nirsLst[i]))) { probes[i].LandmarkPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos2D", nirsLst[i])); if (probes[i].LandmarkPos.GetLength(0) == 3 & probes[i].LandmarkPos.GetLength(1) != 3) { probes[i].LandmarkPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos2D", nirsLst[i]), true); } } else if (nirs.io.groupexists(fileId, String.Format("{0}/probe/landmarkPos", nirsLst[i]))) { probes[i].LandmarkPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos", nirsLst[i])); if (probes[i].LandmarkPos.GetLength(0) == 3 & probes[i].LandmarkPos.GetLength(1) != 3) { probes[i].LandmarkPos = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos", nirsLst[i]), true); } } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/sourcePos3D", nirsLst[i]))) { probes[i].SrcPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos3D", nirsLst[i])); if (probes[i].SrcPos3D.GetLength(0) == 3 & probes[i].SrcPos3D.GetLength(1) != 3) { probes[i].SrcPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/sourcePos3D", nirsLst[i]), true); } } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/detectorPos3D", nirsLst[i]))) { probes[i].DetPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos3D", nirsLst[i])); if (probes[i].DetPos3D.GetLength(0) == 3 & probes[i].DetPos3D.GetLength(1) != 3) { probes[i].DetPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/detectorPos3D", nirsLst[i]), true); } } if (nirs.io.groupexists(fileId, String.Format("{0}/probe/landmarkPos3D", nirsLst[i]))) { if (nirs.io.groupexists(fileId, String.Format("{0}/probe/landmarkPos3D", nirsLst[i]))) { probes[i].LandmarkPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos3D", nirsLst[i])); if (probes[i].LandmarkPos3D.GetLength(0) == 3 & probes[i].LandmarkPos3D.GetLength(1) != 3) { probes[i].LandmarkPos3D = nirs.io.ReadDataArray(fileId, String.Format("{0}/probe/landmarkPos3D", nirsLst[i]), true); } } } probes[i].numDet = probes[i].DetPos.GetLength(0); probes[i].numSrc = probes[i].SrcPos.GetLength(0); probes[i].numWavelengths = wav.Length; probes[i].SourceLabels = new string[probes[i].SrcPos.GetLength(0)]; for (int j = 0; j < probes[i].SrcPos.GetLength(0); j++) { if (nirs.io.groupexists(fileId, String.Format("{0}/probe/sourceLabels{1}", nirsLst[i], j + 1))) { probes[i].SourceLabels[j] = nirs.io.ReadDataString(fileId, String.Format("{0}/probe/sourceLabels{1}", nirsLst[i], j + 1)); } else { probes[i].SourceLabels[j] = string.Format("Source-{0}", j + 1); } } probes[i].DetectorLabels = new string[probes[i].DetPos.GetLength(0)]; for (int j = 0; j < probes[i].DetPos.GetLength(0); j++) { if (nirs.io.groupexists(fileId, String.Format("{0}/probe/detectorLabels{1}", nirsLst[i], j + 1))) { probes[i].DetectorLabels[j] = nirs.io.ReadDataString(fileId, String.Format("{0}/probe/detectorLabels{1}", nirsLst[i], j + 1)); } else { probes[i].DetectorLabels[j] = string.Format("Detector-{0}", j + 1); } } if (probes[i].LandmarkPos != null) { probes[i].LandmarkLabels = new string[probes[i].LandmarkPos.GetLength(0)]; for (int j = 0; j < probes[i].LandmarkPos.GetLength(0); j++) { if (nirs.io.groupexists(fileId, String.Format("{0}/probe/landmarkLabels{1}", nirsLst[i], j + 1))) { probes[i].LandmarkLabels[j] = nirs.io.ReadDataString(fileId, String.Format("{0}/probe/landmarkLabels{1}", nirsLst[i], j + 1)); } else { probes[i].LandmarkLabels[j] = string.Format("Landmark-{0}", j + 1); } } } } // Now, load the data for (int i = 0; i < dataLst.Count; i++) { double[] wav = new double[0]; data[i] = new core.Data(); data[i].description = dataLst[i]; for (int j = 0; j < nirsLst.Count; j++) { if (dataLst[i].Contains(string.Format("{0}/data", nirsLst[j]))) { data[i].probe = probes[j]; data[i].demographics = demographics[j]; if (nirs.io.groupexists(fileId, String.Format("{0}/probe/wavelengths", nirsLst[j]))) { wav = nirs.io.ReadDataVector(fileId, String.Format("{0}/probe/wavelengths", nirsLst[j])); } else { wav = new double[0]; } data[i].stimulus = stimuli[j]; data[i].auxillaries = aux[i]; } } double[] t = nirs.io.ReadDataVector(fileId, String.Format("{0}/time", dataLst[i])); data[i].time = new List <double>(); for (int ii = 0; ii < t.Length; ii++) { data[i].time.Add(t[ii]); } double[,] d = nirs.io.ReadDataArray(fileId, String.Format("{0}/dataTimeSeries", dataLst[i])); if (d.GetLength(0) == t.Length) { d = nirs.io.ReadDataArray(fileId, String.Format("{0}/dataTimeSeries", dataLst[i]), true); } data[i].data = new List <double> [d.GetLength(0)]; for (int ii = 0; ii < d.GetLength(0); ii++) { data[i].data[ii] = new List <double>(); for (int jj = 0; jj < d.GetLength(1); jj++) { data[i].data[ii].Add(d[ii, jj]); } } data[i].numsamples = data[i].time.Count; data[i].probe.numChannels = data[i].data.Length; data[i].probe.ChannelMap = new ChannelMap[data[i].probe.numChannels]; for (int j = 0; j < data[i].probe.numChannels; j++) { data[i].probe.ChannelMap[j] = new ChannelMap(); data[i].probe.ChannelMap[j].sourceindex = (int)nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/sourceIndex", dataLst[i], j + 1)) - 1; data[i].probe.ChannelMap[j].detectorindex = (int)nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/detectorIndex", dataLst[i], j + 1)) - 1; if (wav.Length > 0) { data[i].probe.ChannelMap[j].wavelength = wav[(int)nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/wavelengthIndex", dataLst[i], j + 1)) - 1]; } int datatypeIdx = (int)nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/dataType", dataLst[i], j + 1)); data[i].probe.ChannelMap[j].datatype = (datatype)Enum.ToObject(typeof(datatype), datatypeIdx); if (wav.Length > 0) { data[i].probe.ChannelMap[j].datasubtype = String.Format("{0}nm", data[i].probe.ChannelMap[j].wavelength); } else { data[i].probe.ChannelMap[j].datasubtype = nirs.io.ReadDataString(fileId, String.Format("{0}/measurementList{1}/dataTypeLabel", dataLst[i], j + 1)); } data[i].probe.ChannelMap[j].channelname = String.Format("Src{0}-Det{1}", data[i].probe.ChannelMap[j].sourceindex + 1, data[i].probe.ChannelMap[j].detectorindex + 1); //{optional} if (nirs.io.groupexists(fileId, String.Format("{0}/measurementList{1}/moduleIndex", dataLst[i], j + 1))) { data[i].probe.ChannelMap[j].moduleIndex = (int)nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/moduleIndex", dataLst[i], j + 1)); } if (nirs.io.groupexists(fileId, String.Format("{0}/measurementList{1}/detectorGain", dataLst[i], j + 1))) { data[i].probe.ChannelMap[j].DetectorGain = nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/detectorGain", dataLst[i], j + 1)); } if (nirs.io.groupexists(fileId, String.Format("{0}/measurementList{1}/sourcePower", dataLst[i], j + 1))) { data[i].probe.ChannelMap[j].SourcePower = nirs.io.ReadDataValue(fileId, String.Format("{0}/measurementList{1}/sourcePower", dataLst[i], j + 1)); } } } return(data); // data#/probe/useLocalIndex [int] = 0 }
private static nirs.core.Probe loadxmlprobe(string file, int[] lambda) { // This function loads a probe from an xml file nirs.core.Probe probe = new core.Probe(); XmlDocument doc = new XmlDocument(); XmlDocument doc2; XmlDocument doc3; doc.Load(file); XmlNodeList elemList; XmlNodeList elemListsub; XmlNodeList elemListsub2; probe.numWavelengths = lambda.Length; // Source-positions elemList = doc.GetElementsByTagName("srcpos"); probe.numSrc = elemList.Count; probe.SrcPos = new double[probe.numSrc, 2]; for (int i = 0; i < elemList.Count; i++) { doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("index"); int index = Convert.ToInt32(elemListsub[0].InnerXml) - 1; elemListsub = doc2.GetElementsByTagName("x"); probe.SrcPos[index, 0] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("y"); probe.SrcPos[index, 1] = Convert.ToDouble(elemListsub[0].InnerXml); } // Detector-positions elemList = doc.GetElementsByTagName("detpos"); probe.numDet = elemList.Count; probe.DetPos = new double[probe.numDet, 2]; for (int i = 0; i < elemList.Count; i++) { doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("index"); int index = Convert.ToInt32(elemListsub[0].InnerXml) - 1; elemListsub = doc2.GetElementsByTagName("x"); probe.DetPos[index, 0] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("y"); probe.DetPos[index, 1] = Convert.ToDouble(elemListsub[0].InnerXml); } // 3D corrdinates // Source-positions elemList = doc.GetElementsByTagName("srcpos3D"); if (elemList.Count > 0) { probe.SrcPos3D = new double[probe.numSrc, 3]; for (int i = 0; i < elemList.Count; i++) { doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("index"); int index = Convert.ToInt32(elemListsub[0].InnerXml) - 1; elemListsub = doc2.GetElementsByTagName("x"); probe.SrcPos3D[index, 0] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("y"); probe.SrcPos3D[index, 1] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("z"); probe.SrcPos3D[index, 2] = Convert.ToDouble(elemListsub[0].InnerXml); probe.isregistered = true; } // Detector-positions elemList = doc.GetElementsByTagName("detpos3D"); probe.DetPos3D = new double[probe.numDet, 3]; for (int i = 0; i < elemList.Count; i++) { doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("index"); int index = Convert.ToInt32(elemListsub[0].InnerXml) - 1; elemListsub = doc2.GetElementsByTagName("x"); probe.DetPos3D[index, 0] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("y"); probe.DetPos3D[index, 1] = Convert.ToDouble(elemListsub[0].InnerXml); elemListsub = doc2.GetElementsByTagName("z"); probe.DetPos3D[index, 2] = Convert.ToDouble(elemListsub[0].InnerXml); } } else { probe.isregistered = false; } // Measurement list elemList = doc.GetElementsByTagName("ml"); probe.ChannelMap = new ChannelMap[elemList.Count * lambda.Length]; probe.numChannels = elemList.Count * lambda.Length; for (int j = 0; j < lambda.Length; j++) { for (int i = 0; i < elemList.Count; i++) { int ii = i + j * elemList.Count; probe.ChannelMap[ii] = new ChannelMap(); doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("src"); probe.ChannelMap[ii].sourceindex = Convert.ToInt16(elemListsub[0].InnerXml) - 1; elemListsub = doc2.GetElementsByTagName("det"); probe.ChannelMap[ii].detectorindex = Convert.ToInt16(elemListsub[0].InnerXml) - 1; probe.ChannelMap[ii].wavelength = lambda[j]; probe.ChannelMap[ii].moduleIndex = 0; probe.ChannelMap[ii].SourcePower = 0; probe.ChannelMap[ii].DetectorGain = 0; probe.ChannelMap[ii].datatype = datatype.CW_absoption; probe.ChannelMap[ii].datasubtype = String.Format("raw {0}nm", probe.ChannelMap[ii].wavelength); probe.ChannelMap[ii].channelname = String.Format("Src{0}-Det{1} [{2}nm]", probe.ChannelMap[i].sourceindex + 1, probe.ChannelMap[ii].detectorindex + 1, probe.ChannelMap[ii].wavelength); probe.ChannelMap[ii].dataindex = 0; } } probe.measlistAct = new bool[probe.ChannelMap.Length]; for (int i = 0; i < probe.ChannelMap.Length; i++) { probe.measlistAct[i] = true; } //ROI information probe.ROIs = new List <ROI>(); elemList = doc.GetElementsByTagName("ROI"); for (int i = 0; i < elemList.Count; i++) { ROI rOI = new ROI(); doc2 = new XmlDocument(); doc2.LoadXml("<root>" + elemList[i].InnerXml + "</root>"); elemListsub = doc2.GetElementsByTagName("name"); rOI.name = elemListsub[0].InnerXml; rOI.sourceindex = new List <int>(); rOI.detectorindex = new List <int>(); rOI.weight = new List <double>(); elemListsub = doc2.GetElementsByTagName("meas"); for (int j = 0; j < elemListsub.Count; j++) { doc3 = new XmlDocument(); doc3.LoadXml("<root>" + elemListsub[j].InnerXml + "</root>"); elemListsub2 = doc3.GetElementsByTagName("src"); rOI.sourceindex.Add(Convert.ToInt16(elemListsub2[0].InnerXml) - 1); elemListsub2 = doc3.GetElementsByTagName("det"); rOI.detectorindex.Add(Convert.ToInt16(elemListsub2[0].InnerXml) - 1); elemListsub2 = doc3.GetElementsByTagName("weight"); if (elemListsub2.Count > 0) { rOI.weight.Add(Convert.ToDouble(elemListsub2[0].InnerXml)); } else { rOI.weight.Add(1); } } probe.ROIs.Add(rOI); } return(probe); }