create .csv dump of all metainformation + readme
This commit is contained in:
parent
76dc664bbc
commit
93ed029c33
11
README.md
11
README.md
@ -1 +1,12 @@
|
||||
# tdm_ripper
|
||||
|
||||
## C++ core
|
||||
|
||||
- XML parser employs pugixml https://pugixml.org/
|
||||
- analyse .tdm file
|
||||
- buffer binary .tdx data
|
||||
- convert binary data to datatypes according to given .tdm information
|
||||
|
||||
## Cython wrapper
|
||||
|
||||
- enables use as python module
|
||||
|
@ -31,6 +31,8 @@ print(RP.meta_info(b"SMP_Name").decode('utf-8'))
|
||||
print(RP.meta_info(b"Location").decode('utf-8'))
|
||||
print('\n')
|
||||
|
||||
RP.print_meta(b"meta_information.dat")
|
||||
|
||||
# extract channel and return it to numpy array
|
||||
# channels = RP.get_channel(1)
|
||||
# Nlen = len(channels)
|
||||
|
@ -115,18 +115,32 @@ void tdm_ripper::parse_structure()
|
||||
int groupcount = 0;
|
||||
for (pugi::xml_node anode: subtreedata.children())
|
||||
{
|
||||
// get meta-info contained in tdm_root element
|
||||
if ( std::string(anode.name()).compare("tdm_root") == 0 )
|
||||
{
|
||||
// preliminiary: extract some hard-coded information tags only
|
||||
root_info_.insert(std::pair<std::string,std::string>("name",anode.child_value("name")));
|
||||
root_info_.insert(std::pair<std::string,std::string>("description",anode.child_value("description")));
|
||||
root_info_.insert(std::pair<std::string,std::string>("title",anode.child_value("title")));
|
||||
root_info_.insert(std::pair<std::string,std::string>("author",anode.child_value("author")));
|
||||
}
|
||||
|
||||
if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 )
|
||||
{
|
||||
groupcount++;
|
||||
|
||||
// meta-info is pressumably contained in FIRST channel-group xml tree element
|
||||
// (eventually identify by name = TESTINFOS ??? )
|
||||
if ( groupcount == 1 )
|
||||
for ( pugi::xml_node mnode: anode.child("instance_attributes").children() )
|
||||
{
|
||||
for ( pugi::xml_node mnode: anode.child("instance_attributes").children() )
|
||||
// preliminiary fix for Conti-TDM files since values are one arbitrary tree level above
|
||||
bool pretdmfix = ( std::string(mnode.child_value()).compare("") == 0 ) ? false : true;
|
||||
|
||||
if ( pretdmfix )
|
||||
{
|
||||
meta_info_.insert(std::pair<std::string,std::string>(mnode.attribute("name").value(),
|
||||
mnode.child_value("s")));
|
||||
meta_info_.insert(std::pair<std::string,std::string>(mnode.attribute("name").value(),mnode.child_value()));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta_info_.insert(std::pair<std::string,std::string>(mnode.attribute("name").value(),mnode.child_value("s")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,8 @@ class tdm_ripper
|
||||
pugi::xml_document xml_doc_;
|
||||
pugi::xml_parse_result xml_result_;
|
||||
|
||||
// .tdm-file eventually contains some meta information about measurement
|
||||
// .tdm-file eventually contains some meta information (about measurement)
|
||||
std::map<std::string,std::string> root_info_;
|
||||
std::map<std::string,std::string> meta_info_;
|
||||
|
||||
// binary data container
|
||||
@ -320,7 +321,31 @@ public:
|
||||
// obtain any meta information about .tdm-file if available
|
||||
std::string get_meta(std::string attribute_name)
|
||||
{
|
||||
return meta_info_[attribute_name];
|
||||
// check if key "attribute_name" actually exits
|
||||
std::map<std::string,std::string>::iterator positer = meta_info_.find(attribute_name);
|
||||
bool ispresent = ( positer == meta_info_.end() ) ? false : true;
|
||||
|
||||
return ispresent ? meta_info_[attribute_name] : "key does not exist";
|
||||
}
|
||||
|
||||
// prepare meta information file including all available meta-data
|
||||
void print_meta(const char* filename, std::string sep = ",")
|
||||
{
|
||||
// open file
|
||||
std::ofstream fout(filename);
|
||||
|
||||
for ( const auto& it : root_info_ )
|
||||
{
|
||||
fout<<it.first<<sep<<it.second<<"\n";
|
||||
}
|
||||
fout<<sep<<"\n";
|
||||
for ( const auto& it : meta_info_ )
|
||||
{
|
||||
fout<<it.first<<sep<<it.second<<"\n";
|
||||
}
|
||||
|
||||
// close down file
|
||||
fout.close();
|
||||
}
|
||||
|
||||
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
||||
|
4
main.cpp
4
main.cpp
@ -40,11 +40,15 @@ int main(int argc, char* argv[])
|
||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||
|
||||
// obtain some specific meta information tags
|
||||
std::cout<<"\n"<<ripper.get_meta("SMP_Name")<<"\n";
|
||||
std::cout<<ripper.get_meta("SMP_Aufbau_Nr")<<"\n";
|
||||
std::cout<<ripper.get_meta("SMP_Type")<<"\n";
|
||||
std::cout<<ripper.get_meta("Location")<<"\n\n";
|
||||
|
||||
// print all meta information
|
||||
ripper.print_meta("data/meta_info.csv");
|
||||
|
||||
// for ( int i = 0; i < ripper.num_groups(); i++ )
|
||||
// {
|
||||
// std::cout<<std::setw(10)<<i+1<<std::setw(10)<<ripper.no_channels(i+1)<<"\n";
|
||||
|
1
makefile
1
makefile
@ -19,6 +19,7 @@ clean :
|
||||
rm -f $(EXE) *.o
|
||||
rm -f *.dat
|
||||
rm -f data/*.dat
|
||||
rm -f data/*.csv
|
||||
|
||||
pylib : setup.py pytdm_ripper.pyx tdm_ripper.pxd tdm_ripper.o
|
||||
python3 setup.py build_ext --inplace
|
||||
|
@ -65,5 +65,8 @@ cdef class pytdmripper:
|
||||
def meta_info(self, string attribute_name):
|
||||
return self.cripp.get_meta(attribute_name)
|
||||
|
||||
def print_meta(self, const char* filename):
|
||||
self.cripp.print_meta(filename)
|
||||
|
||||
def close(self):
|
||||
dummy = ""
|
||||
|
@ -29,5 +29,6 @@ cdef extern from "tdm_ripper.hpp":
|
||||
vector[double] channel(int,int)
|
||||
void print_channel(int,const char*)
|
||||
string get_meta(string attribute_name)
|
||||
void print_meta(const char*)
|
||||
# dummy method for compatibility
|
||||
void close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user