[segyio] 182/376: Use signed integer for segy_samples
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:29 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 c6ec5d3d4f7cb46aa7e53549357277464bd63488
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Fri Feb 10 10:11:55 2017 +0100
Use signed integer for segy_samples
Checking for >0 or trapping on overflow is more reasonable (since
arithmetic is done on the samples), and ints carry enough information to
fully represent the samples per trace, so using int is a better choice.
---
applications/segyinspect.c | 2 +-
lib/include/segyio/segy.h | 8 ++++++--
lib/src/segy.c | 8 ++++----
lib/test/segy.c | 20 ++++++++++----------
mex/segyutil.h | 4 ++--
python/segyio/_segyio.c | 8 ++++----
6 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/applications/segyinspect.c b/applications/segyinspect.c
index 1dd7332..643f77c 100644
--- a/applications/segyinspect.c
+++ b/applications/segyinspect.c
@@ -75,7 +75,7 @@ int main(int argc, char* argv[]) {
}
const int format = segy_format( header );
- const unsigned int samples = segy_samples( header );
+ const int samples = segy_samples( header );
const long trace0 = segy_trace0( header );
const unsigned int trace_bsize = segy_trace_bsize( samples );
diff --git a/lib/include/segyio/segy.h b/lib/include/segyio/segy.h
index eb6f13b..d5d72be 100644
--- a/lib/include/segyio/segy.h
+++ b/lib/include/segyio/segy.h
@@ -48,7 +48,11 @@ int segy_close( segy_file* );
unsigned int segy_binheader_size();
int segy_binheader( segy_file*, char* buf );
int segy_write_binheader( segy_file*, const char* buf );
-unsigned int segy_samples( const char* binheader );
+/*
+ * exception: the int returned is the number of samples (the segy standard only
+ * allocates 2 octets for this, so it comfortably sits inside an int
+ */
+int segy_samples( const char* binheader );
int segy_sample_interval( segy_file*, double* dt);
/* exception: the int returned is an enum, SEGY_SORTING, not an error code */
int segy_format( const char* binheader );
@@ -57,7 +61,7 @@ int segy_get_bfield( const char* binheader, int field, int32_t* f );
int segy_set_field( char* traceheader, int field, int32_t val );
int segy_set_bfield( char* binheader, int field, int32_t val );
-unsigned segy_trace_bsize( unsigned int samples );
+unsigned segy_trace_bsize( int samples );
/* byte-offset of the first trace header. */
long segy_trace0( const char* binheader );
/* number of traces in this file */
diff --git a/lib/src/segy.c b/lib/src/segy.c
index 8283a0c..698480b 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -551,13 +551,13 @@ int segy_format( const char* buf ) {
return format;
}
-unsigned int segy_samples( const char* buf ) {
+int segy_samples( const char* buf ) {
int32_t samples;
segy_get_bfield( buf, SEGY_BIN_SAMPLES, &samples );
- return (unsigned int) samples;
+ return samples;
}
-unsigned int segy_trace_bsize( unsigned int samples ) {
+unsigned int segy_trace_bsize( int samples ) {
/* Hard four-byte float assumption */
return samples * 4;
}
@@ -689,7 +689,7 @@ int segy_sample_interval( segy_file* fp, double* dt) {
}
const long trace0 = segy_trace0( bin_header );
- unsigned int samples = segy_samples( bin_header );
+ int samples = segy_samples( bin_header );
const size_t trace_bsize = segy_trace_bsize( samples );
err = segy_traceheader(fp, 0, trace_header, trace0, trace_bsize);
diff --git a/lib/test/segy.c b/lib/test/segy.c
index f254e89..311681f 100644
--- a/lib/test/segy.c
+++ b/lib/test/segy.c
@@ -34,7 +34,7 @@ static void test_interpret_file() {
assertTrue( trace0 == 3600,
"Wrong byte offset of the first trace header. Expected 3600." );
- const unsigned int samples = segy_samples( header );
+ const int samples = segy_samples( header );
assertTrue( samples == 50, "Expected 350 samples per trace." );
const size_t trace_bsize = segy_trace_bsize( samples );
@@ -221,7 +221,7 @@ static void testReadInLine_4(){
segy_file* fp = segy_open( file, "rb" );
assertTrue( 0 == segy_binheader( fp, header ), "Could not read header" );
const long trace0 = segy_trace0( header );
- const unsigned int samples = segy_samples( header );
+ const int samples = segy_samples( header );
const size_t trace_bsize = segy_trace_bsize( samples );
const int format = segy_format( header );
@@ -255,7 +255,7 @@ static void testReadInLine_4(){
assertClose(4.20049f, data[samples-1], 0.0001f);
//middle xline
- size_t middle_line = 2;
+ int middle_line = 2;
//first sample
assertClose(4.22f, data[samples*middle_line+0], 0.0001);
//middle sample
@@ -264,7 +264,7 @@ static void testReadInLine_4(){
assertClose(4.22049f, data[samples*middle_line+samples-1], 0.0001);
//last xline
- size_t last_line = (crosslines_sz-1);
+ int last_line = (crosslines_sz-1);
//first sample
assertClose(4.24f, data[samples*last_line+0], 0);
//middle sample
@@ -296,7 +296,7 @@ static void testReadCrossLine_22(){
segy_file* fp = segy_open( file, "rb" );
assertTrue( 0 == segy_binheader( fp, header ), "Could not read header" );
const long trace0 = segy_trace0( header );
- const unsigned int samples = segy_samples( header );
+ const int samples = segy_samples( header );
const size_t trace_bsize = segy_trace_bsize( samples );
const int format = segy_format( header );
@@ -330,7 +330,7 @@ static void testReadCrossLine_22(){
assertClose(1.22049f, data[samples-1], 0.0001);
//middle inline
- size_t middle_line = 2;
+ int middle_line = 2;
//first sample
assertClose(3.22f, data[samples*middle_line+0], 0.0001);
//middle sample
@@ -339,7 +339,7 @@ static void testReadCrossLine_22(){
assertClose(3.22049f, data[samples*middle_line+samples-1], 0.0001);
//last inline
- size_t last_line = (line_length-1);
+ int last_line = (line_length-1);
//first sample
assertClose(5.22f, data[samples*last_line+0], 0.0001);
//middle sample
@@ -366,7 +366,7 @@ static void test_modify_trace_header() {
err = segy_binheader( fp, bheader );
assertTrue( err == 0, "Could not read header" );
const long trace0 = segy_trace0( bheader );
- const unsigned int samples = segy_samples( bheader );
+ const int samples = segy_samples( bheader );
const size_t trace_bsize = segy_trace_bsize( samples );
char traceh[ SEGY_TRACE_HEADER_SIZE ];
@@ -470,7 +470,7 @@ static void test_trace_header_errors() {
char binheader[ SEGY_BINARY_HEADER_SIZE ];
err = segy_binheader( fp, binheader );
assertTrue( err == 0, "Could not read binary header." );
- const unsigned samples = segy_samples( binheader );
+ const int samples = segy_samples( binheader );
const unsigned bsize = segy_trace_bsize( samples );
const long trace0 = segy_trace0( binheader );
@@ -508,7 +508,7 @@ static void test_file_error_codes() {
assertTrue( err == SEGY_FSEEK_ERROR,
"Could read binary header from invalid file." );
- const unsigned samples = segy_samples( binheader );
+ const int samples = segy_samples( binheader );
const unsigned trace_bsize = segy_trace_bsize( samples );
const long trace0 = segy_trace0( binheader );
diff --git a/mex/segyutil.h b/mex/segyutil.h
index 4f498d7..d76d0ad 100644
--- a/mex/segyutil.h
+++ b/mex/segyutil.h
@@ -22,7 +22,7 @@ typedef struct {
unsigned int offset_count;
double* sample_indexes;
- unsigned int sample_count;
+ int sample_count;
int trace_sorting_format;
@@ -38,7 +38,7 @@ int segyCreateSpec(SegySpec* spec, const char* file, unsigned int inline_field,
void recreateSpec(SegySpec* spec, const mxArray* mex_spec);
struct segy_file_format {
- unsigned int samples;
+ int samples;
long trace0;
unsigned int trace_bsize;
size_t traces;
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index d7a72b4..0a51442 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -493,9 +493,9 @@ static PyObject *py_write_trace_header(PyObject *self, PyObject *args) {
static PyObject *py_trace_bsize(PyObject *self, PyObject *args) {
errno = 0;
- unsigned int sample_count;
+ int sample_count;
- PyArg_ParseTuple(args, "I", &sample_count);
+ PyArg_ParseTuple(args, "i", &sample_count);
unsigned int byte_count = segy_trace_bsize(sample_count);
@@ -569,7 +569,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
if (PyErr_Occurred()) { return NULL; }
long trace0 = segy_trace0(binary_header);
- unsigned int sample_count = segy_samples(binary_header);
+ int sample_count = segy_samples(binary_header);
int format = segy_format(binary_header);
unsigned int trace_bsize = segy_trace_bsize(sample_count);
@@ -627,7 +627,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
PyDict_SetItemString(dict, "xline_field", Py_BuildValue("i", xl_field));
PyDict_SetItemString(dict, "offset_field", Py_BuildValue("i", 37));
PyDict_SetItemString(dict, "trace0", Py_BuildValue("l", trace0));
- PyDict_SetItemString(dict, "sample_count", Py_BuildValue("I", sample_count));
+ PyDict_SetItemString(dict, "sample_count", Py_BuildValue("i", sample_count));
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));
--
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