示例#1
0
        /// <summary>
        /// Scan a dmr file.
        /// </summary>
        /// <param name="files">dmr file to process</param>
        public void Process(string file)
        {
            if (string.IsNullOrEmpty(file))
                return;
            try
            {
                CSVFile csv = new CSVFile();
                string name = file.Substring(file.LastIndexOf("\\") + 1); // Remove path information from string
                csv.Log = NC.App.Loggers.Logger(LMLoggers.AppSection.Data);
                csv.Filename = file;
                csv.ExtractDateFromFilename();
                if (name.IndexOf('.') >= 0)
                    csv.ThisSuffix = name.Substring(name.IndexOf('.'));
                csv.ProcessFile();  // split lines with scanner
                if (csv.Lines.Count < 3)
                {
                    NC.App.Loggers.Logger(LMLoggers.AppSection.Data).TraceEvent(LogLevels.Warning, 34100, "Skipped incomplete " + System.IO.Path.GetFileName(file));
                    return;
                }
                // line 1
                int coeffnum = csv.Lines[0].Length; // 1 -> 3 lines, 2 -> 4 lines, 3 -> 5 lines, 4 -> 6 lines
                int lines = coeffnum + 2;
                if (csv.Lines.Count != lines)
                {
                    NC.App.Loggers.Logger(LMLoggers.AppSection.Data).TraceEvent(LogLevels.Warning, 34100, "Expecting {0} lines, found {1}, skipping {2}", lines, csv.Lines.Count, System.IO.Path.GetFileName(file));
                    return;
                }
                Coefficients.a = GetDouble(csv.Lines[0][0]);
                if (coeffnum > 1)
                    Coefficients.b = GetDouble(csv.Lines[0][1]);
                if (coeffnum > 2)
                    Coefficients.c = GetDouble(csv.Lines[0][2]);
                if (coeffnum > 3)
                    Coefficients.d = GetDouble(csv.Lines[0][3]);

                // line 2 (skipped?)  // URGENT: check if this is used in INCC5
                //Coefficients.var_a = GetDouble(csv.Lines[1][0]);
                //if (coeffnum > 1)
                //	Coefficients.var_b = GetDouble(csv.Lines[2][1]);
                //if (coeffnum > 2)
                //	Coefficients.var_c = GetDouble(csv.Lines[3][2]);
                //if (coeffnum > 3)
                //	Coefficients.var_d = GetDouble(csv.Lines[4][3]);

                // line 3
                Coefficients.var_a = GetDouble(csv.Lines[2][0]);

                // line 4
                if (csv.Lines.Count > 3)
                {
                    if (csv.Lines[4].Length < 2)
                        throw new Exception("Not enough entries on the b coefficient line " + csv.Lines[3].Length.ToString());
                    Coefficients.setcovar(Coeff.a, Coeff.b, GetDouble(csv.Lines[3][0]));
                    Coefficients.var_b = GetDouble(csv.Lines[3][1]);
                }
                if (csv.Lines.Count > 4)
                {
                    if (csv.Lines[4].Length < 3)
                        throw new Exception("Not enough entries on the c coefficient line " + csv.Lines[4].Length.ToString());
                    Coefficients.setcovar(Coeff.a, Coeff.c, GetDouble(csv.Lines[4][0]));
                    Coefficients.setcovar(Coeff.a, Coeff.c, GetDouble(csv.Lines[4][1]));
                    Coefficients.var_c = GetDouble(csv.Lines[4][2]);
                }
                if (csv.Lines.Count > 5)
                {
                    if (csv.Lines[5].Length < 4)
                        throw new Exception("Not enough entries on the d coefficient line " + csv.Lines[5].Length.ToString());
                    Coefficients.setcovar(Coeff.b, Coeff.c, GetDouble(csv.Lines[5][0]));
                    Coefficients.setcovar(Coeff.b, Coeff.d, GetDouble(csv.Lines[5][1]));
                    Coefficients.setcovar(Coeff.c, Coeff.d, GetDouble(csv.Lines[5][2]));
                    Coefficients.var_d = GetDouble(csv.Lines[5][3]);
                }
            } catch (MalformedLineException)  // not a CSV file
            {
                NC.App.Loggers.Logger(LMLoggers.AppSection.Data).TraceEvent(LogLevels.Verbose, 34100, "Skipped " + System.IO.Path.GetFileName(file));
            } catch (Exception e)  // not good
            {
                NC.App.Loggers.Logger(LMLoggers.AppSection.Data).TraceEvent(LogLevels.Verbose, 34100, e.Message + " - Wrongness experienced " + System.IO.Path.GetFileName(file));
            }
        }
示例#2
0
        /// <summary>
        /// Scan a stratum authority file.
        /// Creates a list of Strata and a list of Facilities from the file.
        /// </summary>
        /// <param name="file">file to process</param>
        public void Process(string path)
        {
            if (string.IsNullOrEmpty(path))
                return;
            CSVFile csv = new CSVFile();
            string name = path.Substring(path.LastIndexOf("\\") + 1); // Remove path information from string
            csv.Log = NC.App.Loggers.Logger(LMLoggers.AppSection.Data);
            csv.Filename = path;
            csv.ExtractDateFromFilename();
            if (name.IndexOf('.') >= 0)
                csv.ThisSuffix = name.Substring(name.IndexOf('.'));
            csv.ProcessFile();  // split lines with scanner
            mlogger.TraceEvent(LogLevels.Info, 34100, "Processed " + System.IO.Path.GetFileName(csv.Filename));

            GenerateStrata(csv);
            DoFacs();
            DoStratumIds();
        }
