Ejemplo n.º 1
0
        /// <summary>
        /// Generated the data header
        /// </summary>
        private string DescriptionsToString()
        {
            CSV_Line line = new CSV_Line(Channels.Count);

            for (int i = 0; i < Channels.Count; i++)
            {
                line.SetString(i, Channels[i].Description);
            }
            return(line.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generated the data header
        /// </summary>
        private string DataUnitsToString()
        {
            CSV_Line line = new CSV_Line(Channels.Count);

            for (int i = 0; i < Channels.Count; i++)
            {
                line.SetString(i, Channels[i].Unit);
            }
            return(line.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generated the data header
        /// </summary>
        private string LogMnemonicsToString()
        {
            CSV_Line line = new CSV_Line(Channels.Count);

            for (int i = 0; i < Channels.Count; i++)
            {
                line.SetString(i, Channels[i].Name);
            }
            return(line.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts back to CSV comment string
        /// </summary>
        /// <returns>Converted string</returns>
        public override string ToString()
        {
            CSV_Line line = new CSV_Line(4);

            line.SetString(0, "#" + Name);
            line.SetString(1, Value);
            line.SetString(2, Unit);
            line.SetString(3, Description);
            return(line.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the constant from the string input
        /// </summary>
        /// <param name="input">string as in CSV file</param>
        public CSV_Constant(string input)
        {
            if (!input.StartsWith("#"))
            {
                return;
            }
            input = input.Substring(1);
            CSV_Line line = new CSV_Line(input);
            string   name = line.GetString(0).Trim();

            if (name.Length <= 0)
            {
                return;
            }
            Name        = name;
            Value       = line.GetString(1);
            Unit        = line.GetString(2);
            Description = line.GetString(3);
        }
Ejemplo n.º 6
0
        private void ParseFile()
        {
            FileStream   fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader sr = new StreamReader(fs);
            bool         constant_block_on    = true;
            bool         curve_block_on       = false;
            bool         unit_block_on        = false;
            bool         description_block_on = false;
            bool         data_block_on        = false;

            while (!sr.EndOfStream)
            {
                string s = sr.ReadLine();
                if (s == null)
                {
                    break;
                }

                // read constants if any
                if (constant_block_on)
                {
                    if (s.StartsWith("//"))
                    {
                        CSV_Constant c = new CSV_Constant(s);
                        Constants.Add(c);
                        continue;
                    }
                    else
                    {
                        constant_block_on = false;
                        curve_block_on    = true;
                    }
                }

                // read channel (curve) names
                if (curve_block_on)
                {
                    if (s.StartsWith("//"))
                    {
                        continue;
                    }
                    CSV_Line line = new CSV_Line(s);
                    if (line.IsAllDigital())
                    {
                        for (int i = 1; i <= line.Substrings.Length; i++)
                        {
                            this.Channels.Add(new CSV_Channel("COL_" + i.ToString().PadLeft(3, '0'), ""));
                        }
                        curve_block_on = false;
                        data_block_on  = true;
                    }
                    else
                    {
                        for (int i = 0; i < line.Substrings.Length; i++)
                        {
                            string name = line.Substrings[i];
                            if (name.Length <= 0)
                            {
                                name = "COL_" + i.ToString().PadLeft(3, '0');
                            }
                            this.Channels.Add(new CSV_Channel(name, ""));
                        }
                        curve_block_on = false;
                        unit_block_on  = true;
                        continue;
                    }
                }

                // read unit names
                if (unit_block_on)
                {
                    if (s.StartsWith("//"))
                    {
                        continue;
                    }
                    CSV_Line line = new CSV_Line(s);
                    if (line.IsAllDigital())
                    {
                        unit_block_on = false;
                        data_block_on = true;
                    }
                    else
                    {
                        for (int i = 0; i < this.Channels.Count; i++)
                        {
                            string unit = line.GetString(i);
                            this.Channels[i].Unit = unit;
                        }
                        unit_block_on        = false;
                        description_block_on = true;
                        continue;
                    }
                }

                // read descriptions
                if (description_block_on)
                {
                    if (s.StartsWith("//"))
                    {
                        continue;
                    }
                    CSV_Line line = new CSV_Line(s);
                    if (line.IsAllDigital())
                    {
                        description_block_on = false;
                        data_block_on        = true;
                    }
                    else
                    {
                        for (int i = 0; i < this.Channels.Count; i++)
                        {
                            string description = line.GetString(i);
                            this.Channels[i].Description = description;
                        }
                        description_block_on = false;
                        data_block_on        = true;
                        continue;
                    }
                }

                // read data
                if (data_block_on)
                {
                    if (s.StartsWith("//"))
                    {
                        continue;
                    }
                    CSV_Line line = new CSV_Line(s);
                    for (int i = 0; i < this.Channels.Count; i++)
                    {
                        if (line.Substrings[i].Length < 1)
                        {
                            Channels[i].Data.Add(Double.NaN);
                            continue;
                        }
                        double value = line.GetDouble(i);
                        if (value == MissingValue)
                        {
                            value = Double.NaN;
                        }
                        Channels[i].Data.Add(value);
                    }
                }
            }
            sr.Close();
            fs.Close();
        }