diff --git a/lib/tdm_ripper.cpp b/lib/tdm_ripper.cpp index f631ddb..9d5ebf0 100644 --- a/lib/tdm_ripper.cpp +++ b/lib/tdm_ripper.cpp @@ -106,6 +106,27 @@ void tdm_ripper::parse_structure() group_id_.push_back(anode.attribute("id").value()); group_name_.push_back(anode.child_value("name")); num_channels_group_.push_back(numchann); + + // get time-stamp + pugi::xml_node insatt = anode.child("instance_attributes"); + std::pair startstop; + for ( pugi::xml_node bnode: insatt.children() ) + { + assert( std::string(bnode.name()).compare("double_attribute") == 0 ); + if ( std::string(bnode.attribute("name").value()).compare("Starttime") == 0 ) + { + startstop.first = bnode.child_value(); + } + else if ( std::string(bnode.attribute("name").value()).compare("Stoptime") == 0 ) + { + startstop.second = bnode.child_value(); + } + else + { + assert ( false && "unexpected attribute name" ); + } + } + group_timestamp_.push_back(startstop); } if ( numchann == 0 ) num_empty_groups_++; } @@ -289,8 +310,10 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow) gout< channel_id_, inc_id_, units_, channel_name_; std::vector group_id_, group_name_; + std::vector> group_timestamp_; std::vector num_channels_group_; std::vector channels_group_; std::vector channel_ext_; - // evtl. get group time_stamp of .tdm file in the unix format, i.e. #seconds since 01.01.0000 with average year having 365+97/400 = 365.2425 days // minimum/maximum value in particular channel (is provided in .tdm file as float) std::vector> minmax_; @@ -248,6 +248,52 @@ public: } } + // evtl. get group time_stamp of .tdm file given in unix format + std::string unix_timestamp(std::string unixts) + { + // average year of Gregorian calender + const double avgdaysofyear = 365 + 1./4 - 1./100 + 1./400; + + // std::tm epochStart = {}; + // epochStart.tm_sec = 0; + // epochStart.tm_min = 0; + // epochStart.tm_hour = 0; + // epochStart.tm_mday = 1; + // epochStart.tm_mon = 0; + // epochStart.tm_year = 2040; + // epochStart.tm_wday = 0; + // epochStart.tm_yday = 0; + // epochStart.tm_isdst = -1; + // std::time_t epochtst = std::mktime(&epochStart); + + // convert string to long int = number of second since 0000/01/01 00:00 + long int ts = atol(unixts.c_str()); + + // int year = (int)floor((double)ts/(avgdaysofyear*86400)); + // int month = (int)floor((ts-year*avgdaysofyear*86400)/(30*86400)); + // int day = (int)floor((ts-year*avgdaysofyear*86400-month*30*86400)/86400); + // int daysec = ts-year*avgdaysofyear*86400-month*30*86400-day*86400; + // int hour = (int)floor(daysec/3600.); + // int mins = (int)floor((daysec-hour*3600)/60.); + // int secs = (int)floor((daysec-hour*3600-mins*60)); + + // return std::to_string(year)+"-"+std::to_string(month)+"-"+std::to_string(day) + // +" "+std::to_string(hour)+":"+std::to_string(mins)+":"+std::to_string(secs); + + // use STL to convert timestamp + // std::time_t tstime = std::time_t(ts)-epochtst; + std::time_t tstime = ts - 1970*avgdaysofyear*86400; + return std::ctime(&tstime); + } + + std::string time_stamp(int groupid, bool startstop = true) + { + assert( groupid >= 0 && groupid < num_groups_ ); + + return startstop ? unix_timestamp(group_timestamp_[groupid].first) + : unix_timestamp(group_timestamp_[groupid].second); + } + void list_datatypes(); // convert array of chars to single integer or floating point double