示例#3
0
        /// <summary>
        /// Scan a set of iso and comp iso files.
        /// Creates a list of Isotopics from the iso files.
        /// Creates a list of CompositeIsotopics from the comp files.
        /// </summary>
        /// <param name="files">List of nop and cop files to process</param>
        public void Process(List<string> files)
        {
            if (files == null)
                return;
            foreach (string l in files)
            try
                {
                    CSVFile csv = new CSVFile();
                    string name = l.Substring(l.LastIndexOf("\\") + 1); // Remove path information from string
                    csv.Log = NC.App.Loggers.Logger(LMLoggers.AppSection.Data);
                    csv.Filename = l;
                    csv.ExtractDateFromFilename();
                    if (name.IndexOf('.') >= 0)
                        csv.ThisSuffix = name.Substring(name.IndexOf('.'));
                    csv.ProcessFile();  // split lines with scanner
                    bool isofile = false;
                    CompositeIsotopics ciso = null;
                    Isotopics iso = null;
                    iso = GenIso(csv.Lines[0]);
                    if (isofile = (iso != null))
                    {
                        Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "got an iso file, process all the lines " + System.IO.Path.GetFileName(l));
                        Results.mlogger.TraceEvent(LogLevels.Info, 34100, "Processed " + iso.id + " from " + System.IO.Path.GetFileName(csv.Filename));
                        Results.IsoIsotopics.Add(iso);
                    }
                    else
                    {
                        ciso = (CompositeIsotopics)CompositeIsotopics(csv.Lines[0], headtest: true);
                        if (ciso != null)  // got a header of a comp iso file, process the rest of the lines
                        {
                            Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "got a header of a comp iso file, process the rest of the lines " + System.IO.Path.GetFileName(l));
                            Results.CompIsoIsotopics.Add(ciso);
                        }
                    }
                    for (int i = 1; i < csv.Lines.Count; i++)
                    {
                        string[] entry = csv.Lines[i];
                        if (isofile)
                        {
                            iso = GenIso(entry);
                            if (iso != null)
                            {
                                Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "got an iso file, process all the lines " + System.IO.Path.GetFileName(l));
                                Results.mlogger.TraceEvent(LogLevels.Info, 34100, "Processed " + iso.id + " from " + System.IO.Path.GetFileName(csv.Filename));
                                Results.IsoIsotopics.Add(iso);
                            }
                            else Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "Skipped non-iso token entry");
                        }
                        else
                        {
                            CompositeIsotopic ci = (CompositeIsotopic)CompositeIsotopics(entry, headtest: false);
                            if (ci != null)  // got a header of a comp iso file, process the rest of the lines
                            {
                                ciso.isotopicComponents.Add(ci);
                            }

                        }
                    }
                }
                catch (MalformedLineException )  // not a CSV file
                {
                    Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "Skipped " + System.IO.Path.GetFileName(l));
                }
        }
示例#4
0
        /// <summary>
        /// Scan a dat file.
        /// New facilities, MBAs, strata, inventory change codes, I/O codes, material types, isotopics,
        ///     collar data and item ids will automatically be created if necessary. Already existing items will automatically be overwritten.        
        /// </summary>
        /// <param name="files">dat file to process</param>
        public void Process(string file)
        {
            if (string.IsNullOrEmpty(file))
                return;
            try
            {
                CSVFile csv = new CSVFile();
                string name = file.Substring(file.LastIndexOf("\\") + 1); // Remove path information from string
                csv.Log = NC.App.Loggers.Logger(LMLoggers.AppSection.Data);
                csv.Filename = file;
                csv.ExtractDateFromFilename();
                if (name.IndexOf('.') >= 0)
                    csv.ThisSuffix = name.Substring(name.IndexOf('.'));
                csv.ProcessFile();  // split lines with scanner
                int el = System.Enum.GetValues(typeof(ItemCol)).Length;
                foreach (string[] entry in csv.Lines)
                {
                    List<string> ls = new List<string>(entry);
                    if (entry.Length < el)
                    {
                        ls.AddRange(new string[el - ls.Count]);
                    }

                    PopulateSingletons(ls);
                    string code = Results.ItemTypes[Results.ItemTypes.Count - 1];
                    string isoid = ls[(int)ItemCol.IsoId];
                    if (UseDefaultIso(isoid))
                        isoid = Isotopics.DefaultId;
                    if (CompositeCode(code))
                    {
                        // comp isotopics id and item id iso id fields are the same here
                        Results.CompIsoIsotopics.Add(GenCompIso(ls));
                    } else
                    {
                        // isotopics id and item id iso id fields are the same here, Default
                        Results.IsoIsotopics.Add(GenIso(ls));
                    }
                    if (CollarCode(code))
                    {
                        CollarItemId id = GenColl(ls);
                        CollarItems.Add(id);
                        id.item_id = Results.ItemNames[Results.ItemNames.Count - 1];  // the item id for this entry
                    }
                    ItemId iid = GenItemId(ls);
                    Results.ItemIds.Add(iid);
                    // mass was scooped up in one of the three scanners
                }
            } catch (Microsoft.VisualBasic.FileIO.MalformedLineException)  // not a CSV file
            {
                Results.mlogger.TraceEvent(LogLevels.Verbose, 34100, "Skipped " + System.IO.Path.GetFileName(file));
            }
            Results.ApplyContent();
            Results.DoFacs();
            Results.CompIsotopicGen();
            Results.DoSrcCodes();
        }