Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
3e4ee699ad | |||
7284314fcb | |||
fbbf202a58 | |||
52b41ed9a8 | |||
9afc1958f9 | |||
ef17897ece | |||
66ad358abc | |||
35439dc987 | |||
855cd3adf6 | |||
c54784bb5b | |||
bf461ee42a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ tdmripper
|
|||||||
*.log
|
*.log
|
||||||
tdmreaper
|
tdmreaper
|
||||||
cython/*.cpp
|
cython/*.cpp
|
||||||
|
tdmtermite
|
||||||
|
61
README.md
61
README.md
@@ -2,21 +2,28 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/RecordEvolution/tdm_ripper.git">
|
<a href="https://github.com/RecordEvolution/tdm_ripper.git">
|
||||||
<img
|
<img
|
||||||
alt="tdmreaper.svg"
|
alt="tdmtermite.svg"
|
||||||
src="assets/tdmreaper.svg"
|
src="assets/tdmtermite.svg"
|
||||||
width="400"
|
width="400"
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
The _tdm_reaper_ is a C++ based library that decodes (encodes) the proprietary
|
_TDMtermite_ is a C++ based library that decodes (encodes) the proprietary
|
||||||
file format _TDM/TDX_ for measurement data, which relies upon the
|
file format _TDM/TDX_ for measurement data, which relies upon the
|
||||||
_technical data management_ data model. The TDM format was introduced by
|
_technical data management_ data model. The TDM format was introduced by
|
||||||
[National Instruments](https://www.ni.com) and is employed by
|
[National Instruments](https://www.ni.com) and is employed by
|
||||||
[LabVIEW](https://www.ni.com/de-de/shop/labview.html), LabWindows™/CVI™,
|
[LabVIEW](https://www.ni.com/de-de/shop/labview.html), LabWindows™/CVI™,
|
||||||
Measurement Studio, SignalExpress, and [DIAdem](https://www.ni.com/de-de/shop/data-acquisition-and-control/application-software-for-data-acquisition-and-control-category/what-is-diadem.html).
|
Measurement Studio, SignalExpress, and [DIAdem](https://www.ni.com/de-de/shop/data-acquisition-and-control/application-software-for-data-acquisition-and-control-category/what-is-diadem.html).
|
||||||
|
|
||||||
## Data Format
|
## Overview
|
||||||
|
|
||||||
|
* [TDM file format](#Dataformat)
|
||||||
|
* [Build and Installation](#Installation)
|
||||||
|
* [Usage and Examples](#Usage)
|
||||||
|
* [References](#References)
|
||||||
|
|
||||||
|
## Dataformat
|
||||||
|
|
||||||
Datasets encoded in the TDM/TDX format come along in pairs comprised of a
|
Datasets encoded in the TDM/TDX format come along in pairs comprised of a
|
||||||
.tdm (header) and a .tdx (data) file. While the .tdm file is a human-readable
|
.tdm (header) and a .tdx (data) file. While the .tdm file is a human-readable
|
||||||
@@ -127,7 +134,7 @@ The library can be used both as a _CLI_ based tool and as a _Python_ module.
|
|||||||
|
|
||||||
### CLI tool
|
### CLI tool
|
||||||
|
|
||||||
To install the CLI tool _tdmreaper_ do
|
To install the CLI tool _tdmtermite_ do
|
||||||
|
|
||||||
```Shell
|
```Shell
|
||||||
make install
|
make install
|
||||||
@@ -144,7 +151,7 @@ available, which may be installed via `python3 -m pip install cython` .
|
|||||||
Furthermore, the [Numpy](https://numpy.org) package is recommended to be able
|
Furthermore, the [Numpy](https://numpy.org) package is recommended to be able
|
||||||
to pass arrays of data from the C++ kernel to Python. The _makefile_ provides
|
to pass arrays of data from the C++ kernel to Python. The _makefile_ provides
|
||||||
the target `make cython-requirements` to install all required Python modules.
|
the target `make cython-requirements` to install all required Python modules.
|
||||||
Finally, to build the Python extension _tdm_reaper_ either locally or install
|
Finally, to build the Python extension _tdm_termite_ either locally or install
|
||||||
it the targets `make cython-build` and `make cython-install` are provided.
|
it the targets `make cython-build` and `make cython-install` are provided.
|
||||||
Hence, to install the Python module on the system simply do
|
Hence, to install the Python module on the system simply do
|
||||||
|
|
||||||
@@ -153,19 +160,19 @@ make cython-requirements
|
|||||||
make cython-install
|
make cython-install
|
||||||
```
|
```
|
||||||
|
|
||||||
that makes the module available to be imported as `import tdm_reaper` .
|
that makes the module available to be imported as `import tdm_termite` .
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### CLI tool
|
### CLI tool
|
||||||
|
|
||||||
The usage of the CLI tool is sufficiently clarified by its help message displayed
|
The usage of the CLI tool is sufficiently clarified by its help message displayed
|
||||||
by `tdmreaper --help`. For instance, to extract the data decoded in the pair of
|
by `tdmtermite --help`. For instance, to extract the data decoded in the pair of
|
||||||
files `samples/SineData.tdm` and `samples/SineData.tdx` into the directory
|
files `samples/SineData.tdm` and `samples/SineData.tdx` into the directory
|
||||||
`/home/jack/data/`:
|
`/home/jack/data/`:
|
||||||
|
|
||||||
```Shell
|
```Shell
|
||||||
tdmreaper samples/SineData.tdm samples/SineData.tdx --output /home/jack/data
|
tdmtermite samples/SineData.tdm samples/SineData.tdx --output /home/jack/data
|
||||||
```
|
```
|
||||||
|
|
||||||
The tool can also be used to list the available objects in the TDM dataset, which
|
The tool can also be used to list the available objects in the TDM dataset, which
|
||||||
@@ -173,7 +180,7 @@ are i.a. _channels_, _channelgroups_ and TDX _blocks_. For instance, to list
|
|||||||
all channels and channelgroups (without writing any file output):
|
all channels and channelgroups (without writing any file output):
|
||||||
|
|
||||||
```Shell
|
```Shell
|
||||||
tdmreaper samples/SineData.tdm samples/SineData.tdx --listgroups --listchannels
|
tdmtermite samples/SineData.tdm samples/SineData.tdx --listgroups --listchannels
|
||||||
```
|
```
|
||||||
|
|
||||||
The user may also submit a _filenaming rule_ to control the names of the files the
|
The user may also submit a _filenaming rule_ to control the names of the files the
|
||||||
@@ -182,7 +189,7 @@ and `%c` representing the group id, group name, channel index and channel name
|
|||||||
are defined. The default filenaming option is
|
are defined. The default filenaming option is
|
||||||
|
|
||||||
```Shell
|
```Shell
|
||||||
tdmreaper samples/SineData.tdm samples/SineData.tdx --output /home/jack/data --filenames channelgroup_%G.csv
|
tdmtermite samples/SineData.tdm samples/SineData.tdx --output /home/jack/data --filenames channelgroup_%G.csv
|
||||||
```
|
```
|
||||||
|
|
||||||
which makes the tool write _all channels_ grouped into files according to their
|
which makes the tool write _all channels_ grouped into files according to their
|
||||||
@@ -192,7 +199,7 @@ to extract only a single channel(group) by providing a particular channel(-group
|
|||||||
id in the filenaming flag. For example,
|
id in the filenaming flag. For example,
|
||||||
|
|
||||||
```Shell
|
```Shell
|
||||||
tdmreaper samples/SineData.tdm samples/SineData.tdx --output /home/jack/data -f channel_usi16_%c.csv --includemeta
|
tdmtermite samples/SineData.tdm samples/SineData.tdx --output /home/jack/data -f channel_usi16_%c.csv --includemeta
|
||||||
```
|
```
|
||||||
|
|
||||||
will write the single channel with id `usi16` to the file
|
will write the single channel with id `usi16` to the file
|
||||||
@@ -200,25 +207,25 @@ will write the single channel with id `usi16` to the file
|
|||||||
|
|
||||||
### Python
|
### Python
|
||||||
|
|
||||||
To be able to use the Python module _tdm_reaper_ it first has to be build locally
|
To be able to use the Python module _tdm_termite_ it first has to be build locally
|
||||||
or installed on the system. In the Python interpreter simply do:
|
or installed on the system. In the Python interpreter simply do:
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
import tdm_reaper
|
import tdm_termite
|
||||||
```
|
```
|
||||||
|
|
||||||
to import the module. The TDM files are provided by creating an instance of
|
to import the module. The TDM files are provided by creating an instance of
|
||||||
the _tdm_reaper_ class:
|
the _tdm_termite_ class:
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
# create 'tdm_reaper' instance object
|
# create 'tdm_termite' instance object
|
||||||
try :
|
try :
|
||||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
print("failed to load/decode TDM files: " + str(e))
|
print("failed to load/decode TDM files: " + str(e))
|
||||||
```
|
```
|
||||||
|
|
||||||
After initializing the _tdm_reaper_ object it can be used to extract any of the
|
After initializing the _tdm_termite_ object it can be used to extract any of the
|
||||||
available data. For instance, to list the included channelgroups and channels:
|
available data. For instance, to list the included channelgroups and channels:
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
@@ -234,12 +241,12 @@ As a use case, we have look at listing the ids of all channelgroups and printing
|
|||||||
their data to separate files:
|
their data to separate files:
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
import tdm_reaper
|
import tdm_termite
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# create 'tdm_reaper' instance object
|
# create 'tdm_termite' instance object
|
||||||
try :
|
try :
|
||||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print("failed to load/decode TDM files: " + str(e))
|
print("failed to load/decode TDM files: " + str(e))
|
||||||
|
|
||||||
@@ -267,17 +274,21 @@ for grp in grpids :
|
|||||||
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
||||||
```
|
```
|
||||||
|
|
||||||
For a full example including more details see [python/usage.py](python/usage.py)
|
For a full example including more details see the [extensive example](python/usage.py)
|
||||||
and the absolute minimal example [minimal usage](python/minimal.py). In order
|
and the absolute minimal example [minimal usage](python/minimal.py). In order
|
||||||
to simply extract all data of the TDM datatset and dump it to files in a given
|
to simply extract all data of the TDM datatset and dump it to files in a given
|
||||||
(existing!) directory, do
|
(existing!) directory, do
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
import tdm_reaper
|
import tdm_termite
|
||||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
jack.write_all(b"./my_tdm_data/")
|
jack.write_all(b"./my_tdm_data_directory/")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The interface allows to construct customized file/column headers from any
|
||||||
|
meta-data and provide these headers for usage in file output (see the
|
||||||
|
[example](python/custom.py)).
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
### TDM
|
### TDM
|
||||||
|
100
assets/tdmtermite.svg
Normal file
100
assets/tdmtermite.svg
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
viewBox="0 0 366.72 77.08"
|
||||||
|
version="1.1"
|
||||||
|
id="svg3945"
|
||||||
|
width="366.72"
|
||||||
|
height="77.080002"
|
||||||
|
sodipodi:docname="tdmtermite.svg"
|
||||||
|
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1168"
|
||||||
|
id="namedview19"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="3.8766824"
|
||||||
|
inkscape:cx="199.46638"
|
||||||
|
inkscape:cy="38.540001"
|
||||||
|
inkscape:window-x="2048"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg3945" />
|
||||||
|
<metadata
|
||||||
|
id="metadata3951">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title>flasher</dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<defs
|
||||||
|
id="defs3949" />
|
||||||
|
<title
|
||||||
|
id="title3916">flasher</title>
|
||||||
|
<g
|
||||||
|
id="logog">
|
||||||
|
<path
|
||||||
|
id="path138"
|
||||||
|
d="m 32.86,2 -13,7.5 v 0 h -0.05 v 0 l -0.48,0.28 c -4.27,2.46 -5.68,11.38 -6.06,14.75 L 36.2,11.33 c 0.39,-0.19 7.6,-3.69 13.57,-3.69 h 0.14 L 40.13,2 a 8.15,8.15 0 0 0 -7.27,0"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
<path
|
||||||
|
id="path142"
|
||||||
|
d="M 5.68,17.69 A 8.2,8.2 0 0 0 2,24 v 15.78 c 0,4.9 7,10.48 9.75,12.46 V 25.77 c 0,-0.44 0.6,-8.55 3.65,-13.72 z"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
<path
|
||||||
|
id="path146"
|
||||||
|
d="m 12.1,54.12 v 0 C 11.74,53.88 5,49.41 2,44.24 v 11.14 a 8.2,8.2 0 0 0 3.64,6.3 l 13.5,7.79 c 4.28,2.46 12.7,-0.77 15.81,-2.12 z"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
<path
|
||||||
|
id="path150"
|
||||||
|
d="m 36.79,68 c -0.4,0.19 -7.71,3.75 -13.71,3.69 l 9.78,5.64 a 8.15,8.15 0 0 0 7.27,0 l 13.51,-7.8 c 4.27,-2.46 5.68,-11.39 6.06,-14.75 z"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
<path
|
||||||
|
id="path154"
|
||||||
|
d="M 61.2,27.13 V 53.6 c 0,0.44 -0.6,8.55 -3.65,13.72 l 9.77,-5.64 A 8.2,8.2 0 0 0 71,55.38 V 39.59 c 0,-4.94 -7,-10.5 -9.75,-12.46"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
<path
|
||||||
|
id="path158"
|
||||||
|
d="M 67.31,17.69 53.81,9.9 C 49.53,7.44 41.11,10.67 38,12 l 22.85,13.23 v 0 a 43.43,43.43 0 0 1 5.7,4.51 24,24 0 0 1 4.45,5.35 V 24 a 8.2,8.2 0 0 0 -3.64,-6.3"
|
||||||
|
transform="translate(-2.04,-1.15)"
|
||||||
|
style="fill:#364d5c" />
|
||||||
|
</g>
|
||||||
|
<g
|
||||||
|
id="re" />
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#364d5c;fill-opacity:1;stroke:none"
|
||||||
|
x="74.101189"
|
||||||
|
y="54.47554"
|
||||||
|
id="text3955"><tspan
|
||||||
|
id="tspan3953"
|
||||||
|
x="74.101189"
|
||||||
|
y="54.47554"
|
||||||
|
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:44px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#364d5c;fill-opacity:1"><tspan
|
||||||
|
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold'"
|
||||||
|
id="tspan86">TDMtermite</tspan> </tspan></text>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 4.0 KiB |
@@ -1,17 +1,17 @@
|
|||||||
# distutils: language = c++
|
# distutils: language = c++
|
||||||
|
|
||||||
from tdm_reaper cimport tdm_reaper
|
from tdm_termite cimport tdm_termite
|
||||||
import json as jn
|
import json as jn
|
||||||
# import numpy as np
|
# import numpy as np
|
||||||
|
|
||||||
cdef class tdmreaper:
|
cdef class tdmtermite:
|
||||||
|
|
||||||
# C++ instance of class => stack allocated (requires nullary constructor!)
|
# C++ instance of class => stack allocated (requires nullary constructor!)
|
||||||
cdef tdm_reaper cpp_tdm
|
cdef tdm_termite cpp_tdm
|
||||||
|
|
||||||
# constructor
|
# constructor
|
||||||
def __cinit__(self, string tdmfile, string tdxfile):
|
def __cinit__(self, string tdmfile, string tdxfile):
|
||||||
self.cpp_tdm = tdm_reaper(tdmfile,tdxfile)
|
self.cpp_tdm = tdm_termite(tdmfile,tdxfile)
|
||||||
|
|
||||||
# provide TDM files
|
# provide TDM files
|
||||||
def submit_files(self,string tdmfile, string tdxfile):
|
def submit_files(self,string tdmfile, string tdxfile):
|
||||||
@@ -36,9 +36,9 @@ cdef class tdmreaper:
|
|||||||
return jn.loads(chnstr.decode())
|
return jn.loads(chnstr.decode())
|
||||||
|
|
||||||
# print a channel(-group)
|
# print a channel(-group)
|
||||||
def print_channelgroup(self, string id, const char* filename,
|
def print_channelgroup(self, string id, const char* filename, bool include_meta,
|
||||||
bool include_meta, char delimiter):
|
char delimiter, string column_header):
|
||||||
self.cpp_tdm.print_group(id,filename,include_meta,delimiter)
|
self.cpp_tdm.print_group(id,filename,include_meta,delimiter,column_header)
|
||||||
def print_channel(self, string id, const char* filename,
|
def print_channel(self, string id, const char* filename,
|
||||||
bool include_meta):
|
bool include_meta):
|
||||||
self.cpp_tdm.print_channel(id,filename,include_meta)
|
self.cpp_tdm.print_channel(id,filename,include_meta)
|
||||||
@@ -48,4 +48,4 @@ cdef class tdmreaper:
|
|||||||
grpids = self.cpp_tdm.get_channelgroup_ids()
|
grpids = self.cpp_tdm.get_channelgroup_ids()
|
||||||
for id in grpids :
|
for id in grpids :
|
||||||
grpfile = outputdir.decode() + "/channelgroup_" + id.decode() + ".csv"
|
grpfile = outputdir.decode() + "/channelgroup_" + id.decode() + ".csv"
|
||||||
self.cpp_tdm.print_group(id,grpfile.encode(),True,ord(','))
|
self.cpp_tdm.print_group(id,grpfile.encode(),True,ord(','),"".encode())
|
@@ -3,8 +3,8 @@ from distutils.extension import Extension
|
|||||||
from Cython.Build import cythonize
|
from Cython.Build import cythonize
|
||||||
|
|
||||||
extensions = Extension(
|
extensions = Extension(
|
||||||
name="tdm_reaper",
|
name="tdm_termite",
|
||||||
sources=["cython/py_tdm_reaper.pyx"],
|
sources=["cython/py_tdm_termite.pyx"],
|
||||||
# libraries=[""],
|
# libraries=[""],
|
||||||
# library_dirs=["lib"],
|
# library_dirs=["lib"],
|
||||||
include_dirs=["lib","pugixml"],
|
include_dirs=["lib","pugixml"],
|
||||||
@@ -15,10 +15,10 @@ extensions = Extension(
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
version='0.1',
|
version='0.1',
|
||||||
description='TDMReaper cython extension',
|
description='TDMtermite cython extension',
|
||||||
author='Record Evolution GmbH',
|
author='Record Evolution GmbH',
|
||||||
author_email='mario.fink@record-evolution.de',
|
author_email='mario.fink@record-evolution.de',
|
||||||
url='https://github.com/RecordEvolution/tdm_ripper.git',
|
url='https://github.com/RecordEvolution/tdm_ripper.git',
|
||||||
name="tdm_reaper",
|
name="tdm_termite",
|
||||||
ext_modules=cythonize(extensions)
|
ext_modules=cythonize(extensions)
|
||||||
)
|
)
|
||||||
|
@@ -5,14 +5,14 @@ from libcpp.string cimport string
|
|||||||
from libcpp.vector cimport vector
|
from libcpp.vector cimport vector
|
||||||
from libcpp cimport bool
|
from libcpp cimport bool
|
||||||
|
|
||||||
cdef extern from "tdm_reaper.cpp":
|
cdef extern from "tdm_termite.cpp":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cdef extern from "tdm_reaper.hpp":
|
cdef extern from "tdm_termite.hpp":
|
||||||
cdef cppclass tdm_reaper:
|
cdef cppclass tdm_termite:
|
||||||
# constructor(s)
|
# constructor(s)
|
||||||
tdm_reaper() except +
|
tdm_termite() except +
|
||||||
tdm_reaper(string tdmfile, string tdxfile) except +
|
tdm_termite(string tdmfile, string tdxfile) except +
|
||||||
# provide TDM files
|
# provide TDM files
|
||||||
void submit_files(string tdmfile, string tdxfile) except+
|
void submit_files(string tdmfile, string tdxfile) except+
|
||||||
# get list of channel(-group) ids
|
# get list of channel(-group) ids
|
||||||
@@ -24,5 +24,6 @@ cdef extern from "tdm_reaper.hpp":
|
|||||||
string get_channelgroup_info(string id) except+
|
string get_channelgroup_info(string id) except+
|
||||||
string get_channel_info(string id) except+
|
string get_channel_info(string id) except+
|
||||||
# print a channel(-group)
|
# print a channel(-group)
|
||||||
void print_group(string id, const char* filename, bool include_meta, char delimiter) except+
|
void print_group(string id, const char* filename, bool include_meta,
|
||||||
|
char delimiter, string column_header) except+
|
||||||
void print_channel(string id, const char* filename, bool include_meta) except+
|
void print_channel(string id, const char* filename, bool include_meta) except+
|
@@ -1,32 +1,40 @@
|
|||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
#include "tdm_reaper.hpp"
|
#include "tdm_termite.hpp"
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
tdm_reaper::tdm_reaper()
|
tdm_termite::tdm_termite()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tdm_reaper::tdm_reaper(std::string tdmfile, std::string tdxfile, bool showlog):
|
tdm_termite::tdm_termite(std::string tdmfile, std::string tdxfile, bool showlog):
|
||||||
tdmfile_(tdmfile), tdxfile_(tdxfile)
|
tdmfile_(tdmfile), tdxfile_(tdxfile)
|
||||||
{
|
{
|
||||||
// start processing tdm data model
|
// start processing tdm data model
|
||||||
this->process_tdm(showlog);
|
this->process_tdm(showlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::submit_files(std::string tdmfile, std::string tdxfile, bool showlog)
|
void tdm_termite::submit_files(std::string tdmfile, std::string tdxfile, bool showlog)
|
||||||
{
|
{
|
||||||
// save files
|
// save files
|
||||||
tdmfile_ = tdmfile;
|
tdmfile_ = tdmfile;
|
||||||
tdxfile_ = tdxfile;
|
tdxfile_ = tdxfile;
|
||||||
|
|
||||||
|
// reset and clear all members
|
||||||
|
tdx_blocks_.clear();
|
||||||
|
tdmchannelgroups_.clear();
|
||||||
|
tdmchannels_.clear();
|
||||||
|
submatrices_.clear();
|
||||||
|
localcolumns_.clear();
|
||||||
|
tdxbuffer_.clear();
|
||||||
|
|
||||||
// start processing tdm data model
|
// start processing tdm data model
|
||||||
this->process_tdm(showlog);
|
this->process_tdm(showlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_tdm(bool showlog)
|
void tdm_termite::process_tdm(bool showlog)
|
||||||
{
|
{
|
||||||
// check both tdm, tdx files
|
// check both tdm, tdx files
|
||||||
std::filesystem::path ptdm(tdmfile_), ptdx(tdxfile_);
|
std::filesystem::path ptdm(tdmfile_), ptdx(tdxfile_);
|
||||||
@@ -116,7 +124,7 @@ void tdm_reaper::process_tdm(bool showlog)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_include(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_include(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node
|
// get XML node
|
||||||
pugi::xml_node tdmincl = xml_doc.child("usi:tdm").child("usi:include");
|
pugi::xml_node tdmincl = xml_doc.child("usi:tdm").child("usi:include");
|
||||||
@@ -170,7 +178,7 @@ void tdm_reaper::process_include(bool showlog, pugi::xml_document& xml_doc)
|
|||||||
if ( showlog ) std::cout<<"number of blocks: "<<tdx_blocks_.size()<<"\n\n";
|
if ( showlog ) std::cout<<"number of blocks: "<<tdx_blocks_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_root(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_root(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node
|
// get XML node
|
||||||
pugi::xml_node tdmdataroot = xml_doc.child("usi:tdm").child("usi:data")
|
pugi::xml_node tdmdataroot = xml_doc.child("usi:tdm").child("usi:data")
|
||||||
@@ -190,7 +198,7 @@ void tdm_reaper::process_root(bool showlog, pugi::xml_document& xml_doc)
|
|||||||
if ( showlog ) std::cout<<tdmroot_.get_info()<<"\n";
|
if ( showlog ) std::cout<<tdmroot_.get_info()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_channelgroups(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_channelgroups(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node <usi:data>
|
// get XML node <usi:data>
|
||||||
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
||||||
@@ -228,7 +236,7 @@ void tdm_reaper::process_channelgroups(bool showlog, pugi::xml_document& xml_doc
|
|||||||
if ( showlog ) std::cout<<"number of channelgroups: "<<tdmchannelgroups_.size()<<"\n\n";
|
if ( showlog ) std::cout<<"number of channelgroups: "<<tdmchannelgroups_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_channels(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_channels(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node <usi:data>
|
// get XML node <usi:data>
|
||||||
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
||||||
@@ -272,7 +280,7 @@ void tdm_reaper::process_channels(bool showlog, pugi::xml_document& xml_doc)
|
|||||||
if ( showlog ) std::cout<<"number of channels: "<<tdmchannels_.size()<<"\n\n";
|
if ( showlog ) std::cout<<"number of channels: "<<tdmchannels_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_submatrices(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_submatrices(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node <usi:data>
|
// get XML node <usi:data>
|
||||||
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
||||||
@@ -311,7 +319,7 @@ void tdm_reaper::process_submatrices(bool showlog, pugi::xml_document& xml_doc)
|
|||||||
if ( showlog ) std::cout<<"number of submatrices: "<<submatrices_.size()<<"\n\n";
|
if ( showlog ) std::cout<<"number of submatrices: "<<submatrices_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::process_localcolumns(bool showlog, pugi::xml_document& xml_doc)
|
void tdm_termite::process_localcolumns(bool showlog, pugi::xml_document& xml_doc)
|
||||||
{
|
{
|
||||||
// get XML node <usi:data>
|
// get XML node <usi:data>
|
||||||
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
pugi::xml_node tdmdata = xml_doc.child("usi:tdm").child("usi:data");
|
||||||
@@ -427,7 +435,7 @@ void tdm_reaper::process_localcolumns(bool showlog, pugi::xml_document& xml_doc)
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
std::string tdm_reaper::get_channel_overview(format chformatter)
|
std::string tdm_termite::get_channel_overview(format chformatter)
|
||||||
{
|
{
|
||||||
// summarize all output in single string
|
// summarize all output in single string
|
||||||
std::string channels_summary;
|
std::string channels_summary;
|
||||||
@@ -466,7 +474,7 @@ std::string tdm_reaper::get_channel_overview(format chformatter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename tdmelement>
|
template<typename tdmelement>
|
||||||
std::string tdm_reaper::get_overview(format formatter)
|
std::string tdm_termite::get_overview(format formatter)
|
||||||
{
|
{
|
||||||
// summarize all output in single string
|
// summarize all output in single string
|
||||||
std::string summary;
|
std::string summary;
|
||||||
@@ -492,12 +500,12 @@ std::string tdm_reaper::get_overview(format formatter)
|
|||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
template std::string tdm_reaper::get_overview<tdm_channelgroup>(format formatter);
|
template std::string tdm_termite::get_overview<tdm_channelgroup>(format formatter);
|
||||||
template std::string tdm_reaper::get_overview<submatrix>(format formatter);
|
template std::string tdm_termite::get_overview<submatrix>(format formatter);
|
||||||
template std::string tdm_reaper::get_overview<localcolumn>(format formatter);
|
template std::string tdm_termite::get_overview<localcolumn>(format formatter);
|
||||||
template std::string tdm_reaper::get_overview<block>(format formatter);
|
template std::string tdm_termite::get_overview<block>(format formatter);
|
||||||
|
|
||||||
void tdm_reaper::summarize_member(tdm_channelgroup chp, std::string& summary, format& formatter)
|
void tdm_termite::summarize_member(tdm_channelgroup chp, std::string& summary, format& formatter)
|
||||||
{
|
{
|
||||||
for ( std::map<std::string,tdm_channelgroup>::iterator it=this->tdmchannelgroups_.begin();
|
for ( std::map<std::string,tdm_channelgroup>::iterator it=this->tdmchannelgroups_.begin();
|
||||||
it!=this->tdmchannelgroups_.end(); ++it)
|
it!=this->tdmchannelgroups_.end(); ++it)
|
||||||
@@ -507,7 +515,7 @@ void tdm_reaper::summarize_member(tdm_channelgroup chp, std::string& summary, fo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::summarize_member(submatrix sbm, std::string& summary, format& formatter)
|
void tdm_termite::summarize_member(submatrix sbm, std::string& summary, format& formatter)
|
||||||
{
|
{
|
||||||
for ( std::map<std::string,submatrix>::iterator it=this->submatrices_.begin();
|
for ( std::map<std::string,submatrix>::iterator it=this->submatrices_.begin();
|
||||||
it!=this->submatrices_.end(); ++it)
|
it!=this->submatrices_.end(); ++it)
|
||||||
@@ -517,7 +525,7 @@ void tdm_reaper::summarize_member(submatrix sbm, std::string& summary, format& f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::summarize_member(localcolumn lcc, std::string& summary, format& formatter)
|
void tdm_termite::summarize_member(localcolumn lcc, std::string& summary, format& formatter)
|
||||||
{
|
{
|
||||||
for ( std::map<std::string,localcolumn>::iterator it=this->localcolumns_.begin();
|
for ( std::map<std::string,localcolumn>::iterator it=this->localcolumns_.begin();
|
||||||
it!=this->localcolumns_.end(); ++it)
|
it!=this->localcolumns_.end(); ++it)
|
||||||
@@ -527,7 +535,7 @@ void tdm_reaper::summarize_member(localcolumn lcc, std::string& summary, format&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::summarize_member(block blk, std::string& summary, format& formatter)
|
void tdm_termite::summarize_member(block blk, std::string& summary, format& formatter)
|
||||||
{
|
{
|
||||||
for ( std::map<std::string,block>::iterator it=this->tdx_blocks_.begin();
|
for ( std::map<std::string,block>::iterator it=this->tdx_blocks_.begin();
|
||||||
it!=this->tdx_blocks_.end(); ++it)
|
it!=this->tdx_blocks_.end(); ++it)
|
||||||
@@ -540,7 +548,7 @@ void tdm_reaper::summarize_member(block blk, std::string& summary, format& forma
|
|||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// extract channel by id
|
// extract channel by id
|
||||||
std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
|
std::vector<tdmdatatype> tdm_termite::get_channel(std::string& id)
|
||||||
{
|
{
|
||||||
// check for existence of required channel id (=key)
|
// check for existence of required channel id (=key)
|
||||||
if ( tdmchannels_.count(id) == 1 )
|
if ( tdmchannels_.count(id) == 1 )
|
||||||
@@ -645,7 +653,7 @@ std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
void tdm_reaper::print_channel(std::string &id, const char* filename, bool include_meta)
|
void tdm_termite::print_channel(std::string &id, const char* filename, bool include_meta)
|
||||||
{
|
{
|
||||||
// check required path
|
// check required path
|
||||||
this->check_filename_path(filename);
|
this->check_filename_path(filename);
|
||||||
@@ -690,7 +698,8 @@ void tdm_reaper::print_channel(std::string &id, const char* filename, bool inclu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta, char sep)
|
void tdm_termite::print_group(std::string &id, const char* filename, bool include_meta,
|
||||||
|
char sep, std::string column_header)
|
||||||
{
|
{
|
||||||
// check required path
|
// check required path
|
||||||
this->check_filename_path(filename);
|
this->check_filename_path(filename);
|
||||||
@@ -716,6 +725,7 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
|||||||
|
|
||||||
int width = 25;
|
int width = 25;
|
||||||
|
|
||||||
|
// file header
|
||||||
if ( include_meta )
|
if ( include_meta )
|
||||||
{
|
{
|
||||||
// group meta data
|
// group meta data
|
||||||
@@ -773,6 +783,30 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
|||||||
allchns.push_back(chndat);
|
allchns.push_back(chndat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// provide column header (with channel ids)
|
||||||
|
if ( column_header.empty() )
|
||||||
|
{
|
||||||
|
for ( std::string chn: chngrp.channels_ )
|
||||||
|
{
|
||||||
|
// use given csv separator token
|
||||||
|
if ( sep == ' ' )
|
||||||
|
{
|
||||||
|
fou<<std::setw(width)<<std::left<<chn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fou<<chn;
|
||||||
|
}
|
||||||
|
if ( chn != chngrp.channels_.back() && sep != ' ' ) fou<<sep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fou<<column_header;
|
||||||
|
}
|
||||||
|
fou<<"\n";
|
||||||
|
|
||||||
|
// write data
|
||||||
for ( unsigned int row = 0; row < maxrows; row++ )
|
for ( unsigned int row = 0; row < maxrows; row++ )
|
||||||
{
|
{
|
||||||
for ( unsigned int chi = 0; chi < chngrp.channels_.size(); chi++ )
|
for ( unsigned int chi = 0; chi < chngrp.channels_.size(); chi++ )
|
||||||
@@ -789,19 +823,8 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
|||||||
fou<<allchns.at(chi).at(row);
|
fou<<allchns.at(chi).at(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( sep == ' ' )
|
|
||||||
{
|
|
||||||
fou<<std::setw(width)<<std::left<<"";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fou<<sep;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( chi+1 < chngrp.channels_.size() ) fou<<sep;
|
if ( chi+1 < chngrp.channels_.size() && sep != ' ' ) fou<<sep;
|
||||||
}
|
}
|
||||||
fou<<"\n";
|
fou<<"\n";
|
||||||
}
|
}
|
||||||
@@ -811,7 +834,7 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::check_filename_path(const char* filename)
|
void tdm_termite::check_filename_path(const char* filename)
|
||||||
{
|
{
|
||||||
// declare filesystem path instance from filename
|
// declare filesystem path instance from filename
|
||||||
std::filesystem::path pt(filename);
|
std::filesystem::path pt(filename);
|
||||||
@@ -827,7 +850,7 @@ void tdm_reaper::check_filename_path(const char* filename)
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
void tdm_reaper::check_local_datatypes()
|
void tdm_termite::check_local_datatypes()
|
||||||
{
|
{
|
||||||
std::cout<<"\nmachine's C++ datatypes:\n";
|
std::cout<<"\nmachine's C++ datatypes:\n";
|
||||||
std::cout<<std::setw(25)<<std::left<<"char:"
|
std::cout<<std::setw(25)<<std::left<<"char:"
|
||||||
@@ -858,7 +881,7 @@ void tdm_reaper::check_local_datatypes()
|
|||||||
<<std::setw(5)<<std::left<<sizeof(long double)<<"byte(s)\n\n";
|
<<std::setw(5)<<std::left<<sizeof(long double)<<"byte(s)\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_reaper::check_datatype_consistency()
|
void tdm_termite::check_datatype_consistency()
|
||||||
{
|
{
|
||||||
// check datatype consistency, i.e. "local" representation of datatypes
|
// check datatype consistency, i.e. "local" representation of datatypes
|
||||||
for ( tdm_datatype el: tdm_datatypes )
|
for ( tdm_datatype el: tdm_datatypes )
|
||||||
@@ -901,7 +924,7 @@ void tdm_reaper::check_datatype_consistency()
|
|||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
template<typename datatype>
|
template<typename datatype>
|
||||||
void tdm_reaper::convert_data_to_type(std::vector<unsigned char> &buffer,
|
void tdm_termite::convert_data_to_type(std::vector<unsigned char> &buffer,
|
||||||
std::vector<tdmdatatype> &channel)
|
std::vector<tdmdatatype> &channel)
|
||||||
{
|
{
|
||||||
// check number of elements of type "datatype" in buffer
|
// check number of elements of type "datatype" in buffer
|
@@ -1,7 +1,7 @@
|
|||||||
// ------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------- //
|
||||||
|
|
||||||
#ifndef TDM_REAPER
|
#ifndef TDM_TERMITE
|
||||||
#define TDM_REAPER
|
#define TDM_TERMITE
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
class tdm_reaper
|
class tdm_termite
|
||||||
{
|
{
|
||||||
// .tdm and .tdx paths/filenames
|
// .tdm and .tdx paths/filenames
|
||||||
std::string tdmfile_;
|
std::string tdmfile_;
|
||||||
@@ -39,13 +39,13 @@ class tdm_reaper
|
|||||||
// tdm meta-data
|
// tdm meta-data
|
||||||
tdm_meta meta_data_;
|
tdm_meta meta_data_;
|
||||||
|
|
||||||
// blocks of data in .tdx file
|
|
||||||
std::map<std::string,block> tdx_blocks_;
|
|
||||||
|
|
||||||
// resconstruct "tdm_datatype.hpp: tdm_datatypes" as map to quickly map
|
// resconstruct "tdm_datatype.hpp: tdm_datatypes" as map to quickly map
|
||||||
// "valueType"/"channel_datatype" to full datatype
|
// "valueType"/"channel_datatype" to full datatype
|
||||||
std::map<std::string,tdm_datatype> tdmdt_name_, tdmdt_chan_;
|
std::map<std::string,tdm_datatype> tdmdt_name_, tdmdt_chan_;
|
||||||
|
|
||||||
|
// blocks of data in .tdx file
|
||||||
|
std::map<std::string,block> tdx_blocks_;
|
||||||
|
|
||||||
// tdm root
|
// tdm root
|
||||||
tdm_root tdmroot_;
|
tdm_root tdmroot_;
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ class tdm_reaper
|
|||||||
|
|
||||||
// tdm channels
|
// tdm channels
|
||||||
std::map<std::string,tdm_channel> tdmchannels_;
|
std::map<std::string,tdm_channel> tdmchannels_;
|
||||||
|
std::map<std::string,std::vector<tdm_datatype>> tdmchannels_data_;
|
||||||
|
|
||||||
// submatrices and local_columns
|
// submatrices and local_columns
|
||||||
std::map<std::string,submatrix> submatrices_;
|
std::map<std::string,submatrix> submatrices_;
|
||||||
@@ -114,11 +115,11 @@ class tdm_reaper
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
// encoding
|
// encoding
|
||||||
// tdm_reaper(std::vector<std::string> csvfile);
|
// tdm_termite(std::vector<std::string> csvfile);
|
||||||
|
|
||||||
// decoding
|
// decoding
|
||||||
tdm_reaper();
|
tdm_termite();
|
||||||
tdm_reaper(std::string tdmfile, std::string tdxfile = std::string(""),
|
tdm_termite(std::string tdmfile, std::string tdxfile = std::string(""),
|
||||||
bool showlog = false);
|
bool showlog = false);
|
||||||
|
|
||||||
// provide (tdm,tdx) files
|
// provide (tdm,tdx) files
|
||||||
@@ -238,7 +239,8 @@ public:
|
|||||||
|
|
||||||
// dump a single channel/entire group (identified by id) to file
|
// dump a single channel/entire group (identified by id) to file
|
||||||
void print_channel(std::string &id, const char* filename, bool include_meta = true);
|
void print_channel(std::string &id, const char* filename, bool include_meta = true);
|
||||||
void print_group(std::string &id, const char* filename, bool include_meta = true, char sep = ' ');
|
void print_group(std::string &id, const char* filename, bool include_meta = true,
|
||||||
|
char sep = ' ', std::string column_header = std::string(""));
|
||||||
void check_filename_path(const char* filename);
|
void check_filename_path(const char* filename);
|
||||||
|
|
||||||
// check machine's datatypes
|
// check machine's datatypes
|
16
makefile
16
makefile
@@ -1,10 +1,10 @@
|
|||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
|
|
||||||
# declare name of executable
|
# declare name of executable
|
||||||
EXE = tdmreaper
|
EXE = tdmtermite
|
||||||
|
|
||||||
# sources and headers
|
# sources and headers
|
||||||
SRC := tdm_reaper
|
SRC := tdm_termite
|
||||||
HPP = $(wildcard lib/*.hpp)
|
HPP = $(wildcard lib/*.hpp)
|
||||||
|
|
||||||
# compiler and C++ standard
|
# compiler and C++ standard
|
||||||
@@ -17,7 +17,7 @@ OPT = -O3 -Wall -Werror -Wunused-variable -Wsign-compare
|
|||||||
LIB = pugixml/
|
LIB = pugixml/
|
||||||
|
|
||||||
# determine git version/commit tag
|
# determine git version/commit tag
|
||||||
GTAG := $(shell git tag | head -n1)
|
GTAG := $(shell git tag | tail -n1)
|
||||||
GHSH := $(shell git rev-parse HEAD | head -c8)
|
GHSH := $(shell git rev-parse HEAD | head -c8)
|
||||||
|
|
||||||
# define install location
|
# define install location
|
||||||
@@ -77,16 +77,16 @@ cython-help : cython/setup.py
|
|||||||
cython-list : cython/setup.py
|
cython-list : cython/setup.py
|
||||||
python3 $< --name --description --author --author-email --url
|
python3 $< --name --description --author --author-email --url
|
||||||
|
|
||||||
cython-build : cython/setup.py cython/tdm_reaper.pxd cython/py_tdm_reaper.pyx $(HPP) lib/tdm_reaper.cpp
|
cython-build : cython/setup.py cython/tdm_termite.pxd cython/py_tdm_termite.pyx $(HPP) lib/tdm_termite.cpp
|
||||||
python3 $< build_ext --inplace
|
python3 $< build_ext --inplace
|
||||||
cp -v tdm_reaper.cpython-*.so python/
|
cp -v tdm_termite.cpython-*.so python/
|
||||||
|
|
||||||
cython-install : cython/setup.py cython/tdm_reaper.pxd cython/py_tdm_reaper.pyx $(HPP) lib/tdm_reaper.cpp
|
cython-install : cython/setup.py cython/tdm_termite.pxd cython/py_tdm_termite.pyx $(HPP) lib/tdm_termite.cpp
|
||||||
python3 $< install
|
python3 $< install
|
||||||
|
|
||||||
clean-cython :
|
clean-cython :
|
||||||
rm -vf cython/py_tdm_reaper.cpp
|
rm -vf cython/py_tdm_termite.cpp
|
||||||
rm -vf tdm_reaper.cpython-*.so python/tdm_reaper.cpython-*.so
|
rm -vf tdm_termite.cpython-*.so python/tdm_termite.cpython-*.so
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
|
50
python/custom.py
Normal file
50
python/custom.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
import tdm_termite
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
# create 'tdm_termite' instance object
|
||||||
|
try :
|
||||||
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
|
except RuntimeError as e :
|
||||||
|
print("failed to load/decode TDM files: " + str(e))
|
||||||
|
|
||||||
|
# list ids of channelgroups
|
||||||
|
grpids = jack.get_channelgroup_ids()
|
||||||
|
|
||||||
|
# iterate through group-ids
|
||||||
|
for grp in grpids[0:2] :
|
||||||
|
|
||||||
|
# obtain meta data of channelgroups
|
||||||
|
grpinfo = jack.get_channelgroup_info(grp)
|
||||||
|
print( json.dumps(grpinfo,sort_keys=False,indent=4) )
|
||||||
|
|
||||||
|
# get channel meta-data and compose header
|
||||||
|
column_header = ""
|
||||||
|
chns = grpinfo['channels'].split(' ')
|
||||||
|
for chn in chns :
|
||||||
|
# obtain channel's meta-data as dictionary (JSON)
|
||||||
|
chninfo = jack.get_channel_info(chn.encode())
|
||||||
|
# print( json.dumps(chninfo,sort_keys=False,indent=4) )
|
||||||
|
# choose e.g. channel-id and name to compose column header
|
||||||
|
chnhead = ( str(chninfo['channel-id']) + "("
|
||||||
|
+ str(chninfo['name']).replace(',',' ') + ")" )
|
||||||
|
# append to full header
|
||||||
|
column_header = column_header + chnhead + ","
|
||||||
|
# remove last comma
|
||||||
|
column_header = column_header[0:-1]
|
||||||
|
|
||||||
|
print("column_header:\n"+column_header+"\n")
|
||||||
|
|
||||||
|
# write channelgroup to file
|
||||||
|
try :
|
||||||
|
grpname = re.sub('[^A-Za-z0-9]','',grpinfo['name'])
|
||||||
|
grpfile = str("./channelgroup_") + str(grp.decode()) + "_" + str(grpname) + str(".csv")
|
||||||
|
jack.print_channelgroup(grp, # id of group to be written
|
||||||
|
grpfile.encode(), # filename
|
||||||
|
False, # no meta-data header
|
||||||
|
ord(','), # csv separator character
|
||||||
|
column_header.encode() # provide column header
|
||||||
|
)
|
||||||
|
except RuntimeError as e :
|
||||||
|
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
@@ -1,15 +1,20 @@
|
|||||||
|
|
||||||
import tdm_reaper
|
import tdm_termite
|
||||||
|
|
||||||
# create 'tdm_reaper' instance object
|
# create 'tdm_termite' instance object
|
||||||
try :
|
try :
|
||||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
# list ids of channelgroups
|
# list ids of channelgroups
|
||||||
grpids = jack.get_channelgroup_ids()
|
grpids = jack.get_channelgroup_ids()
|
||||||
# iterate through groups
|
# iterate through groups
|
||||||
for grp in grpids :
|
for grp in grpids :
|
||||||
# write channelgroup to file (prepend './' for local directory!!)
|
# write channelgroup to file (prepend './' for local directory!!)
|
||||||
grpfile = "./channelgroup_" + str(grp.decode()) + ".csv"
|
grpfile = "./channelgroup_" + str(grp.decode()) + ".csv"
|
||||||
jack.print_channelgroup(grp,grpfile.encode(),True,ord(' '))
|
jack.print_channelgroup(grp, # id of group to be written
|
||||||
|
grpfile.encode(), # filename
|
||||||
|
False, # include meta-data fileheader?
|
||||||
|
ord(','), # csv separator character
|
||||||
|
b"" # (empty=default) column header
|
||||||
|
)
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print("failed to load/decode/write TDM files: " + str(e))
|
print("failed to load/decode/write TDM files: " + str(e))
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
import tdm_reaper
|
import tdm_termite
|
||||||
# import numpy as np
|
# import numpy as np
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# create 'tdm_reaper' instance object
|
# create 'tdm_termite' instance object
|
||||||
try :
|
try :
|
||||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
jack = tdm_termite.tdmtermite(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print("failed to load/decode TDM files: " + str(e))
|
print("failed to load/decode TDM files: " + str(e))
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ for grp in grpids[0:2] :
|
|||||||
# write channelgroup to file
|
# write channelgroup to file
|
||||||
try :
|
try :
|
||||||
grpname = re.sub('[^A-Za-z0-9]','',grpinfo['name'])
|
grpname = re.sub('[^A-Za-z0-9]','',grpinfo['name'])
|
||||||
grpfile = "channelgroup_" + str(grp) + "_" + str(grpname) + ".csv"
|
grpfile = "./channelgroup_" + str(grp) + "_" + str(grpname) + ".csv"
|
||||||
jack.print_channelgroup(grp.encode(),grpfile.encode(),True,ord(' '))
|
jack.print_channelgroup(grp.encode(),grpfile.encode(),True,ord(' '),b'')
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ for chn in chnids[0:2] :
|
|||||||
print(str(chndata[0:6]) + " ...")
|
print(str(chndata[0:6]) + " ...")
|
||||||
|
|
||||||
# write channel to file
|
# write channel to file
|
||||||
chnfile = "channel_" + str(chn) + ".csv"
|
chnfile = "./channel_" + str(chn) + ".csv"
|
||||||
try :
|
try :
|
||||||
jack.print_channel(chn.encode(),chnfile.encode(),True)
|
jack.print_channel(chn.encode(),chnfile.encode(),True)
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
|
14
src/main.cpp
14
src/main.cpp
@@ -1,6 +1,6 @@
|
|||||||
// ------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------- //
|
||||||
|
|
||||||
#include "tdm_reaper.hpp"
|
#include "tdm_termite.hpp"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
@@ -15,12 +15,12 @@ const std::string githash("HASHSTRING");
|
|||||||
void show_usage()
|
void show_usage()
|
||||||
{
|
{
|
||||||
std::cout<<"\n"
|
std::cout<<"\n"
|
||||||
<<"tdmreaper ["<<gittag<<"-g"<<githash<<"] (github.com/RecordEvolution/tdm_ripper.git)"
|
<<"tdmtermite ["<<gittag<<"-g"<<githash<<"] (github.com/RecordEvolution/TDMtermite.git)"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<"Decode TDM/TDX files and dump data as *.csv"
|
<<"Decode TDM/TDX files and dump data as *.csv"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<"Usage:\n\n"
|
<<"Usage:\n\n"
|
||||||
<<" tdmreaper <tdm-file> <tdx-file> [options]"
|
<<" tdmtermite <tdm-file> <tdx-file> [options]"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<"Options:"
|
<<"Options:"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
@@ -55,7 +55,7 @@ void show_usage()
|
|||||||
typedef std::map<std::string,std::string> optkeys;
|
typedef std::map<std::string,std::string> optkeys;
|
||||||
|
|
||||||
const std::string argmsg = std::string("both .tdm and .tdx file must be provided!");
|
const std::string argmsg = std::string("both .tdm and .tdx file must be provided!");
|
||||||
const std::string arguse = std::string("see $ tdmreaper --help for usage");
|
const std::string arguse = std::string("see $ tdmtermite --help for usage");
|
||||||
|
|
||||||
optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,7 @@ optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
|||||||
else if ( std::string(argv[1]) == std::string("--version")
|
else if ( std::string(argv[1]) == std::string("--version")
|
||||||
|| std::string(argv[1]) == std::string("-v") )
|
|| std::string(argv[1]) == std::string("-v") )
|
||||||
{
|
{
|
||||||
std::cout<<"tdmreaper "<<gittag<<"-g"<<githash<<"\n";
|
std::cout<<"tdmtermite "<<gittag<<"-g"<<githash<<"\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -270,8 +270,8 @@ int main(int argc, char* argv[])
|
|||||||
std::string csvsep = cfgopts.count("csvsep") == 1 ? cfgopts.at("csvsep")
|
std::string csvsep = cfgopts.count("csvsep") == 1 ? cfgopts.at("csvsep")
|
||||||
: std::string(",");
|
: std::string(",");
|
||||||
|
|
||||||
// declare and initialize tdm_reaper instance
|
// declare and initialize tdm_termite instance
|
||||||
tdm_reaper jack;
|
tdm_termite jack;
|
||||||
try {
|
try {
|
||||||
jack.submit_files(cfgopts.at("tdm"),cfgopts.at("tdx"),false);
|
jack.submit_files(cfgopts.at("tdm"),cfgopts.at("tdx"),false);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
Reference in New Issue
Block a user