[segyio] 42/376: Fixed a crossline / inline length calculation bug

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit 8c0f624e02fa87ae55ce338a11c5ebaffb9b0ff6
Author: Jean-Paul Balabanian <jepebe at users.noreply.github.com>
Date:   Tue Oct 18 12:36:04 2016 +0200

    Fixed a crossline / inline length calculation bug
---
 python/segyio/_segyio.c | 11 ++---------
 src/segyio/segy.c       | 38 ++++----------------------------------
 src/segyio/segy.h       | 19 +++++--------------
 tests/test_segy.c       | 31 ++++++++++++-------------------
 tests/test_segyio_c.py  | 19 ++++++++++++++++---
 5 files changed, 39 insertions(+), 79 deletions(-)

diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 43304a0..05dbfab 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -443,16 +443,9 @@ static PyObject *py_init_line_metrics(PyObject *self, PyObject *args) {
 
     PyArg_ParseTuple(args, "iIIII", &sorting, &trace_count, &inline_count, &crossline_count, &offset_count);
 
-    unsigned int iline_length;
-    int error = segy_inline_length(sorting, trace_count, crossline_count, offset_count, &iline_length);
+    unsigned int iline_length = segy_inline_length(crossline_count);
 
-    //Only check first call since the only error that can occur is SEGY_INVALID_SORTING
-    if (error != 0) {
-        return py_handle_segy_error(error, errno);
-    }
-
-    unsigned int xline_length;
-    segy_crossline_length(sorting, trace_count, inline_count, offset_count, &xline_length);
+    unsigned int xline_length = segy_crossline_length(inline_count);
 
     unsigned int iline_stride;
     segy_inline_stride(sorting, inline_count, &iline_stride);
diff --git a/src/segyio/segy.c b/src/segyio/segy.c
index dc13c74..dc42ab4 100644
--- a/src/segyio/segy.c
+++ b/src/segyio/segy.c
@@ -816,42 +816,12 @@ int segy_count_lines( FILE* fp,
     return SEGY_OK;
 }
 
-int segy_inline_length( int sorting,
-                        unsigned int traces,
-                        unsigned int crossline_count,
-                        unsigned int offsets,
-                        unsigned int* line_length ) {
-
-    if( sorting == INLINE_SORTING ) {
-        *line_length = crossline_count;
-        return SEGY_OK;
-    }
-
-    if( sorting == CROSSLINE_SORTING ) {
-        *line_length = traces / (crossline_count * offsets);
-        return SEGY_OK;
-    }
-
-    return SEGY_INVALID_SORTING;
+unsigned int segy_inline_length(unsigned int crossline_count) {
+    return crossline_count;
 }
 
-int segy_crossline_length( int sorting,
-                           unsigned int traces,
-                           unsigned int inline_count,
-                           unsigned int offsets,
-                           unsigned int* line_length ) {
-
-    if( sorting == INLINE_SORTING ) {
-        *line_length = inline_count;
-        return SEGY_OK;
-    }
-
-    if( sorting == CROSSLINE_SORTING ) {
-        *line_length = traces / (inline_count * offsets);
-        return SEGY_OK;
-    }
-
-    return SEGY_INVALID_SORTING;
+unsigned int segy_crossline_length(unsigned int inline_count) {
+    return inline_count;
 }
 
 int segy_inline_indices( FILE* fp,
diff --git a/src/segyio/segy.h b/src/segyio/segy.h
index 9de955c..3e92d84 100644
--- a/src/segyio/segy.h
+++ b/src/segyio/segy.h
@@ -158,23 +158,14 @@ int segy_count_lines( FILE*,
                       unsigned int trace_bsize );
 /*
  * Find the `line_length` for the inlines. Assumes all inlines, crosslines and
- * traces don't vary in length. `offsets` can be found with `segy_offsets`, and
- * `traces` can be found with `segy_traces`.
- *
+ * traces don't vary in length.
+ * *
  * `inline_count` and `crossline_count` are the two values obtained with
  * `segy_count_lines`.
  */
-int segy_inline_length( int sorting,
-                        unsigned int traces,
-                        unsigned int crossline_count,
-                        unsigned int offsets,
-                        unsigned int* line_length );
-
-int segy_crossline_length( int sorting,
-                           unsigned int traces,
-                           unsigned int inline_count,
-                           unsigned int offsets,
-                           unsigned int* line_length );
+unsigned int segy_inline_length(unsigned int crossline_count);
+
+unsigned int segy_crossline_length(unsigned int inline_count);
 
 /*
  * Find the indices of the inlines and write to `buf`. `offsets` are the number
diff --git a/tests/test_segy.c b/tests/test_segy.c
index 77ed6c8..39ee295 100644
--- a/tests/test_segy.c
+++ b/tests/test_segy.c
@@ -76,8 +76,7 @@ void test_interpret_file() {
     assertTrue( err == 0, "Could not determine 2484's trace0." );
     assertTrue( line_trace0 == 15, "Line 4 should start at traceno 15." );
 
-    err = segy_inline_length( sorting, traces, inlines_sz, offsets, &line_length );
-    assertTrue( err == 0, "Could not determine line length." );
+    line_length = segy_inline_length( crosslines_sz);
     assertTrue( line_length == 5, "Inline length should be 5." );
 
     /* Crossline-specific information */
@@ -96,8 +95,7 @@ void test_interpret_file() {
     assertTrue( err == 0, "Could not determine 22's trace0." );
     assertTrue( line_trace0 == 2, "Line 22 should start at traceno 2." );
 
-    err = segy_crossline_length( sorting, traces, inlines_sz, offsets, &line_length );
-    assertTrue( err == 0, "Failure finding length" );
+    line_length = segy_crossline_length( inlines_sz );
     assertTrue( line_length == 5, "Crossline length should be 5." );
 
     fclose( fp );
@@ -231,9 +229,11 @@ void testReadInLine_4(){
       && !segy_count_lines( fp, xl, offsets, &inlines_sz, &crosslines_sz, trace0, trace_bsize )
       && !segy_inline_indices( fp, il, sorting, inlines_sz, crosslines_sz, offsets, inline_indices, trace0, trace_bsize )
       && !segy_inline_stride( sorting, inlines_sz, &stride )
-      && !segy_line_trace0( 4, crosslines_sz, stride, inline_indices, inlines_sz, &line_trace0 )
-      && !segy_inline_length( sorting, traces, inlines_sz, offsets, &line_length )
-      && !segy_read_line( fp, line_trace0, line_length, stride, data, trace0, trace_bsize )
+      && !segy_line_trace0( 4, crosslines_sz, stride, inline_indices, inlines_sz, &line_trace0 );
+
+    line_length = segy_inline_length(crosslines_sz);
+
+      ok = ok && !segy_read_line( fp, line_trace0, line_length, stride, data, trace0, trace_bsize )
       && !segy_to_native( format, inline_length * samples, data );
 
     assertTrue( ok, "Error in setup. "
@@ -304,9 +304,11 @@ void testReadCrossLine_22(){
       && !segy_count_lines( fp, xl, offsets, &inlines_sz, &crosslines_sz, trace0, trace_bsize )
       && !segy_crossline_indices( fp, xl, sorting, inlines_sz, crosslines_sz, offsets, crossline_indices, trace0, trace_bsize )
       && !segy_crossline_stride( sorting, crosslines_sz, &stride )
-      && !segy_line_trace0( 22, crosslines_sz, stride, crossline_indices, inlines_sz, &line_trace0 )
-      && !segy_crossline_length( sorting, traces, inlines_sz, offsets, &line_length )
-      && !segy_read_line( fp, line_trace0, line_length, stride, data, trace0, trace_bsize )
+      && !segy_line_trace0( 22, crosslines_sz, stride, crossline_indices, inlines_sz, &line_trace0 );
+
+    line_length = segy_crossline_length(inlines_sz);
+
+    ok = ok && !segy_read_line( fp, line_trace0, line_length, stride, data, trace0, trace_bsize )
       && !segy_to_native( format, crossline_length * samples, data );
 
     assertTrue( ok, "Error in setup. "
@@ -557,15 +559,6 @@ void test_error_codes_sans_file() {
     err = segy_crossline_stride( INLINE_SORTING + 3, 10, &stride );
     assertTrue( err == SEGY_INVALID_SORTING,
                 "Expected sorting to be invalid." );
-
-    err = segy_inline_length( INLINE_SORTING + 3, 10, 10, 10, NULL );
-    assertTrue( err == SEGY_INVALID_SORTING,
-                "Expected sorting to be invalid." );
-
-    err = segy_crossline_length( INLINE_SORTING + 3, 10, 10, 10, NULL );
-    assertTrue( err == SEGY_INVALID_SORTING,
-                "Expected sorting to be invalid." );
-
 }
 
 
diff --git a/tests/test_segyio_c.py b/tests/test_segyio_c.py
index bd73b6b..b261c38 100644
--- a/tests/test_segyio_c.py
+++ b/tests/test_segyio_c.py
@@ -155,9 +155,6 @@ class _segyioTests(TestCase):
         crossline_count = metrics['xline_count']
         offset_count = metrics['offset_count']
 
-        with self.assertRaises(RuntimeError):
-            metrics = _segyio.init_line_metrics(0, trace_count, inline_count, crossline_count, offset_count)
-
         metrics = _segyio.init_line_metrics(sorting, trace_count, inline_count, crossline_count, offset_count)
 
         self.assertEqual(metrics['xline_length'], 5)
@@ -165,6 +162,22 @@ class _segyioTests(TestCase):
         self.assertEqual(metrics['iline_length'], 5)
         self.assertEqual(metrics['iline_stride'], 1)
 
+        # (sorting, trace_count, inline_count, crossline_count, offset_count)
+        metrics = _segyio.init_line_metrics(1, 15, 3, 5, 1)
+
+        self.assertEqual(metrics['xline_length'], 3)
+        self.assertEqual(metrics['xline_stride'], 1)
+        self.assertEqual(metrics['iline_length'], 5)
+        self.assertEqual(metrics['iline_stride'], 3)
+
+        metrics = _segyio.init_line_metrics(2, 15, 3, 5, 1)
+
+        self.assertEqual(metrics['xline_length'], 3)
+        self.assertEqual(metrics['xline_stride'], 5)
+        self.assertEqual(metrics['iline_length'], 5)
+        self.assertEqual(metrics['iline_stride'], 1)
+
+
     def test_metrics(self):
         f = _segyio.open(self.filename, "r")
         binary_header = _segyio.read_binaryheader(f)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list