activate support for implicit_linear/raw_linear representation
This commit is contained in:
@@ -302,6 +302,22 @@ struct localcolumn {
|
||||
std::string values_; // -> refers to usi:data -> _sequence
|
||||
std::string external_id_;
|
||||
|
||||
localcolumn () {
|
||||
id_ = std::string("");
|
||||
name_ = std::string("");
|
||||
description_ = std::string("");
|
||||
measurement_quantity_ = std::string("");
|
||||
submatrix_ = std::string("");
|
||||
global_flag_ = 15;
|
||||
independent_ = 0;
|
||||
minimum_ = 0.0;
|
||||
maximum_ = 0.0;
|
||||
sequence_representation_ = std::string("explicit");
|
||||
generation_parameters_ = { 0.0, 1.0 };
|
||||
values_ = std::string("");
|
||||
external_id_ = std::string("");
|
||||
}
|
||||
|
||||
const std::string get_info() { return get_info(defformat); }
|
||||
const std::string get_info(format& formatter)
|
||||
{
|
||||
@@ -313,6 +329,7 @@ struct localcolumn {
|
||||
std::make_pair("minimum",std::to_string(minimum_)),
|
||||
std::make_pair("maximum",std::to_string(maximum_)),
|
||||
std::make_pair("sequence_representation",sequence_representation_),
|
||||
std::make_pair("generation_parameters",join<double>(generation_parameters_)),
|
||||
std::make_pair("values",values_),
|
||||
std::make_pair("external",external_id_) });
|
||||
|
||||
|
@@ -107,7 +107,7 @@ public:
|
||||
// obtain number as double
|
||||
double as_double()
|
||||
{
|
||||
double num;
|
||||
double num = 0.0;
|
||||
if ( dtidx_ == 0 ) num = (double)sint16_;
|
||||
else if ( dtidx_ == 1 ) num = (double)sint32_;
|
||||
else if ( dtidx_ == 2 ) num = (double)uint8_;
|
||||
|
@@ -100,6 +100,20 @@ static std::string join_strings(std::vector<std::string> &thestring, const char*
|
||||
return joined;
|
||||
}
|
||||
|
||||
// join a list of numbers
|
||||
template<class numtype>
|
||||
static std::string join(std::vector<numtype> &thevec, const char* sep = " ")
|
||||
{
|
||||
std::string joined;
|
||||
for ( unsigned int i = 0; i < thevec.size(); i++ )
|
||||
{
|
||||
joined += std::to_string(thevec.at(i));
|
||||
if ( i+1 < thevec.size() ) joined += std::string(sep);
|
||||
}
|
||||
|
||||
return joined;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
@@ -352,8 +352,22 @@ void tdm_reaper::process_localcolumns(bool showlog, pugi::xml_document& xml_doc)
|
||||
lcmax = lcmax.empty() ? std::string("0.0") : lcmax;
|
||||
locc.maximum_ = std::stod(lcmax);
|
||||
locc.sequence_representation_ = loccol.child_value("sequence_representation");
|
||||
// TODO
|
||||
// .... loccal.child_value("generation_parameters");
|
||||
std::string genpar = loccol.child_value("generation_parameters");
|
||||
// check for any given generation parameters (applies to 'implicit_linear' channels only)
|
||||
if ( !genpar.empty() )
|
||||
{
|
||||
// check for two floats
|
||||
std::vector<std::string> params = this->split(genpar,std::string(" "));
|
||||
if ( params.size() == 2 )
|
||||
{
|
||||
// remove default elements and insert new numbers
|
||||
locc.generation_parameters_.clear();
|
||||
for ( std::string el: params )
|
||||
{
|
||||
locc.generation_parameters_.push_back(std::stod(el));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> vl = this->extract_ids(loccol.child_value("values"));
|
||||
if ( vl.size() == 1 )
|
||||
@@ -541,10 +555,13 @@ std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
|
||||
}
|
||||
localcolumn loccol = localcolumns_.at(chn.local_columns_[0]);
|
||||
|
||||
if ( loccol.sequence_representation_ != "explicit" )
|
||||
// check sequence_representation
|
||||
if ( loccol.sequence_representation_ != "explicit"
|
||||
&& loccol.sequence_representation_ != "implicit_linear"
|
||||
&& loccol.sequence_representation_ != "raw_linear" )
|
||||
{
|
||||
throw std::runtime_error(std::string("unsupported sequence_representation: ")
|
||||
+ loccol.sequence_representation_);
|
||||
+ loccol.sequence_representation_ );
|
||||
}
|
||||
|
||||
// use "values" id to map to external block
|
||||
@@ -598,6 +615,26 @@ std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
|
||||
throw std::runtime_error(std::string("unsupported/unknown datatype") + blk.value_type_);
|
||||
}
|
||||
|
||||
// apply offset and factor for implicit_linear and raw_linear representation
|
||||
if ( loccol.sequence_representation_ == "implicit_linear"
|
||||
|| loccol.sequence_representation_ == "raw_linear" )
|
||||
{
|
||||
// datatype has to be 'DT_DOUBLE' for these representations
|
||||
if ( chn.datatype_ != std::string("DT_DOUBLE") )
|
||||
{
|
||||
throw std::runtime_error( std::string("inconsistent sequence_representation and datatype: ")
|
||||
+ chn.id_ + std::string(",") + loccol.sequence_representation_
|
||||
+ std::string(",") + chn.datatype_ );
|
||||
}
|
||||
|
||||
// scale and shift channel
|
||||
for ( auto &el: datavec )
|
||||
{
|
||||
el = loccol.generation_parameters_[0]
|
||||
+ el.as_double()*loccol.generation_parameters_[1];
|
||||
}
|
||||
}
|
||||
|
||||
return datavec;
|
||||
}
|
||||
else
|
||||
@@ -754,7 +791,14 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
||||
}
|
||||
else
|
||||
{
|
||||
fou<<std::setw(width)<<std::left<<"";
|
||||
if ( sep == ' ' )
|
||||
{
|
||||
fou<<std::setw(width)<<std::left<<"";
|
||||
}
|
||||
else
|
||||
{
|
||||
fou<<sep;
|
||||
}
|
||||
}
|
||||
|
||||
if ( chi+1 < chngrp.channels_.size() ) fou<<sep;
|
||||
|
@@ -80,6 +80,37 @@ class tdm_reaper
|
||||
return listofids;
|
||||
}
|
||||
|
||||
// split string into substrings by delimiting string
|
||||
std::vector<std::string> split(std::string fullstring, std::string delstr)
|
||||
{
|
||||
// declare array of resulting strings
|
||||
std::vector<std::string> splitstrings(0);
|
||||
|
||||
// parse input string for substring
|
||||
while ( fullstring.find(delstr) != std::string::npos )
|
||||
{
|
||||
// find first occurence of delimiting string in 'mystring'
|
||||
std::size_t delpos = fullstring.find(delstr);
|
||||
|
||||
// extract substring
|
||||
std::string stringel = fullstring.substr(0,delpos);
|
||||
|
||||
// append first word to array
|
||||
if ( !stringel.empty() )
|
||||
{
|
||||
splitstrings.push_back(stringel);
|
||||
}
|
||||
|
||||
// remove first word from 'fullstring'
|
||||
fullstring = fullstring.substr(delpos+delstr.size(),fullstring.size());
|
||||
}
|
||||
|
||||
// append last word to array
|
||||
splitstrings.push_back(fullstring);
|
||||
|
||||
return splitstrings;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// encoding
|
||||
|
Reference in New Issue
Block a user