[segyio] 185/376: Use signed int for trace count

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:30 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 429e4ff06b4143811be08fcb9ac196f1064eb3f0
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Mon Feb 13 09:58:33 2017 +0100

    Use signed int for trace count
    
    Trace count is used in arithmetic, which makes signed a better choice.
    Additionally, the trace cardinality is comfortably within the range of
    regular signed integers, and a negative count is a more obvious bug
    symptom.
---
 applications/segyinfo.c    |  6 +++---
 applications/segyinspect.c |  2 +-
 lib/include/segyio/segy.h  |  4 ++--
 lib/src/segy.c             | 22 +++++-----------------
 lib/test/segy.c            |  8 ++++----
 mex/segyutil.c             |  2 +-
 mex/segyutil.h             |  2 +-
 python/segyio/_segyio.c    | 10 +++++-----
 8 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/applications/segyinfo.c b/applications/segyinfo.c
index c6cd1c2..acf7b23 100644
--- a/applications/segyinfo.c
+++ b/applications/segyinfo.c
@@ -60,7 +60,7 @@ int main(int argc, char* argv[]) {
         exit( err );
     }
 
-    size_t traces;
+    int traces;
     err = segy_traces( fp, &traces, trace0, trace_bsize );
 
     if( err != 0 ) {
@@ -70,7 +70,7 @@ int main(int argc, char* argv[]) {
 
     printf( "Sample format: %d\n", format );
     printf( "Samples per trace: %d\n", samples );
-    printf( "Traces: %zu\n", traces );
+    printf( "Traces: %d\n", traces );
     printf("Extended text header count: %d\n", extended_headers );
     puts("");
 
@@ -103,7 +103,7 @@ int main(int argc, char* argv[]) {
 
     int min_sample_count = 999999999;
     int max_sample_count = 0;
-    for( int i = 0; i < (int)traces; ++i ) {
+    for( int i = 0; i < traces; ++i ) {
         err = segy_traceheader( fp, i, traceh, trace0, trace_bsize );
         if( err != 0 ) {
             perror( "Unable to read trace" );
diff --git a/applications/segyinspect.c b/applications/segyinspect.c
index 9c73f94..a2e7584 100644
--- a/applications/segyinspect.c
+++ b/applications/segyinspect.c
@@ -79,7 +79,7 @@ int main(int argc, char* argv[]) {
     const long trace0 = segy_trace0( header );
     const int trace_bsize = segy_trace_bsize( samples );
 
-    size_t traces;
+    int traces;
     err = segy_traces( fp, &traces, trace0, trace_bsize );
 
     if( err != 0 ) {
diff --git a/lib/include/segyio/segy.h b/lib/include/segyio/segy.h
index d0196bf..ea3be4b 100644
--- a/lib/include/segyio/segy.h
+++ b/lib/include/segyio/segy.h
@@ -69,7 +69,7 @@ int segy_trace_bsize( int samples );
 /* byte-offset of the first trace header. */
 long segy_trace0( const char* binheader );
 /* number of traces in this file */
-int segy_traces( segy_file*, size_t*, long trace0, int trace_bsize );
+int segy_traces( segy_file*, int*, long trace0, int trace_bsize );
 
 int segy_sample_indexes(segy_file* fp, double* buf, double t0, double dt, size_t count);
 
@@ -111,7 +111,7 @@ int segy_sorting( segy_file*,
 int segy_offsets( segy_file*,
                   int il,
                   int xl,
-                  unsigned int traces,
+                  int traces,
                   unsigned int* offsets,
                   long trace0,
                   int trace_bsize );
diff --git a/lib/src/segy.c b/lib/src/segy.c
index 172d96e..260a9db 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -661,7 +661,7 @@ int segy_write_traceheader( segy_file* fp,
  * This function assumes that *all traces* are of the same size.
  */
 int segy_traces( segy_file* fp,
-                 size_t* traces,
+                 int* traces,
                  long trace0,
                  int trace_bsize ) {
 
@@ -778,10 +778,9 @@ int segy_sorting( segy_file* fp,
     segy_get_field( traceheader, xl, &xl0 );
     segy_get_field( traceheader, SEGY_TR_OFFSET, &off0 );
 
-    size_t traces_size_t;
-    err = segy_traces( fp, &traces_size_t, trace0, trace_bsize );
+    int traces;
+    err = segy_traces( fp, &traces, trace0, trace_bsize );
     if( err != 0 ) return err;
-    const int traces = traces_size_t;
     int traceno = 1;
 
     do {
@@ -824,7 +823,7 @@ int segy_sorting( segy_file* fp,
 int segy_offsets( segy_file* fp,
                   int il,
                   int xl,
-                  unsigned int traces,
+                  int traces,
                   unsigned int* out,
                   long trace0,
                   int trace_bsize ) {
@@ -966,7 +965,7 @@ int segy_count_lines( segy_file* fp,
     err = count_lines( fp, field, offsets, &l2count, trace0, trace_bsize );
     if( err != 0 ) return err;
 
-    size_t traces;
+    int traces;
     err = segy_traces( fp, &traces, trace0, trace_bsize );
     if( err != 0 ) return err;
 
@@ -1031,13 +1030,8 @@ int segy_inline_indices( segy_file* fp,
                          unsigned int* buf,
                          long trace0,
                          int trace_bsize) {
-    int err;
 
     if( sorting == SEGY_INLINE_SORTING ) {
-        size_t traces;
-        err = segy_traces( fp, &traces, trace0, trace_bsize );
-        if( err != 0 ) return err;
-
         unsigned int stride = crossline_count * offsets;
         return segy_line_indices( fp, il, 0, stride, inline_count, buf, trace0, trace_bsize );
     }
@@ -1059,17 +1053,11 @@ int segy_crossline_indices( segy_file* fp,
                             long trace0,
                             int trace_bsize ) {
 
-    int err;
-
     if( sorting == SEGY_INLINE_SORTING ) {
         return segy_line_indices( fp, xl, 0, offsets, crossline_count, buf, trace0, trace_bsize );
     }
 
     if( sorting == SEGY_CROSSLINE_SORTING ) {
-        size_t traces;
-        err = segy_traces( fp, &traces, trace0, trace_bsize );
-        if( err != 0 ) return err;
-
         unsigned int stride = inline_count * offsets;
         return segy_line_indices( fp, xl, 0, stride, crossline_count, buf, trace0, trace_bsize );
     }
diff --git a/lib/test/segy.c b/lib/test/segy.c
index f313e74..48f77d8 100644
--- a/lib/test/segy.c
+++ b/lib/test/segy.c
@@ -17,7 +17,7 @@ static void test_interpret_file() {
     int err;
     char header[ SEGY_BINARY_HEADER_SIZE ];
     int sorting;
-    size_t traces;
+    int traces;
     unsigned int inlines_sz, crosslines_sz;
     unsigned int offsets, stride;
     unsigned int line_trace0, line_length;
@@ -208,7 +208,7 @@ static void testReadInLine_4(){
     const char *file = "test-data/small.sgy";
 
     int sorting;
-    size_t traces;
+    int traces;
     unsigned int inlines_sz, crosslines_sz;
     unsigned int offsets, stride;
     unsigned int line_trace0, line_length;
@@ -283,7 +283,7 @@ static void testReadCrossLine_22(){
     const char *file = "test-data/small.sgy";
 
     int sorting;
-    size_t traces;
+    int traces;
     unsigned int inlines_sz, crosslines_sz;
     unsigned int offsets, stride;
     unsigned int line_trace0, line_length;
@@ -535,7 +535,7 @@ static void test_file_error_codes() {
     err = segy_read_textheader(fp, NULL);
     assertTrue( err == SEGY_FSEEK_ERROR, "Could seek in invalid file." );
 
-    size_t traces;
+    int traces;
     err = segy_traces( fp, &traces, 3600, 350 );
     assertTrue( err == SEGY_FSEEK_ERROR, "Could seek in invalid file." );
 
diff --git a/mex/segyutil.c b/mex/segyutil.c
index 07ec51e..20b654f 100644
--- a/mex/segyutil.c
+++ b/mex/segyutil.c
@@ -46,7 +46,7 @@ int segyCreateSpec(SegySpec* spec, const char* file, unsigned int inline_field,
     const long trace0 = segy_trace0( header );
 
     spec->trace_bsize = segy_trace_bsize( segy_samples( header ) );
-    size_t traces;
+    int traces;
     errc = segy_traces(fp, &traces, trace0, spec->trace_bsize);
     if (errc != 0) {
         goto CLEANUP;
diff --git a/mex/segyutil.h b/mex/segyutil.h
index d76d0ad..a2bdef0 100644
--- a/mex/segyutil.h
+++ b/mex/segyutil.h
@@ -41,7 +41,7 @@ struct segy_file_format {
     int samples;
     long trace0;
     unsigned int trace_bsize;
-    size_t traces;
+    int traces;
     int format;
 };
 
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 0c73a37..877249c 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -522,12 +522,12 @@ static PyObject *py_get_dt(PyObject *self, PyObject *args) {
 static PyObject *py_init_line_metrics(PyObject *self, PyObject *args) {
     errno = 0;
     SEGY_SORTING sorting;
-    unsigned int trace_count;
+    int trace_count;
     unsigned int inline_count;
     unsigned int crossline_count;
     unsigned int offset_count;
 
-    PyArg_ParseTuple(args, "iIIII", &sorting, &trace_count, &inline_count, &crossline_count, &offset_count);
+    PyArg_ParseTuple(args, "iiIII", &sorting, &trace_count, &inline_count, &crossline_count, &offset_count);
 
     unsigned int iline_length = segy_inline_length(crossline_count);
 
@@ -580,7 +580,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
         return py_handle_segy_error_with_fields(error, errno, il_field, xl_field, 2);
     }
 
-    size_t trace_count;
+    int trace_count;
     error = segy_traces(p_FILE, &trace_count, trace0, trace_bsize);
 
     if (error != 0) {
@@ -588,7 +588,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
     }
 
     unsigned int offset_count;
-    error = segy_offsets(p_FILE, il_field, xl_field, (unsigned int) trace_count, &offset_count, trace0, trace_bsize);
+    error = segy_offsets(p_FILE, il_field, xl_field, trace_count, &offset_count, trace0, trace_bsize);
 
     if (error != 0) {
         return py_handle_segy_error_with_fields(error, errno, il_field, xl_field, 2);
@@ -631,7 +631,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
     PyDict_SetItemString(dict, "format", Py_BuildValue("i", format));
     PyDict_SetItemString(dict, "trace_bsize", Py_BuildValue("i", trace_bsize));
     PyDict_SetItemString(dict, "sorting", Py_BuildValue("i", sorting));
-    PyDict_SetItemString(dict, "trace_count", Py_BuildValue("k", trace_count));
+    PyDict_SetItemString(dict, "trace_count", Py_BuildValue("i", trace_count));
     PyDict_SetItemString(dict, "offset_count", Py_BuildValue("I", offset_count));
     PyDict_SetItemString(dict, "iline_count", Py_BuildValue("I", il_count));
     PyDict_SetItemString(dict, "xline_count", Py_BuildValue("I", xl_count));

-- 
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