|
|
|
@ -3,9 +3,14 @@
@@ -3,9 +3,14 @@
|
|
|
|
|
#include <pybind11/stl.h> |
|
|
|
|
#include <vector> |
|
|
|
|
#include <fstream> |
|
|
|
|
#include <iostream> |
|
|
|
|
#include <ctime> |
|
|
|
|
#include <cmath> |
|
|
|
|
#include "stormpci.h" |
|
|
|
|
#include "string.h" |
|
|
|
|
|
|
|
|
|
namespace py = pybind11; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define STRINGIFY(x) #x |
|
|
|
|
#define MACRO_STRINGIFY(x) STRINGIFY(x) |
|
|
|
@ -43,10 +48,12 @@ double distance(double lat1, double lon1, double lat2, double lon2)
@@ -43,10 +48,12 @@ double distance(double lat1, double lon1, double lat2, double lon2)
|
|
|
|
|
class BlockReader |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
BlockReader(const std::string &fn){ |
|
|
|
|
BlockReader(const std::string &fn, long int seek_position){ |
|
|
|
|
f = std::ifstream(fn, std::fstream::binary); |
|
|
|
|
pos = seek_position; |
|
|
|
|
} |
|
|
|
|
BlockBinary& read_block(){ |
|
|
|
|
f.seekg(pos); |
|
|
|
|
f.read(reinterpret_cast<char*>(&_single_block), sizeof(BlockBinary)); |
|
|
|
|
if (not f){ |
|
|
|
|
throw; |
|
|
|
@ -56,13 +63,16 @@ public:
@@ -56,13 +63,16 @@ public:
|
|
|
|
|
return _single_block; |
|
|
|
|
} |
|
|
|
|
std::vector<BlockBinary>& read_all_blocks(){ |
|
|
|
|
f.seekg(pos); |
|
|
|
|
bool read_successfully = true; |
|
|
|
|
while (read_successfully){ |
|
|
|
|
f.read(reinterpret_cast<char*>(&_single_block), sizeof(BlockBinary)); |
|
|
|
|
if (not f){ |
|
|
|
|
if (f) { |
|
|
|
|
_blocks_vector.push_back(_single_block); |
|
|
|
|
pos += sizeof(BlockBinary); |
|
|
|
|
} else { |
|
|
|
|
read_successfully = false; |
|
|
|
|
} |
|
|
|
|
_blocks_vector.push_back(_single_block); |
|
|
|
|
} |
|
|
|
|
return _blocks_vector; |
|
|
|
|
} |
|
|
|
@ -76,7 +86,6 @@ private:
@@ -76,7 +86,6 @@ private:
|
|
|
|
|
std::vector<BlockBinary> _blocks_vector; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
namespace py = pybind11; |
|
|
|
|
|
|
|
|
|
PYBIND11_MODULE(stormpci_bin_reader, m) { |
|
|
|
|
m.doc() = R"pbdoc( |
|
|
|
@ -92,7 +101,7 @@ PYBIND11_MODULE(stormpci_bin_reader, m) {
@@ -92,7 +101,7 @@ PYBIND11_MODULE(stormpci_bin_reader, m) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
py::class_<BlockReader>(m, "BlockReader") |
|
|
|
|
.def(py::init<const std::string &>()) |
|
|
|
|
.def(py::init<const std::string &, long int>(), py::arg("fn"), py::arg("seek")=int(0)) |
|
|
|
|
.def("read_block", &BlockReader::read_block) |
|
|
|
|
.def("read_all_blocks", &BlockReader::read_all_blocks); |
|
|
|
|
|
|
|
|
@ -100,6 +109,9 @@ PYBIND11_MODULE(stormpci_bin_reader, m) {
@@ -100,6 +109,9 @@ PYBIND11_MODULE(stormpci_bin_reader, m) {
|
|
|
|
|
.def_readonly("strike", &BlockBinary::strike) |
|
|
|
|
.def_readonly("device_id", &BlockBinary::device_id) |
|
|
|
|
.def_readonly("experiment_id", &BlockBinary::experiment_id) |
|
|
|
|
.def_property_readonly("raw_data", [](const BlockBinary bb) { |
|
|
|
|
return py::bytes(reinterpret_cast<const char*>(&bb), sizeof(bb)); |
|
|
|
|
}) |
|
|
|
|
.def("__repr__", |
|
|
|
|
[](const BlockBinary &bb) { |
|
|
|
|
std::stringstream stream; |
|
|
|
|