Initial commit based on common repo commit ffeb9c9b

This commit is contained in:
2021-04-22 15:57:00 +02:00
commit 8b2a408e6f
107 changed files with 61542 additions and 0 deletions

125
libs/swig/gempa/CAPS.i Normal file
View File

@ -0,0 +1,125 @@
%feature("notabstract") Gempa::CAPS::AnyDataRecord;
%include "stdint.i"
%init
%{
import_array();
%}
%module CAPS
%{
#define SWIG_FILE_WITH_INIT
#include <gempa/caps/utils.h>
#include <gempa/caps/anypacket.h>
#include <gempa/caps/datetime.h>
#include <gempa/caps/log.h>
#include <gempa/caps/mseedpacket.h>
#include <gempa/caps/packet.h>
#include <gempa/caps/plugin.h>
typedef Gempa::CAPS::Plugin::Buffer Buffer;
#include <gempa/caps/rawpacket.h>
#include <gempa/caps/riff.h>
#include <gempa/caps/rtcm2packet.h>
#include <gempa/caps/socket.h>
#include <gempa/caps/mseed/spclock.h>
#include <numpy/ndarrayobject.h>
%}
%extend Gempa::CAPS::Plugin {
Gempa::CAPS::Plugin::Status push(const std::string &net, const std::string &sta,
const std::string &loc, const std::string &cha,
const Time &stime, int16_t numerator, int16_t denominator,
const std::string &uom,
PyObject *obj, int type
) {
PyArrayObject *arr = NULL;
Gempa::CAPS::DataType dataType = (Gempa::CAPS::DataType)type;
Gempa::CAPS::Plugin::Status status = Gempa::CAPS::Plugin::PacketLoss;
switch(type) {
case Gempa::CAPS::DT_INT8:
arr = (PyArrayObject*) PyArray_ContiguousFromObject(obj, PyArray_CHAR, 1, 1);
if ( arr == NULL )
break;
status = self->push(net, sta, loc, cha, stime, numerator, denominator,
uom, (int8_t*)(arr->data), arr->dimensions[0], dataType);
break;
case Gempa::CAPS::DT_INT16:
arr = (PyArrayObject*) PyArray_ContiguousFromObject(obj, PyArray_INT16, 1, 1);
if ( arr == NULL )
break;
status = self->push(net, sta, loc, cha, stime, numerator, denominator,
uom, (int16_t*)(arr->data), arr->dimensions[0], dataType);
break;
case Gempa::CAPS::DT_INT32:
arr = (PyArrayObject*) PyArray_ContiguousFromObject(obj, PyArray_INT32, 1, 1);
if ( arr == NULL )
break;
status = self->push(net, sta, loc, cha, stime, numerator, denominator,
uom, (int32_t*)(arr->data), arr->dimensions[0], dataType);
break;
case Gempa::CAPS::DT_FLOAT:
arr = (PyArrayObject*) PyArray_ContiguousFromObject(obj, PyArray_FLOAT32, 1, 1);
if ( arr == NULL )
break;
status = self->push(net, sta, loc, cha, stime, numerator, denominator,
uom, (float*)(arr->data), arr->dimensions[0], dataType);
break;
case Gempa::CAPS::DT_DOUBLE:
arr = (PyArrayObject*) PyArray_ContiguousFromObject(obj, PyArray_FLOAT64, 1, 1);
if ( arr == NULL )
break;
status = self->push(net, sta, loc, cha, stime, numerator, denominator,
uom, (double*)(arr->data), arr->dimensions[0], dataType);
break;
default:
break;
}
Py_XDECREF(arr);
return status;
}
Gempa::CAPS::Plugin::Status push(const std::string &net, const std::string &sta,
const std::string &loc, const std::string &cha,
const Time &stime, uint16_t numerator,
uint16_t denominator, const std::string &format,
PyObject *obj) {
char *data;
Py_ssize_t len;
if ( PyBytes_AsStringAndSize(obj, &data, &len) == -1 )
return Gempa::CAPS::Plugin::PacketLoss;
return self->push(net, sta, loc, cha, stime, numerator,
denominator, format, data, len);
}
};
%include "exception.i"
%include "std_string.i"
%include "numpy.i"
%include "gempa/caps/api.h"
%include "gempa/caps/datetime.h"
%include "gempa/caps/packet.h"
%include "gempa/caps/pluginpacket.h"
%include "gempa/caps/anypacket.h"
%include "gempa/caps/log.h"
%include "gempa/caps/mseed/spclock.h"
%include "gempa/caps/mseed/encoder.h"
%include "gempa/caps/encoderfactory.h"
%include "gempa/caps/mseedpacket.h"
typedef Gempa::CAPS::Plugin::Buffer Buffer;
%include "gempa/caps/plugin.h"
%include "gempa/caps/rawpacket.h"
%include "gempa/caps/riff.h"
%include "gempa/caps/rtcm2packet.h"
%include "gempa/caps/socket.h"
%include <carrays.i>
%array_class(char, charArray);
%include "gempa/caps/utils.h"

