[segyio] 343/376: Add applications/segyio-catb

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:56 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 d719549bc4efb9fd18bf38f2461acca3e4c129ec
Author: Håvard Våge Opheim <hvop at statoil.com>
Date:   Mon Aug 14 13:50:39 2017 +0200

    Add applications/segyio-catb
    
    A cat-like program that prints the binary header of a SEG-Y file
---
 applications/CMakeLists.txt     |   9 ++
 applications/segyio-catb.c      | 176 ++++++++++++++++++++++++++++++++++++++++
 applications/test/test_segyb.py |  83 +++++++++++++++++++
 man/CMakeLists.txt              |   3 +-
 man/segyio-catb.1               |  25 ++++++
 5 files changed, 295 insertions(+), 1 deletion(-)

diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt
index 121f988..1720d95 100644
--- a/applications/CMakeLists.txt
+++ b/applications/CMakeLists.txt
@@ -25,6 +25,13 @@ target_compile_definitions(segyio-cath PRIVATE
     -Dsegyio_MINOR=${segyio_MINOR}
 )
 
+add_executable(segyio-catb segyio-catb.c)
+target_link_libraries(segyio-catb segyio apputils)
+target_compile_definitions(segyio-catb PRIVATE
+    -Dsegyio_MAJOR=${segyio_MAJOR}
+    -Dsegyio_MINOR=${segyio_MINOR}
+)
+
 add_executable(segyio-crop segyio-crop.c)
 target_link_libraries(segyio-crop segyio apputils)
 target_compile_definitions(segyio-crop PRIVATE
@@ -43,7 +50,9 @@ install(TARGETS segyinfo DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
 install(TARGETS segyinspect DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
 
 install(TARGETS segyio-cath DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS segyio-catb DESTINATION ${CMAKE_INSTALL_BINDIR})
 install(TARGETS segyio-catr DESTINATION ${CMAKE_INSTALL_BINDIR})
 install(TARGETS segyio-crop DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 add_python_test(applications.apps   test/apps.py)
+add_python_test(python.segyb        test/test_segyb.py)
diff --git a/applications/segyio-catb.c b/applications/segyio-catb.c
new file mode 100644
index 0000000..d1a7fe2
--- /dev/null
+++ b/applications/segyio-catb.c
@@ -0,0 +1,176 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <getopt.h>
+#include <unistd.h>
+
+#include "apputils.h"
+#include <segyio/segy.h>
+
+static int printhelp(){
+    puts( "Usage: segyio-catb [OPTION]... [FILE]...\n"
+          "Concatenate the binary header from FILE(s) to seismic unix "
+          "output.\n"
+          "\n"
+          "--version    output version information and exit\n" 
+          "--help       display this help and exit\n"
+          "\n"
+        );
+    return 0;
+}
+
+static int printversion(){
+    printf( "segyio-catb (segyio version %d.%d)\n",
+             segyio_MAJOR, segyio_MINOR );
+    return 1;
+}
+
+static int get_binary_value( char* binheader, int bfield ){
+    int32_t f;
+    segy_get_bfield( binheader, bfield, &f );
+    return f;
+}
+
+struct options {
+    int version, help;
+    const char* errmsg;
+};
+
+static struct options parse_options( int argc, char** argv ){
+    struct options opts;
+    opts.version = 0, opts.help = 0;
+    opts.errmsg = NULL;
+
+    struct options opthelp, optversion;
+    opthelp.help = 1, opthelp.errmsg = NULL;
+    optversion.version = 1, optversion.errmsg = NULL;
+    
+    static struct option long_options[] = {
+        {"version",     no_argument,    0,    'V'},
+        {"help",        no_argument,    0,    'h'},
+        {0, 0, 0, 0}
+    };
+
+    opterr = 1;
+     
+    while( true ){
+
+        int option_index = 0;
+        int c = getopt_long( argc, argv, "",
+                            long_options, &option_index);
+
+        if ( c == -1 ) break;
+        
+        switch( c ){
+            case  0: break;
+            case 'h': return opthelp;
+            case 'V': return optversion;
+            default: 
+                 opthelp.errmsg = "";
+                 return opthelp;
+        }
+    }
+    return opts;
+}
+
+int main( int argc, char** argv ){
+
+   static const char* su[ 30 ] = {
+        "jobid",
+        "lino",
+        "reno",
+        "ntrpr",
+        "nart",
+        "hdt",
+        "dto",
+        "hns",
+        "nso",
+        "format",
+        "fold",
+        "tsort",
+        "vscode",
+        "hsfs",
+        "hsfe",
+        "hslen",
+        "hstyp",
+        "schn",
+        "hstas",
+        "hstae",
+        "htatyp",
+        "hcorr",
+        "bgrcv",
+        "rcvm",
+        "mfeet",
+        "polyt",
+        "vpol",
+        "rev",
+        "trflag",
+        "exth"
+    };
+
+    static int bfield_value[ 30 ] = {
+        SEGY_BIN_JOB_ID,
+        SEGY_BIN_LINE_NUMBER,
+        SEGY_BIN_REEL_NUMBER,
+        SEGY_BIN_TRACES,
+        SEGY_BIN_AUX_TRACES,
+        SEGY_BIN_INTERVAL,
+        SEGY_BIN_INTERVAL_ORIG,
+        SEGY_BIN_SAMPLES,
+        SEGY_BIN_SAMPLES_ORIG,
+        SEGY_BIN_FORMAT,
+        SEGY_BIN_ENSEMBLE_FOLD,
+        SEGY_BIN_SORTING_CODE,
+        SEGY_BIN_VERTICAL_SUM,
+        SEGY_BIN_SWEEP_FREQ_START,
+        SEGY_BIN_SWEEP_FREQ_END,
+        SEGY_BIN_SWEEP_LENGTH,
+        SEGY_BIN_SWEEP,
+        SEGY_BIN_SWEEP_CHANNEL,
+        SEGY_BIN_SWEEP_TAPER_START,
+        SEGY_BIN_SWEEP_TAPER_END,
+        SEGY_BIN_TAPER,
+        SEGY_BIN_CORRELATED_TRACES,
+        SEGY_BIN_BIN_GAIN_RECOVERY,
+        SEGY_BIN_AMPLITUDE_RECOVERY,
+        SEGY_BIN_MEASUREMENT_SYSTEM,
+        SEGY_BIN_IMPULSE_POLARITY,
+        SEGY_BIN_VIBRATORY_POLARITY,
+        SEGY_BIN_SEGY_REVISION,
+        SEGY_BIN_TRACE_FLAG,
+        SEGY_BIN_EXT_HEADERS
+    };
+    
+    if( argc == 1 ){
+         int err = errmsg(2, "Missing argument\n");
+         printhelp();
+         return err;
+    }
+
+    struct options opts = parse_options( argc, argv );
+   
+    if( opts.help )    return printhelp();
+    if( opts.version ) return printversion();
+
+    for( int i = optind; i < argc; ++i ){
+        segy_file* fp = segy_open( argv[ i ], "r" );
+
+        if( !fp ) return errmsg(opterr, "No such file or directory");
+
+        char binheader[ SEGY_BINARY_HEADER_SIZE ];
+        int err = segy_binheader( fp, binheader );        
+
+        if( err ) return errmsg(opterr, "Unable to read binary header"); 
+
+        for( int c = 0; c < 30; ++c ){
+            printf( "%s\t%d\n", su[ c ],
+                    get_binary_value( binheader, bfield_value[ c ] ));
+        }
+        
+        segy_close( fp );
+    }
+    return 0;
+}
+
diff --git a/applications/test/test_segyb.py b/applications/test/test_segyb.py
new file mode 100644
index 0000000..df35584
--- /dev/null
+++ b/applications/test/test_segyb.py
@@ -0,0 +1,83 @@
+import unittest
+import subprocess
+import os
+
+class TestSegyB(unittest.TestCase):
+
+    actual_output = [
+        b"jobid\t0",
+        b"lino\t0",
+        b"reno\t0",
+        b"ntrpr\t25",
+        b"nart\t0",
+        b"hdt\t4000",
+        b"dto\t0",
+        b"hns\t50",
+        b"nso\t0",
+        b"format\t1",
+        b"fold\t0",
+        b"tsort\t0",
+        b"vscode\t0",
+        b"hsfs\t0",
+        b"hsfe\t0",
+        b"hslen\t0",
+        b"hstyp\t0",
+        b"schn\t0",
+        b"hstas\t0",
+        b"hstae\t0",
+        b"htatyp\t0",
+        b"hcorr\t0",
+        b"bgrcv\t0",
+        b"rcvm\t0",
+        b"mfeet\t0",
+        b"polyt\t0",
+        b"vpol\t0",
+        b"rev\t0",
+        b"trflag\t0",
+        b"exth\t0"
+    ]
+    work_dir = '../../build'
+    cmd_base = './applications/segyio-catb'
+    FNULL = open(os.devnull, 'w')
+
+    def test_help(self):
+        cmd = self.cmd_base + ' --help'
+        result = subprocess.check_output(cmd, shell=True, cwd=self.work_dir)
+        self.assertEqual(result[0:18], b'Usage: segyio-catb')
+
+    def test_segy_in(self):
+        filepath = self.work_dir + '/python/test-data/small.sgy'
+        cmd = self.cmd_base + ' python/test-data/small.sgy'
+        result = subprocess.check_output(cmd, shell=True, cwd=self.work_dir)
+        result_list = result.split(b'\n')
+        for i in range(len(self.actual_output)):
+            self.assertEqual(result_list[i], self.actual_output[i])
+
+    def test_non_segy_in(self):
+        cmd = self.cmd_base + ' ../applications/CMakeLists.txt'
+        result = subprocess.call(cmd,
+                                 shell=True,
+                                 stderr=self.FNULL,
+                                 cwd=self.work_dir)
+        self.assertEqual(result, 1)
+
+    def test_none_file(self):
+        cmd = self.cmd_base + ' nothing'
+        result = subprocess.call(cmd,
+                                 shell=True,
+                                 stderr=self.FNULL,
+                                 cwd=self.work_dir)
+        self.assertEqual(result, 1)
+
+    def test_empty_string_in(self):
+        cmd = self.cmd_base + ' ';
+        result = subprocess.call(cmd,
+                                 shell=True,
+                                 stderr=self.FNULL,
+                                 stdout=self.FNULL,
+                                 cwd=self.work_dir)
+        self.assertEqual(result, 2)
+
+if __name__ == '__main__':
+    unittest.main()
+
diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt
index 56cbca2..abcaba0 100644
--- a/man/CMakeLists.txt
+++ b/man/CMakeLists.txt
@@ -5,6 +5,7 @@ if(NOT UNIX)
 endif()
 
 install(FILES segyio-cath.1
-              segyio-crop.1
+              segyio-catb.1
+              segyio-crop.1          
         DESTINATION ${CMAKE_INSTALL_MANDIR}
 )
diff --git a/man/segyio-catb.1 b/man/segyio-catb.1
new file mode 100644
index 0000000..721e148
--- /dev/null
+++ b/man/segyio-catb.1
@@ -0,0 +1,25 @@
+.TH SEGYIO-CATB 1
+.SH NAME
+segyio-catb \- Concatenate SEG-Y binary header and print on seismic unix format
+.SH SYNPOSIS
+.B segyio-catb
+[\fIOPTION\fR]...
+[\fIFILE\fR]...
+.SH DESCRIPTION
+.B segyio-catb
+Concatenate the SEG-Y binary header in FILEs.
+
+.SH OPTIONS
+.TP
+.BR \-\-version
+output version information and exit
+
+.TP
+.BR \-\-help
+display this help and exit
+
+.SH COPYRIGHT
+Copyright © Statoil ASA. License LPLv3+: GNU LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>.
+
+.PP
+This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.   

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