Exemplo n.º 1
0
        private bool LoadNuclideLibrary()
        {
            if (!File.Exists(GAEnvironment.NuclideLibraryFile))
            {
                return(false);
            }

            try
            {
                // Load nuclide library from file
                using (TextReader reader = File.OpenText(GAEnvironment.NuclideLibraryFile))
                {
                    NuclideLibrary.Clear();
                    char[] itemDelims   = new char[] { ' ', '\t' };
                    char[] energyDelims = new char[] { ':' };
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (String.IsNullOrEmpty(line) || line.StartsWith("#")) // Skip comments
                        {
                            continue;
                        }
                        string[] items        = line.Split(itemDelims, StringSplitOptions.RemoveEmptyEntries);
                        string   name         = items[0];
                        double   halfLife     = Convert.ToDouble(items[1], CultureInfo.InvariantCulture);
                        string   halfLifeUnit = items[2];

                        // Parse nuclide
                        NuclideInfo ni = new NuclideInfo(name, halfLife, halfLifeUnit);

                        // Parse energies
                        for (int i = 3; i < items.Length; i++)
                        {
                            string[] energy = items[i].Split(energyDelims, StringSplitOptions.RemoveEmptyEntries);
                            double   e      = Convert.ToDouble(energy[0], CultureInfo.InvariantCulture);
                            double   p      = Convert.ToDouble(energy[1], CultureInfo.InvariantCulture);
                            ni.Energies.Add(new NuclideEnergy(e, p));
                        }

                        // Store nuclide
                        NuclideLibrary.Add(ni);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void lbNuclides_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (session == null || !session.IsLoaded)
            {
                return;
            }

            // Remove current nuclide lines from graph
            GraphPane pane = graphSession.GraphPane;

            pane.GraphObjList.RemoveAll(o => isGraphObjectType(o.Tag, GraphObjectType.Energy));

            if (lbNuclides.SelectedItems.Count > 0)
            {
                double offset_y = 0d;

                // Display lines for currently selected nuclide
                NuclideInfo ni = (NuclideInfo)lbNuclides.SelectedItems[0];
                foreach (NuclideEnergy ne in ni.Energies)
                {
                    int ch = GetChannelFromEnergy(session.Detector, ne.Energy, 0, (int)session.NumChannels);
                    if (ch == -1)
                    {
                        // If no channel is found, or energy is outside current spectrum, continue to next energy
                        log.Warn("No channel found for energy: " + ni.Name + " " + ne.Energy.ToString());
                        continue;
                    }

                    // Add energy line
                    LineObj line = new LineObj(Color.ForestGreen, (double)ch, pane.YAxis.Scale.Min, (double)ch, pane.YAxis.Scale.Max);
                    makeGraphObjectType(ref line.Tag, GraphObjectType.Energy);
                    pane.GraphObjList.Add(line);

                    // Add probability text
                    TextObj label = new TextObj(ne.Probability.ToString() + " %", (double)ch, pane.YAxis.Scale.Max - offset_y, CoordType.AxisXY2Scale, AlignH.Left, AlignV.Top);
                    makeGraphObjectType(ref label.Tag, GraphObjectType.Energy);
                    label.FontSpec.Border.IsVisible = false;
                    label.FontSpec.Size             = 9f;
                    label.FontSpec.Fill.Color       = SystemColors.ButtonFace;
                    label.ZOrder = ZOrder.D_BehindAxis;
                    pane.GraphObjList.Add(label);
                    offset_y += pane.YAxis.Scale.Max / 25d;
                }
            }

            // Update graph
            graphSession.RestoreScale(pane);
            graphSession.AxisChange();
            graphSession.Refresh();
        }
Exemplo n.º 3
0
        private bool LoadNuclideLibrary()
        {
            if (!File.Exists(CrashEnvironment.NuclideLibraryFile))
                return false;

            // Load nuclide library from file
            using (TextReader reader = File.OpenText(CrashEnvironment.NuclideLibraryFile))
            {
                NuclideLibrary.Clear();
                char[] itemDelims = new char[] { ' ', '\t' };
                char[] energyDelims = new char[] { ':' };
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (String.IsNullOrEmpty(line) || line.StartsWith("#")) // Skip comments
                        continue;
                    string[] items = line.Split(itemDelims, StringSplitOptions.RemoveEmptyEntries);
                    string name = items[0];
                    double halfLife = Convert.ToDouble(items[1], CultureInfo.InvariantCulture);
                    string halfLifeUnit = items[2];

                    // Parse nuclide
                    NuclideInfo ni = new NuclideInfo(name, halfLife, halfLifeUnit);

                    // Parse energies
                    for (int i = 3; i < items.Length; i++)
                    {
                        string[] energy = items[i].Split(energyDelims, StringSplitOptions.RemoveEmptyEntries);
                        double e = Convert.ToDouble(energy[0], CultureInfo.InvariantCulture);
                        double p = Convert.ToDouble(energy[1], CultureInfo.InvariantCulture);
                        ni.Energies.Add(new NuclideEnergy(e, p));
                    }

                    // Store nuclide
                    NuclideLibrary.Add(ni);
                }             
            }
            return true;
        }