Compare commits
No commits in common. "08e2589dfd5dcc48d1088cc8bd43218c3cf5862c" and "fdd107fbb3492c63ce5ff162ac3f6db8c6741428" have entirely different histories.
08e2589dfd
...
fdd107fbb3
@ -171,18 +171,14 @@ Options:
|
||||
-c, --listchannels list channels
|
||||
-b, --listblocks list IMC key-blocks
|
||||
-d, --output output directory to print channels
|
||||
-s, --delimiter csv delimiter/separator char for output
|
||||
-h, --help show this help message
|
||||
-v, --version display version
|
||||
```
|
||||
|
||||
For instance, to show a list of all channels included in `sample-data.raw`, you
|
||||
do `imctermite sample-data.raw --listchannels`. No output files are
|
||||
written by default. Output files are written only when an existing (!) directory
|
||||
is provided as argument to the `--output` option. By default, every output file
|
||||
is written using a `,` delimiter. You may provide any custom separator with the
|
||||
option `--delimiter`. For example, in order to use `|`, the binary is called with
|
||||
options `imctermite sample-data.raw -b -c -s '|'`.
|
||||
written by default. Output files are written only when an existing (!) directory is provided as argument to
|
||||
the `--output` option.
|
||||
|
||||
### Python
|
||||
|
||||
@ -222,3 +218,4 @@ in the Python folder.
|
||||
- https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html
|
||||
- https://github.com/Apollo3zehn/ImcFamosFile
|
||||
- https://pypi.org/help/#apitoken
|
||||
|
||||
|
@ -14,7 +14,6 @@ cdef extern from "imc_raw.hpp" namespace "imc":
|
||||
void set_file(string rawfile) except +
|
||||
# get JSON list of channels
|
||||
vector[string] get_channels(bool json, bool data) except +
|
||||
# print single channel/all channels
|
||||
void print_channel(string channeluuid, string outputdir, char delimiter) except +
|
||||
void print_channels(string outputdir, char delimiter) except +
|
||||
# print all channels
|
||||
void print_channels(string outputdir) except +
|
||||
void print_table(string outputfile) except +
|
||||
|
@ -25,11 +25,9 @@ cdef class imctermite:
|
||||
chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst]
|
||||
return chnlstjn
|
||||
|
||||
# print single channel/all channels
|
||||
def print_channel(self, string channeluuid, string outputfile, char delimiter):
|
||||
self.cpp_imc.print_channel(channeluuid,outputfile,delimiter)
|
||||
def print_channels(self, string outputdir, char delimiter):
|
||||
self.cpp_imc.print_channels(outputdir,delimiter)
|
||||
# print channels
|
||||
def print_channels(self, string outputdir):
|
||||
self.cpp_imc.print_channels(outputdir)
|
||||
|
||||
# print table including channels
|
||||
def print_table(self, string outputfile):
|
||||
|
@ -15,7 +15,7 @@ extensions = Extension(
|
||||
|
||||
setup(
|
||||
name="imc_termite",
|
||||
version='1.2.5',
|
||||
version='1.2.4',
|
||||
description='IMCtermite cython extension',
|
||||
author='Record Evolution GmbH',
|
||||
author_email='mario.fink@record-evolution.de',
|
||||
|
@ -381,7 +381,7 @@ namespace imc
|
||||
}
|
||||
|
||||
// print channel
|
||||
void print(std::string filename, const char sep = ',', int width = 25)
|
||||
void print(std::string filename, const char sep = ' ', int width = 25)
|
||||
{
|
||||
std::ofstream fou(filename);
|
||||
|
||||
|
@ -332,38 +332,14 @@ namespace imc
|
||||
return channels;
|
||||
}
|
||||
|
||||
// print single specific channel
|
||||
void print_channel(std::string channeluuid, std::string outputfile, const char sep)
|
||||
{
|
||||
// check for given parent directory of output file
|
||||
std::filesystem::path pdf = outputfile;
|
||||
if ( !std::filesystem::is_directory(pdf.parent_path()) )
|
||||
{
|
||||
throw std::runtime_error(std::string("required directory does not exist: ")
|
||||
+ pdf.parent_path().u8string() );
|
||||
}
|
||||
|
||||
// find channel with given name
|
||||
if ( channels_.count(channeluuid) == 1 )
|
||||
{
|
||||
channels_.at(channeluuid).print(outputfile,sep);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(std::string("channel does not exist:")
|
||||
+ channeluuid);
|
||||
}
|
||||
}
|
||||
|
||||
// print all channels into given directory
|
||||
void print_channels(std::string output, const char sep)
|
||||
// print all channels in directory
|
||||
void print_channels(std::string output)
|
||||
{
|
||||
// check for given directory
|
||||
std::filesystem::path pd = output;
|
||||
if ( !std::filesystem::is_directory(pd) )
|
||||
{
|
||||
throw std::runtime_error(std::string("given directory does not exist: ")
|
||||
+ output);
|
||||
throw std::runtime_error("given directory does not exist");
|
||||
}
|
||||
|
||||
for ( std::map<std::string,imc::channel>::iterator it = channels_.begin();
|
||||
@ -376,7 +352,7 @@ namespace imc
|
||||
std::filesystem::path pf = pd / filenam;
|
||||
|
||||
// and print the channel
|
||||
it->second.print(pf,sep);
|
||||
it->second.print(pf);
|
||||
}
|
||||
}
|
||||
|
||||
|
2
makefile
2
makefile
@ -93,7 +93,7 @@ cython-install : check-vtag $(CTAG) $(CYT)setup.py $(CYT)imc_termite.pxd $(CYT)p
|
||||
cython-clean :
|
||||
rm -vf imc_termite.cpython-*.so
|
||||
rm -vf $(PYT)imc_termite.cpython-*.so
|
||||
rm -rvf build/
|
||||
rm -rv build/
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# pip
|
||||
|
@ -6,7 +6,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
||||
|
||||
setup(
|
||||
name="IMCtermite",
|
||||
version="1.2.5",
|
||||
version="1.2.4",
|
||||
author="Record Evolution GmbH",
|
||||
author_email="mario.fink@record-evolution.de",
|
||||
maintainer="Record Evolution GmbH",
|
||||
|
@ -7,16 +7,16 @@ import pyarrow as pa
|
||||
import pyarrow.parquet as pq
|
||||
from pathlib import Path
|
||||
|
||||
fileobj1 = Path("samples/datasetA/").rglob("*.raw")
|
||||
fileobj1 = Path("smp/Rangerover_Evoque_F-RR534_2019-05-07/").rglob("*.raw")
|
||||
rawlist1 = [str(fl) for fl in fileobj1]
|
||||
|
||||
fileobj2 = Path("samples/datasetB/").rglob("*.raw")
|
||||
fileobj2 = Path("smp/Mercedes_E-Klasse-2019-08-08/").rglob("*.raw")
|
||||
rawlist2 = [str(fl) for fl in fileobj2]
|
||||
|
||||
rawlist = rawlist1 #[rawlist1[0],rawlist1[4],rawlist2[0],rawlist2[6]]
|
||||
for fil in rawlist2 :
|
||||
rawlist.append(fil)
|
||||
rawlist.append("./README.md")
|
||||
rawlist.append("smp/pressure_Vacuum.asc")
|
||||
|
||||
print("")
|
||||
print(rawlist)
|
||||
|
@ -1,11 +1,10 @@
|
||||
|
||||
import imc_termite
|
||||
import json
|
||||
import os
|
||||
|
||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||
try :
|
||||
imcraw = imc_termite.imctermite(b"samples/exampleB.raw")
|
||||
imcraw = imc_termite.imctermite(b"samples/sampleA.raw")
|
||||
except RuntimeError as e :
|
||||
raise Exception("failed to load/parse raw-file: " + str(e))
|
||||
|
||||
@ -23,16 +22,7 @@ print(len(chnydata))
|
||||
print(len(chnxdata))
|
||||
|
||||
# print the channels into a specific directory
|
||||
imcraw.print_channels(b"./data",ord(','))
|
||||
|
||||
# print all channels separately
|
||||
idx = 0
|
||||
for chn in channels :
|
||||
print(str(idx)+" : "+chn['name']+" : "+chn['uuid'])
|
||||
filname = os.path.join("./data",str(idx) + "_" + chn['name']+".csv")
|
||||
print(filname)
|
||||
imcraw.print_channel(chn['uuid'].encode(),filname.encode(),ord(','))
|
||||
idx = idx + 1
|
||||
imcraw.print_channels(b"./")
|
||||
|
||||
# print all channels in single file
|
||||
# imcraw.print_table(b"./data/allchannels.csv")
|
||||
imcraw.print_table(b"./allchannels.csv")
|
||||
|
75
src/main.cpp
75
src/main.cpp
@ -32,37 +32,25 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
||||
// parse all CLI arguments
|
||||
for ( int i = 1; i < argc; i++ )
|
||||
{
|
||||
// if ( std::string(argv[i]) == std::string("--showmeta")
|
||||
// || std::string(argv[i]) == std::string("-m") )
|
||||
// {
|
||||
// prsdkeys.insert(std::pair<std::string,std::string>("showmeta",argv[i]));
|
||||
// }
|
||||
if ( std::string(argv[i]) == std::string("--showmeta")
|
||||
|| std::string(argv[i]) == std::string("-m") )
|
||||
{
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("showmeta",argv[i]));
|
||||
}
|
||||
// else if ( std::string(argv[i]) == std::string("--listgroups")
|
||||
// || std::string(argv[i]) == std::string("-g") )
|
||||
// {
|
||||
// prsdkeys.insert(std::pair<std::string,std::string>("listgroups",argv[i]));
|
||||
// }
|
||||
if ( std::string(argv[i]) == std::string("--listchannels")
|
||||
else if ( std::string(argv[i]) == std::string("--listchannels")
|
||||
|| std::string(argv[i]) == std::string("-c") )
|
||||
{
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("listchannels",argv[i]));
|
||||
if ( i+1 < argc ) {
|
||||
if ( argv[i+1][0] != '-' ) {
|
||||
std::cerr<<"option --list-channels does not take any argument\n";
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid","channels"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--listblocks")
|
||||
|| std::string(argv[i]) == std::string("-b") )
|
||||
{
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("listblocks",argv[i]));
|
||||
if ( i+1 < argc ) {
|
||||
if ( argv[i+1][0] != '-' ) {
|
||||
std::cerr<<"option --list-blocks does not take any argument\n";
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid","listblocks"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--output")
|
||||
|| std::string(argv[i]) == std::string("-d") )
|
||||
@ -78,20 +66,6 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--delimiter")
|
||||
|| std::string(argv[i]) == std::string("-s") )
|
||||
{
|
||||
if ( i+1 == argc || argv[i+1][0] == '-' )
|
||||
{
|
||||
std::cerr<<"invalid or missing --delimiter argument\n";
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid","delimiter"));
|
||||
}
|
||||
else
|
||||
{
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("delimiter",argv[i+1]));
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--help")
|
||||
|| std::string(argv[i]) == std::string("-h") )
|
||||
{
|
||||
@ -110,13 +84,13 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
||||
std::cerr<<"invalid or unkown argument: "<<argv[i]<<"\n";
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
||||
}
|
||||
// // or missing filenames
|
||||
// else if ( std::string(argv[i]).find(".raw") == std::string::npos )
|
||||
// {
|
||||
// std::cerr<<"doesn't look like a .raw file (make sure to include extension in filename!): "
|
||||
// <<argv[i]<<"\n";
|
||||
// prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
||||
// }
|
||||
// or missing filenames
|
||||
else if ( std::string(argv[i]).find(".raw") == std::string::npos )
|
||||
{
|
||||
std::cerr<<"doesn't look like a .raw file (make sure to include extension in filename!): "
|
||||
<<argv[i]<<"\n";
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,13 +121,9 @@ void show_usage()
|
||||
<<" -c, --listchannels list channels\n"
|
||||
<<" -b, --listblocks list IMC key-blocks\n"
|
||||
<<" -d, --output output directory to print channels\n"
|
||||
<<" -s, --delimiter csv delimiter/separator char for output\n"
|
||||
<<" -h, --help show this help message \n"
|
||||
<<" -v, --version display version\n"
|
||||
<<"\n"
|
||||
<<"Example:"
|
||||
<<" $ ./imctermite sample/data_A.raw -c -b -d ./data -s ','"
|
||||
<<"\n\n";
|
||||
<<"\n";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
@ -239,22 +209,7 @@ int main(int argc, char* argv[])
|
||||
if ( cfgopts.count("output") == 1 )
|
||||
{
|
||||
try {
|
||||
// check and use desired delimiter
|
||||
char delim;
|
||||
if ( cfgopts.count("delimiter") == 1 )
|
||||
{
|
||||
if ( cfgopts.at("delimiter").size() > 1 )
|
||||
{
|
||||
throw std::runtime_error("invalid delimiter comprised of more than a single char");
|
||||
}
|
||||
delim = cfgopts.at("delimiter")[0];
|
||||
}
|
||||
// use comma by default
|
||||
else
|
||||
{
|
||||
delim = ',';
|
||||
}
|
||||
imcraw.print_channels(cfgopts.at("output"),delim);
|
||||
imcraw.print_channels(cfgopts.at("output"));
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr<<"failed to print channels for "<<rawfile<<": "<<e.what()<<"\n";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user