[segyio] 216/376: Accelerate mex/get_header

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:35 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 cdffa67c2c687c4cbcc8ef94c28b5968bd654630
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Mon Feb 27 09:40:34 2017 +0100

    Accelerate mex/get_header
    
    The C function segy_field_forall is a perfect fit for the matlab
    get_header function. Same function, but faster.
---
 mex/Segy.m                |  2 +-
 mex/segy_get_header_mex.c | 41 +++++++++++++----------------------------
 2 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/mex/Segy.m b/mex/Segy.m
index 151ba2b..9009adc 100644
--- a/mex/Segy.m
+++ b/mex/Segy.m
@@ -49,7 +49,7 @@ classdef Segy
         end
 
         % Goal:
-        %   Fast reading of trace header words in segy filenamele.
+        %   Fast reading of trace header words in segy file.
         %
         % Algorithm:
         %   Use keyword as specified in available_headers. If byte location is
diff --git a/mex/segy_get_header_mex.c b/mex/segy_get_header_mex.c
index ec2e77f..85adf38 100644
--- a/mex/segy_get_header_mex.c
+++ b/mex/segy_get_header_mex.c
@@ -11,51 +11,36 @@
 void mexFunction(int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[]) {
 
-    char* msg1;
-    char* msg2;
+    char* msg1 = "";
+    char* msg2 = "";
     int err;
 
     const char* filename = mxArrayToString( prhs[ 0 ] );
     segy_file* fp = segyfopen( prhs[ 0 ], "rb" );
 
+    if( !fp ) goto cleanup;
+
     int field = mxGetScalar( prhs[ 1 ] );
 
     struct segy_file_format fmt = filefmt( fp );
 
     plhs[0] = mxCreateNumericMatrix( 1, fmt.traces, mxINT32_CLASS, mxREAL );
-    int32_t* out = mxGetData( plhs[ 0 ] );
-
-    char header[ SEGY_TRACE_HEADER_SIZE ];
-
-    for( int i = 0; i < fmt.traces; ++i ) {
-        int32_t f;
-        err = segy_traceheader( fp, i, header, fmt.trace0, fmt.trace_bsize );
-
-        if( err != 0 ) {
-            msg1 = "segy:get_header:segy_traceheader";
-            msg2 = strerror( errno );
-            goto cleanup;
-        }
+    int* out = mxGetData( plhs[ 0 ] );
 
-        err = segy_get_field( header, field, &f );
 
-        if( err != 0 ) {
-            msg1 = "segy:get_header:segy_get_field";
-            msg2 = "Error reading header field.";
-            goto cleanup;
-        }
-
-        out[ i ] = f;
-    }
+    err = segy_field_forall( fp, field,
+                             0, fmt.traces, 1, /* start, stop, step */
+                             out, fmt.trace0, fmt.trace_bsize );
 
+    int no = errno;
     segy_close( fp );
 
+    if( err != SEGY_OK )
+        mexErrMsgIdAndTxt( "segy:get_header:forall", strerror( errno ) );
+
     plhs[ 1 ] = mxCreateDoubleScalar( fmt.traces );
     return;
 
 cleanup:
-    segy_close( fp );
-
-cleanup_fopen:
-    mexErrMsgIdAndTxt( msg1, msg2 );
+    mexErrMsgIdAndTxt( "segy:get_header:fopen", strerror( errno ) );
 }

-- 
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