diff --git a/lib/tdm_reaper.cpp b/lib/tdm_reaper.cpp index 36bbb60..68b4a1a 100644 --- a/lib/tdm_reaper.cpp +++ b/lib/tdm_reaper.cpp @@ -660,6 +660,107 @@ void tdm_reaper::print_channel(std::string &id, const char* filename, bool inclu fou.close(); } +void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta) +{ + // check for group id + if ( this->tdmchannelgroups_.count(id) != 1 ) + { + throw std::invalid_argument(std::string("channelgroup id does not exist: ") + id); + } + else + { + // 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 group") + + e.what() ); + } + + // get group object + tdm_channelgroup chngrp = this->tdmchannelgroups_.at(id); + + int width = 25; + + if ( include_meta ) + { + // group meta data + fou<<"# "< grpschs; + for ( std::string chn: chngrp.channels_ ) + { + if ( this->tdmchannels_.count(chn) == 1 ) + { + grpschs.push_back(this->tdmchannels_.at(chn)); + } + else + { + throw std::runtime_error("channel not found"); + } + } + + fou<<"# "; + for ( tdm_channel chn: grpschs ) fou<> allchns; + unsigned int maxrows = 0; // TODO use submatrix info to determine rows!!! + for ( std::string chn: chngrp.channels_ ) + { + std::vector chndat = this->get_channel(chn); + if ( chndat.size() > maxrows ) maxrows = chndat.size(); + allchns.push_back(chndat); + } + + for ( unsigned int row = 0; row < maxrows; row++ ) + { + for ( unsigned int chi = 0; chi < chngrp.channels_.size(); chi++ ) + { + if ( allchns.at(chi).size() > row ) + { + fou< diff --git a/lib/tdm_reaper.hpp b/lib/tdm_reaper.hpp index f211ebf..cd4e347 100644 --- a/lib/tdm_reaper.hpp +++ b/lib/tdm_reaper.hpp @@ -188,7 +188,7 @@ public: // 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); + void print_group(std::string &id, const char* filename, bool include_meta = true); private: diff --git a/src/main.cpp b/src/main.cpp index 0101c9a..8ab92e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -201,11 +201,12 @@ int main(int argc, char* argv[]) std::cout<(formatter)<<"\n"; std::cout<(formatter)<<"\n"; - // std::vector chgrids = jack.get_channelgroup_ids(); - // for ( auto id: chgrids ) - // { - // - // } + std::vector chgrids = jack.get_channelgroup_ids(); + for ( auto id: chgrids ) + { + std::string filenam = std::string("channelgroup_") + id + std::string(".dat"); + jack.print_group(id,filenam.c_str(),true); + } std::vector chids = jack.get_channel_ids(); for ( auto id: chids )