1928
libs/swig/gempa/CAPS.py Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
FIND_PACKAGE(PythonLibs REQUIRED)
FIND_PACKAGE(PythonInterp REQUIRED)
SET(PYTHON_LIBRARY_SUFFIX /python)
SET(PYTHON_LIBRARY_PATH lib${PYTHON_LIBRARY_SUFFIX})
FIND_PACKAGE(Numpy)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(../../../system/libs/swig)
FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem)
IF (CMAKE_COMPILER_IS_GNUCC)
# Important for O2 compilation
ADD_DEFINITIONS("-fno-strict-aliasing")
ENDIF (CMAKE_COMPILER_IS_GNUCC)
SET(
WRAPPER_MODULES
CAPS
)
FIND_PACKAGE(OpenSSL REQUIRED)
SET(WRAPPER_MODULE_CAPS_EXTRA_LIBS capsclient ${Boost_filesystem_LIBRARY} ${OPENSSL_LIBRARIES})
FOREACH (wrapper_module ${WRAPPER_MODULES})
SET(
${wrapper_module}_SOURCES
${wrapper_module}PYTHON_wrap.cxx
${WRAPPER_MODULE_${wrapper_module}_EXTRA_FILES}
)
ADD_LIBRARY(_${wrapper_module} MODULE ${${wrapper_module}_SOURCES})
SET_TARGET_PROPERTIES(_${wrapper_module} PROPERTIES PREFIX "")
TARGET_LINK_LIBRARIES(_${wrapper_module} ${PYTHON_LIBRARIES})
TARGET_LINK_LIBRARIES(_${wrapper_module} ${WRAPPER_MODULE_${wrapper_module}_EXTRA_LIBS})
ENDFOREACH (wrapper_module)
#SC_SWIG_GET_MODULE_PATH(_module_path)
SET(_module_path ${CMAKE_INSTALL_PREFIX}/lib/python/gempa)
FOREACH (wrapper_module ${WRAPPER_MODULES})
INSTALL(
TARGETS _${wrapper_module}
LIBRARY DESTINATION ${_module_path}
)
INSTALL(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
DESTINATION ${_module_path}
)
INSTALL(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/${wrapper_module}.py
DESTINATION ${_module_path}
)
INSTALL(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${wrapper_module}.pyc
DESTINATION ${_module_path}
OPTIONAL
)
INSTALL(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${wrapper_module}.pyo
DESTINATION ${_module_path}
OPTIONAL
)
ADD_CUSTOM_COMMAND(
TARGET _${wrapper_module}
POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/py-compile ARGS --python \"${PYTHON_EXECUTABLE}\" --destdir ${CMAKE_CURRENT_BINARY_DIR} ${wrapper_module}.py
)
ENDFOREACH (wrapper_module)

View File

2
libs/swig/gempa/codegen.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
swig -c++ -I../../ -o CAPSPYTHON_wrap.cxx -python CAPS.i

3161
libs/swig/gempa/numpy.i Normal file

File diff suppressed because it is too large Load Diff