Skip to content

Segy field data cleanup - #636

Merged
achaikou merged 10 commits into
equinor:mainfrom
achaikou:segy_field_data_cleanup
Jul 29, 2025
Merged

Segy field data cleanup#636
achaikou merged 10 commits into
equinor:mainfrom
achaikou:segy_field_data_cleanup

Conversation

@achaikou

Copy link
Copy Markdown
Contributor

C get/set field cleanup that came up before and during proof-of-concept implementation for tracemaps.
Seems like nothing of the removed code is needed as it still would be us who would parse and return all fields from all trace headers.

achaikou added 10 commits July 25, 2025 20:37
Specialized versions are not needed for the moment and we should be fine
with more general functions.

Partly reverses commits "Introduce segy_get_field_[type]" / "Introduce
segy_set_field_[type]" to make tests to use just int.
For current code it is safe because in current tests/internal functions
all values are 4 bytes or less and there are no 4-bytes unsigned
integers in current headers.

General segy_get/set_field_int integer specialization is left as is for
now as it is heavily used internally in segy.c code. We should aim to
reconsider this before 2.0 release as otherwise it would become a
permanent part of the C interface.

General int specialization is mostly used in functions dealing with
fields important for segy layout. These functions would require logic
update as those fields have overriding "extended" field. For those
general segy_get_field/segy_set_field would be used and it might present
an opportunity to get rid of "int" specialization there completely.

Why we might want to get rid of general segy_get/set_field_int integer
specialization:
- more general segy_get_field/segy_set_field function is available
- having two ways in the interface to do the same thing is confusing
- general "int" version might be dangerous in library source code as we
now want to be very careful with types of fields we read.
Now it exists purely for developer's convenience due to segyio 1.0
having only int fields.
We should aim to use segy_get_field/segy_set_field where it ok to do so.
Then we can decide whether it could be removed from the interface
completely.

Note that specialization would still be heavily used in
tests/matlab/applications, but if we manage to get rid of it in the main
code, it could become tests-only helper.
Function is exposed in the header only for "application", which are
supposed to be test-only applications. We should avoid having test-only
functions in the interface.
segy_get_field now requires segy_field_data passed as argument, instead
of creating and returning it on its own.

Given that library has been available for a long time and there exist
C-library users only, consistency in the return functions is highly
desirable.

Only few functions that can't fail return value instead of error code.
From the presence of .error member we know that segy_get_field can fail,
so it makes sense for it to return the error code.

That also allows us to have consistency between all get-set methods.
"Init" became impractical as the only thing that it inits now is the
datatype.

Solution could be simplified even more if we in future decide to make
binary header-fields not 3200, but 0 based.
Then "segy_field_datatype" might disappear altogether.
.datatype field is kind of pointless at the moment.
- In C we can't easily force someone to set datatype the same moment
when .value is set. So nothing prevents us from setting value to i16 and
datatype to u32.
- In theory we can simply pass segy_field_value as an argument instead
of passing full segy_field_data. However it doesn't fit into the spirit
of function, as without knowing .datatype we can't interpret value on
its own and are forced to do it according to the field mapping table
instead of the actual datatype.

The best option seems to force .datatype being set by checking that it
corresponds to the datatype retrieved from field mapping.

Additionally fd doesn't have to be a pointer. We should treat that value
as any other local primitive as it is not that big in size.
@achaikou
achaikou force-pushed the segy_field_data_cleanup branch from 59aa6b6 to b7837d5 Compare July 25, 2025 19:12
Comment thread applications/segyinfo.c

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.

Comment thread lib/src/segy.c
switch ( fd->datatype ) {

case SEGY_SIGNED_INTEGER_8_BYTE:
memcpy( &(fd->value.i64), header + (fd->field_index -1), formatsize( fd->datatype ) );

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.

-1 was used to reduce the number of required variables.

@achaikou
achaikou merged commit dd94fc2 into equinor:main Jul 29, 2025
33 checks passed
@achaikou
achaikou deleted the segy_field_data_cleanup branch August 25, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants