Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (f.currentTrace != null)
     {
         f.ReadNextTrace();
         refreshTraceHeader();
     }
 }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var i in listBox1.Items)
            {
                String f  = (string)i;
                string f0 = System.IO.Path.GetDirectoryName(f) + System.IO.Path.DirectorySeparatorChar + System.IO.Path.GetFileNameWithoutExtension(f) + "_corr.sgy";

                SEGYFile s0 = new SEGYFile();
                if (s0.Open(f) == 0)
                {
                    break;
                }
                SEGYFile s1 = new SEGYFile();
                if (s1.Open(f0) == 0)
                {
                    s0.Close();
                    break;
                }

                s0.ReadFileHeader();
                s1.Write(s0.FileHeader.Copy());
                while (s0.ReadNextTrace())
                {
                    SEGYTrace t = s0.currentTrace.Copy();
                    short     waterDepthMsec = t.TraceHeader.delayRecordingTimeMsec;
                    t.TraceHeader.delayRecordingTimeMsec = 0;
                    //t.TraceHeader.waterDepthAtSource = (int)waterDepthMsec;
                    s1.Write(t);
                }
                s0.Close();
                s1.Close();
            }
        }
Esempio n. 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var i in listBox1.Items)
            {
                String f  = (string)i;
                string f0 = System.IO.Path.GetDirectoryName(f) + System.IO.Path.DirectorySeparatorChar + System.IO.Path.GetFileNameWithoutExtension(f) + ".gps";

                SEGYFile s0 = new SEGYFile();
                if (s0.Open(f) == 0)
                {
                    break;
                }
                var s1 = File.CreateText(f0);
                if (s1 == null)
                {
                    break;
                }

                s0.ReadFileHeader();

                while (s0.ReadNextTrace())
                {
                    SEGYTrace t = s0.currentTrace;
                    if (t.TraceHeader.traceNumberWithinOriginalFieldRecord == 1)
                    {
                        s1.WriteLine(t.timeTracedRecorded.ToString(), " ", t.sourcePositionX.ToString(), " ", t.sourcePositionY.ToString());
                    }
                }
                s0.Close();
                s1.Close();
            }
        }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var i in listBox1.Items)
            {
                String f  = (string)i;
                string f0 = System.IO.Path.GetDirectoryName(f) + System.IO.Path.DirectorySeparatorChar + System.IO.Path.GetFileNameWithoutExtension(f) + "_corr.sgy";

                SEGYFile s0 = new SEGYFile();
                if (s0.Open(f) == 0)
                {
                    break;
                }
                SEGYFile s1 = new SEGYFile();
                if (s1.Open(f0) == 0)
                {
                    s0.Close();
                    break;
                }

                s0.ReadFileHeader();
                var fh = s0.FileHeader.Copy();
                fh.SetFileHeader(0, 39, "C39 File processed by FixOBSSEGY Sept/2019");
                s1.Write(fh);
                while (s0.ReadNextTrace())
                {
                    if (s0.currentTrace.TraceHeader.numberOfSamplesInTrace < 1000 || s0.currentTrace.TraceHeader.numberOfSamplesInTrace > 60000)
                    {
                        break;
                    }
                    if (s0.currentTrace.timeTracedRecorded < new DateTime(1950, 1, 1))
                    {
                        break;
                    }
                    SEGYTrace t = s0.currentTrace.Copy();
                    if (checkBoxSwitch.Checked)
                    {
                        var s = t.TraceHeader.sourceCoordinateX;
                        t.TraceHeader.sourceCoordinateX = t.TraceHeader.sourceCoordinateY;
                        t.TraceHeader.sourceCoordinateY = s;
                        s = t.TraceHeader.groupCoordinateX;
                        t.TraceHeader.groupCoordinateX = t.TraceHeader.groupCoordinateY;
                        t.TraceHeader.groupCoordinateY = s;
                    }
                    if (checkBoxlldec.Checked)
                    {
                        t.TraceHeader.coordinateUnits = 3;
                    }
                    if (checkBoxllsa.Checked)
                    {
                        t.TraceHeader.coordinateUnits = 2;
                    }
                    s1.Write(t);
                }
                s0.Close();
                s1.Close();
            }
        }
