Exemple #1
0
 /// <summary>
 /// write a trace to disk
 /// </summary>
 /// <param name="trace">input trace header</param>
 /// <returns>true is successful</returns>
 public bool Write(SEGYTrace trace)
 {
     if (positionOfEndofFileHeaders < 3600)
     {
         return(false);                                   // no file header written yet
     }
     return(trace.Write(this.SEGYwriter));
 }
Exemple #2
0
        /// <summary>
        /// write the trace to XML
        /// </summary>
        /// <param name="outputXMLFileName">output XML file name</param>
        /// <param name="trace">input trace</param>
        /// <returns>true is successful</returns>
        public bool WriteXML(string outputXMLFileName, SEGYTrace trace)
        {
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(trace.GetType());
            System.IO.FileStream file = System.IO.File.Create(outputXMLFileName);

            writer.Serialize(file, trace);
            file.Close();
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// read an SEGY trace in XML format
        /// </summary>
        /// <param name="inputXMLFileName">input SEGYTrace XML file name</param>
        /// <returns>pointer to SEGYTrace</returns>
        public static SEGYTrace ReadXMLTrace(string inputXMLFileName)
        {
            SEGYTrace overview = new SEGYTrace();

            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(overview.GetType());
            System.IO.StreamReader file = new System.IO.StreamReader(
                inputXMLFileName);
            overview = (SEGYTrace)reader.Deserialize(file);
            file.Close();
            return(overview);
        }
Exemple #4
0
 /// <summary>
 /// add a trace to the end of the Traces list
 /// </summary>
 /// <param name="trace">add a trace</param>
 public void AddTrace(SEGYTrace trace)
 {
     if (Traces.Count == 0)
     {
         trace.positionOfTraceInFile = positionOfEndofFileHeaders;
     }
     else
     {
         trace.positionOfTraceInFile = Traces[Traces.Count - 1].positionOfTraceInFile + Traces[Traces.Count - 1].totalLengthOfTraceData;
     }
     Traces.Add(trace);
 }
Exemple #5
0
 /// <summary>
 /// re-read the file and reindex the trace locations
 /// </summary>
 public void ReindexTracePositions()
 {
     for (int i = 0; i < Traces.Count; i++)
     {
         SEGYTrace trace = Traces[i];
         if (i == 0)
         {
             trace.positionOfTraceInFile = positionOfEndofFileHeaders;
         }
         else
         {
             trace.positionOfTraceInFile = Traces[i - 1].positionOfTraceInFile + Traces[i - 1].totalLengthOfTraceData;
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// write a trace to a BinaryWriter stream
        /// </summary>
        /// <param name="bw">output stream pointer</param>
        /// <returns>true if successful</returns>
        public bool Write(System.IO.BinaryWriter bw)
        {
            if (bw == null)
            {
                return(false);
            }
            this.positionOfTraceInFile = bw.BaseStream.Position;

            SEGYTrace trace = this;

            byte[] bytesToWrite = trace.TraceHeader.TraceHeaderBuffer;
            bw.Write(bytesToWrite);

            bytesToWrite = trace.TraceData.TraceDataBuffer;
            bw.Write(bytesToWrite);

            return(true);
        }
Exemple #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.folderBrowserDialog1.Description = "Enter the destination for the corrected SEGY file";
            if (this.folderBrowserDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            // read throught input file and make corrections to trace positions as needed
            sf            = new SEGYlib.SEGYFile();
            inputSEGYfile = this.openFileDialog1.FileName;
            sf.Open(this.openFileDialog1.FileName);
            if (!sf.isSEGY())
            {
                sf.Close();
                return;
            }

            string outputFileName = this.folderBrowserDialog1.SelectedPath + System.IO.Path.DirectorySeparatorChar.ToString() + System.IO.Path.GetFileNameWithoutExtension(inputSEGYfile) + "fix.sgy";


            SEGYlib.SEGYFile sf2 = new SEGYlib.SEGYFile();
            sf2.Open(outputFileName);

            sf2.FileHeader = sf.FileHeader.Copy();
            sf2.Write(sf2.FileHeader);

            while (sf.ReadNextTrace())
            {
                SEGYlib.SEGYTrace tr = sf.currentTrace;

                SEGYlib.SEGYTrace newTr = tr.Copy();
                newTr.TraceHeader.scalarToBeAppliedToAllCoordinates *= -1;
                newTr.sourcePositionX = newTr.sourcePositionX / 10;
                newTr.sourcePositionY = newTr.sourcePositionY / 10;

                sf2.Write(newTr);
            }

            sf.Close();
            sf2.Close();
        }
Exemple #8
0
        /// <summary>
        /// make a deep copy of a SEGY Trace
        /// </summary>
        /// <returns>pointer to a deep copy of the input trace</returns>
        public SEGYTrace Copy()
        {
            SEGYTrace newTrace = new SEGYTrace();

            newTrace.Intialize(this.iSEGYTraceHeader.bigEndian, iformat);

            byte[] newTraceDataBuffer = null;
            if (this.iSEGYTraceData.TraceDataBuffer != null)
            {
                newTraceDataBuffer = new byte[this.iSEGYTraceData.TraceDataBuffer.Length];
                Array.Copy(this.iSEGYTraceData.TraceDataBuffer, newTraceDataBuffer, this.iSEGYTraceData.TraceDataBuffer.Length);
            }  // copies value contents

            byte[] newTraceHeaderBuffer = new byte[this.iSEGYTraceHeader.TraceHeaderBuffer.Length];
            Array.Copy(this.iSEGYTraceHeader.TraceHeaderBuffer, newTraceHeaderBuffer, this.iSEGYTraceHeader.TraceHeaderBuffer.Length);

            newTrace.iSEGYTraceData.TraceDataBuffer     = newTraceDataBuffer;
            newTrace.iSEGYTraceHeader.TraceHeaderBuffer = newTraceHeaderBuffer;

            newTrace.positionOfTraceInFile = -1; // trace has not been written to a file yet;

            return(newTrace);
        }
Exemple #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.folderBrowserDialog1.Description = "Enter the destination for the corrected SEGY file";
            if (this.folderBrowserDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }


            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                int c = 0;
                // read throught input file and make corrections to trace positions as needed
                SEGYlib.SEGYFile sf            = new SEGYlib.SEGYFile();
                string           inputSEGYfile = (string)listBox1.Items[i];
                sf.Open(this.openFileDialog1.FileName);

                string outputFileName = this.folderBrowserDialog1.SelectedPath + System.IO.Path.DirectorySeparatorChar.ToString() + System.IO.Path.GetFileNameWithoutExtension(inputSEGYfile) + "rev0.sgy";
                this.toolStripStatusLabel1.Text = "Writing " + outputFileName;
                Application.DoEvents();

                SEGYlib.SEGYFile sf2 = new SEGYlib.SEGYFile();
                sf2.Open(outputFileName);

                sf2.FileHeader = sf.FileHeader.Copy();

                sf2.FileHeader.segyFormatRevisionNumber = 0; // convert to version 0
                sf2.FileHeader.numberOfExtendedTextualFileHeaderRecordsFollowing = 0;
                if (sf2.FileHeader.ExtendedTextHeader.Count > 1)
                {
                    sf2.FileHeader.ExtendedTextHeader.RemoveRange(1, sf2.FileHeader.ExtendedTextHeader.Count - 1);
                }

                sf2.Write(sf2.FileHeader);

                while (sf.ReadNextTrace())
                {
                    SEGYlib.SEGYTrace tr = sf.currentTrace;

                    SEGYlib.SEGYTrace newTr = tr.Copy();

                    sf2.Write(newTr);
                    c++;
                    if ((c % 100) == 0)
                    {
                        toolStripStatusLabel2.Text += ".";
                        if (toolStripStatusLabel2.Text.Length > 50)
                        {
                            toolStripStatusLabel2.Text = ".";
                        }
                        Application.DoEvents();
                    }
                }

                sf.Close();
                sf2.Close();
            }
            toolStripStatusLabel2.Text      = "";
            this.toolStripStatusLabel1.Text = "Done";
            Application.DoEvents();
        }
Exemple #10
0
        private void fixTraceLengths(string f, string g)
        {
            // setup datum trasformation
            DataRow r = datumDT.Rows[datum_number];

            //find ellipsoid parameters
            int ellipse_number = ellipsoidDT.Rows.Count - 1; // last entry is wgs 84

            for (int i = 0; i < ellipsoidDT.Rows.Count - 1; i++)
            {
                if (String.Compare(r[1].ToString(), ellipsoidDT.Rows[i][0].ToString()) == 0)
                {
                    ellipse_number = i;
                    break;
                }
            }

            double a_in   = Convert.ToDouble(ellipsoidDT.Rows[ellipse_number][1]);
            double fi_in  = Convert.ToDouble(ellipsoidDT.Rows[ellipse_number][2]);
            double dX     = Convert.ToDouble(r[2]);
            double dY     = Convert.ToDouble(r[3]);
            double dZ     = Convert.ToDouble(r[4]);
            double a_out  = Convert.ToDouble(ellipsoidDT.Rows[ellipsoidDT.Rows.Count - 1][1]);
            double fi_out = Convert.ToDouble(ellipsoidDT.Rows[ellipsoidDT.Rows.Count - 1][2]);

            NETGeographicLib.Geocentric fw = new NETGeographicLib.Geocentric(a_in, 1.0 / fi_in);
            NETGeographicLib.Geocentric rw = new NETGeographicLib.Geocentric(a_out, 1.0 / fi_out);

            SEGYlib.SEGYFile sf = new SEGYFile();
            sf.Open(f);                                    // open an existing SEGY file

            SEGYlib.SEGYFile sf2 = new SEGYlib.SEGYFile(); // create a new SEGY file
            sf2.Open(g);

            sf2.FileHeader = sf.FileHeader.Copy();  // copy the input trace header
            if (checkBox2.Checked)
            {
                sf2.FileHeader.numberOfSamplesPerDataTrace = Convert.ToUInt16((maxTime - minTime) * 1e3 / sf2.FileHeader.sampleIntervalInMicroseconds);
            }
            if (checkBox3.Checked)
            {
                sf2.FileHeader.SetFileHeader(0, 36, "C36 Positions coverted to Lat/Lon : " + DateTime.Now.ToShortDateString());
            }
            sf2.Write(sf2.FileHeader);  // write out the header
            int  c    = 0;
            bool flip = true;

            System.IO.StreamWriter tw = null;

            if (checkBox1.Checked)
            {
                // create a zone report
                string z = System.IO.Path.ChangeExtension(g, ".prj");
                tw = System.IO.File.CreateText(z);
            }
            while (sf.ReadNextTrace())
            {
                SEGYlib.SEGYTrace tr    = sf.currentTrace;
                SEGYlib.SEGYTrace newTr = tr.Copy();
                if (checkBox2.Checked)
                {
                    // pad top and bottom of trace
                    maxTraceLength = Convert.ToInt32((maxTime - minTime) * 1e3 / tr.TraceHeader.sampleIntervalUsec);
                    // delay offset
                    int delayoffset = (int)((newTr.TraceHeader.delayRecordingTimeMsec - minTime) * 1e3 / (double)newTr.TraceHeader.sampleIntervalUsec);
                    // pad top of trace
                    newTr.Resize(maxTraceLength, delayoffset);
                    newTr.TraceHeader.delayRecordingTimeMsec = (short)minTime;
                }


                if (checkBox1.Checked || checkBoxDatum.Checked || checkBox3.Checked)
                {
                    // switch to UTM
                    if (tr.isLatLon)
                    {
                        double lon = tr.sourcePositionX;
                        double lat = tr.sourcePositionY;
                        if (checkBoxDatum.Checked)
                        {
                            double h = 0;
                            double X, Y, Z;
                            fw.Forward(lat, lon, 0.0, out X, out Y, out Z);
                            X += dX;
                            Y += dY;
                            Z += dZ;
                            rw.Reverse(X, Y, Z, out lat, out lon, out h);
                            newTr.sourcePositionX = lon;
                            newTr.sourcePositionY = lat;
                        }
                        if (checkBox1.Checked)
                        {
                            // convert to geocentric
                            double x, y;
                            int    setzone, zone;
                            bool   north;
                            setzone = Convert.ToInt32(this.numericUpDown1.Value);
                            NETGeographicLib.UTMUPS.Forward(lat, lon, out zone, out north, out x, out y, setzone, false);
                            tw.WriteLine(lat.ToString() + " " + lon.ToString() + " " + x.ToString() + " " + y.ToString() + " " + zone.ToString());

                            newTr.TraceHeader.coordinateUnits = 1;
                            newTr.TraceHeader.scalarToBeAppliedToAllCoordinates = -100;
                            newTr.sourcePositionY = y;
                            newTr.sourcePositionX = x;
                        }
                    }
                    else
                    {
                        int    setzone, zone;
                        bool   north;
                        double lat, lon;

                        double x = tr.sourcePositionX;
                        double y = tr.sourcePositionY;
                        if (x > 0 && x < 1000000.0)
                        {
                            setzone = Convert.ToInt32(this.numericUpDown1.Value);
                            NETGeographicLib.UTMUPS.Reverse(setzone, true, x, y, out lon, out lat, false);
                        }
                        else
                        {
                            lon = 0;
                            lat = 0;
                        }
                        newTr.TraceHeader.coordinateUnits = 2;
                        newTr.TraceHeader.scalarToBeAppliedToAllCoordinates = -100;
                        newTr.sourcePositionY = lon;
                        newTr.sourcePositionX = lat;
                        if (checkBoxDatum.Checked)
                        {
                            double h = 0;
                            double X, Y, Z;
                            fw.Forward(lat, lon, 0.0, out X, out Y, out Z);
                            X += dX;
                            Y += dY;
                            Z += dZ;
                            rw.Reverse(X, Y, Z, out lat, out lon, out h);
                            newTr.sourcePositionX = lon;
                            newTr.sourcePositionY = lat;
                        }
                    }
                }



                sf2.Write(newTr);
                c++;
                if (c >= 4949)
                {
                    int ibreak = 0;
                }
                if (c % 100 == 0)
                {
                    toolStripStatusLabel1.Text = "Writing  " + g + " ";
                    if (flip)
                    {
                        toolStripStatusLabel1.Text += "\\";
                        flip = false;
                    }
                    else
                    {
                        toolStripStatusLabel1.Text += "/";
                        flip = true;
                    }
                    Application.DoEvents();
                }
            }

            if (tw != null)
            {
                tw.Close();
            }
            sf.Close();
            sf2.Close();
        }
Exemple #11
0
        /// <summary>
        /// read the next trace in the file
        /// </summary>
        /// <returns>true is successful</returns>
        public bool ReadNextTrace(bool onlyheader = false)
        {
            if (this.iSEGYFileHeader == null)
            {
                return(false);
            }

            this.iSEGYTrace = new SEGYTrace();
            this.iSEGYTrace.Intialize(this.isBigEndian, this.iSEGYFileHeader.dataSampleFormatCode);

            long currentFilePosition = this.SEGYreader.BaseStream.Position;

            this.iSEGYTrace.positionOfTraceInFile = currentFilePosition;

            // read trace header
            byte[] tmpTraceHeader = this.SEGYreader.ReadBytes(240);
            if (tmpTraceHeader.Length < 240)
            {
                return(false);
            }

            this.iSEGYTrace.TraceHeader.TraceHeaderBuffer = tmpTraceHeader; // store byte stream of trace header


            // read trace data
            int bytesToRead = this.iSEGYTrace.TraceHeader.numberOfSamplesInTrace;

            if (bytesToRead <= 0)
            {
                // use fileheader value
                bytesToRead = iSEGYFileHeader.numberOfSamplesPerDataTrace;
            }
            if (this.iSEGYFileHeader.dataSampleFormatCode == 1 || this.iSEGYFileHeader.dataSampleFormatCode == 2 || this.iSEGYFileHeader.dataSampleFormatCode == 5)
            {
                bytesToRead *= 4;
            }
            else if (this.iSEGYFileHeader.dataSampleFormatCode == 3)
            {
                bytesToRead *= 2;
            }
            else if (this.iSEGYFileHeader.dataSampleFormatCode == 8)
            {
                bytesToRead *= 1;
            }
            else
            {
                // System.Windows.Forms.MessageBox.Show("this.iSEGYFileHeader.dataSampleFormatCode = " + this.iSEGYFileHeader.dataSampleFormatCode.ToString() + " is not supported");
                return(false);
            }

            if (!onlyheader)
            {
                byte[] tmpTraceData = this.SEGYreader.ReadBytes(bytesToRead);

                if (tmpTraceData.Length < bytesToRead)
                {
                    this.SEGYreader.BaseStream.Position = currentFilePosition;
                    return(false);
                }
                this.iSEGYTrace.TraceData.TraceDataBuffer = tmpTraceData;
            }
            else
            {
                // advance file pointer to skip by trace data
                if (this.SEGYreader.BaseStream.Position + bytesToRead > this.SEGYreader.BaseStream.Length)
                {
                    return(false);
                }
                this.SEGYreader.BaseStream.Position += bytesToRead;
            }


            return(true);
        }