Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
234876c5a9 | ||
![]() |
bafc018566 | ||
fdd107fbb3 | |||
cd4ce55e7e | |||
27683cbbd6 | |||
25a51215a0 | |||
36c02089aa | |||
cd75689d32 | |||
57c7f6021b | |||
83922c343f | |||
72378877ec | |||
e7094d0125 | |||
16a77ecf1e |
18
README.md
18
README.md
@@ -1,13 +1,11 @@
|
|||||||
|
|
||||||
<p align="center">
|
[](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/alerts/)
|
||||||
<a href="https://record-evolution.de/reswarm">
|
[](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/context:cpp)
|
||||||
<img
|
[](https://lgtm.com/projects/g/RecordEvolution/IMCtermite/context:python)
|
||||||
alt="imctermite.svg"
|
[](https://img.shields.io/github/license/RecordEvolution/IMCtermite)
|
||||||
src="assets/imctermite.svg"
|
[](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)
|
||||||
width="400"
|
|
||||||
/>
|
# IMCtermite
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
_IMCtermite_ provides access to the proprietary data format
|
_IMCtermite_ provides access to the proprietary data format
|
||||||
_IMC Bus Format_ with the file extension _.raw_ introduced and developed by
|
_IMC Bus Format_ with the file extension _.raw_ introduced and developed by
|
||||||
@@ -219,3 +217,5 @@ in the Python folder.
|
|||||||
- https://www.imc-tm.de/produkte/messtechnik-hardware/imc-cronosflex/ueberblick/
|
- https://www.imc-tm.de/produkte/messtechnik-hardware/imc-cronosflex/ueberblick/
|
||||||
- https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html
|
- https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html
|
||||||
- https://github.com/Apollo3zehn/ImcFamosFile
|
- https://github.com/Apollo3zehn/ImcFamosFile
|
||||||
|
- https://pypi.org/help/#apitoken
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ cdef extern from "imc_raw.hpp" namespace "imc":
|
|||||||
void set_file(string rawfile) except +
|
void set_file(string rawfile) except +
|
||||||
# get JSON list of channels
|
# get JSON list of channels
|
||||||
vector[string] get_channels(bool json, bool data) except +
|
vector[string] get_channels(bool json, bool data) except +
|
||||||
# print all channels
|
# print single channel/all channels
|
||||||
void print_channels(string outputdir) except +
|
void print_channel(string channeluuid, string outputdir, char delimiter) except +
|
||||||
|
void print_channels(string outputdir, char delimiter) except +
|
||||||
void print_table(string outputfile) except +
|
void print_table(string outputfile) except +
|
||||||
|
@@ -22,17 +22,19 @@ cdef class imctermite:
|
|||||||
# get JSON list of channels
|
# get JSON list of channels
|
||||||
def get_channels(self, bool data):
|
def get_channels(self, bool data):
|
||||||
chnlst = self.cpp_imc.get_channels(True,data)
|
chnlst = self.cpp_imc.get_channels(True,data)
|
||||||
chnlstjn = [jn.loads(chn.decode(errors="ignore"),parse_float=decimal.Decimal) for chn in chnlst]
|
chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst]
|
||||||
return chnlstjn
|
return chnlstjn
|
||||||
|
|
||||||
# print channels
|
# print single channel/all channels
|
||||||
def print_channels(self, string outputdir):
|
def print_channel(self, string channeluuid, string outputfile, char delimiter):
|
||||||
self.cpp_imc.print_channels(outputdir)
|
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
|
# print table including channels
|
||||||
def print_table(self, string outputfile):
|
def print_table(self, string outputfile):
|
||||||
chnlst = self.cpp_imc.get_channels(True,True)
|
chnlst = self.cpp_imc.get_channels(True,True)
|
||||||
chnlstjn = [jn.loads(chn.decode(errors="ignore"),parse_float=decimal.Decimal) for chn in chnlst]
|
chnlstjn = [jn.loads(chn.decode(errors="ignore")) for chn in chnlst]
|
||||||
with open(outputfile.decode(),'w') as fout:
|
with open(outputfile.decode(),'w') as fout:
|
||||||
for chn in chnlstjn:
|
for chn in chnlstjn:
|
||||||
fout.write('#' +str(chn['xname']).rjust(19)+str(chn['yname']).rjust(20)+'\n')
|
fout.write('#' +str(chn['xname']).rjust(19)+str(chn['yname']).rjust(20)+'\n')
|
||||||
|
@@ -15,7 +15,7 @@ extensions = Extension(
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="imc_termite",
|
name="imc_termite",
|
||||||
version='1.2.3',
|
version='1.2.4',
|
||||||
description='IMCtermite cython extension',
|
description='IMCtermite cython extension',
|
||||||
author='Record Evolution GmbH',
|
author='Record Evolution GmbH',
|
||||||
author_email='mario.fink@record-evolution.de',
|
author_email='mario.fink@record-evolution.de',
|
||||||
|
@@ -147,7 +147,7 @@ namespace imc
|
|||||||
std::string group_uuid_, group_name_, group_comment_;
|
std::string group_uuid_, group_name_, group_comment_;
|
||||||
|
|
||||||
// constructor takes channel's block environment
|
// constructor takes channel's block environment
|
||||||
channel(channel_env chnenv, std::map<std::string,imc::block>* blocks,
|
channel(channel_env &chnenv, std::map<std::string,imc::block>* blocks,
|
||||||
std::vector<unsigned char>* buffer):
|
std::vector<unsigned char>* buffer):
|
||||||
chnenv_(chnenv), blocks_(blocks), buffer_(buffer),
|
chnenv_(chnenv), blocks_(blocks), buffer_(buffer),
|
||||||
factor_(1.), offset_(0.),
|
factor_(1.), offset_(0.),
|
||||||
@@ -381,7 +381,7 @@ namespace imc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print channel
|
// 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);
|
std::ofstream fou(filename);
|
||||||
|
|
||||||
|
@@ -70,6 +70,21 @@ namespace imc
|
|||||||
// identify type
|
// identify type
|
||||||
short int& dtype() { return dtidx_; }
|
short int& dtype() { return dtidx_; }
|
||||||
|
|
||||||
|
// copy constructor
|
||||||
|
datatype(const datatype &num)
|
||||||
|
{
|
||||||
|
this->ubyte_ = num.ubyte_;
|
||||||
|
this->sbyte_ = num.sbyte_;
|
||||||
|
this->ushort_ = num.ushort_;
|
||||||
|
this->sshort_ = num.sshort_;
|
||||||
|
this->ulint_ = num.ulint_;
|
||||||
|
this->slint_ = num.slint_;
|
||||||
|
this->sfloat_ = num.sfloat_;
|
||||||
|
this->sdouble_ = num.sdouble_;
|
||||||
|
this->sdigital_ = num.sdigital_;
|
||||||
|
this->dtidx_ = num.dtidx_;
|
||||||
|
}
|
||||||
|
|
||||||
// overall assignment operator
|
// overall assignment operator
|
||||||
datatype& operator=(const datatype &num)
|
datatype& operator=(const datatype &num)
|
||||||
{
|
{
|
||||||
|
@@ -501,16 +501,16 @@ namespace imc
|
|||||||
second_ = std::stod( get_parameter(buffer,¶meters[7]) );
|
second_ = std::stod( get_parameter(buffer,¶meters[7]) );
|
||||||
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm* ts;
|
struct tm ts;
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
ts = localtime(&rawtime);
|
localtime_r(&rawtime,&ts);
|
||||||
ts->tm_mday = day_;
|
ts.tm_mday = day_;
|
||||||
ts->tm_mon = month_-1;
|
ts.tm_mon = month_-1;
|
||||||
ts->tm_year = year_-1900;
|
ts.tm_year = year_-1900;
|
||||||
ts->tm_hour = hour_;
|
ts.tm_hour = hour_;
|
||||||
ts->tm_min = minute_;
|
ts.tm_min = minute_;
|
||||||
ts->tm_sec = (int)second_;
|
ts.tm_sec = (int)second_;
|
||||||
timestamp_ = asctime(ts);
|
asctime_r(&ts,×tamp_[0]);
|
||||||
// timestamp_ = std::to_string(year_) + std::string("-") + std::to_string(month_)
|
// timestamp_ = std::to_string(year_) + std::string("-") + std::to_string(month_)
|
||||||
// + std::string("-") + std::to_string(day_)
|
// + std::string("-") + std::to_string(day_)
|
||||||
// + std::string("T") + std::to_string(hour_)
|
// + std::string("T") + std::to_string(hour_)
|
||||||
|
@@ -174,7 +174,7 @@ namespace imc
|
|||||||
// check consistency of blocks
|
// check consistency of blocks
|
||||||
void check_consistency()
|
void check_consistency()
|
||||||
{
|
{
|
||||||
for ( unsigned long int b = 0; b < this->rawblocks_.size()-1; b++ )
|
for ( unsigned long int b = 0; b < this->rawblocks_.size()-1 && this->rawblocks_.size() > 0; b++ )
|
||||||
{
|
{
|
||||||
if ( this->rawblocks_[b].get_end() >= this->rawblocks_[b+1].get_begin() )
|
if ( this->rawblocks_[b].get_end() >= this->rawblocks_[b+1].get_begin() )
|
||||||
{
|
{
|
||||||
@@ -300,7 +300,7 @@ namespace imc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// list a particular type of block
|
// list a particular type of block
|
||||||
std::vector<imc::block> list_blocks(imc::key mykey)
|
std::vector<imc::block> list_blocks(const imc::key &mykey)
|
||||||
{
|
{
|
||||||
std::vector<imc::block> myblocks;
|
std::vector<imc::block> myblocks;
|
||||||
for ( imc::block blk: this->rawblocks_ )
|
for ( imc::block blk: this->rawblocks_ )
|
||||||
@@ -332,14 +332,38 @@ namespace imc
|
|||||||
return channels;
|
return channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print all channels in directory
|
// print single specific channel
|
||||||
void print_channels(std::string output)
|
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
|
// check for given directory
|
||||||
std::filesystem::path pd = output;
|
std::filesystem::path pd = output;
|
||||||
if ( !std::filesystem::is_directory(pd) )
|
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<std::string,imc::channel>::iterator it = channels_.begin();
|
for ( std::map<std::string,imc::channel>::iterator it = channels_.begin();
|
||||||
@@ -352,7 +376,7 @@ namespace imc
|
|||||||
std::filesystem::path pf = pd / filenam;
|
std::filesystem::path pf = pd / filenam;
|
||||||
|
|
||||||
// and print the channel
|
// and print the channel
|
||||||
it->second.print(pf);
|
it->second.print(pf,sep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
makefile
8
makefile
@@ -53,6 +53,12 @@ cpp-clean :
|
|||||||
rm -vf $(EXE)
|
rm -vf $(EXE)
|
||||||
rm -vf *.o
|
rm -vf *.o
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
# linter and code check
|
||||||
|
|
||||||
|
check-code:
|
||||||
|
cppcheck --enable=all -I lib/ src/main.cpp
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
||||||
# check version consistency of git tags and version string in package.json
|
# check version consistency of git tags and version string in package.json
|
||||||
|
|
||||||
@@ -87,7 +93,7 @@ cython-install : check-vtag $(CTAG) $(CYT)setup.py $(CYT)imc_termite.pxd $(CYT)p
|
|||||||
cython-clean :
|
cython-clean :
|
||||||
rm -vf imc_termite.cpython-*.so
|
rm -vf imc_termite.cpython-*.so
|
||||||
rm -vf $(PYT)imc_termite.cpython-*.so
|
rm -vf $(PYT)imc_termite.cpython-*.so
|
||||||
rm -rv build/
|
rm -rvf build/
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
||||||
# pip
|
# pip
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
||||||
|
|
||||||
import glob
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# find source files
|
# find source files
|
||||||
|
@@ -11,6 +11,9 @@ sdist: ../cython/py_imc_termite.pyx ../cython/imc_termite.pxd ../cython/py_imc_t
|
|||||||
cp -v ../LICENSE ./
|
cp -v ../LICENSE ./
|
||||||
python3 setup.py sdist
|
python3 setup.py sdist
|
||||||
|
|
||||||
|
# authentication:
|
||||||
|
# - username: __token__
|
||||||
|
# - password: <token value including pypi-prefix>
|
||||||
upload:
|
upload:
|
||||||
python3 -m twine upload dist/$(shell ls -t dist/ | head -n1)
|
python3 -m twine upload dist/$(shell ls -t dist/ | head -n1)
|
||||||
|
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
|
|
||||||
from setuptools import setup, Extension
|
from setuptools import setup, Extension
|
||||||
import os
|
|
||||||
|
|
||||||
with open("README.md", "r", encoding="utf-8") as fh:
|
with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="IMCtermite",
|
name="IMCtermite",
|
||||||
version="1.2.3",
|
version="1.2.4",
|
||||||
author="Record Evolution GmbH",
|
author="Record Evolution GmbH",
|
||||||
author_email="mario.fink@record-evolution.de",
|
author_email="mario.fink@record-evolution.de",
|
||||||
maintainer="Record Evolution GmbH",
|
maintainer="Record Evolution GmbH",
|
||||||
|
@@ -5,19 +5,18 @@ import raw_eater
|
|||||||
import raw_meat
|
import raw_meat
|
||||||
import pyarrow as pa
|
import pyarrow as pa
|
||||||
import pyarrow.parquet as pq
|
import pyarrow.parquet as pq
|
||||||
import glob
|
|
||||||
from pathlib import Path
|
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]
|
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]
|
rawlist2 = [str(fl) for fl in fileobj2]
|
||||||
|
|
||||||
rawlist = rawlist1 #[rawlist1[0],rawlist1[4],rawlist2[0],rawlist2[6]]
|
rawlist = rawlist1 #[rawlist1[0],rawlist1[4],rawlist2[0],rawlist2[6]]
|
||||||
for fil in rawlist2 :
|
for fil in rawlist2 :
|
||||||
rawlist.append(fil)
|
rawlist.append(fil)
|
||||||
rawlist.append("smp/pressure_Vacuum.asc")
|
rawlist.append("./README.md")
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
print(rawlist)
|
print(rawlist)
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
import imc_termite
|
import imc_termite
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
# declare and initialize instance of "imctermite" by passing a raw-file
|
# declare and initialize instance of "imctermite" by passing a raw-file
|
||||||
try :
|
try :
|
||||||
imcraw = imc_termite.imctermite(b"samples/sampleA.raw")
|
imcraw = imc_termite.imctermite(b"samples/exampleB.raw")
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
raise Exception("failed to load/parse raw-file: " + str(e))
|
raise Exception("failed to load/parse raw-file: " + str(e))
|
||||||
|
|
||||||
@@ -22,7 +23,16 @@ print(len(chnydata))
|
|||||||
print(len(chnxdata))
|
print(len(chnxdata))
|
||||||
|
|
||||||
# print the channels into a specific directory
|
# 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
|
# print all channels in single file
|
||||||
imcraw.print_table(b"./allchannels.csv")
|
# imcraw.print_table(b"./data/allchannels.csv")
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
|
|
||||||
import imc_termite
|
import imc_termite
|
||||||
import json
|
import json
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# list files in sample directory
|
# list files in sample directory
|
||||||
# fileobj1 = Path("samples/").rglob("*.raw")
|
# fileobj1 = Path("samples/").rglob("*.raw")
|
||||||
|
82
src/main.cpp
82
src/main.cpp
@@ -32,25 +32,37 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
|||||||
// parse all CLI arguments
|
// parse all CLI arguments
|
||||||
for ( int i = 1; i < argc; i++ )
|
for ( int i = 1; i < argc; i++ )
|
||||||
{
|
{
|
||||||
if ( std::string(argv[i]) == std::string("--showmeta")
|
// if ( std::string(argv[i]) == std::string("--showmeta")
|
||||||
|| std::string(argv[i]) == std::string("-m") )
|
// || std::string(argv[i]) == std::string("-m") )
|
||||||
{
|
// {
|
||||||
prsdkeys.insert(std::pair<std::string,std::string>("showmeta",argv[i]));
|
// prsdkeys.insert(std::pair<std::string,std::string>("showmeta",argv[i]));
|
||||||
}
|
// }
|
||||||
// else if ( std::string(argv[i]) == std::string("--listgroups")
|
// else if ( std::string(argv[i]) == std::string("--listgroups")
|
||||||
// || std::string(argv[i]) == std::string("-g") )
|
// || std::string(argv[i]) == std::string("-g") )
|
||||||
// {
|
// {
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("listgroups",argv[i]));
|
// prsdkeys.insert(std::pair<std::string,std::string>("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") )
|
|| std::string(argv[i]) == std::string("-c") )
|
||||||
{
|
{
|
||||||
prsdkeys.insert(std::pair<std::string,std::string>("listchannels",argv[i]));
|
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")
|
else if ( std::string(argv[i]) == std::string("--listblocks")
|
||||||
|| std::string(argv[i]) == std::string("-b") )
|
|| std::string(argv[i]) == std::string("-b") )
|
||||||
{
|
{
|
||||||
prsdkeys.insert(std::pair<std::string,std::string>("listblocks",argv[i]));
|
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")
|
else if ( std::string(argv[i]) == std::string("--output")
|
||||||
|| std::string(argv[i]) == std::string("-d") )
|
|| std::string(argv[i]) == std::string("-d") )
|
||||||
@@ -66,6 +78,20 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
|||||||
i = i + 1;
|
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")
|
else if ( std::string(argv[i]) == std::string("--help")
|
||||||
|| std::string(argv[i]) == std::string("-h") )
|
|| std::string(argv[i]) == std::string("-h") )
|
||||||
{
|
{
|
||||||
@@ -84,13 +110,13 @@ optkeys parse_args(int argc, char* argv[], bool list_args = false)
|
|||||||
std::cerr<<"invalid or unkown argument: "<<argv[i]<<"\n";
|
std::cerr<<"invalid or unkown argument: "<<argv[i]<<"\n";
|
||||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
||||||
}
|
}
|
||||||
// or missing filenames
|
// // or missing filenames
|
||||||
else if ( std::string(argv[i]).find(".raw") == std::string::npos )
|
// 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!): "
|
// std::cerr<<"doesn't look like a .raw file (make sure to include extension in filename!): "
|
||||||
<<argv[i]<<"\n";
|
// <<argv[i]<<"\n";
|
||||||
prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
// prsdkeys.insert(std::pair<std::string,std::string>("invalid",argv[i]));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +147,13 @@ void show_usage()
|
|||||||
<<" -c, --listchannels list channels\n"
|
<<" -c, --listchannels list channels\n"
|
||||||
<<" -b, --listblocks list IMC key-blocks\n"
|
<<" -b, --listblocks list IMC key-blocks\n"
|
||||||
<<" -d, --output output directory to print channels\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"
|
<<" -h, --help show this help message \n"
|
||||||
<<" -v, --version display version\n"
|
<<" -v, --version display version\n"
|
||||||
<<"\n";
|
<<"\n"
|
||||||
|
<<"Example:"
|
||||||
|
<<" $ ./imctermite sample/data_A.raw -c -b -d ./data -s ','"
|
||||||
|
<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------//
|
||||||
@@ -178,6 +208,13 @@ int main(int argc, char* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// catch invalid or empty ".raw" file
|
||||||
|
if ( imcraw.blocks().size() == 0 )
|
||||||
|
{
|
||||||
|
std::cerr<<"this appears to be an empty/invalid '.raw' file since no blocks were found"<<"\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// list blocks
|
// list blocks
|
||||||
if ( cfgopts.count("listblocks") == 1 )
|
if ( cfgopts.count("listblocks") == 1 )
|
||||||
{
|
{
|
||||||
@@ -202,7 +239,22 @@ int main(int argc, char* argv[])
|
|||||||
if ( cfgopts.count("output") == 1 )
|
if ( cfgopts.count("output") == 1 )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
imcraw.print_channels(cfgopts.at("output"));
|
// 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);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr<<"failed to print channels for "<<rawfile<<": "<<e.what()<<"\n";
|
std::cerr<<"failed to print channels for "<<rawfile<<": "<<e.what()<<"\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user