Esempio n. 5
0
        private void runToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (string f in listBox1.Items)
            {
                fseg = new SEGYFile();
                fseg.Open(f);
                fseg.ReadFileHeader();


                SEGYFile fn  = new SEGYFile();
                string   fnn = f.Replace(".sgy", "_clipped.sgy");
                //create new filename
                if (System.IO.File.Exists(fnn))
                {
                    System.IO.File.Delete(fnn);
                }
                fn.Open(fnn);
                fn.FileHeader = fseg.FileHeader.Copy();
                fn.Write(fn.FileHeader);

                while (fseg.ReadNextTrace())
                {
                    if (fseg.currentTrace.TraceHeader.yearDataRecorded != 2001 || fseg.currentTrace.TraceHeader.dayOfYear > 366)
                    {
                        int i = 0;
                        break;
                    }
                    // set 1140 thru 1222 to zero in trace block ( las 82 entries )
                    byte[] buff = fseg.currentTrace.TraceData.TraceDataBuffer;
                    // since 4 byte words
                    for (int i = buff.Length - 82 * 4; i < buff.Length; i++)
                    {
                        buff[i] = 0;
                    }
                    fn.Write(fseg.currentTrace);
                }

                fn.Close();
                fseg.Close();
            }
        }
Esempio n. 6
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Title = "Open SEGY File";
            if (this.openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            f = new SEGYFile();
            currentTraceNumber = 0;
            if (f.Open(this.openFileDialog1.FileName) == 0)
            {
                return;
            }
            if (f.FileHeader.isSEGYFileHeaderAscii)
            {
                checkBoxIsEBCDIC.Checked = false;
            }
            refreshFileheader();
            //read first trace
            f.ReadNextTrace();

            refreshTraceHeader();
        }
