From a6ab3daf874b073af94df4838e8c017345bf46e2 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Fri, 22 Jan 2021 18:38:17 +0100 Subject: [PATCH] print channels --- lib/tdm_reaper.cpp | 34 +++++++++++++++++++++++++++++----- lib/tdm_reaper.hpp | 6 +++++- src/main.cpp | 29 ++++++++++------------------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/lib/tdm_reaper.cpp b/lib/tdm_reaper.cpp index 7e9752e..36bbb60 100644 --- a/lib/tdm_reaper.cpp +++ b/lib/tdm_reaper.cpp @@ -544,7 +544,6 @@ void tdm_reaper::summarize_member(block blk, std::string& summary, format& forma // -------------------------------------------------------------------------- // // extract channel by id -// template std::vector tdm_reaper::get_channel(std::string& id) { // check for existence of required channel id (=key) @@ -625,14 +624,39 @@ std::vector tdm_reaper::get_channel(std::string& id) } } -void tdm_reaper::print_channel(std::string &id, const char* filename) +// -------------------------------------------------------------------------- // + +void tdm_reaper::print_channel(std::string &id, const char* filename, bool include_meta) { - std::ofstream fou(filename); + // declare file stream + std::ofstream fou; + try { + fou.open(filename); + } catch ( const std::exception& e) { + throw std::runtime_error( std::string("failed to open file to dump channel") + + e.what() ); + } - std::vector chn; // = this->get_channel(id); + // get channel object + tdm_channel chn = this->tdmchannels_.at(id); + if ( include_meta ) + { + int width = 20; + fou< chndata = this->get_channel(id); + for ( auto el: chndata ) fou< std::string get_overview(format formatter); +private: void summarize_member(submatrix sbm, std::string& summary, format& formatter); void summarize_member(localcolumn lcc, std::string& summary, format& formatter); void summarize_member(block blk, std::string& summary, format& formatter); +public: // get list of channelgroup ids std::vector get_channelgroup_ids() @@ -184,7 +186,9 @@ public: // extract channel by id std::vector get_channel(std::string& id); - void print_channel(std::string &id, const char* filename); + // 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_group(std::string &id, const char* filename); private: diff --git a/src/main.cpp b/src/main.cpp index 1b84161..0101c9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -201,29 +201,20 @@ int main(int argc, char* argv[]) std::cout<(formatter)<<"\n"; std::cout<(formatter)<<"\n"; - std::string chid("usi14"); - std::vector chdata = jack.get_channel(chid); - - std::cout<<"channel size: "< chgrids = jack.get_channelgroup_ids(); - // for ( auto el: chgrids ) std::cout< chids = jack.get_channel_ids(); - // for ( auto el: chids ) std::cout< chids = jack.get_channel_ids(); + for ( auto id: chids ) + { + std::string filenam = std::string("channel_") + id + std::string(".dat"); + // std::vector chdata = jack.get_channel(id); + jack.print_channel(id,filenam.c_str(),true); + } + // print list of groups or channels to stdout // if ( listgroups ) jack.list_groups(); // if ( listchannels ) jack.list_channels();