remove assertions, check validity of file format
This commit is contained in:
parent
3711a94f8b
commit
4ef68695b3
@ -71,6 +71,9 @@ private:
|
|||||||
// save all data, i.e. physical values of measured entities as 64bit double
|
// save all data, i.e. physical values of measured entities as 64bit double
|
||||||
std::vector<double> datmes_;
|
std::vector<double> datmes_;
|
||||||
|
|
||||||
|
// check format validity
|
||||||
|
bool valid_ = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@ -100,11 +103,18 @@ public:
|
|||||||
// extract data corresponding to predefined markers from buffer
|
// extract data corresponding to predefined markers from buffer
|
||||||
find_markers();
|
find_markers();
|
||||||
|
|
||||||
|
// proceed only, if markers suggest data is valid *.raw format
|
||||||
|
if ( valid_ )
|
||||||
|
{
|
||||||
// split data corresponding to markers into segments
|
// split data corresponding to markers into segments
|
||||||
split_segments();
|
split_segments();
|
||||||
|
|
||||||
// convert binary data to arrays of intrinsic data types
|
// convert binary data to arrays of intrinsic data types
|
||||||
convert_data(showlog);
|
convert_data(showlog);
|
||||||
|
|
||||||
|
// check result
|
||||||
|
if ( segments_.size() == 0 || datmes_.size() == 0 ) valid_ = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@ -203,9 +213,13 @@ public:
|
|||||||
}
|
}
|
||||||
totalmarksize += datasec_[mrk.first].size();
|
totalmarksize += datasec_[mrk.first].size();
|
||||||
}
|
}
|
||||||
assert ( totalmarksize > 0 && "didn't find any predefined marker => probably not a valid .raw-file" );
|
// std::cout<<"totalmarksize "<<totalmarksize<<"\n";
|
||||||
std::cout<<"\n";
|
|
||||||
|
|
||||||
|
// check validity of format
|
||||||
|
// assert ( totalmarksize > 0 && "didn't find any predefined marker => probably not a valid .raw-file" );
|
||||||
|
if ( totalmarksize < 100 ) valid_ = false;
|
||||||
|
|
||||||
|
std::cout<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all predefined markers
|
// get all predefined markers
|
||||||
@ -320,7 +334,13 @@ public:
|
|||||||
&& "internally inconsistent 'punit' marker" );
|
&& "internally inconsistent 'punit' marker" );
|
||||||
|
|
||||||
// just don't support weird datatypes
|
// just don't support weird datatypes
|
||||||
assert ( dattype > 2 && dattype < 12 );
|
// assert ( dattype > 2 && dattype < 12 );
|
||||||
|
if ( dattype == 9 || dattype == 10 || dattype > 11 )
|
||||||
|
{
|
||||||
|
valid_ = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
// switch for datatypes
|
// switch for datatypes
|
||||||
switch ( dattype )
|
switch ( dattype )
|
||||||
@ -384,6 +404,8 @@ public:
|
|||||||
}
|
}
|
||||||
std::cout<<"\n\n";
|
std::cout<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert bytes to specific datatype
|
// convert bytes to specific datatype
|
||||||
@ -455,51 +477,59 @@ public:
|
|||||||
std::cout<<std::dec;
|
std::cout<<std::dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get validity of format
|
||||||
|
bool get_valid()
|
||||||
|
{
|
||||||
|
return valid_;
|
||||||
|
}
|
||||||
|
|
||||||
// get timestep
|
// get timestep
|
||||||
double get_dt()
|
double get_dt()
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
|
|
||||||
return std::stod(segments_["sampl marker"][2]);
|
return valid_ ? std::stod(segments_["sampl marker"][2]) : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get time unit
|
// get time unit
|
||||||
std::string get_temp_unit()
|
std::string get_temp_unit()
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
|
|
||||||
return segments_["sampl marker"][5];
|
return valid_ ? segments_["sampl marker"][5] : std::string("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get name of measured entity
|
// get name of measured entity
|
||||||
std::string get_name()
|
std::string get_name()
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
|
|
||||||
return segments_["ename marker"][6];
|
return valid_ ? segments_["ename marker"][6] : std::string("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get unit of measured entity
|
// get unit of measured entity
|
||||||
std::string get_unit()
|
std::string get_unit()
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
|
|
||||||
return segments_["punit marker"][7];
|
return valid_ ? segments_["punit marker"][7] : std::string("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get time offset
|
// get time offset
|
||||||
double get_time_offset()
|
double get_time_offset()
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
|
|
||||||
return std::stod(segments_["minma marker"][11]);
|
return valid_ ? std::stod(segments_["minma marker"][11]) : -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get time array
|
// get time array
|
||||||
std::vector<double> get_time()
|
std::vector<double> get_time()
|
||||||
{
|
{
|
||||||
assert ( datmes_.size() > 0 );
|
// assert ( datmes_.size() > 0 );
|
||||||
|
|
||||||
|
if ( valid_ )
|
||||||
|
{
|
||||||
// declare array of time
|
// declare array of time
|
||||||
std::vector<double> timearr;
|
std::vector<double> timearr;
|
||||||
|
|
||||||
@ -515,6 +545,11 @@ public:
|
|||||||
|
|
||||||
return timearr;
|
return timearr;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::vector<double>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get size/length of data
|
// get size/length of data
|
||||||
unsigned long int get_n()
|
unsigned long int get_n()
|
||||||
@ -525,7 +560,7 @@ public:
|
|||||||
// get data array encoded as floats/doubles
|
// get data array encoded as floats/doubles
|
||||||
std::vector<double>& get_data()
|
std::vector<double>& get_data()
|
||||||
{
|
{
|
||||||
assert ( datmes_.size() > 0 );
|
// assert ( datmes_.size() > 0 );
|
||||||
|
|
||||||
return datmes_;
|
return datmes_;
|
||||||
}
|
}
|
||||||
@ -541,20 +576,22 @@ public:
|
|||||||
// write data to csv-like file
|
// write data to csv-like file
|
||||||
void write_data(std::string filename, int precision = 9, int width = 25)
|
void write_data(std::string filename, int precision = 9, int width = 25)
|
||||||
{
|
{
|
||||||
assert ( segments_.size() > 0 );
|
// assert ( segments_.size() > 0 );
|
||||||
assert ( datmes_.size() > 0 );
|
// assert ( datmes_.size() > 0 );
|
||||||
|
|
||||||
|
if ( valid_ )
|
||||||
|
{
|
||||||
// open file
|
// open file
|
||||||
std::ofstream fout(filename.c_str());
|
std::ofstream fout(filename.c_str());
|
||||||
|
|
||||||
// write header
|
// write header
|
||||||
// fout<<"# ";
|
// fout<<"# ";
|
||||||
std::string colA = std::string("Time [") + get_temp_unit() + std::string("]");
|
std::string colA = std::string("Time [") + get_temp_unit() + std::string("]");
|
||||||
std::string colB = get_name() + std::string(" [") + get_unit() + std::string("]");
|
std::string colB = get_name() + std::string(" [") + get_unit() + std::string("]");
|
||||||
if ( width > 0 )
|
if ( width > 0 )
|
||||||
{
|
{
|
||||||
// fout<<std::setw(width)<<std::left<<colA;
|
// fout<<std::setw(width)<<std::left<<colA;
|
||||||
// fout<<std::setw(width)<<std::left<<colB;
|
// fout<<std::setw(width)<<std::left<<colB;
|
||||||
fout<<std::setw(width)<<std::right<<"Time";
|
fout<<std::setw(width)<<std::right<<"Time";
|
||||||
fout<<std::setw(width)<<std::right<<get_name();
|
fout<<std::setw(width)<<std::right<<get_name();
|
||||||
fout<<"\n";
|
fout<<"\n";
|
||||||
@ -563,7 +600,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fout<<colA<<","<<colB;
|
// fout<<colA<<","<<colB;
|
||||||
fout<<"Time"<<","<<get_name()<<"\n";
|
fout<<"Time"<<","<<get_name()<<"\n";
|
||||||
fout<<get_temp_unit()<<";"<<get_unit();
|
fout<<get_temp_unit()<<";"<<get_unit();
|
||||||
}
|
}
|
||||||
@ -598,6 +635,7 @@ public:
|
|||||||
// close file
|
// close file
|
||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
import raw_eater
|
import raw_eater
|
||||||
|
|
||||||
eatraw = raw_eater.raweater(b"sample/pressure_Vacuum.raw")
|
eatraw = raw_eater.raweater(b"sample/pressure_Vacuum.raw")
|
||||||
|
# eatraw = raw_eater.raweater(b"/home/mario/Downloads/FAMOS_Datenformat_ab61.pdf")
|
||||||
|
|
||||||
|
print(str(eatraw.validity()))
|
||||||
|
|
||||||
print(eatraw.channel_name())
|
print(eatraw.channel_name())
|
||||||
print(eatraw.unit())
|
print(eatraw.unit())
|
||||||
|
@ -14,6 +14,8 @@ from libcpp cimport bool
|
|||||||
cdef extern from "lib/raweat.hpp":
|
cdef extern from "lib/raweat.hpp":
|
||||||
cdef cppclass raw_eater:
|
cdef cppclass raw_eater:
|
||||||
raw_eater(string) except +
|
raw_eater(string) except +
|
||||||
|
# get validity of data format
|
||||||
|
bool get_valid()
|
||||||
# get channel name and unit
|
# get channel name and unit
|
||||||
string get_name()
|
string get_name()
|
||||||
string get_unit()
|
string get_unit()
|
||||||
|
@ -14,6 +14,9 @@ cdef class raweater:
|
|||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
del self.rawit
|
del self.rawit
|
||||||
|
|
||||||
|
def validity(self):
|
||||||
|
return self.rawit.get_valid()
|
||||||
|
|
||||||
def channel_name(self):
|
def channel_name(self):
|
||||||
return self.rawit.get_name()
|
return self.rawit.get_name()
|
||||||
|
|
||||||
@ -34,4 +37,3 @@ cdef class raweater:
|
|||||||
|
|
||||||
def print(self, const char* csvfile):
|
def print(self, const char* csvfile):
|
||||||
return self.rawit.write_data(csvfile)
|
return self.rawit.write_data(csvfile)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user