Esempio n. 7
0
        private void scanFile()
        {
            if (this.listBox1.SelectedIndex < 0)
            {
                return;
            }
            string   f = (string)listBox1.SelectedItem;
            SEGYFile s = new SEGYFile();

            s.Open(f);
            s.Traces = new List <SEGYlib.SEGYTrace>();
            s.ReadFileHeader();
            int  c    = 0;
            bool flip = true;

            l1norms = new System.Collections.ArrayList();
            while (s.ReadNextTrace())
            {
                SEGYTrace tr = s.currentTrace;
                // calculate l1 norm of trace enegy
                //double l1 = 0;
                //for (int i = 0; i < tr.TraceData.Data.Length; i++) l1 += Math.Abs(tr.TraceData.Data[i]);
                //l1norms.Add(l1);
                //    tr.TraceData.TraceDataBuffer = null;
                s.Traces.Add(tr);
                c++;
                if (c % 100 == 0)
                {
                    toolStripStatusLabel1.Text = "Reading " + f + " ";
                    if (flip)
                    {
                        toolStripStatusLabel1.Text += "\\";
                        flip = false;
                    }
                    else
                    {
                        toolStripStatusLabel1.Text += "/";
                        flip = true;
                    }
                    Application.DoEvents();
                }
            }
            //s.ReadAllTraceHeaders();
            int tmin     = s.Traces[0].TraceHeader.numberOfSamplesInTrace;
            int tmax     = tmin;
            int delaymin = s.Traces[0].TraceHeader.delayRecordingTimeMsec;
            int delaymax = Convert.ToInt32(delaymin + s.Traces[0].TraceHeader.numberOfSamplesInTrace * s.Traces[0].TraceHeader.sampleIntervalUsec / 1e3);

            for (int i = 0; i < s.Traces.Count; i++)
            {
                int ti = s.Traces[i].TraceHeader.numberOfSamplesInTrace;
                if (ti < tmin)
                {
                    tmin = ti;
                }
                if (ti > tmax)
                {
                    tmax = ti;
                }
                if (s.Traces[i].TraceHeader.delayRecordingTimeMsec < delaymin)
                {
                    delaymin = s.Traces[i].TraceHeader.delayRecordingTimeMsec;
                }
                int tm = Convert.ToInt32(s.Traces[i].TraceHeader.delayRecordingTimeMsec + s.Traces[i].TraceHeader.numberOfSamplesInTrace * s.Traces[i].TraceHeader.sampleIntervalUsec / 1e3);
                if (tm > delaymax)
                {
                    delaymax = tm;
                }
            }
            s.Close();
            this.toolStripStatusLabel1.Text = "Trace length varies from " + tmin.ToString() + " to " + tmax.ToString();
            maxTraceLength = tmax;
            minTime        = delaymin;
            maxTime        = delaymax;
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var i in listBox1.Items)
            {
                String f  = (string)i;
                string f0 = System.IO.Path.GetDirectoryName(f) + System.IO.Path.DirectorySeparatorChar + System.IO.Path.GetFileNameWithoutExtension(f) + "_corr.sgy";
                if (File.Exists(f0))
                {
                    File.Delete(f0);
                }

                SEGYFile s0 = new SEGYFile();
                if (s0.Open(f) == 0)
                {
                    break;
                }
                SEGYFile s1 = new SEGYFile();
                if (s1.Open(f0) == 0)
                {
                    s0.Close();
                    break;
                }

                s0.ReadFileHeader();
                s1.Write(s0.FileHeader.Copy());
                int count = 0;
                toolStripStatusLabel1.Text = "Writing " + f0 + " : ";
                while (s0.ReadNextTrace())
                {
                    SEGYTrace t = s0.currentTrace.Copy();  // seismic data
                    if (t.TraceHeader.traceIdentificationCode != 1)
                    {
                        continue;
                    }
                    // find water depth of source in meters
                    var srcDepth = Convert.ToDouble(t.TraceHeader.sourceDepthBelowSurface);
                    var fac      = t.TraceHeader.scalarForAllElevationsAndDepths;
                    if (fac < 0)
                    {
                        srcDepth /= -fac;
                    }
                    else if (fac > 0)
                    {
                        srcDepth *= fac;
                    }
                    // calculate the corresponding time delay in seconds
                    var twt     = 2 * srcDepth / 1500; // assume vw = 1500 m/s
                    var twtmsec = twt * 1e3;
                    t.TraceHeader.delayRecordingTimeMsec = Convert.ToInt16(Math.Floor(twtmsec));
                    var remainder = twtmsec - t.TraceHeader.delayRecordingTimeMsec;
                    // corresponding number of samples to pad trace for fractional delay times
                    var nsamp = Convert.ToInt32(remainder * 1e3 / t.TraceHeader.sampleIntervalUsec);
                    var data  = t.TraceData.Data;
                    // mute start of trace
                    if (this.checkBox1.Checked)
                    {
                        int mutedelay = Convert.ToInt32(Convert.ToDouble(this.numericUpDown1.Value) * 1e3 / Convert.ToDouble(t.TraceHeader.sampleIntervalUsec));
                        for (int ii = 0; ii < mutedelay; ii++)
                        {
                            data[ii] = 0;
                        }
                    }
                    var datanew = new double[data.Length]; // should be initializes to zero
                    Array.Copy(data, 0, datanew, nsamp, data.Length - nsamp);
                    t.TraceData.Data = datanew;
                    s1.Write(t);
                    count++;
                    if (count % 100 == 0)
                    {
                        toolStripStatusLabel2.Text = count.ToString();
                        Application.DoEvents();
                    }
                }
                s0.Close();
                s1.Close();
            }
            toolStripStatusLabel1.Text = "."; toolStripStatusLabel2.Text = ".";
        }