[segyio] 311/376: Add segy_rotation_cw
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:50 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 1130d236caceb8db466e826af6c1c012464ff259
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Thu Jun 22 15:59:57 2017 +0200
Add segy_rotation_cw
Add the function `segy_rotation_cw` that finds the rotation, defined as
the angle between the line between the first and last trace on the first
line and the axis given by increasing CDP-Y coordinates.
---
cmake/check_includes.cmake | 2 +-
lib/CMakeLists.txt | 14 +++++-----
lib/include/segyio/segy.h | 35 +++++++++++++++++++++++
lib/src/segy.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
lib/src/segy.def | 1 +
5 files changed, 113 insertions(+), 8 deletions(-)
diff --git a/cmake/check_includes.cmake b/cmake/check_includes.cmake
index d6e4be4..01e64b8 100644
--- a/cmake/check_includes.cmake
+++ b/cmake/check_includes.cmake
@@ -11,7 +11,7 @@ if (HAVE_NETINET_IN_H)
elseif (HAVE_ARPA_INET_H)
add_definitions("-DHAVE_ARPA_INET_H")
elseif (HAVE_WINSOCK2_H)
- list(APPEND SEGYIO_LIBRARIES ws2_32)
+ set(ws2 ws2_32)
add_definitions("-DHAVE_WINSOCK2_H")
else()
message(FATAL_ERROR "Could not find htons.")
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 0dbaf3c..2dc87ac 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -14,11 +14,15 @@ if(WINDOWS)
set(DLL_EXPORT_FILES src/segy.def)
endif()
+if(NOT MSVC)
+ set(math "m")
+endif()
+
#
# static build
#
add_library(segyio-static STATIC ${SOURCE_FILES})
-target_link_libraries(segyio-static ${SEGYIO_LIBRARIES})
+target_link_libraries(segyio-static ${math} ${ws2})
set_target_properties(segyio-static PROPERTIES
OUTPUT_NAME ${STATIC_NAME}
CLEAN_DIRECT_OUTPUT 1)
@@ -32,7 +36,7 @@ target_include_directories(
# dynamic build
#
add_library(segyio-shared SHARED ${SOURCE_FILES} ${DLL_EXPORT_FILES})
-target_link_libraries(segyio-shared ${SEGYIO_LIBRARIES})
+target_link_libraries(segyio-shared ${math} ${ws2})
set_target_properties(segyio-shared PROPERTIES
SOVERSION ${segyio_MAJOR}
VERSION ${segyio_MAJOR}
@@ -70,13 +74,9 @@ configure_file(${testdata}/small.sgy test-data/small.sgy COPYONLY)
configure_file(${testdata}/small.sgy test-data/small-traceheader.sgy COPYONLY)
configure_file(${testdata}/text.sgy test-data/text.sgy COPYONLY)
-if(NOT MSVC)
- set(math "m")
-endif()
-
foreach (src segy utils)
add_executable(test${src} test/${src}.c)
- target_link_libraries(test${src} segyio-shared ${math})
+ target_link_libraries(test${src} segyio-shared)
target_include_directories(test${src} PRIVATE src)
add_test(c.${src} test${src})
add_memcheck_test(test${src} test${src})
diff --git a/lib/include/segyio/segy.h b/lib/include/segyio/segy.h
index a075fe4..37e4e9b 100644
--- a/lib/include/segyio/segy.h
+++ b/lib/include/segyio/segy.h
@@ -324,6 +324,41 @@ int segy_line_trace0( int lineno,
int* traceno );
/*
+ * Find the `rotation` of the survey in radians.
+ *
+ * Returns the clock-wise rotation around north, i.e. the angle between the
+ * first line given and north axis. In this context, north is the direction
+ * that yields a higher CDP-Y coordinate, and east is the direction that yields
+ * a higher CDP-X coordinate.
+ *
+ * N
+ * |
+ * |
+ * | +
+ * | |~~/``````/
+ * | | /------/
+ * | |/,,,,,,/
+ * |
+ * +--------------- E
+ *
+ *
+ * When the survey is as depicted, and the first line is starting in the
+ * south-west corner and goes north, the angle (~~) is < pi/4. If the first
+ * line is parallel with equator moving east, the angle is pi/2.
+ *
+ * The return value is in the domain [0, 2pi)
+ */
+int segy_rotation_cw( segy_file*,
+ int line_length,
+ int stride,
+ int offsets,
+ const int* linenos,
+ int linenos_sz,
+ float* rotation,
+ long trace0,
+ int trace_bsize );
+
+/*
* Find the stride needed for an inline/crossline traversal.
*/
int segy_inline_stride( int sorting,
diff --git a/lib/src/segy.c b/lib/src/segy.c
index 71b51aa..2072f7a 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include <limits.h>
+#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1548,3 +1549,71 @@ int segy_textheader_size( void ) {
int segy_binheader_size( void ) {
return SEGY_BINARY_HEADER_SIZE;
}
+
+static int scaled_cdp( segy_file* fp,
+ int traceno,
+ float* cdpx,
+ float* cdpy,
+ long trace0,
+ int trace_bsize ) {
+ int32_t x, y, scalar;
+ char trheader[ SEGY_TRACE_HEADER_SIZE ];
+
+ int err = segy_traceheader( fp, traceno, trheader, trace0, trace_bsize );
+ if( err != 0 ) return err;
+
+ err = segy_get_field( trheader, SEGY_TR_CDP_X, &x );
+ if( err != 0 ) return err;
+ err = segy_get_field( trheader, SEGY_TR_CDP_Y, &y );
+ if( err != 0 ) return err;
+ err = segy_get_field( trheader, SEGY_TR_SOURCE_GROUP_SCALAR, &scalar );
+ if( err != 0 ) return err;
+
+ float scale = scalar;
+ if( scalar == 0 ) scale = 1.0;
+ if( scalar < 0 ) scale = -1.0 / scale;
+
+ *cdpx = x * scale;
+ *cdpy = y * scale;
+
+ return SEGY_OK;
+}
+
+int segy_rotation_cw( segy_file* fp,
+ int line_length,
+ int stride,
+ int offsets,
+ const int* linenos,
+ int linenos_sz,
+ float* rotation,
+ long trace0,
+ int trace_bsize ) {
+
+ struct coord { float x, y; } nw, sw;
+
+ int err;
+ int traceno;
+ err = segy_line_trace0( linenos[0], line_length,
+ stride,
+ offsets,
+ linenos,
+ linenos_sz,
+ &traceno );
+ if( err != 0 ) return err;
+
+ err = scaled_cdp( fp, traceno, &sw.x, &sw.y, trace0, trace_bsize );
+ if( err != 0 ) return err;
+
+ /* read the last trace in the line */
+ traceno += (line_length - 1) * stride * offsets;
+ err = scaled_cdp( fp, traceno, &nw.x, &nw.y, trace0, trace_bsize );
+ if( err != 0 ) return err;
+
+ float x = nw.x - sw.x;
+ float y = nw.y - sw.y;
+ float radians = x || y ? atan2( x, y ) : 0;
+ if( radians < 0 ) radians += 2 * acos(-1);
+
+ *rotation = radians;
+ return SEGY_OK;
+}
diff --git a/lib/src/segy.def b/lib/src/segy.def
index 90411f7..260f029 100644
--- a/lib/src/segy.def
+++ b/lib/src/segy.def
@@ -44,6 +44,7 @@ segy_crossline_indices
segy_line_trace0
segy_inline_stride
segy_crossline_stride
+segy_rotation_cw
segy_seek
segy_ftell
ebcdic2ascii
--
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