- add cython .cpp files to .gitignore

- raweat.hpp: add empty constructor and introduce "set_file"
- rawmerge.hpp: add initial channel and write_table method
- add rawmeat example to pyt/example.py
- add raw_merger.hpp to main.cpp
This commit is contained in:
Mario Fink 2020-08-10 14:54:15 +02:00
parent 23f933f68e
commit 7316d59c2c
5 changed files with 120 additions and 8 deletions

2
.gitignore vendored
View File

@ -12,4 +12,6 @@ nohup.out
raw_eater.cpp
cyt/*.cpp
*.o

View File

@ -83,6 +83,27 @@ public:
this->setup_and_conversion(showlog);
}
raw_eater()
{
}
// provide/set new raw file
void set_file(std::string rawfile)
{
std::cout<<"raw_eater::set_file "<<rawfile<<"\n";
// set file
rawfile_ = rawfile;
// reset arrays
datasec_.clear();
segments_.clear();
datmes_.clear();
// do setup and conversion
setup_and_conversion(true);
}
// set up and conversion
void setup_and_conversion(bool showlog)
{

View File

@ -21,16 +21,24 @@ private:
// number of channels
int num_channels_;
// (merged) channel data
// (merged) channel data related to SINGLE time series
std::vector<std::vector<double>> channels_;
std::vector<double> timeseries_;
// channel meta data
// temporal unit and channel meta data
std::string temp_unit_;
std::vector<std::string> channel_names_;
public:
// constructor
raw_merger(std::string rawfile): raw_eater(rawfile)
{
// add first initial channel
this->add_channel(rawfile);
}
raw_merger(): raw_eater()
{
}
@ -44,17 +52,92 @@ public:
// add a single channel and its associated time series
bool add_channel(std::string rawfile)
{
return true;
// set raw file and perform conversion
this->set_file(rawfile);
// add first/initial time series (and channel data)
if ( timeseries_.size() == 0 && channels_.size() == 0 )
{
std::cout<<"adding first channel\n";
// insert timeseries and its unit
timeseries_ = this->get_time();
temp_unit_ = this->get_temp_unit();
// insert channel data and its meta data
channels_.push_back(this->get_data());
channel_names_.push_back(this->get_name() + std::string(" [")
+ this->get_unit() + std::string("]"));
return true;
}
else
{
// TODO check consistency of time series, time unit, channels....
return false;
}
}
// print all data to file
void write_table(std::string filename, char delimiter = ',', int precision = 6, int width = 25)
{
// if at least one channel including its time series is present
if ( timeseries_.size() > 0 && channels_.size() > 0 )
{
// open file
std::ofstream fout(filename.c_str());
if ( fout.good() )
{
// define temporal column header
std::string colTime = std::string("Time [") + temp_unit_ + std::string("]");
// write header
if ( delimiter != ' ' )
{
fout<<colTime;
for ( std::string chnam: this->channel_names_ ) fout<<delimiter<<chnam;
}
else
{
fout<<std::setw(width)<<std::right<<colTime;
for ( std::string chnam: this->channel_names_ ) fout<<std::setw(width)<<std::right<<chnam;
}
fout<<"\n";
// write actual time and channel data
unsigned long int tidx = 0;
for ( double ti: this->timeseries_ )
{
if ( delimiter != ' ' )
{
fout<<std::fixed<<std::dec<<std::setprecision(precision)<<ti;
for ( std::vector<double> chn: this->channels_ )
{
fout<<delimiter<<std::dec<<std::setprecision(precision)<<chn[tidx];
}
}
else
{
fout<<std::fixed<<std::dec<<std::setprecision(precision)
<<std::setw(width)<<std::right<<ti;
for ( std::vector<double> chn: this->channels_ )
{
fout<<std::fixed<<std::dec<<std::setprecision(precision)
<<std::setw(width)<<std::right<<chn[tidx];
}
}
fout<<"\n";
// count number of samples
tidx++;
}
// close file
fout.close();
}
}
}
};
#endif

View File

@ -15,7 +15,8 @@ for rf in rawlist :
print("converting " + str(rf) + "...\n" + 90*("-") + "\n")
# setup instance of "raw_eater" and trigger conversion
eatraw = raw_eater.raweater(rf.encode())
# eatraw = raw_eater.raweater(rf.encode())
eatraw = raw_meat.rawmerger(rf.encode())
# check validity of file format
if eatraw.validity() :

View File

@ -30,7 +30,10 @@ int main(int argc, char* argv[])
std::string rawfile(argv[1]);
// declare instance of "raw_eater"
raw_eater eatraw(rawfile,true);
// raw_eater eatraw(rawfile,true);
// declare instance of "raw_merger"
raw_merger eatmea(rawfile);
//eatraw.show_markers();
@ -58,8 +61,10 @@ int main(int argc, char* argv[])
// for ( unsigned long int i = 0; i < 10; i++ ) std::cout<<mydata[i]<<"\n";
// write data in csv-file
eatraw.write_table(std::string(argv[2]));
// eatraw.write_table(std::string(argv[2]));
// eatraw.write_table(std::string(argv[2]),' ');
// eatmea.write_table(std::string(argv[2]));
eatmea.write_table(std::string(argv[2]),' ');
return 0;
}