CLI version: add option for delimiter token of csv output
This commit is contained in:
parent
fdd107fbb3
commit
bafc018566
@ -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);
|
||||
|
||||
|
@ -333,7 +333,7 @@ namespace imc
|
||||
}
|
||||
|
||||
// print all channels in directory
|
||||
void print_channels(std::string output)
|
||||
void print_channels(std::string output, const char sep)
|
||||
{
|
||||
// check for given directory
|
||||
std::filesystem::path pd = output;
|
||||
@ -352,7 +352,7 @@ namespace imc
|
||||
std::filesystem::path pf = pd / filenam;
|
||||
|
||||
// and print the channel
|
||||
it->second.print(pf);
|
||||
it->second.print(pf,sep);
|
||||
}
|
||||
}
|
||||
|
||||
|
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 -rv build/
|
||||
rm -rvf build/
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# pip
|
||||
|
26
src/main.cpp
26
src/main.cpp
@ -66,6 +66,20 @@ 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 --output 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") )
|
||||
{
|
||||
@ -121,9 +135,13 @@ 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";
|
||||
<<"\n"
|
||||
<<"Example:"
|
||||
<<" $ ./imctermite sample/data_A.raw -c -b -d ./data -s ','"
|
||||
<<"\n\n";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
@ -209,7 +227,11 @@ int main(int argc, char* argv[])
|
||||
if ( cfgopts.count("output") == 1 )
|
||||
{
|
||||
try {
|
||||
imcraw.print_channels(cfgopts.at("output"));
|
||||
if ( cfgopts.at("delimiter").size() > 1 )
|
||||
{
|
||||
throw std::runtime_error("invalid delimiter comprised of more than a single char");
|
||||
}
|
||||
imcraw.print_channels(cfgopts.at("output"),cfgopts.at("delimiter")[0]);
|
||||
} 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