Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
CIBW_ENVIRONMENT_WINDOWS: >
CMAKE_GENERATOR="${{ matrix.cmake_generator }}"
CMAKE_GENERATOR_PLATFORM="${{ matrix.cmake_generator_platform }}"
CIBW_SKIP: pp* *-musllinux_* cp36-* cp37-* cp38-*
CIBW_SKIP: pp* *-musllinux_* cp36-* cp37-* cp38-* cp314*
CIBW_ARCHS: ${{ matrix.arch }}
run: |
python -m cibuildwheel --output-dir wheelhouse python/
Expand Down
16 changes: 8 additions & 8 deletions applications/segyinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

static void printSegyTraceInfo( const char* buf ) {
int cdp, tsf, xl, il;
segy_get_field_i32( buf, SEGY_TR_ENSEMBLE, &cdp );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type specific functions was added by POs request.

segy_get_field_i32( buf, SEGY_TR_SEQ_FILE, &tsf );
segy_get_field_i32( buf, SEGY_TR_CROSSLINE, &xl );
segy_get_field_i32( buf, SEGY_TR_INLINE, &il );
segy_get_field_int( buf, SEGY_TR_ENSEMBLE, &cdp );
segy_get_field_int( buf, SEGY_TR_SEQ_FILE, &tsf );
segy_get_field_int( buf, SEGY_TR_CROSSLINE, &xl );
segy_get_field_int( buf, SEGY_TR_INLINE, &il );

printf("cdp: %d\n", cdp );
printf("TraceSequenceFile: %d\n", tsf );
Expand Down Expand Up @@ -55,8 +55,8 @@ int main(int argc, char* argv[]) {
const int samples = segy_samples( header );
const long trace0 = segy_trace0( header );
const int trace_bsize = segy_trace_bsize( samples );
int16_t extended_headers;
err = segy_get_field_i16( header, SEGY_BIN_EXT_HEADERS, &extended_headers );
int extended_headers;
err = segy_get_field_int( header, SEGY_BIN_EXT_HEADERS, &extended_headers );

if( err != 0 ) {
perror( "Can't read 'extended headers' field from binary header" );
Expand Down Expand Up @@ -113,8 +113,8 @@ int main(int argc, char* argv[]) {
exit( err );
}

int16_t sample_count;
err = segy_get_field_i16( traceh, SEGY_TR_SAMPLE_COUNT, &sample_count );
int sample_count;
err = segy_get_field_int( traceh, SEGY_TR_SAMPLE_COUNT, &sample_count );

if( err != 0 ) {
fprintf( stderr, "Invalid trace header field: %d\n", SEGY_TR_SAMPLE_COUNT );
Expand Down
82 changes: 51 additions & 31 deletions applications/segyio-catb.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ typedef struct {
const char* description;
} binary_field_type;

static void u64_to_buf(char *buf, size_t buflen, unsigned long long int value) {
snprintf(buf, buflen, "%llu", value);
}

static void i64_to_buf(char *buf, size_t buflen, long long int value) {
snprintf(buf, buflen, "%lld", value);
}

int main( int argc, char** argv ){

if( argc == 1 ){
Expand Down Expand Up @@ -151,39 +159,51 @@ int main( int argc, char** argv ){

int nr_fields = sizeof(field_data)/sizeof(binary_field_type);
for( int c = 0; c < nr_fields; ++c ){
segy_field_data fd = segy_get_field( binheader, field_data[c].offset );
if ( fd.error ) return errmsg( fd.error, "Unable to read field" );

int byte_offset = (field_data[c].offset - SEGY_TEXT_HEADER_SIZE);
const char* short_name = field_data[c].short_name;
const char* description = field_data[c].description;

if( fd.datatype == SEGY_UNSIGNED_INTEGER_8_BYTE ) {
unsigned long long int field = fd.value.u64;
if( opts.nonzero && field == 0) continue;
if( opts.description )
printf( "%s\t%llu\t%d\t%s\n", short_name, field, byte_offset, description );
else
printf( "%-10s\t%llu\n", short_name, field );
segy_field_data fd;
err = segy_get_field( binheader, field_data[c].offset, &fd );
if ( err ) return errmsg( err, "Unable to read field" );

bool value_is_zero = false;
char value_str[40]; // should be enough for all strings

switch( fd.datatype ) {
case SEGY_UNSIGNED_INTEGER_8_BYTE: {
u64_to_buf( value_str, sizeof( value_str ), fd.value.u64 );
} break;
case SEGY_UNSIGNED_SHORT_2_BYTE: {
u64_to_buf( value_str, sizeof( value_str ), fd.value.u16 );
} break;
case SEGY_UNSIGNED_CHAR_1_BYTE: {
u64_to_buf( value_str, sizeof( value_str ), fd.value.u8 );
} break;
case SEGY_SIGNED_INTEGER_4_BYTE: {
i64_to_buf( value_str, sizeof( value_str ), fd.value.i32 );
} break;
case SEGY_SIGNED_SHORT_2_BYTE: {
i64_to_buf( value_str, sizeof( value_str ), fd.value.i16 );
} break;
case SEGY_IEEE_FLOAT_8_BYTE: {
double value = fd.value.f64;
value_is_zero = (value == 0.0);
snprintf( value_str, sizeof( value_str ), "%f", value );
} break;
default: {
return errmsg( -1, "Unhandled field format" );
}
}
else if( fd.datatype == SEGY_IEEE_FLOAT_8_BYTE ) {
double field = fd.value.f64;
if( opts.nonzero && field == 0.0) continue;
if( opts.description )
printf( "%s\t%f\t%d\t%s\n", short_name, field, byte_offset, description );
else
printf( "%-10s\t%f\n", short_name, field );

if (strcmp( value_str, "0" ) == 0) {
value_is_zero = true;
}
else {
int field;
err = segy_field_data_to_int( &fd, &field );
if( err ) return errmsg( err, "Unable to convert segy_field_data to int32" );

if( opts.nonzero && field == 0) continue;
if( opts.description )
printf( "%s\t%d\t%d\t%s\n", short_name, field, byte_offset, description );
else
printf( "%-10s\t%d\n", short_name, field );

if( opts.nonzero && value_is_zero ) continue;
if( opts.description ) {
int byte_offset = (field_data[c].offset - SEGY_TEXT_HEADER_SIZE);
const char* short_name = field_data[c].short_name;
const char* description = field_data[c].description;
printf( "%s\t%s\t%d\t%s\n", short_name, value_str, byte_offset, description );
} else {
printf( "%-10s\t%s\n", field_data[c].short_name, value_str );
}
}
segy_close( fp );
Expand Down
4 changes: 2 additions & 2 deletions applications/segyio-cath.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static int ext_headers( segy_file* fp ) {

if( err ) return -1;

int16_t ext;
err = segy_get_field_i16( binary, SEGY_BIN_EXT_HEADERS, &ext );
int ext;
err = segy_get_field_int( binary, SEGY_BIN_EXT_HEADERS, &ext );
if( err ) return -2;
return ext;
}
Expand Down
26 changes: 13 additions & 13 deletions applications/segyio-crop.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static struct delay delay_recording_time( const char* trheader,
int dt,
int samples ) {

int16_t t0;
segy_get_field_i16( trheader, SEGY_TR_DELAY_REC_TIME, &t0 );
int16_t trdt;
segy_get_field_i16( trheader, SEGY_TR_SAMPLE_INTER, &trdt );
int t0;
segy_get_field_int( trheader, SEGY_TR_DELAY_REC_TIME, &t0 );
int trdt;
segy_get_field_int( trheader, SEGY_TR_SAMPLE_INTER, &trdt );
if( trdt ) dt = trdt;

/*
Expand Down Expand Up @@ -408,8 +408,8 @@ int main( int argc, char** argv ) {
if( sz != 1 ) exit( errmsg2( errno, "Unable to write binary header",
strerror( errno ) ) );

int16_t ext_headers;
int err = segy_get_field_i16(binheader, SEGY_BIN_EXT_HEADERS, &ext_headers);
int ext_headers;
int err = segy_get_field_int(binheader, SEGY_BIN_EXT_HEADERS, &ext_headers);
if( err != SEGY_OK ) exit( errmsg( -1, "Malformed binary header" ) );

for( int i = 0; i < ext_headers; ++i ) {
Expand All @@ -424,10 +424,10 @@ int main( int argc, char** argv ) {
}

if( verbosity > 2 ) puts( "Computing samples-per-trace" );
int16_t bindt;
segy_get_field_i16( binheader, SEGY_BIN_INTERVAL, &bindt );
uint16_t src_samples;
err = segy_get_field_u16( binheader, SEGY_BIN_SAMPLES, &src_samples );
int bindt;
segy_get_field_int( binheader, SEGY_BIN_INTERVAL, &bindt );
int src_samples;
err = segy_get_field_int( binheader, SEGY_BIN_SAMPLES, &src_samples );
if( err != SEGY_OK )
exit( errmsg( -2, "Could not determine samples per trace" ) );

Expand Down Expand Up @@ -514,9 +514,9 @@ int main( int argc, char** argv ) {
bindt,
src_samples );

segy_set_field_u16( trheader, SEGY_TR_SAMPLE_COUNT, d.len );
segy_set_field_i16( trheader, SEGY_TR_DELAY_REC_TIME, d.delay );
segy_set_field_u16( binheader, SEGY_BIN_SAMPLES, d.len );
segy_set_field_int( trheader, SEGY_TR_SAMPLE_COUNT, d.len );
segy_set_field_int( trheader, SEGY_TR_DELAY_REC_TIME, d.delay );
segy_set_field_int( binheader, SEGY_BIN_SAMPLES, d.len );

if( verbosity > 2 ) printf( "Copying trace %lld\n", traces );
sz = fwrite( trheader, TRHSIZE, 1, dst );
Expand Down
35 changes: 8 additions & 27 deletions lib/include/segyio/segy.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ typedef union {
typedef struct {
segy_field_value value;
uint8_t datatype;
int32_t field_index;
int32_t field_offset;
int32_t error;
} segy_field_data;

segy_file* segy_open( const char* path, const char* mode );
Expand Down Expand Up @@ -194,33 +191,17 @@ int segy_set_format( segy_datasource*, int format );
*/
int segy_set_endianness( segy_datasource*, int opt );

/* Initialize the segy_field_data structure using the field number
*
* If the field number is greater than SEGY_TEXT_HEADER_SIZE [3200]
* the field is assumed to be a binary header field.
* Binary header field: field_index = (field number)-3200, field_offset = 3200
* Trace header field : field_index = field number, field_offset = 0
* Tables tr_field_type and bin_field_type are used to set the datatype.
/* Gets field datatype from field id. Depending on field value, binary or trace
* mapping table would be used.
* The int returned is the field datatype, not an error code.
*/
int segy_init_field_data(int field, segy_field_data* fd);

int segy_get_field_u8( const char* header, int field, uint8_t* val );
int segy_get_field_u16( const char* header, int field, uint16_t* val );
int segy_get_field_u64( const char* header, int field, uint64_t* val );
int segy_get_field_i16( const char* header, int field, int16_t* val );
int segy_get_field_i32( const char* header, int field, int32_t* val );
int segy_get_field_f64( const char* header, int field, double* val );
int segy_field_datatype( int field );

int segy_get_field( const char* header, int field, segy_field_data* fd );
int segy_set_field( char* header, int field, segy_field_data fd );

int segy_get_field_int( const char* header, int field, int* f );
segy_field_data segy_get_field( const char* header, int field);
int segy_field_data_to_int( const segy_field_data* fd, int* val );

int segy_set_field_i16( char* header, const int field, const int16_t val );
int segy_set_field_i32( char* header, const int field, const int32_t val );
int segy_set_field_u16( char* header, const int field, const uint16_t val );
int segy_set_field_u64( char* header, const int field, const uint64_t val );
int segy_set_field_f64( char* header, const int field, const double val );
int segy_set_field_int( char* header, const int field, const int val );
int segy_set_field( char* header, segy_field_data* fd );

int segy_field_forall( segy_datasource*,
int field,
Expand Down
Loading
Loading