[segyio] 191/376: Use signed int for trace indices
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:31 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 82fe8acf66e483d838a4e108c72c2ca35bdc3187
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Tue Feb 14 13:48:12 2017 +0100
Use signed int for trace indices
---
lib/include/segyio/segy.h | 10 +++++-----
lib/src/segy.c | 20 ++++++++++----------
lib/src/segyio/util.h | 2 +-
lib/test/segy.c | 5 +++--
mex/segy_put_traces_mex.c | 2 +-
mex/segy_read_write_line_mex.c | 3 +--
mex/segy_read_write_ps_line_mex.c | 2 +-
python/segyio/_segyio.c | 25 +++++++++++++------------
python/test/segyio_c.py | 6 +++---
9 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/lib/include/segyio/segy.h b/lib/include/segyio/segy.h
index dfa4767..7e87995 100644
--- a/lib/include/segyio/segy.h
+++ b/lib/include/segyio/segy.h
@@ -133,13 +133,13 @@ int segy_offset_indices( segy_file*,
* buffer sent to write must be converted to target float.
*/
int segy_readtrace( segy_file*,
- unsigned int traceno,
+ int traceno,
float* buf,
long trace0,
int trace_bsize );
int segy_writetrace( segy_file*,
- unsigned int traceno,
+ int traceno,
const float* buf,
long trace0,
int trace_bsize );
@@ -154,7 +154,7 @@ int segy_from_native( int format,
float* buf );
int segy_read_line( segy_file* fp,
- unsigned int line_trace0,
+ int line_trace0,
unsigned int line_length,
unsigned int stride,
int offsets,
@@ -163,7 +163,7 @@ int segy_read_line( segy_file* fp,
int trace_bsize );
int segy_write_line( segy_file* fp,
- unsigned int line_trace0,
+ int line_trace0,
unsigned int line_length,
unsigned int stride,
int offsets,
@@ -259,7 +259,7 @@ int segy_line_trace0( unsigned int lineno,
int offsets,
const unsigned int* linenos,
const unsigned int linenos_sz,
- unsigned int* traceno );
+ int* traceno );
/*
* Find the stride needed for an inline/crossline traversal.
diff --git a/lib/src/segy.c b/lib/src/segy.c
index c83ff43..a58d714 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -1077,7 +1077,7 @@ static int skip_traceheader( segy_file* fp ) {
}
int segy_readtrace( segy_file* fp,
- unsigned int traceno,
+ int traceno,
float* buf,
long trace0,
int trace_bsize ) {
@@ -1104,7 +1104,7 @@ int segy_readtrace( segy_file* fp,
}
int segy_writetrace( segy_file* fp,
- unsigned int traceno,
+ int traceno,
const float* buf,
long trace0,
int trace_bsize ) {
@@ -1182,10 +1182,10 @@ int segy_from_native( int format,
* Determine the position of the element `x` in `xs`.
* Returns -1 if the value cannot be found
*/
-static long index_of( unsigned int x,
- const unsigned int* xs,
- unsigned int sz ) {
- for( unsigned int i = 0; i < sz; i++ ) {
+static int index_of( int x,
+ const unsigned int* xs,
+ int sz ) {
+ for( int i = 0; i < sz; i++ ) {
if( xs[i] == x )
return i;
}
@@ -1206,7 +1206,7 @@ static long index_of( unsigned int x,
* segy_readtrace returns.
*/
int segy_read_line( segy_file* fp,
- unsigned int line_trace0,
+ int line_trace0,
unsigned int line_length,
unsigned int stride,
int offsets,
@@ -1240,7 +1240,7 @@ int segy_read_line( segy_file* fp,
* segy_readtrace returns.
*/
int segy_write_line( segy_file* fp,
- unsigned int line_trace0,
+ int line_trace0,
unsigned int line_length,
unsigned int stride,
int offsets,
@@ -1269,9 +1269,9 @@ int segy_line_trace0( unsigned int lineno,
int offsets,
const unsigned int* linenos,
const unsigned int linenos_sz,
- unsigned int* traceno ) {
+ int* traceno ) {
- long index = index_of( lineno, linenos, linenos_sz );
+ int index = index_of( lineno, linenos, linenos_sz );
if( index < 0 ) return SEGY_MISSING_LINE_INDEX;
diff --git a/lib/src/segyio/util.h b/lib/src/segyio/util.h
index b461779..dcc86b1 100644
--- a/lib/src/segyio/util.h
+++ b/lib/src/segyio/util.h
@@ -18,7 +18,7 @@ void ebcdic2ascii( const char* ebcdic, char* ascii );
void ascii2ebcdic( const char* ascii, char* ebcdic );
void ibm2ieee(void* to, const void* from);
void ieee2ibm(void* to, const void* from);
-int segy_seek( struct segy_file_handle*, unsigned int, long, int );
+int segy_seek( struct segy_file_handle*, int, long, int );
long long segy_ftell( struct segy_file_handle* );
#ifdef __cplusplus
diff --git a/lib/test/segy.c b/lib/test/segy.c
index 48f77d8..a73410f 100644
--- a/lib/test/segy.c
+++ b/lib/test/segy.c
@@ -210,8 +210,9 @@ static void testReadInLine_4(){
int sorting;
int traces;
unsigned int inlines_sz, crosslines_sz;
- unsigned int offsets, stride;
- unsigned int line_trace0, line_length;
+ int offsets, line_trace0;
+ unsigned int stride;
+ unsigned int line_length;
/* test specific consts */
const int il = SEGY_TR_INLINE, xl = SEGY_TR_CROSSLINE;
diff --git a/mex/segy_put_traces_mex.c b/mex/segy_put_traces_mex.c
index 4f6de85..894d9a7 100644
--- a/mex/segy_put_traces_mex.c
+++ b/mex/segy_put_traces_mex.c
@@ -41,7 +41,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
}
float* itr = out;
- for( size_t i = first_trace; i < fmt.traces; ++i ) {
+ for( int i = first_trace; i < fmt.traces; ++i ) {
err = segy_writetrace( fp, i, itr, fmt.trace0, fmt.trace_bsize );
itr += fmt.samples;
diff --git a/mex/segy_read_write_line_mex.c b/mex/segy_read_write_line_mex.c
index 38129fe..9b0e754 100644
--- a/mex/segy_read_write_line_mex.c
+++ b/mex/segy_read_write_line_mex.c
@@ -46,8 +46,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
segy_file* fp;
- unsigned int line_trace0;
-
+ int line_trace0;
int errc = segy_line_trace0( index, line_length, stride, offsets, line_indexes, line_count, &line_trace0 );
if (errc != 0) {
goto CLEANUP;
diff --git a/mex/segy_read_write_ps_line_mex.c b/mex/segy_read_write_ps_line_mex.c
index cb520fb..ee60c51 100644
--- a/mex/segy_read_write_ps_line_mex.c
+++ b/mex/segy_read_write_ps_line_mex.c
@@ -36,7 +36,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
segy_file* fp;
- unsigned int line_trace0;
+ int line_trace0;
int errc = segy_line_trace0( index, line_length, stride, offsets, line_indexes, line_count, &line_trace0 );
if( errc != SEGY_OK ) {
mexErrMsgIdAndTxt( "segy:get_ps_line:wrong_line_number",
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 93404f5..389a8d0 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -639,7 +639,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
return Py_BuildValue("O", dict);
}
-static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsigned int expected) {
+static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsigned int expected, const char* fmt) {
static const Py_buffer zero_buffer;
Py_buffer buffer = zero_buffer;
if (!PyObject_CheckBuffer(object)) {
@@ -648,8 +648,9 @@ static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsign
}
PyObject_GetBuffer(object, &buffer, PyBUF_FORMAT | PyBUF_C_CONTIGUOUS | PyBUF_WRITEABLE);
- if (strcmp(buffer.format, "I") != 0) {
- PyErr_Format(PyExc_TypeError, "The destination for %s is not a buffer object of type 'uintc'", name);
+ if (strcmp(buffer.format, fmt) != 0) {
+ const char* target = strcmp(fmt, "I") == 0 ? "uintc" : "intc";
+ PyErr_Format(PyExc_TypeError, "The destination for %s is not a buffer object of type '%s'", name, target);
PyBuffer_Release(&buffer);
return buffer;
}
@@ -694,18 +695,18 @@ static PyObject *py_init_indices(PyObject *self, PyObject *args) {
if (PyErr_Occurred()) { return NULL; }
- Py_buffer iline_buffer = check_and_get_buffer(iline_out, "inline", iline_count);
+ Py_buffer iline_buffer = check_and_get_buffer(iline_out, "inline", iline_count, "I");
if (PyErr_Occurred()) { return NULL; }
- Py_buffer xline_buffer = check_and_get_buffer(xline_out, "crossline", xline_count);
+ Py_buffer xline_buffer = check_and_get_buffer(xline_out, "crossline", xline_count, "I");
if (PyErr_Occurred()) {
PyBuffer_Release(&iline_buffer);
return NULL;
}
- Py_buffer offsets_buffer = check_and_get_buffer(offset_out, "offsets", offset_count);
+ Py_buffer offsets_buffer = check_and_get_buffer(offset_out, "offsets", offset_count, "i");
if (PyErr_Occurred()) {
PyBuffer_Release(&iline_buffer);
@@ -774,7 +775,7 @@ static PyObject *py_fread_trace0(PyObject *self, PyObject *args) {
}
PyObject_GetBuffer(indices_object, &buffer, PyBUF_FORMAT | PyBUF_C_CONTIGUOUS);
- unsigned int trace_no;
+ int trace_no;
unsigned int linenos_sz = (unsigned int) PyObject_Length(indices_object);
int error = segy_line_trace0(lineno, other_line_length, stride, offsets, buffer.buf, linenos_sz, &trace_no);
PyBuffer_Release( &buffer );
@@ -783,7 +784,7 @@ static PyObject *py_fread_trace0(PyObject *self, PyObject *args) {
return py_handle_segy_error_with_index_and_name(error, errno, lineno, type_name);
}
- return Py_BuildValue("I", trace_no);
+ return Py_BuildValue("i", trace_no);
}
static PyObject *py_read_trace(PyObject *self, PyObject *args) {
@@ -865,14 +866,14 @@ static PyObject *py_read_trace(PyObject *self, PyObject *args) {
static PyObject *py_write_trace(PyObject *self, PyObject *args) {
errno = 0;
PyObject *file_capsule = NULL;
- unsigned int trace_no;
+ int trace_no;
PyObject *buffer_in;
long trace0;
int trace_bsize;
int format;
unsigned int samples;
- PyArg_ParseTuple(args, "OIOlIiI", &file_capsule, &trace_no, &buffer_in, &trace0, &trace_bsize, &format, &samples);
+ PyArg_ParseTuple(args, "OiOlIiI", &file_capsule, &trace_no, &buffer_in, &trace0, &trace_bsize, &format, &samples);
segy_file *p_FILE = get_FILE_pointer_from_capsule(file_capsule);
@@ -911,7 +912,7 @@ static PyObject *py_write_trace(PyObject *self, PyObject *args) {
static PyObject *py_read_line(PyObject *self, PyObject *args) {
errno = 0;
PyObject *file_capsule = NULL;
- unsigned int line_trace0;
+ int line_trace0;
unsigned int line_length;
unsigned int stride;
int offsets;
@@ -921,7 +922,7 @@ static PyObject *py_read_line(PyObject *self, PyObject *args) {
int format;
unsigned int samples;
- PyArg_ParseTuple(args, "OIIIiOlIiI", &file_capsule,
+ PyArg_ParseTuple(args, "OiIIiOlIiI", &file_capsule,
&line_trace0,
&line_length, &stride, &offsets,
&buffer_in,
diff --git a/python/test/segyio_c.py b/python/test/segyio_c.py
index 1511be2..e4ba307 100644
--- a/python/test/segyio_c.py
+++ b/python/test/segyio_c.py
@@ -236,7 +236,7 @@ class _segyioTests(TestCase):
# Happy Path
iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
- offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.uintc)
+ offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
_segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
self.assertListEqual([1, 2, 3, 4, 5], list(iline_indexes))
@@ -264,7 +264,7 @@ class _segyioTests(TestCase):
iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
- offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.uintc)
+ offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
_segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
with self.assertRaises(KeyError):
@@ -398,7 +398,7 @@ class _segyioTests(TestCase):
iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
- offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.uintc)
+ offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
_segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
return f, metrics, iline_indexes, xline_indexes
--
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