include/implement csvseparator option

This commit is contained in:
Mario Fink 2021-01-25 18:06:37 +01:00
parent 02adaa7908
commit 529b80f4f9
3 changed files with 25 additions and 7 deletions

View File

@ -673,7 +673,7 @@ void tdm_reaper::print_channel(std::string &id, const char* filename, bool inclu
fou.close(); fou.close();
} }
void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta) void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta, char sep)
{ {
// check for group id // check for group id
if ( this->tdmchannelgroups_.count(id) != 1 ) if ( this->tdmchannelgroups_.count(id) != 1 )
@ -758,13 +758,23 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
for ( unsigned int chi = 0; chi < chngrp.channels_.size(); chi++ ) for ( unsigned int chi = 0; chi < chngrp.channels_.size(); chi++ )
{ {
if ( allchns.at(chi).size() > row ) if ( allchns.at(chi).size() > row )
{
// use given csv separator token
if ( sep == ' ' )
{ {
fou<<std::setw(width)<<std::left<<allchns.at(chi).at(row); fou<<std::setw(width)<<std::left<<allchns.at(chi).at(row);
} }
else else
{
fou<<allchns.at(chi).at(row);
}
}
else
{ {
fou<<std::setw(width)<<std::left<<""; fou<<std::setw(width)<<std::left<<"";
} }
if ( chi+1 < chngrp.channels_.size() ) fou<<sep;
} }
fou<<"\n"; fou<<"\n";
} }

View File

@ -216,7 +216,7 @@ 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); void print_group(std::string &id, const char* filename, bool include_meta = true, char sep = ' ');
private: private:

View File

@ -191,11 +191,19 @@ optkeys parse_args(int argc, char* argv[], bool showargs = false)
|| std::string(argv[i]) == std::string("-s") ) || std::string(argv[i]) == std::string("-s") )
{ {
if ( argc > i+1 ) if ( argc > i+1 )
{
if ( std::string(argv[i+1]).size() == 1 )
{ {
prsdkeys.insert(std::pair<std::string,std::string>("csvsep",argv[i+1])); prsdkeys.insert(std::pair<std::string,std::string>("csvsep",argv[i+1]));
i += 1; i += 1;
} }
else else
{
std::cerr<<"invalid argument of --csvsep\n";
prsdkeys.insert(std::pair<std::string,std::string>("invalidoption",argv[i+1]));
}
}
else
{ {
std::cerr<<"missing argument for "<<argv[i]<<"\n"; std::cerr<<"missing argument for "<<argv[i]<<"\n";
prsdkeys.insert(std::pair<std::string,std::string>("invalidoption","")); prsdkeys.insert(std::pair<std::string,std::string>("invalidoption",""));
@ -335,7 +343,7 @@ int main(int argc, char* argv[])
std::filesystem::path outfile = pd / filenm; std::filesystem::path outfile = pd / filenm;
// write entire channelgroup to file // write entire channelgroup to file
jack.print_group(id,outfile.c_str(),includemeta); jack.print_group(id,outfile.c_str(),includemeta,csvsep.at(0));
} }
} }
} }