From f4ecf48218e0c6f22fb7e0505e253ddad012339e Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Wed, 10 Feb 2021 20:01:11 +0100 Subject: [PATCH] start group - channel - component - buffer association --- lib/imc_block.hpp | 16 +++++++++ lib/imc_key.hpp | 2 +- lib/imc_raw.hpp | 86 ++++++++++++++++++++++++++++++++++++++++++++-- lib/imc_result.hpp | 30 ++++++++++++++++ src/main.cpp | 9 +++-- 5 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 lib/imc_result.hpp diff --git a/lib/imc_block.hpp b/lib/imc_block.hpp index 967f083..2596c52 100644 --- a/lib/imc_block.hpp +++ b/lib/imc_block.hpp @@ -142,6 +142,22 @@ namespace imc return parambuff; } + // get single parameter as string + std::string get_parameter(parameter& param) + { + // check parameter w.r.t. to block + if ( param.begin() < begin_ || param.end() > end_ ) + { + throw std::logic_error("inconsistent parameter offsets"); + } + std::string prm(""); + for ( unsigned long int i = param.begin()+1; i <= param.end(); i++ ) + { + prm.push_back( (char)((*buffer_)[i]) ); + } + return prm; + } + // get info string std::string get_info(bool include_object = true, int width = 20) { diff --git a/lib/imc_key.hpp b/lib/imc_key.hpp index 2d738f2..b561ecf 100644 --- a/lib/imc_key.hpp +++ b/lib/imc_key.hpp @@ -71,7 +71,7 @@ namespace imc {"CT", key(true,"CT","text definition",1)}, {"CG", key(true,"CG","group of components",1)}, {"CD", key(true,"CD","abscissa description",1)}, - {"CD", key(true,"CD","abscissa description",2)}, + // {"CD2", key(true,"CD","abscissa description",2)}, {"CZ", key(true,"CZ","scaling of z-axis",1)}, {"CC", key(true,"CC","start of component",1)}, {"CP", key(true,"CP","buffer, datatype and samples of component",1)}, diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index 26f0b05..90ae105 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -11,6 +11,7 @@ #include "imc_block.hpp" #include "imc_datatype.hpp" #include "imc_object.hpp" +#include "imc_result.hpp" //---------------------------------------------------------------------------// @@ -233,9 +234,90 @@ namespace imc } // list all channels - std::vector list_channels() + std::vector list_channels() { - return this->list_blocks(imc::keys.at("CN")); + std::vector channels; + for ( imc::block blk: this->rawblocks_ ) + { + if ( blk.get_key() == imc::keys.at("CN") ) + { + imc::parameter prm = blk.get_parameters()[6]; + channels.push_back(blk.get_parameter(prm)); + } + } + + return channels; + } + + // get specific channel data + // TODO generalize and simplify channel extraction!! + imc::channel_tab get_channel(std::string channel) + { + // declare single channel table + imc::channel_tab chtab; + + // ordinate parameters + std::string yunit = std::string(""); + unsigned long int num_samples = -1; + // imc::datatype dtype; + int numbits = -1; + double yoffset = -1.0, yfactor = -1.0; + + // abscissa parameters + double dx = -1.0; + double xoffset = -1.0; + std::string xunit = std::string(""); + + // search block for required parameters + for ( imc::block blk: this->rawblocks_ ) + { + if ( blk.get_key() == imc::keys.at("CR") ) + { + yunit = blk.get_parameter(blk.get_parameters()[7]); + } + + if ( blk.get_key() == imc::keys.at("Cb") ) + { + num_samples = std::stoul(blk.get_parameter(blk.get_parameters()[7])); + xoffset = std::stod(blk.get_parameter(blk.get_parameters()[11])); + } + + if ( blk.get_key() == imc::keys.at("CP") ) + { + numbits = std::stoi(blk.get_parameter(blk.get_parameters()[5])); + } + + if ( blk.get_key() == imc::keys.at("CR") ) + { + yfactor = std::stod(blk.get_parameter(blk.get_parameters()[3])); + yoffset = std::stod(blk.get_parameter(blk.get_parameters()[4])); + yunit = blk.get_parameter(blk.get_parameters()[7]); + } + + if ( blk.get_key() == imc::keys.at("CD") ) + { + std::cout<<"got CD\n"; + dx = std::stod(blk.get_parameter(blk.get_parameters()[2])); + xunit = blk.get_parameter(blk.get_parameters()[7]); + } + } + + std::cout<<"yunit:"< xaxis_; + std::string xunit_; + + // ordinate + // std::vector yaxis_; + std::vector yaxis_; + std::string yunit_; + }; + +} + +#endif + +//---------------------------------------------------------------------------// diff --git a/src/main.cpp b/src/main.cpp index 565da34..10957e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -193,8 +193,13 @@ int main(int argc, char* argv[]) // for ( auto blk: CSblocks ) std::cout< groups = imcraw.list_groups(); // for ( auto blk: groups ) std::cout< channels = imcraw.list_channels(); - // for ( auto blk: channels ) std::cout< channels = imcraw.list_channels(); + // for ( auto chn: channels ) + // { + // std::cout<