Example #1
0
        private void swapConstant(LAS_Constant c)
        {
            string tmp = c.Value;

            c.Value       = c.Description;
            c.Description = tmp;
        }
Example #2
0
        /// <summary>
        /// Sets the LAS constant by name, adding a new parameter if necessary
        /// </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 void SetConstant(string name, string unit, string value, string description)
        {
            foreach (LAS_Constant lc in Constants)
            {
                if (lc.Name != name)
                {
                    continue;
                }
                lc.Value = value;
                return;
            }
            LAS_Constant newP = new LAS_Constant(name, unit, value, description);

            Constants.Add(newP);
        }
Example #3
0
        /// <summary>
        /// Sets the LAS constant by name, adding a new parameter if necessary
        /// </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 (LAS_Constant lc in Parameters)
            {
                if (lc.Name != name)
                {
                    continue;
                }
                lc.Value = value;
                return;
            }
            LAS_Constant newP = new LAS_Constant(name, unit, value, description);

            Parameters.Add(newP);
        }
Example #4
0
        /// <summary>
        /// Construsctor; reads the LAS file header to memory
        /// </summary>
        /// <param name="filename">File name</param>
        /// <param name="ParseData">Set to true is data parsing is needed</param>
        public LAS_File(string filename, bool ParseData) : base(filename)
        {
            FileStream   fs = null;
            StreamReader sr = null;

            try
            {
                fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                sr = new StreamReader(fs);
                bool version_info_block_on   = false;
                bool well_info_block_on      = false;
                bool curve_info_block_on     = false;
                bool parameter_info_block_on = false;
                bool other_info_block_on     = false;
                bool data_on = false;
                while (!sr.EndOfStream)
                {
                    string s  = sr.ReadLine();
                    string s2 = s.ToLower();

                    if (s2.StartsWith("~version"))
                    {
                        version_info_block_on   = true;
                        well_info_block_on      = false;
                        curve_info_block_on     = false;
                        parameter_info_block_on = false;
                        other_info_block_on     = false;
                        data_on = false;
                        continue;
                    }
                    if (s2.StartsWith("~well"))
                    {
                        version_info_block_on   = false;
                        well_info_block_on      = true;
                        curve_info_block_on     = false;
                        parameter_info_block_on = false;
                        other_info_block_on     = false;
                        data_on = false;
                        continue;
                    }
                    if (s2.StartsWith("~curv") || s2.StartsWith("~log_definition"))
                    {
                        version_info_block_on   = false;
                        well_info_block_on      = false;
                        curve_info_block_on     = true;
                        parameter_info_block_on = false;
                        other_info_block_on     = false;
                        data_on = false;
                        continue;
                    }
                    if (s2.StartsWith("~paramet") || s2.StartsWith("~log_parameter"))
                    {
                        version_info_block_on   = false;
                        well_info_block_on      = false;
                        curve_info_block_on     = false;
                        parameter_info_block_on = true;
                        other_info_block_on     = false;
                        data_on = false;
                        continue;
                    }
                    if (s2.ToLower().StartsWith("~other"))
                    {
                        version_info_block_on   = false;
                        well_info_block_on      = false;
                        curve_info_block_on     = false;
                        parameter_info_block_on = false;
                        other_info_block_on     = true;
                        data_on = false;
                        continue;
                    }
                    if (s2.ToUpper().StartsWith("~A") || s2.StartsWith("~log_data"))
                    {
                        version_info_block_on   = false;
                        well_info_block_on      = false;
                        curve_info_block_on     = false;
                        parameter_info_block_on = false;
                        other_info_block_on     = false;
                        data_on = true;
                        if (!ParseData)
                        {
                            break;
                        }
                        continue;
                    }
                    if (version_info_block_on)
                    {
                        if (s.StartsWith("#"))
                        {
                            continue;
                        }
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        LAS_Constant lc = new LAS_Constant(s);
                        if (lc.Name.ToUpper() == "VERS" && !lc.Value.StartsWith("2."))
                        {
                            throw new Exception("LAS version other than 2.x cannot be handled.");
                        }
                        if (lc.Name.ToUpper() == "WRAP" && !lc.Value.StartsWith("N"))
                        {
                            throw new Exception("Wrapped data cannot be handled by most clients. Do not use LAS wrap.");
                        }
                        Version.Add(lc);
                    }
                    if (well_info_block_on)
                    {
                        if (s.StartsWith("#"))
                        {
                            continue;
                        }
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        LAS_Constant lc = new LAS_Constant(s);
                        if (lc.Name == "NULL")
                        {
                            MissingValue = Convert.ToDouble(lc.Value);
                        }
                        Constants.Add(lc);
                    }
                    if (curve_info_block_on)
                    {
                        if (s.StartsWith("#"))
                        {
                            continue;
                        }
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        LAS_Channel lc = new LAS_Channel(s);
                        Channels.Add(lc);
                    }
                    if (parameter_info_block_on)
                    {
                        if (s.StartsWith("#"))
                        {
                            continue;
                        }
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        LAS_Constant lc = new LAS_Constant(s);
                        Parameters.Add(lc);
                    }
                    if (other_info_block_on)
                    {
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        LAS_InfoLine lil = new LAS_InfoLine(s);
                        InfoLines.Add(lil);
                    }
                    if (data_on)
                    {
                        if (s.StartsWith("#"))
                        {
                            continue;
                        }
                        if (s.Length <= 1)
                        {
                            continue;
                        }
                        if (s.StartsWith("~A"))
                        {
                            continue;
                        }
                        m_RawData.Add(s);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            ConvertConstantsFromEarlierLAS();

            // parse data to channels
            if (Channels.Count <= 0)
            {
                throw new Exception("No curves have been declared in the file.");
            }
            foreach (string s in m_RawData)
            {
                string[] ss = s.Split(_space_split, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < ss.Length; i++)
                {
                    Channels[i].AddData(ss[i], MissingValue);
                }
            }
            m_RawData.Clear();
        }