started conversion of eInt types
This commit is contained in:
parent
6abb84ef7f
commit
9f2deae08a
@ -7,7 +7,6 @@ tdm_ripper::tdm_ripper(std::string tdmfile, std::string tdxfile):
|
|||||||
num_channels_group_(0), channels_group_(0),
|
num_channels_group_(0), channels_group_(0),
|
||||||
byteoffset_(0), length_(0), type_(0)
|
byteoffset_(0), length_(0), type_(0)
|
||||||
{
|
{
|
||||||
// TODO directly provide the C datatype to be used!!
|
|
||||||
datatypes_ = {
|
datatypes_ = {
|
||||||
{"eInt8Usi",8},
|
{"eInt8Usi",8},
|
||||||
{"eInt16Usi",16},
|
{"eInt16Usi",16},
|
||||||
@ -128,55 +127,55 @@ void tdm_ripper::parse_structure()
|
|||||||
&& num_channels_ == (int)channels_group_.size() );
|
&& num_channels_ == (int)channels_group_.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_ripper::show_channels(int width, int maxshow)
|
void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
|
||||||
{
|
{
|
||||||
std::cout<<std::setw(width)<<"index";
|
gout<<std::setw(width)<<"index";
|
||||||
std::cout<<std::setw(width)<<"id";
|
gout<<std::setw(width)<<"id";
|
||||||
std::cout<<std::setw(2*width)<<"name";
|
gout<<std::setw(2*width)<<"name";
|
||||||
std::cout<<std::setw(width)<<"offset";
|
gout<<std::setw(width)<<"offset";
|
||||||
std::cout<<std::setw(width)<<"length";
|
gout<<std::setw(width)<<"length";
|
||||||
std::cout<<std::setw(width)<<"datatype";
|
gout<<std::setw(width)<<"datatype";
|
||||||
std::cout<<std::setw(width)<<"group";
|
gout<<std::setw(width)<<"group";
|
||||||
std::cout<<std::setw(width)<<"group id";
|
gout<<std::setw(width)<<"group id";
|
||||||
std::cout<<std::setw(width)<<"group name";
|
gout<<std::setw(width)<<"group name";
|
||||||
std::cout<<std::setw(width)<<"num channels";
|
gout<<std::setw(width)<<"num channels";
|
||||||
std::cout<<"\n";
|
gout<<"\n";
|
||||||
std::cout<<std::setfill('-')<<std::setw(11*width+1)<<"\n";
|
gout<<std::setfill('-')<<std::setw(11*width+1)<<"\n";
|
||||||
std::cout<<std::setfill(' ');
|
gout<<std::setfill(' ');
|
||||||
|
|
||||||
for ( int i = 0; i < num_channels_ && i < maxshow; i++ )
|
for ( int i = 0; i < num_channels_ && i < maxshow; i++ )
|
||||||
{
|
{
|
||||||
std::cout<<std::setw(width)<<i+1;
|
gout<<std::setw(width)<<i+1;
|
||||||
std::cout<<std::setw(width)<<channel_id_[i];
|
gout<<std::setw(width)<<channel_id_[i];
|
||||||
std::cout<<std::setw(2*width)<<channel_name_[i];
|
gout<<std::setw(2*width)<<channel_name_[i];
|
||||||
std::cout<<std::setw(width)<<byteoffset_[i];
|
gout<<std::setw(width)<<byteoffset_[i];
|
||||||
std::cout<<std::setw(width)<<length_[i];
|
gout<<std::setw(width)<<length_[i];
|
||||||
std::cout<<std::setw(width)<<type_[i];
|
gout<<std::setw(width)<<type_[i];
|
||||||
std::cout<<std::setw(width)<<channels_group_[i];
|
gout<<std::setw(width)<<channels_group_[i];
|
||||||
std::cout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
||||||
std::cout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
||||||
std::cout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
||||||
std::cout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
std::cout<<"\n\n";
|
gout<<"\n\n";
|
||||||
|
|
||||||
if ( num_channels_ > maxshow )
|
if ( num_channels_ > maxshow )
|
||||||
{
|
{
|
||||||
for ( int i = num_channels_-maxshow; i < num_channels_; i++ )
|
for ( int i = num_channels_-maxshow; i < num_channels_; i++ )
|
||||||
{
|
{
|
||||||
std::cout<<std::setw(width)<<i+1;
|
gout<<std::setw(width)<<i+1;
|
||||||
std::cout<<std::setw(width)<<channel_id_[i];
|
gout<<std::setw(width)<<channel_id_[i];
|
||||||
std::cout<<std::setw(2*width)<<channel_name_[i];
|
gout<<std::setw(2*width)<<channel_name_[i];
|
||||||
std::cout<<std::setw(width)<<byteoffset_[i];
|
gout<<std::setw(width)<<byteoffset_[i];
|
||||||
std::cout<<std::setw(width)<<length_[i];
|
gout<<std::setw(width)<<length_[i];
|
||||||
std::cout<<std::setw(width)<<type_[i];
|
gout<<std::setw(width)<<type_[i];
|
||||||
std::cout<<std::setw(width)<<channels_group_[i];
|
gout<<std::setw(width)<<channels_group_[i];
|
||||||
std::cout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
||||||
std::cout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
||||||
std::cout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
||||||
std::cout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
std::cout<<"\n\n";
|
gout<<"\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +232,43 @@ void tdm_ripper::show_structure()
|
|||||||
std::cout<<"\n\n";
|
std::cout<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tdm_ripper::list_datatypes()
|
||||||
|
{
|
||||||
|
// show datatype size on machine
|
||||||
|
int width = 30;
|
||||||
|
|
||||||
|
std::cout<<std::setw(width)<<"size of short int: "<<sizeof(short int)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of int: "<<sizeof(int)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of long int: "<<sizeof(long int)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of unsigned short int: "<<sizeof(unsigned short int)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of unsigned int: "<<sizeof(unsigned int)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of unsigned long int: "<<sizeof(unsigned long int)<<"\n\n";
|
||||||
|
|
||||||
|
std::cout<<std::setw(width)<<"size of float: "<<sizeof(float)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of double: "<<sizeof(double)<<"\n";
|
||||||
|
std::cout<<std::setw(width)<<"size of long double: "<<sizeof(long double)<<"\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert array of chars to integer
|
||||||
|
int tdm_ripper::convert_int(std::vector<unsigned char> bych)
|
||||||
|
{
|
||||||
|
assert( bych.size() == sizeof(int) );
|
||||||
|
assert( endianness_ );
|
||||||
|
|
||||||
|
int df = 0.0;
|
||||||
|
|
||||||
|
uint8_t *dfcast = reinterpret_cast<uint8_t*>(&df);
|
||||||
|
|
||||||
|
for ( int i = 0; i < (int)sizeof(int); i++ )
|
||||||
|
{
|
||||||
|
dfcast[i] = (int)bych[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return df;
|
||||||
|
}
|
||||||
|
|
||||||
// convert array of chars to floating point double
|
// convert array of chars to floating point double
|
||||||
double tdm_ripper::convert_float(std::vector<unsigned char> bych)
|
double tdm_ripper::convert_double(std::vector<unsigned char> bych)
|
||||||
{
|
{
|
||||||
assert( bych.size() == sizeof(double) );
|
assert( bych.size() == sizeof(double) );
|
||||||
assert( endianness_ );
|
assert( endianness_ );
|
||||||
@ -254,15 +288,19 @@ double tdm_ripper::convert_float(std::vector<unsigned char> bych)
|
|||||||
return df;
|
return df;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<double> tdm_ripper::convert_channel(int byteoffset, int length, int typesize)
|
std::vector<double> tdm_ripper::convert_channel(int byteoffset, int length, std::string type)
|
||||||
{
|
{
|
||||||
std::vector<double> chann(length);
|
std::vector<double> chann(length);
|
||||||
|
|
||||||
|
int typesize = datatypes_[type]/CHAR_BIT;
|
||||||
|
|
||||||
for ( int i = 0; i < length; i++ )
|
for ( int i = 0; i < length; i++ )
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> cseg(tdxbuf_.begin()+byteoffset+i*typesize,
|
std::vector<unsigned char> cseg(tdxbuf_.begin()+byteoffset+i*typesize,
|
||||||
tdxbuf_.begin()+byteoffset+(i+1)*typesize);
|
tdxbuf_.begin()+byteoffset+(i+1)*typesize);
|
||||||
chann[i] = convert_float(cseg);
|
|
||||||
|
if ( type.compare("eInt32Usi") == 0 ) chann[i] = convert_int(cseg);
|
||||||
|
if ( type.compare("eFloat64Usi") == 0 ) chann[i] = convert_double(cseg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chann;
|
return chann;
|
||||||
@ -272,8 +310,9 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
|
|||||||
{
|
{
|
||||||
assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" );
|
assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" );
|
||||||
|
|
||||||
return convert_channel(byteoffset_[channelid-1],length_[channelid-1],
|
return convert_channel(byteoffset_[channelid-1],length_[channelid-1],type_[channelid-1]);
|
||||||
datatypes_[type_[channelid-1]]/CHAR_BIT);
|
// return convert_channel(byteoffset_[channelid-1],length_[channelid-1],
|
||||||
|
// datatypes_[type_[channelid-1]]/CHAR_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdm_ripper::print_channel(int channelid, const char* filename, int width)
|
void tdm_ripper::print_channel(int channelid, const char* filename, int width)
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
void parse_structure();
|
void parse_structure();
|
||||||
|
|
||||||
void show_channels(int width = 15, int maxshow = 300);
|
void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 300);
|
||||||
|
|
||||||
void show_structure();
|
void show_structure();
|
||||||
|
|
||||||
@ -77,16 +77,27 @@ public:
|
|||||||
return num_groups_;
|
return num_groups_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert array of chars to single floating point double
|
void list_datatypes();
|
||||||
double convert_float(std::vector<unsigned char> bych);
|
|
||||||
|
// convert array of chars to single integer or floating point double
|
||||||
|
int convert_int(std::vector<unsigned char> bych);
|
||||||
|
double convert_double(std::vector<unsigned char> bych);
|
||||||
|
|
||||||
// convert entire channel, i.e. expert of .tdx binary file
|
// convert entire channel, i.e. expert of .tdx binary file
|
||||||
std::vector<double> convert_channel(int byteoffset, int length, int typesize);
|
// std::vector<double> convert_channel(int byteoffset, int length, int typesize);
|
||||||
|
std::vector<double> convert_channel(int byteoffset, int length, std::string type);
|
||||||
|
|
||||||
std::vector<double> get_channel(int channelid);
|
std::vector<double> get_channel(int channelid);
|
||||||
|
|
||||||
void print_channel(int channelid, const char* filename, int width = 15);
|
void print_channel(int channelid, const char* filename, int width = 15);
|
||||||
|
|
||||||
|
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
||||||
|
// by constructing xml document tree and write data to binary .tdx
|
||||||
|
// void set_channels(std::vector<std::string> channels);
|
||||||
|
// void set_groups(std::vector<std::string> groups);
|
||||||
|
// void set_assigment(std::vector<int> assignment);
|
||||||
|
// void set_channel(int i, std::vector<double> data);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
15
main.cpp
15
main.cpp
@ -10,17 +10,22 @@ int main(int argc, char* argv[])
|
|||||||
// declare and initialize tdm_ripper
|
// declare and initialize tdm_ripper
|
||||||
tdm_ripper ripper(argv[1]);
|
tdm_ripper ripper(argv[1]);
|
||||||
|
|
||||||
ripper.show_channels();
|
ripper.list_datatypes();
|
||||||
|
|
||||||
|
ripper.list_channels();
|
||||||
|
std::ofstream fout("list_of_channels.dat");
|
||||||
|
ripper.list_channels(fout);
|
||||||
|
fout.close();
|
||||||
// ripper.show_structure();
|
// ripper.show_structure();
|
||||||
|
|
||||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n\n";
|
std::cout<<"number of channels "<<ripper.num_channels()<<"\n\n";
|
||||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||||
|
|
||||||
// std::vector<double> channA = ripper.get_channel(9);
|
std::vector<double> channA = ripper.get_channel(1);
|
||||||
// for ( auto el: channA ) std::cout<<el<<"\n";
|
for ( auto el: channA ) std::cout<<el<<"\n";
|
||||||
// std::cout<<"\n\n";
|
std::cout<<"\n\n";
|
||||||
|
|
||||||
for ( int i = 0; i < 20; i++ )
|
for ( int i = 0; i < 12; i++ )
|
||||||
{
|
{
|
||||||
ripper.print_channel(i+1,("channel_"+std::to_string(i+1)+".dat").c_str());
|
ripper.print_channel(i+1,("channel_"+std::to_string(i+1)+".dat").c_str());
|
||||||
}
|
}
|
||||||
|
1
makefile
1
makefile
@ -16,6 +16,7 @@ tdm_ripper.o : lib/tdm_ripper.cpp lib/tdm_ripper.hpp
|
|||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -f $(EXE) *.o
|
rm -f $(EXE) *.o
|
||||||
|
rm -f *.dat
|
||||||
|
|
||||||
pylib : setup.py pytdm_ripper.pyx tdm_ripper.pxd tdm_ripper.o
|
pylib : setup.py pytdm_ripper.pyx tdm_ripper.pxd tdm_ripper.o
|
||||||
python3 setup.py build_ext --inplace
|
python3 setup.py build_ext --inplace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user