string CommandOptionWithTimeArg :: checkArguments() { string errstr = CommandOptionWithAnyArg::checkArguments(); if (errstr != string()) return errstr; vector<string>::size_type vecindex; for(vecindex = 0; vecindex < value.size(); vecindex++) { string thisTimeSpec = getTimeSpec(vecindex); if (thisTimeSpec != string()) { try { DayTime dt; dt.setToString(value[vecindex], thisTimeSpec); times.push_back(dt); } catch (...) { errstr += "\"" + value[vecindex] + "\" is not a valid time."; } } else errstr += "\"" + value[vecindex] + "\" is not a valid time."; } return errstr; }
/// returns 0 if all tests pass int main() { using gpstk::DayTime; try { cout << "BOT:" << DayTime(gpstk::DayTime::BEGINNING_OF_TIME) << endl; cout << "EOT:" << DayTime(gpstk::DayTime::END_OF_TIME) << endl; DayTime dt; dt.setSystemTime(); cout << "Check that the output matches the current UTC time." << endl << "string printf()" << endl; dtft(cout, dt, "mjd: %Q (%.0Q)"); dtft(cout, dt, "mjd: %5.3Q"); dtft(cout, dt, "mdy: %02m/%02d/%04Y"); dtft(cout, dt, "hms: %02H:%02M:%02S"); dtft(cout, dt, "hms: %02H:%02M:%06.3f"); dtft(cout, dt, "cal: %A, %B %d, %Y"); dtft(cout, dt, "week: %F(%G)"); dtft(cout, dt, "sow: %g"); dtft(cout, dt, "sow: %06.3g"); dtft(cout, dt, "doy: %j:%s"); dtft(cout, dt, "dow: %w"); dtft(cout, dt, "z: %Z (%z)"); dtft(cout, dt, "unix: %U.%06u"); cout << endl << "The following functions use DayTime::setToString()" << endl; string format = "%02m/%02d/%04Y %02H:%02M:%02S"; string st = dt.printf(format); DayTime q; q.setToString(st, format); dtft(cout, q, format); cout << "Tests complete." << endl; return 0; } catch(gpstk::Exception& e) { cout << e << endl; } catch(...) { cout << "Some other exception thrown..." << endl; } cout << "Exiting with exceptions." << endl; return -1; }
gpstk::DayTime ConstellationSet::parseDate(string date) throw(InvalidDateString) { string whitespace = " \t\r\n"; string::size_type end = date.find_last_not_of(whitespace); string::size_type front = date.find("STATUS"); front = date.find_first_not_of(whitespace, front+6); string dateString = date.substr(front, end-front+1); DayTime dt; try { //cout << dateString << endl; dt.setToString(dateString, "%d %b %Y"); dt.setSecOfDay( (DayTime::SEC_DAY/2) ); return dt; } catch(DayTime::DayTimeException exc) { string s = "Invalid date: '" + dateString + "'"; //cout << s << endl; ConstellationSet::InvalidDateString excids(s); GPSTK_THROW(excids); } }
void SVExclusionList::addFile( const std::string filename ) throw(SVExclusionList::SVExclusionFileNotFound) { char file[100]; sscanf(filename.c_str(),"%s",file); FILE* inf = fopen(file, "rt"); if (inf==0) { char text[200]; sprintf(text,"Exclusion file not found. Filename: %s",filename.c_str()); std::string sout = text; SVExclusionFileNotFound noSVXFile( sout ); GPSTK_THROW(noSVXFile); } std::string temps; DayTime tempDTs; std::string tempe; DayTime tempDTe; int lineCount =0; char fileLine[200]; while (fgets(fileLine, 200, inf)) { lineCount++; //cout << "------------- Line " << lineCount << endl; string whiteSpace = " \t\n\r"; string lineIn = fileLine; // strip trailing whitespace string::size_type endIndex = lineIn.find_last_not_of(whiteSpace); lineIn = lineIn.substr( 0, endIndex+1 ); string lead2Chars = lineIn.substr(0,2); if (lead2Chars.compare("TS")==0) { string::size_type q1 = lineIn.find('"'); string::size_type q2 = lineIn.find('"',(q1+1)); if (q1!=string::npos && q2!=string::npos) { timeSpecString = lineIn.substr((q1+1),(q2-q1-1)); // debug //cout << " New timeSpecString '" << timeSpecString << "'." << endl; } else { readFailCount++; string failString = buildFailString( "Invalid TS specification at", lineCount, filename); readFailList.push_back( failString ); } } if (lead2Chars.compare("EX")==0) { string::size_type c1 = lineIn.find(','); string::size_type c2 = lineIn.find(',',(c1+1)); string::size_type c3 = lineIn.find(',',(c2+1)); if (c1!=string::npos && c2!=string::npos) { std::string comment = ""; int PRNID = StringUtils::asInt(lineIn.substr(2, (c1-1)) ); if (PRNID<0 || PRNID>gpstk::MAX_PRN) { readFailCount++; string failString = buildFailString( "PRN ID out of range", lineCount, filename); readFailList.push_back( failString ); continue; } temps = lineIn.substr((c1+1),(c2-c1-1)); string::size_type nonWhiteBeg = temps.find_first_not_of(whiteSpace); string::size_type nonWhiteEnd = temps.find_last_not_of(whiteSpace); //cout << "Before trimming. temps, Beg, End = '" << temps << "', " << nonWhiteBeg << ", " << nonWhiteEnd << "." << endl; if (nonWhiteEnd!=string::npos) temps = temps.substr(nonWhiteBeg,nonWhiteEnd-nonWhiteBeg+1); else temps = temps.substr(nonWhiteBeg); //cout << "c3, string::npos = " << c3 << ", " << string::npos << endl; if (c3!=string::npos) { tempe = lineIn.substr(c2+1, (c3-c2-1) ); comment = lineIn.substr(c3+1); nonWhiteBeg = comment.find_first_not_of(whiteSpace); comment = comment.substr(nonWhiteBeg); } else tempe = lineIn.substr(c2+1); nonWhiteBeg = tempe.find_first_not_of(whiteSpace); nonWhiteEnd = tempe.find_last_not_of(whiteSpace); //cout << "Before trimming. tempe, Beg, End = '" << tempe << "', " << nonWhiteBeg << ", " << nonWhiteEnd << "." << endl; if (nonWhiteEnd!=string::npos) tempe = tempe.substr(nonWhiteBeg,nonWhiteEnd-nonWhiteBeg+1); else tempe = tempe.substr(nonWhiteBeg); try { //cout << "Input start string: '" << temps << "'." << endl; tempDTs.setToString( temps, timeSpecString ); //cout << "Input end string: '" << tempe << "'." << endl; tempDTe.setToString( tempe, timeSpecString ); if (tempDTs<=tempDTe) { SVExclusion svEx( tempDTs, tempDTe, PRNID, comment ); // Add exclusion to the multimap addExclusion( svEx ); } else { readFailCount++; string failString = buildFailString( "Start time after end time", lineCount, filename); readFailList.push_back( failString ); } } catch (DayTime::DayTimeException& dte) { readFailCount++; string failString = buildFailString( dte.getText(), lineCount, filename); readFailList.push_back( failString ); } catch (DayTime::FormatException& fe) { readFailCount++; string failString = buildFailString( fe.getText(), lineCount, filename); readFailList.push_back( failString ); } catch (gpstk::StringUtils::StringException& se) { readFailCount++; string failString = buildFailString( se.getText(), lineCount, filename); readFailList.push_back( failString ); } } else { readFailCount++; string failString = buildFailString( "Invalid EX line format at", lineCount, filename); readFailList.push_back( failString ); } } } fclose(inf); }