diff --git a/cython/imc_termite.pxd b/cython/imc_termite.pxd index ccd65e9..7433ce7 100644 --- a/cython/imc_termite.pxd +++ b/cython/imc_termite.pxd @@ -14,6 +14,7 @@ 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 all channels - void print_channels(string outputdir) except + + # print single channel/all channels + void print_channel(string channeluuid, string outputdir, char delimiter) except + + void print_channels(string outputdir, char delimiter) except + void print_table(string outputfile) except + diff --git a/cython/py_imc_termite.pyx b/cython/py_imc_termite.pyx index be7a8bd..3e34892 100644 --- a/cython/py_imc_termite.pyx +++ b/cython/py_imc_termite.pyx @@ -25,9 +25,11 @@ cdef class imctermite: chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst] return chnlstjn - # print channels - def print_channels(self, string outputdir): - self.cpp_imc.print_channels(outputdir) + # 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 table including channels def print_table(self, string outputfile): diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index 54092c8..4f40fec 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -332,14 +332,38 @@ namespace imc return channels; } - // print all channels in directory + // 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) { // check for given directory std::filesystem::path pd = output; if ( !std::filesystem::is_directory(pd) ) { - throw std::runtime_error("given directory does not exist"); + throw std::runtime_error(std::string("given directory does not exist: ") + + output); } for ( std::map::iterator it = channels_.begin(); diff --git a/python/example.py b/python/example.py index e6a78f7..a4c2a88 100644 --- a/python/example.py +++ b/python/example.py @@ -7,16 +7,16 @@ import pyarrow as pa import pyarrow.parquet as pq from pathlib import Path -fileobj1 = Path("smp/Rangerover_Evoque_F-RR534_2019-05-07/").rglob("*.raw") +fileobj1 = Path("samples/datasetA/").rglob("*.raw") rawlist1 = [str(fl) for fl in fileobj1] -fileobj2 = Path("smp/Mercedes_E-Klasse-2019-08-08/").rglob("*.raw") +fileobj2 = Path("samples/datasetB/").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("smp/pressure_Vacuum.asc") +rawlist.append("./README.md") print("") print(rawlist) diff --git a/python/usage.py b/python/usage.py index 1726722..751b586 100644 --- a/python/usage.py +++ b/python/usage.py @@ -1,10 +1,11 @@ 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/sampleA.raw") + imcraw = imc_termite.imctermite(b"samples/exampleB.raw") except RuntimeError as e : raise Exception("failed to load/parse raw-file: " + str(e)) @@ -22,7 +23,16 @@ print(len(chnydata)) print(len(chnxdata)) # print the channels into a specific directory -imcraw.print_channels(b"./") +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 # print all channels in single file -imcraw.print_table(b"./allchannels.csv") +# imcraw.print_table(b"./data/allchannels.csv") diff --git a/src/main.cpp b/src/main.cpp index 69dc3ef..da8b512 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,25 +32,37 @@ 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("showmeta",argv[i])); - } + // if ( std::string(argv[i]) == std::string("--showmeta") + // || std::string(argv[i]) == std::string("-m") ) + // { + // prsdkeys.insert(std::pair("showmeta",argv[i])); + // } // else if ( std::string(argv[i]) == std::string("--listgroups") // || std::string(argv[i]) == std::string("-g") ) // { // prsdkeys.insert(std::pair("listgroups",argv[i])); // } - else if ( std::string(argv[i]) == std::string("--listchannels") + if ( std::string(argv[i]) == std::string("--listchannels") || std::string(argv[i]) == std::string("-c") ) { prsdkeys.insert(std::pair("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("invalid","channels")); + } + } } else if ( std::string(argv[i]) == std::string("--listblocks") || std::string(argv[i]) == std::string("-b") ) { prsdkeys.insert(std::pair("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("invalid","listblocks")); + } + } } else if ( std::string(argv[i]) == std::string("--output") || std::string(argv[i]) == std::string("-d") ) @@ -71,7 +83,7 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false) { if ( i+1 == argc || argv[i+1][0] == '-' ) { - std::cerr<<"invalid or missing --output argument\n"; + std::cerr<<"invalid or missing --delimiter argument\n"; prsdkeys.insert(std::pair("invalid","delimiter")); } else @@ -98,13 +110,13 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false) std::cerr<<"invalid or unkown argument: "<("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!): " - <("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!): " + // <("invalid",argv[i])); + // } } } @@ -227,11 +239,22 @@ int main(int argc, char* argv[]) if ( cfgopts.count("output") == 1 ) { try { - if ( cfgopts.at("delimiter").size() > 1 ) + // check and use desired delimiter + char delim; + if ( cfgopts.count("delimiter") == 1 ) { - throw std::runtime_error("invalid delimiter comprised of more than a single char"); + if ( cfgopts.at("delimiter").size() > 1 ) + { + throw std::runtime_error("invalid delimiter comprised of more than a single char"); + } + delim = cfgopts.at("delimiter")[0]; } - imcraw.print_channels(cfgopts.at("output"),cfgopts.at("delimiter")[0]); + // use comma by default + else + { + delim = ','; + } + imcraw.print_channels(cfgopts.at("output"),delim); } catch (const std::exception& e) { std::cerr<<"failed to print channels for "<