void OrbElemRinex::adjustBeginningValidity() { if (!dataLoaded()) return; // The nominal beginning of validity is calculated from // the fit interval and the Toe. In RINEX the fit duration // in hours is stored in the file. long oneHalfInterval = ((long)fitDuration/2) * 3600; // If we assume this is the SECOND set of elements in a set // (which is an assumption of this function - see the .hpp) then // the "small offset in Toe" will actually push the Toe-oneHalfInterval // too early. For example, consider the following case. // Toe : 19:59:44 (really near 20:00:00) // first xMit : 18:00:00 (nominal) // Blindly setting beginValid top Toe - 1/2 fit interval will // result in 17:59:44. But 18:00:00 actually is the right answer // because the -16 second offset is an artifact. // // Therefore, we are FIRST going to remove that offset, // THEN determine beginValid. long sow = (long) (static_cast<GPSWeekSecond>(ctToe)).sow; short week = (static_cast<GPSWeekSecond>(ctToe)).week; sow = sow + (3600 - (sow%3600)); CommonTime adjustedToe = GPSWeekSecond(week, (double) sow); adjustedToe.setTimeSystem(TimeSystem::GPS); beginValid = adjustedToe - oneHalfInterval; return; }
CommonTime Rinex3ObsData::parseTime(const string& line, const Rinex3ObsHeader& hdr, const TimeSystem& ts) const throw(FFStreamError) { try { // check if the spaces are in the right place - an easy // way to check if there's corruption in the file if( (line[ 1] != ' ') || (line[ 6] != ' ') || (line[ 9] != ' ') || (line[12] != ' ') || (line[15] != ' ') || (line[18] != ' ') || (line[29] != ' ') || (line[30] != ' ')) { FFStreamError e("Invalid time format"); GPSTK_THROW(e); } // if there's no time, just return a bad time if(line.substr(2,27) == string(27, ' ')) return CommonTime::BEGINNING_OF_TIME; int year, month, day, hour, min; double sec; year = asInt( line.substr( 2, 4)); month = asInt( line.substr( 7, 2)); day = asInt( line.substr(10, 2)); hour = asInt( line.substr(13, 2)); min = asInt( line.substr(16, 2)); sec = asDouble(line.substr(19, 11)); // Real Rinex has epochs 'yy mm dd hr 59 60.0' surprisingly often. double ds = 0; if(sec >= 60.) { ds = sec; sec = 0.0; } CommonTime rv = CivilTime(year,month,day,hour,min,sec).convertToCommonTime(); if(ds != 0) rv += ds; rv.setTimeSystem(ts); return rv; } // string exceptions for substr are caught here catch (std::exception &e) { FFStreamError err("std::exception: " + string(e.what())); GPSTK_THROW(err); } catch (gpstk::Exception& e) { FFStreamError err(e); GPSTK_THROW(err); } } // end parseTime
//============================================================ // Test Suite: timeSystemTest() //============================================================ // // Test will check the TimeSystem comparisons when using // the comparison operators. // //============================================================ int timeSystemTest( void ) { TestUtil testFramework( "CommonTime", "Differing TimeSystem == Operator", __FILE__, __LINE__ ); CommonTime GPS1; GPS1.set( 1000, 200, 0.2, TimeSystem(2) ); CommonTime GPS2; GPS2.set( 100, 200, 0.2, TimeSystem(2) ); CommonTime UTC1; UTC1.set( 1000, 200, 0.2, TimeSystem(5) ); CommonTime UNKNOWN; UNKNOWN.set( 1000, 200, 0.2, TimeSystem(0) ); CommonTime ANY; ANY.set( 1000, 200, 0.2, TimeSystem(1) ); //---------------------------------------- // ??? //---------------------------------------- testFramework.assert( !(GPS1 == GPS2), "Verify same Time System but different time inequality", __LINE__ ); testFramework.assert( GPS1.getTimeSystem() == GPS2.getTimeSystem(), "Verify same Time System equality", __LINE__ ); //---------------------------------------- // Differing TimeSystem != Operator //---------------------------------------- testFramework.changeSourceMethod( "Differing TimeSystem != Operator" ); testFramework.assert( GPS1 != UTC1, "Verify different Time System but same time inequality", __LINE__ ); testFramework.assert( GPS1 != UNKNOWN, "Verify different Time System but same time inequality", __LINE__ ); //---------------------------------------- // ANY TimeSystem == Operator //---------------------------------------- testFramework.changeSourceMethod( "ANY TimeSystem == Operator" ); testFramework.assert( GPS1 == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=GPS comparisons", __LINE__ ); testFramework.assert( UTC1 == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=UTC comparisons", __LINE__ ); testFramework.assert( UNKNOWN == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=UNKOWN comparisons", __LINE__ ); //---------------------------------------- // ANY TimeSystem < Operator //---------------------------------------- testFramework.changeSourceMethod( "ANY TimeSystem < Operator" ); testFramework.assert( !(GPS2 == ANY) && (GPS2 < ANY), "Verify TimeSystem=ANY does not matter in other operator comparisons", __LINE__ ); //---------------------------------------- // setTimeSystem //---------------------------------------- testFramework.changeSourceMethod( "setTimeSystem" ); UNKNOWN.setTimeSystem( TimeSystem(2) ); //Set the Unknown TimeSystem testFramework.assert( UNKNOWN.getTimeSystem()==TimeSystem(2), "Ensure resetting a Time System changes it", __LINE__ ); //---------------------------------------- // The End! //---------------------------------------- return testFramework.countFails(); }
int main(int argc, char *argv[]) { string Usage( "Usage: bc2sp3 <RINEX nav file(s)> [options]\n" " Read RINEX nav file(s) and write to SP3(a or c) file.\n" " Options (defaults):\n" " --in <file> Read the input file <file> (--in is optional, repeatable) ()\n" " --out <file> Name the output file <file> (sp3.out)\n" " --tb <time> Output beginning epoch; <time> = week,sec-of-week (earliest in input)\n" " --te <time> Output ending epoch; <time> = week,sec-of-week (latest in input)\n" " --outputC Output version c (no correlation) (otherwise a)\n" " --msg \"...\" Add ... as a comment to the output header (repeatable)\n" " --verbose Output to screen: dump headers, data, etc\n" " --help Print this message and quit\n" ); if(argc < 2) { cout << Usage; return -1; } try { bool verbose=false; //char version_out='a'; SP3Header::Version version_out(SP3Header::SP3a); int i,j; size_t k,nfile; string fileout("sp3.out"); vector<string> inputFiles; vector<string> comments; map<SatID,long> IODEmap; CommonTime begTime=CommonTime::BEGINNING_OF_TIME; CommonTime endTime=CommonTime::END_OF_TIME; CommonTime tt; GPSEphemerisStore BCEph; SP3Header sp3header; SP3Data sp3data; for(i=1; i<argc; i++) { if(argv[i][0] == '-') { string arg(argv[i]); if(arg == string("--outputC")) { version_out = SP3Header::SP3c; //'c'; if(verbose) cout << " Output version c\n"; } else if(arg == string("--in")) { inputFiles.push_back(string(argv[++i])); if(verbose) cout << " Input file name " << inputFiles[inputFiles.size()-1] << endl; } else if(arg == string("--out")) { fileout = string(argv[++i]); if(verbose) cout << " Output file name " << fileout << endl; } else if(arg == string("--tb")) { arg = string(argv[++i]); int wk=StringUtils::asInt(StringUtils::stripFirstWord(arg,',')); double sow=StringUtils::asDouble(StringUtils::stripFirstWord(arg,',')); begTime=GPSWeekSecond(wk,sow); begTime.setTimeSystem(TimeSystem::GPS); if(verbose) cout << " Begin time " << printTime(begTime,"%Y/%02m/%02d %2H:%02M:%06.3f = %F/%10.3g") << endl; } else if(arg == string("--te")) { arg = string(argv[++i]); int wk=StringUtils::asInt(StringUtils::stripFirstWord(arg,',')); double sow=StringUtils::asDouble(StringUtils::stripFirstWord(arg,',')); endTime=GPSWeekSecond(wk,sow); endTime.setTimeSystem(TimeSystem::GPS); if(verbose) cout << " End time " << printTime(endTime,"%Y/%02m/%02d %2H:%02M:%06.3f = %F/%10.3g") << endl; } else if(arg == string("--msg")) { comments.push_back(string(argv[++i])); if(verbose) cout << " Add comment " << comments[comments.size()-1] << endl; } else if(arg == string("--help")) { cout << Usage; return -1; } else if(arg == string("--verbose")) verbose = true; else cout << "Ignore unknown option: " << arg << endl; } else { inputFiles.push_back(string(argv[i])); if(verbose) cout << " Input file name " << inputFiles[inputFiles.size()-1] << endl; } } if(inputFiles.size() == 0) { cout << "Error - no input filename specified. Abort.\n"; return -1; } // open the output SP3 file SP3Stream outstrm(fileout.c_str(),ios::out); outstrm.exceptions(ifstream::failbit); for(nfile=0; nfile<inputFiles.size(); nfile++) { RinexNavHeader rnh; RinexNavData rnd; RinexNavStream rns(inputFiles[nfile].c_str()); if(!rns) { cout << "Could not open input file " << inputFiles[nfile] << endl; continue; } rns.exceptions(ifstream::failbit); if(verbose) cout << "Reading file " << inputFiles[nfile] << endl; rns >> rnh; if(verbose) { cout << "Input"; rnh.dump(cout); } while(rns >> rnd) if(rnd.health == 0) BCEph.addEphemeris(rnd); } if (verbose) { cout << "Number of ephemerides loaded: " << BCEph.size() << endl; cout << " Initial time: " << printTime(BCEph.getInitialTime(),"%03j.%02H:%02M:%02S, %P") << endl; cout << " Final time: " << printTime(BCEph.getFinalTime(),"%03j.%02H:%02M:%02S, %P") << endl; } // time limits, if not given by user if(begTime == CommonTime::BEGINNING_OF_TIME) begTime = BCEph.getInitialTime(); if(endTime == CommonTime::END_OF_TIME) endTime = BCEph.getFinalTime(); // define the data version and the header info if(version_out == SP3Header::SP3c) { // data and header must have the correct version //sp3data.version = sp3header.version = SP3Header::SP3c; sp3header.system = SP3SatID(); sp3header.timeSystem = TimeSystem::GPS; sp3header.basePV = 0.0; sp3header.baseClk = 0.0; } else { //sp3data.version = sp3header.version = SP3Header::SP3a; //'a'; } // fill the header //sp3header.pvFlag = 'V'; sp3header.containsVelocity = true; sp3header.time = CommonTime::END_OF_TIME; sp3header.epochInterval = 900.0; // hardcoded here only sp3header.dataUsed = "BCE"; sp3header.coordSystem = "WGS84"; sp3header.orbitType = " "; sp3header.agency = "ARL"; // determine which SVs, with accuracy, start time, epoch interval, // number of epochs, for header // this is a pain.... sp3header.numberOfEpochs = 0; tt = begTime; while(tt < endTime) { bool foundSome = false; for(i=1; i<33; i++) { // for each PRN ... SatID sat(i,SatID::systemGPS); try { GPSEphemeris ee = BCEph.findEphemeris(sat, tt); } catch(InvalidRequest& nef) { continue; } if(sp3header.satList.find(sat) == sp3header.satList.end()) { sp3header.satList[sat] = 0; // sat accuracy = ? IODEmap[sat] = -1; } if(!foundSome) { sp3header.numberOfEpochs++; foundSome = true; if(tt < sp3header.time) sp3header.time = tt; } } tt += sp3header.epochInterval; } // add comments if(comments.size() > 0) { // try to keep existing comments for(k=0; k<comments.size(); k++) { if(k > 3) { cout << "Warning - only 4 comments are allowed in SP3 header.\n"; break; } sp3header.comments.push_back(comments[i]); } } // dump the SP3 header if(verbose) sp3header.dump(cout); // write the header outstrm << sp3header; // sigmas to output (version c) for(j=0; j<4; j++) sp3data.sig[j]=0; // sigma = ? tt = begTime; tt.setTimeSystem(TimeSystem::Any); while(tt < endTime) { bool epochOut=false; for(i=1; i<33; i++) { long iode; SatID sat(i,SatID::systemGPS); Xvt xvt; GPSEphemeris ee; try { ee = BCEph.findEphemeris(sat, tt); } catch(InvalidRequest& nef) { continue; } sp3data.sat = sat; xvt = BCEph.getXvt(sat, tt); // epoch if(!epochOut) { sp3data.time = tt; sp3data.RecType = '*'; outstrm << sp3data; if(verbose) sp3data.dump(cout); epochOut = true; } // Position sp3data.RecType = 'P'; for(j=0; j<3; j++) sp3data.x[j] = xvt.x[j]/1000.0; // km // must remove the relativity correction from Xvt::clkbias // see EngEphemeris::svXvt() - also convert to microsec sp3data.clk = (xvt.clkdrift - ee.svRelativity(tt)) * 1000000.0; //if(version_out == 'c') for(j=0; j<4; j++) sp3data.sig[j]=... iode = ee.IODE; if(IODEmap[sat] == -1) IODEmap[sat] = iode; if(IODEmap[sat] != iode) { sp3data.orbitManeuverFlag = true; IODEmap[sat] = iode; } else sp3data.orbitManeuverFlag = false; outstrm << sp3data; if(verbose) sp3data.dump(cout); // Velocity sp3data.RecType = 'V'; for(j=0; j<3; j++) sp3data.x[j] = xvt.v[j]/10.0; // dm/s sp3data.clk = xvt.clkdrift; // s/s //if(version_out == 'c') for(j=0; j<4; j++) sp3data.sig[j]=... outstrm << sp3data; if(verbose) sp3data.dump(cout); } tt += sp3header.epochInterval; } // don't forget this outstrm << "EOF" << endl; outstrm.close(); if(verbose) cout << "Wrote " << sp3header.numberOfEpochs << " records" << endl; } catch (Exception& e) { cout << e; return -1; } catch (...) { cout << "Caught an unknown exception" << endl; return -1; } return 0; }
void mixedScanTime( CommonTime& t, const string& str, const string& fmt ) { try { using namespace gpstk::StringUtils; // Get the mapping of character (from fmt) to value (from str). TimeTag::IdToValue info; TimeTag::getInfo( str, fmt, info ); // These indicate which information has been found. bool hsow( false ), hweek( false ), hfullweek( false ), hdow( false ), hyear( false ), hmonth( false ), hday( false ), hzcount( false ), hdoy( false ), hzcount29( false ), hhour( false ), hmin( false ), hsec( false ), hsod( false ), hepoch( false ), hunixsec( false ), hunixusec( false ), hbdsw( false ), hqzsw( false ), hgalw( false ), hbdsfw( false ), hqzsfw( false ), hgalfw( false ), hbdse( false ), hqzse( false ), hgale( false); #pragma unused(hunixsec,hunixusec) // MJD, Julian Date, ANSI time, Unix time, and 32-bit Zcounts // are treated as stand-alone types and are not mixed with others // if detected. // These variables will hold the values for use later. double isow, isod, isec; int iweek, ifullweek, idow, iyear, imonth, iday, izcount, idoy, izcount29, ihour, imin, iepoch; TimeSystem ts; for( TimeTag::IdToValue::iterator itr = info.begin(); itr != info.end(); itr++ ) { switch( itr->first ) { case 'P': ts.fromString(itr->second); t.setTimeSystem(ts); break; case 'Q': t = MJD( asLongDouble(itr->second) ); return; case 'J': t = JulianDate( asLongDouble(itr->second) ); return; case 'C': t = GPSWeekZcount().setZcount32( asInt(itr->second) ); return; case 'K': t = ANSITime( asInt(itr->second) ); return; case 'U': case 'u': { UnixTime tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } break; case 'Z': hzcount = true; izcount = asInt(itr->second); break; case 's': hsod = true; isod = asDouble(itr->second); break; case 'g': hsow = true; isow = asDouble(itr->second); break; case 'w': idow = asInt(itr->second); hdow = true; break; case 'G': hweek = true; iweek = asInt(itr->second); break; case 'F': hfullweek = true; ifullweek = asInt(itr->second); break; case 'j': hdoy = true; idoy = asInt(itr->second); break; case 'b': case 'B': hmonth = true; imonth = asInt(itr->second); break; case 'Y': case 'y': hyear = true; iyear = asInt(itr->second); break; case 'a': case 'A': { hdow = true; string thisDay = firstWord( itr->second ); lowerCase(thisDay); if (isLike(thisDay, "sun.*")) idow = 0; else if (isLike(thisDay, "mon.*")) idow = 1; else if (isLike(thisDay, "tue.*")) idow = 2; else if (isLike(thisDay, "wed.*")) idow = 3; else if (isLike(thisDay, "thu.*")) idow = 4; else if (isLike(thisDay, "fri.*")) idow = 5; else if (isLike(thisDay, "sat.*")) idow = 6; } break; case 'm': hmonth = true; imonth = asInt(itr->second); break; case 'd': hday = true; iday = asInt(itr->second); break; case 'H': hhour = true; ihour = asInt(itr->second); break; case 'M': hmin = true; imin = asInt(itr->second); break; case 'S': hsec = true; isec = asDouble(itr->second); break; case 'f': hsec = true; isec = asDouble(itr->second); break; case 'c': hzcount29 = true; izcount29 = asInt(itr->second); break; case 'E': hepoch = true; iepoch = asInt(itr->second); break; case 'R': hepoch = hbdse = true; iepoch = asInt(itr->second); break; case 'T': hepoch = hgale = true; iepoch = asInt(itr->second); break; case 'V': hepoch = hqzse = true; iepoch = asInt(itr->second); break; case 'D': hfullweek = hbdsfw = true; break; case 'e': hweek = hbdsw = true; break; case 'L': hfullweek = hgalfw = true; break; case 'l': hweek = hgalw = true; break; case 'I': hfullweek = hqzsfw = true; break; case 'i': hweek = hqzsw = true; break; default: // do nothing break; }; } bool hbds(hbdse || hbdsfw || hbdsw); bool hgal(hgale || hgalfw || hgalw); bool hqzs(hqzse || hqzsfw || hqzsw); // We'll copy this time to 't' after all of the processing. CommonTime ct; ct.setTimeSystem(t.getTimeSystem()); // Go through all of the types in order of least precise to most // precise. if( hepoch ) { WeekSecond *ptt; if(hbds) ptt = new BDSWeekSecond(ct); else if(hqzs) ptt = new QZSWeekSecond(ct); else if(hgal) ptt = new GALWeekSecond(ct); else ptt = new GPSWeekSecond(ct); ptt->setEpoch( iepoch ); ct = ptt->convertToCommonTime(); } if( hyear ) { YDSTime tt(ct); tt.year = iyear; ct = tt.convertToCommonTime(); } if( hmonth ) { CivilTime tt(ct); tt.month = imonth; ct = tt.convertToCommonTime(); } if( hfullweek ) { WeekSecond *ptt; if(hbds) ptt = new BDSWeekSecond(ct); else if(hqzs) ptt = new QZSWeekSecond(ct); else if(hgal) ptt = new GALWeekSecond(ct); else ptt = new GPSWeekSecond(ct); ptt->week = ifullweek; ct = ptt->convertToCommonTime(); } if( hweek ) { WeekSecond *ptt; if(hbds) ptt = new BDSWeekSecond(ct); else if(hqzs) ptt = new QZSWeekSecond(ct); else if(hgal) ptt = new GALWeekSecond(ct); else ptt = new GPSWeekSecond(ct); ptt->setModWeek(iweek); ct = ptt->convertToCommonTime(); } if( hdow ) { WeekSecond *ptt; if(hbds) ptt = new BDSWeekSecond(ct); else if(hqzs) ptt = new QZSWeekSecond(ct); else if(hgal) ptt = new GALWeekSecond(ct); else ptt = new GPSWeekSecond(ct); ptt->sow = static_cast<double>(idow) * SEC_PER_DAY; ct = ptt->convertToCommonTime(); } if( hday ) { CivilTime tt(ct); tt.day = iday; ct = tt.convertToCommonTime(); } if( hdoy ) { YDSTime tt(ct); tt.doy = idoy; ct = tt.convertToCommonTime(); } if( hzcount29 ) { GPSWeekZcount tt(ct); tt.setZcount29( izcount29 ); ct = tt.convertToCommonTime(); } if( hzcount ) { GPSWeekZcount tt(ct); tt.zcount = izcount; ct = tt.convertToCommonTime(); } if( hhour ) { CivilTime tt(ct); tt.hour = ihour; ct = tt.convertToCommonTime(); } if( hmin ) { CivilTime tt(ct); tt.minute = imin; ct = tt.convertToCommonTime(); } if( hsow ) { WeekSecond *ptt; if(hbds) ptt = new BDSWeekSecond(ct); else if(hqzs) ptt = new QZSWeekSecond(ct); else if(hgal) ptt = new GALWeekSecond(ct); else ptt = new GPSWeekSecond(ct); ptt->sow = isow; ct = ptt->convertToCommonTime(); } if( hsod ) { YDSTime tt(ct); tt.sod = isod; ct = tt.convertToCommonTime(); } if( hsec ) { CivilTime tt(ct); tt.second = isec; ct = tt.convertToCommonTime(); } t = ct; } catch( gpstk::StringUtils::StringException& se ) { GPSTK_RETHROW( se ); } }
void scanTime( CommonTime& t, const string& str, const string& fmt ) { try { using namespace gpstk::StringUtils; // Get the mapping of character (from fmt) to value (from str). TimeTag::IdToValue info; TimeTag::getInfo( str, fmt, info ); // These indicate which information has been found. bool hmjd( false ), hsow( false ), hweek( false ), hfullweek( false ), hdow( false ), hyear( false ), hmonth( false ), hday( false ), hzcount( false ), hdoy( false ), hzcount29( false ), hzcount32( false ), hhour( false ), hmin( false ), hsec( false ), hsod( false ), hunixsec( false ), hunixusec( false ), hepoch( false ), hansi( false ), hjulian( false ), hbdsw( false ), hqzsw( false ), hgalw( false ), hbdsfw( false ), hqzsfw( false ), hgalfw( false ), hbdse( false ), hqzse( false ), hgale( false); // These are to hold data that no one parses. int idow(0); TimeSystem ts; for( TimeTag::IdToValue::iterator itr = info.begin(); itr != info.end(); itr++ ) { switch( itr->first ) { case 'P': ts.fromString(itr->second); t.setTimeSystem(ts); break; case 'Q': hmjd = true; break; case 'Z': hzcount = true; break; case 's': hsod = true; break; case 'g': hsow = true; break; case 'w': idow = asInt( itr->second ); hdow = true; break; case 'G': hweek = true; break; case 'F': hfullweek = true; break; case 'j': hdoy = true; break; case 'b': case 'B': hmonth = true; break; case 'Y': case 'y': hyear = true; break; case 'a': case 'A': { hdow = true; string thisDay = firstWord( itr->second ); lowerCase(thisDay); if (isLike(thisDay, "sun.*")) idow = 0; else if (isLike(thisDay, "mon.*")) idow = 1; else if (isLike(thisDay, "tue.*")) idow = 2; else if (isLike(thisDay, "wed.*")) idow = 3; else if (isLike(thisDay, "thu.*")) idow = 4; else if (isLike(thisDay, "fri.*")) idow = 5; else if (isLike(thisDay, "sat.*")) idow = 6; else { hdow = false; } } break; case 'm': hmonth = true; break; case 'd': hday = true; break; case 'H': hhour = true; break; case 'M': hmin = true; break; case 'S': hsec = true; break; case 'f': hsec = true; // a small hack to make fractional seconds work info['S'] = info['f']; break; case 'U': hunixsec = true; break; case 'u': hunixusec = true; break; case 'c': hzcount29 = true; break; case 'C': hzcount32 = true; break; case 'J': hjulian = true; break; case 'K': hansi = true; break; case 'E': hepoch = true; break; case 'R': hepoch = hbdse = true; break; case 'T': hepoch = hgale = true; break; case 'V': hepoch = hqzse = true; break; case 'D': hfullweek = hbdsfw = true; break; case 'e': hweek = hbdsw = true; break; case 'L': hfullweek = hgalfw = true; break; case 'l': hweek = hgalw = true; break; case 'I': hfullweek = hqzsfw = true; break; case 'i': hweek = hqzsw = true; break; default: { // do nothing } break; }; } // end loop over Id/Value pairs if( hyear ) { if( hmonth && hday ) { CivilTime tt; tt.setFromInfo( info ); if( hsod ) { convertSODtoTime( asDouble( info['s'] ), tt.hour, tt.minute, tt.second ); } t = tt.convertToCommonTime(); return; } else // use YDSTime as default { YDSTime tt; tt.setFromInfo( info ); if( hhour && hmin && hsec ) { tt.sod = convertTimeToSOD( asInt( info['H'] ), asInt( info['M'] ), asDouble( info['S'] ) ); } t = tt.convertToCommonTime(); return; } } // end of if( hyear ) if( hzcount32 || (hfullweek && hzcount) || (hepoch && (hzcount29 || (hweek && hzcount))) ) { GPSWeekZcount tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } if ( (hepoch && hweek) || hfullweek ) { WeekSecond* ptt; if(hbdse || hbdsfw || hbdsw) ptt = new BDSWeekSecond(); else if(hqzse || hqzsfw || hqzsw) ptt = new QZSWeekSecond(); else if(hgale || hgalfw || hgalw) ptt = new GALWeekSecond(); else ptt = new GPSWeekSecond(); ptt->setFromInfo(info); if( hdow && !hsow ) { ptt->sow = asInt( info['w'] ) * SEC_PER_DAY; if( hsod ) { ptt->sow += asDouble( info['s'] ); } else if( hhour && hmin && hsec ) { ptt->sow += convertTimeToSOD( asInt( info['H'] ), asInt( info['M'] ), asDouble( info['S'] ) ); } } t = ptt->convertToCommonTime(); return; } if( hmjd ) { MJD tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } if( hjulian ) { JulianDate tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } if( hansi ) { ANSITime tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } if( hunixsec || hunixusec ) { UnixTime tt; tt.setFromInfo( info ); t = tt.convertToCommonTime(); return; } InvalidRequest ir("Incomplete time specification for readTime"); GPSTK_THROW( ir ); } catch( gpstk::StringUtils::StringException& se ) { GPSTK_RETHROW( se ); } }
double TimeSystemCorrection :: Correction(const CommonTime& ct) const { double corr(0.0), dt; TimeSystem fromTS(ct.getTimeSystem()); GPSWeekSecond gpsws; CommonTime refTime; Exception e("Unable to compute correction - wrong TimeSystem"); Exception eSBAS("TimeSystemCorrection SBAS <=> UTC has not been implemented"); switch(type) { case GPUT: if(fromTS != TimeSystem::GPS && fromTS != TimeSystem::UTC) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::GPS) // GPS => UTC corr = -A0-A1*dt; else // UTC => GPS corr = A0+A1*dt; break; case GAUT: if(fromTS != TimeSystem::GAL && fromTS != TimeSystem::UTC) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::GAL) // GAL => UTC corr = A0+A1*dt; else // UTC => GAL corr = -A0-A1*dt; break; case SBUT: GPSTK_THROW(eSBAS); break; case GLUT: if(fromTS != TimeSystem::GLO && fromTS != TimeSystem::UTC) { GPSTK_THROW(e); } if(fromTS == TimeSystem::GLO) // GLO => UTC corr = A0; else // UTC => GLO corr = -A0; break; case GPGA: if(fromTS != TimeSystem::GPS && fromTS != TimeSystem::GAL) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::GPS) // GPS => GAL corr = A0+A1*dt; else // GAL => GPS corr = -A0-A1*dt; break; case GLGP: if(fromTS != TimeSystem::GLO && fromTS != TimeSystem::GPS) { GPSTK_THROW(e); } if(fromTS == TimeSystem::GLO) // GLO => GPS corr = A0; else // GPS => GLO corr = -A0; break; case QZGP: if(fromTS != TimeSystem::QZS && fromTS != TimeSystem::GPS) { GPSTK_THROW(e); } if(fromTS == TimeSystem::QZS) // QZS => GPS corr = 0.0; // TD? else // GPS => QZS corr = 0.0; // TD? break; case QZUT: if(fromTS != TimeSystem::QZS && fromTS != TimeSystem::UTC) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::QZS) // QZS => UTC corr = A0+A1*dt; else // UTC => QZS corr = -A0-A1*dt; break; case BDUT: if(fromTS != TimeSystem::BDT && fromTS != TimeSystem::UTC) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::BDT) // BDT => UTC corr = A0+A1*dt; else // UTC => BDT corr = -A0-A1*dt; break; case BDGP: if(fromTS != TimeSystem::BDT && fromTS != TimeSystem::GPS) { GPSTK_THROW(e); } // dt = fromTime - refTime gpsws = GPSWeekSecond(refWeek,refSOW); refTime = gpsws.convertToCommonTime(); refTime.setTimeSystem(fromTS); dt = ct - refTime; if(fromTS == TimeSystem::BDT) // BDT => GPS corr = A0; else // GPS => BDT corr = -A0; break; default: Exception e("TimeSystemCorrection is not defined."); GPSTK_THROW(e); break; } return corr; }