Exemple #1
0
        /// <summary>
        /// Creates a deep copy of this constant
        /// </summary>
        /// <returns></returns>
        public override Oilfield_Constant Clone()
        {
            CSV_Constant tmp = new CSV_Constant();

            tmp.Name        = this.Name;
            tmp.Unit        = this.Unit;
            tmp.Value       = this.Value;
            tmp.Description = this.Description;
            return(tmp);
        }
Exemple #2
0
        /// <summary>
        /// Sets the CSV parameter by name, adding a new parameter if necessary
        /// Note that parameters cannot be saved to CSV file - they are for run-time only
        /// </summary>
        /// <param name="name">Constant name</param>
        /// <param name="unit">Constant unit</param>
        /// <param name="value">Constant value</param>
        /// <param name="value">Description</param>
        public override void SetParameter(string name, string unit, string value, string description)
        {
            foreach (CSV_Constant c in Parameters)
            {
                if (c.Name != name)
                {
                    continue;
                }
                c.Value = value;
                return;
            }
            CSV_Constant newP = new CSV_Constant(name, unit, value, description);

            Parameters.Add(newP);
        }
Exemple #3
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();
        }