static int getSerialNumber(int mjd) throw(DayTime::DayTimeException) { DayTime t; t.setMJD(double(mjd)); return getSerialNumber(t); }
//------------------------------------------------------------------------------------ double GMST(DayTime t) { try { // days' since epoch = +/-(integer+0.5) double days = t.JD() - 2451545; int d=int(days); if(d < 0 && days==double(d)) d++; days = d + (days<0.0 ? -0.5 : 0.5); double Tp = days/36525.0; // Compute GMST double G; //G = 24060.0 + 50.54841 + 8640184.812866*Tp; // seconds (24060s = 6h 41min) //G /= 86400.0; // instead, divide the above equation by 86400.0 manually... G = 0.27847222 + 0.00058505104167 + 100.0021390378009*Tp; G += (0.093104 - 6.2e-6*Tp)*Tp*Tp/86400.0; // seconds/86400 = circles double r=1.002737909350795 + (5.9006e-11 - 5.9e-15*Tp)*Tp; G += r*t.secOfDay()/86400.0; // circles G *= 360.0; // degrees //G = fmod(G,360.0); //if(G < -180.0) G += 360.0; //if(G > 180.0) G -= 360.0; return G; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } }
MPSim::~MPSim() { DayTime endTime; logStream << "Execution end at: " << endTime.printf(epochFormat) << endl; logStream << "Total execution time: " << endTime - startTime << " seconds" << endl; }
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; }
void xINCDayTime :: FinishUp (void) { gpstk::DayTime dtorig(2000,12,1,0,0,0.); DayTime endTime; cout << endl << setprecision(4); cout << endTime.printf("Completed on %B %d, %Y %H:%02M:%02S") << endl; cout << "Processing time " << endTime-startTime << " seconds." << endl; cout << endl; }
//------------------------------------------------------------------------------------ int main(int argc, char **argv) { try { totaltime = clock(); int iret,nfile,reading,nread; // Title and description Title = PrgmName + ", part of the GPS ToolKit, Ver " + PrgmVers + ", Run "; PrgmEpoch.setLocalTime(); Title += PrgmEpoch.printf("%04Y/%02m/%02d %02H:%02M:%02S"); Title += "\n"; cout << Title; // get command line iret=GetCommandLine(argc, argv); if(iret) return iret; PrevEpoch = DayTime::BEGINNING_OF_TIME; // loop over input files - reading them twice Ninterps = 0; for(reading=1; reading <= 2; reading++) { nread = 0; for(nfile=0; nfile<PIC.InputObsName.size(); nfile++) { iret = ReadFile(nfile,reading); if(iret < 0) break; nread++; } // quit if error if(iret < 0) break; if(nread>0) { iret = AfterReadingFiles(reading); if(iret < 0) break; } CurrEpoch = DayTime::BEGINNING_OF_TIME; } PIC.oflog << PrgmName << " did " << Ninterps << " interpolations" << endl; totaltime = clock()-totaltime; PIC.oflog << PrgmName << " timing: " << fixed << setprecision(3) << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds.\n"; cout << PrgmName << " timing: " << fixed << setprecision(3) << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds.\n"; PIC.oflog.close(); return iret; } catch(FFStreamError& e) { cout << "FFStream exception:\n" << e << endl; } catch(Exception& e) { cout << "GPSTK exception:\n" << e << endl; } catch (...) { cout << "Unknown exception in main." << endl; } } // end main()
/// 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; }
//------------------------------------------------------------------------------------ int OutputClockData(void) throw(Exception) { try { if(CI.Verbose) oflog << "BEGIN OutputClockData()" << endl; if(CI.OutputClkFile.empty()) return 0; int i; DayTime tt; map<string,Station>::const_iterator it; format f166(16,6),f92(9,2,2),f96(9,6); // open an output file for Clk data ofstream clkofs; clkofs.open(CI.OutputClkFile.c_str(),ios::out); if(clkofs.is_open()) { oflog << "Opened file " << CI.OutputClkFile << " for DD data output." << endl; clkofs << "# " << Title << endl; clkofs << "CLK site week sec_wk Rx_clk_bias(m) Sig(m) TT_off(s)\n"; } else { // TD error msg return -1; } // loop over stations for(it=Stations.begin(); it != Stations.end(); it++) { // loop over epochs for(i=0; i<it->second.ClockBuffer.size(); i++) { tt = FirstEpoch + it->second.CountBuffer[i]*CI.DataInterval; clkofs << "CLK " << it->first << " " << tt.printf("%4F %10.3g") << " " << f166 << it->second.ClockBuffer[i] << " " << f92 << it->second.ClkSigBuffer[i] // TD add clock polynomial Evaluate(tt) << " " << f92 << it->second.RxTimeOffset[i] << endl; } // loop over epochs } // loop over stations clkofs.close(); return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } } // end OutputClockData()
void NavSum::getNewTime(DayTime& dt) { short week = -1; double SOW; string buf; short done = 0; while (!done) { cout << " Enter full GPS week: "; getline(cin, buf); istringstream instr(buf); instr >> week; if (week != -1) done = 1; else cout << " Error entering week. Please try again." << endl; } // Now reset flag and get SOW done = 0; while (!done) { cout << " Enter GPS seconds of week: "; getline(cin,buf); istringstream instr(buf); instr >> SOW; if ((SOW >= 0.0L) && (SOW < 604800.0L) ) done = 1; else cout << " Error entering SOW. Please try again." << endl; } dt.setGPSfullweek(week, SOW); }
// Update the file name, returns true if the file name changed bool updateFileName(const DayTime& t=DayTime()) { bool openedNewFile = false; const std::string newFilename=t.printf(filespec); if (currentFilename.size() == 0 && newFilename.size() > 0) { currentFilename = newFilename; currentTime = t; BaseStream::open(currentFilename.c_str(), omode); if (debugLevel) std::cout << "Opened " << currentFilename << std::endl; openedNewFile=true; } else if (newFilename == currentFilename) { currentTime = t; openedNewFile=false; } else { if (debugLevel) std::cout << "Closing " << currentFilename << std::endl; BaseStream::close(); currentFilename = newFilename; currentTime = t; BaseStream::open(currentFilename.c_str(), omode); if (debugLevel) std::cout << "Opened " << currentFilename << std::endl; openedNewFile=true; } return openedNewFile; };
bool testRandomAccessors(DayTime &dtb, DayTime &dte, long ndates) { bool cumulativeResult=true; // Seed the random number generator gpstk::DayTime dt; unsigned int seed= (unsigned int) dt.GPSsow(); srand(seed); unsigned long dayDiff = (unsigned long) ceil(dte.MJD() - dtb.MJD()); for (int j=0;j<ndates;++j) // Loop through set of random days { double dayDelta = floor( rand()*1./ RAND_MAX * dayDiff); double sodDelta = rand()*1./RAND_MAX; gpstk::DayTime testDate; testDate.setMJD(dtb.MJD()+dayDelta+sodDelta); short year = testDate.year(); short month = testDate.month(); short dom = testDate.day(); short hour = testDate.hour(); short minute = testDate.minute(); double seconds = testDate.second(); short doy = testDate.DOY(); double sod = testDate.DOYsecond(); short week = testDate.GPSfullweek()%1024; double sow = testDate.GPSsow(); long zcount = testDate.GPSzcount(); short hintYear = testDate.year(); double MJD = testDate.MJD(); cumulativeResult = cumulativeResult && testMutators( year, month, dom, hour, minute, seconds, doy, sod, week, sow, zcount, hintYear, MJD ); } // End loop over random dates return cumulativeResult; }
ConstellationDefinition ConstellationSet::findCD( const gpstk::DayTime dt ) const throw(NoConstellationFound) { DayTime localDT = dt; localDT.setSecOfDay( (DayTime::SEC_DAY/2) ); // Set to noon to match CDs // Best case (hopefully nominal) is that there is a definition // available for the date in question. CI ci = cdMap.find(localDT); //cout << "Found in map: " << ci->first << endl; if (ci==cdMap.end()) { // If no, first check to see whether date in question is later // than any date available. if (localDT>getLatestDate()) { ConstellationSet::NoConstellationFound exc("All Constellation Definitions Too Early"); GPSTK_THROW(exc); } // If not, start at the day of interest and back up until we // find a definition or hit the earliest definition bool done = false; localDT -= DayTime::SEC_DAY; while (!done && localDT > getEarliestDate() ) { ci = cdMap.find(localDT); if (ci!=cdMap.end()) done = true; localDT -= DayTime::SEC_DAY; } // Did not find one before reaching the "head" of the list if (!done) { ConstellationSet::NoConstellationFound exc("All Constellation Definitions Too Late"); GPSTK_THROW(exc); } } ConstellationDefinition cd = ci->second; return(cd); }
int main(int argc, char* argv[]) { try { DayTime time; cout << "Hello world!" << endl; cout << " The current GPS week is " << time.GPSfullweek() << endl; cout << " The day of the GPS week is " << time.GPSday() << endl; cout << " The seconds of the GPS week is " << time.GPSsecond() << endl; } catch( Exception error) { cout << error << endl; exit(-1); } exit(0); }
//------------------------------------------------------------------------------------ // Solar ephemeris, in ECEF coordinates. // Accuracy is about 1 arcminute, when t is within 2 centuries of 2000. // Ref. Astronomical Almanac pg C24, as presented on USNO web site. // input // t epoch of interest // output // lat,lon,R latitude, longitude and distance (deg,deg,m in ECEF) of sun at t. // AR apparent angular radius of sun as seen at Earth (deg) at t. void SolarPosition(DayTime t, double& lat, double& lon, double& R, double& AR) { try { //const double mPerAU = 149598.0e6; double D; // days since J2000 double g,q; double L; // sun's geocentric apparent ecliptic longitude (deg) //double b=0; // sun's geocentric apparent ecliptic latitude (deg) double e; // mean obliquity of the ecliptic (deg) //double R; // sun's distance from Earth (m) double RA; // sun's right ascension (deg) double DEC; // sun's declination (deg) //double AR; // sun's apparent angular radius as seen at Earth (deg) D = t.JD() - 2451545.0; g = (357.529 + 0.98560028 * D) * DEG_TO_RAD; q = 280.459 + 0.98564736 * D; L = (q + 1.915 * ::sin(g) + 0.020 * ::sin(2*g)) * DEG_TO_RAD; e = (23.439 - 0.00000036 * D) * DEG_TO_RAD; RA = atan2(::cos(e)*::sin(L),::cos(L)) * RAD_TO_DEG; DEC = ::asin(::sin(e)*::sin(L)) * RAD_TO_DEG; //equation of time = apparent solar time minus mean solar time //= [q-RA (deg)]/(15deg/hr) // compute the hour angle of the vernal equinox = GMST and convert RA to lon lon = fmod(RA-GMST(t),360.0); if(lon < -180.0) lon += 360.0; if(lon > 180.0) lon -= 360.0; lat = DEC; // ECEF unit vector in direction Earth to sun //xhat = ::cos(lat*DEG_TO_RAD)*::cos(lon*DEG_TO_RAD); //yhat = ::cos(lat*DEG_TO_RAD)*::sin(lon*DEG_TO_RAD); //zhat = ::sin(lat*DEG_TO_RAD); // R in AU R = 1.00014 - 0.01671 * ::cos(g) - 0.00014 * ::cos(2*g); // apparent angular radius in degrees AR = 0.2666/R; // convert to meters R *= 149598.0e6; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } }
ObsRngDev::ObsRngDev( const double prange, const SatID& svid, const DayTime& time, const ECEF& rxpos, const XvtStore<SatID>& eph, GeoidModel& gm, bool svTime) : obstime(time), svid(svid), ord(0), wonky(false) { computeOrd(prange, rxpos, eph, gm, svTime); Geodetic gx(rxpos, &gm); NBTropModel nb(gx.getAltitude(), gx.getLatitude(), time.DOYday()); computeTrop(nb); }
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); } }
bool MPSim::initialize(int argc, char *argv[]) throw() { if(!BasicFramework::initialize(argc, argv)) return false; if (logfileOption.getCount()>0) { logFileName = StringUtils::asString(logfileOption.getValue().front()); } logStream.open( logFileName.c_str() ); logStream << "mpsim log file" << endl; logStream << "Execution started at: " << startTime.printf(epochFormat) << endl; return true; }
ObsRngDev::ObsRngDev( const double prange, const SatID& svid, const DayTime& time, const ECEF& rxpos, const XvtStore<SatID>& eph, GeoidModel& gm, const IonoModelStore& ion, IonoModel::Frequency fq, bool svTime) : obstime(time), svid(svid), ord(0), wonky(false) { computeOrd(prange, rxpos, eph, gm, svTime); Geodetic gx(rxpos, &gm); NBTropModel nb(gx.getAltitude(), gx.getLatitude(), time.DOYday()); computeTrop(nb); iono = ion.getCorrection(time, gx, elevation, azimuth, fq); ord -= iono; }
ObsRngDev::ObsRngDev( const double prange1, const double prange2, const SatID& svid, const DayTime& time, const ECEF& rxpos, const XvtStore<SatID>& eph, GeoidModel& gm, bool svTime) : obstime(time), svid(svid), ord(0), wonky(false) { // for dual frequency see ICD-GPS-211, section 20.3.3.3.3.3 double icpr = (prange2 - GAMMA * prange1)/IGAMMA; iono = prange1 - icpr; computeOrd(icpr, rxpos, eph, gm, svTime); Geodetic gx(rxpos, &gm); NBTropModel nb(gx.getAltitude(), gx.getLatitude(), time.DOYday()); computeTrop(nb); }
int DumpGrid(DayTime& time, string dumpfile) { try { ofstream ofs; // open output file ofs.open(dumpfile.c_str(),ios_base::out); if (!ofs) return -6; else lofs << "Opened output file " << dumpfile << endl; if (Grid.size() == 0) return 0; int i; for (i=0; i<Grid.size(); i++) { ofs << " " << time.printf("%4F %8.1g") << fixed << setprecision(3) << " " << setw(7) << Grid[i].lon << " " << setw(6) << Grid[i].lat << " " << setw(7) << Grid[i].gdop << " " << setw(7) << Grid[i].pdop << " " << setw(7) << Grid[i].hdop << " " << setw(7) << Grid[i].vdop << " " << setw(7) << Grid[i].tdop << " " << setw(6) << Grid[i].nsvs << fixed << setprecision(7) << " " << setw(9) << Grid[i].bdop << " " << endl; } ofs.close(); return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } }
//------------------------------------------------------------------------------------ int main(int argc, char **argv) { try { // ------------------------------------------------------------------ // START totaltime = clock(); int iret; DayTime CurrEpoch; // Title title and version Title = PrgmName + ", ARL:UT DD phase estimation processor, Ver " + Version; // PrgmDesc description PrgmDesc = " Prgm " + PrgmName + " will read GPS data from any number of RINEX obs files and process them\n" " in a double-differenced carrier phase estimation algorithm to produce precise\n" " estimates of relative positions. Input is on the command line, or of the same\n" " format in a file (see -f<file> below). DDBase is built on the GPS Toolkit (GPSTk).\n" " NB. Input option --DT <data_interval_(seconds)> is optional but recommended.\n" " NB. Stations are defined, and many inputs for each are identified, by a label\n" " (called station label or id below), which is case sensitive and must be used\n" " consistently throughout. It cannot be 'X','Y' or 'Z' nor contain '-' or '_';\n" " four characters work best.\n" " NB. There must be at least two stations defined, with observation file(s)\n" " provided for each, and at least one station must be fixed.\n" " Options may be given in an input file (see -f<file>); the '#' character marks\n" " a comment, to EOL. All input options are shown below, followed by a\n" " description, and the default value, if there is one, in ().\n"; // get current time time_t timer; struct tm *tblock; timer = time(NULL); tblock = localtime(&timer); CurrEpoch.setYMDHMS(1900+tblock->tm_year,1+tblock->tm_mon, tblock->tm_mday,tblock->tm_hour,tblock->tm_min,tblock->tm_sec); // print title and current time to screen Title += CurrEpoch.printf(", Run %04Y/%02m/%02d %02H:%02M:%02S"); cout << Title << endl; for(;;) { // ------------------------------------------------------------------ // get command line input; -99 is 'help' return if((iret = CI.GetCmdInput(argc, argv))) break; // ------------------------------------------------------------------ // test command input for validity if((iret = CI.ValidateCmdInput())) break; // dump command input to log if(CI.Verbose) { cout << "Output is directed to log file " << CI.LogFile << endl; CI.Dump(oflog); } // if 'validate' switch is on, quit here if(CI.Validate) break; // ------------------------------------------------------------------ // Configure #1 if((iret = Configure(1))) break; // ------------------------------------------------------------------ // Open and read all files, compute PR solution, edit and buffer raw data if((iret = ReadAndProcessRawData())) break; // ------------------------------------------------------------------ // Edit buffers if((iret = EditRawDataBuffers())) break; // ------------------------------------------------------------------ // Output raw data buffers if((iret = OutputRawDataBuffers())) break; // ------------------------------------------------------------------ // Configure #2 if((iret = Configure(2))) break; // ------------------------------------------------------------------ // clock processing if((iret = ClockModel())) break; // ------------------------------------------------------------------ // synchronization of data to epoch (SolutionEpoch) if((iret = Synchronization())) break; // ------------------------------------------------------------------ // correct ephemeris range, elevation, and compute phase windup if((iret = RecomputeFromEphemeris())) break; // ------------------------------------------------------------------ // Orbit processing if((iret = EphemerisImprovement())) break; // ------------------------------------------------------------------ // output 'raw' data here OutputRawData(); // ------------------------------------------------------------------ // Compute or read the timetable if((iret = Timetable())) break; // ------------------------------------------------------------------ // Compute double differences, and buffer if((iret = DoubleDifference())) break; // ------------------------------------------------------------------ // Edit double differences if((iret = EditDDs())) break; // ------------------------------------------------------------------ // Configure #3 : prepare estimation if((iret = Configure(3))) break; // ------------------------------------------------------------------ // Estimation if((iret = Estimation())) break; break; } // end for(;;) // END -------------------------------------------------------------- // error condition? -99 is 'normal' help return from GetCmdInput if(iret != -99) { if(iret) { cerr << PrgmName << " terminating with error code " << iret << endl; oflog << PrgmName << " terminating with error code " << iret << endl; } // compute run time totaltime = clock()-totaltime; cout << PrgmName << " timing: " << fixed << setprecision(3) << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds." << endl; oflog << PrgmName << " timing: " << fixed << setprecision(3) << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds." << endl; } return iret; } catch(Exception& e) { cerr << "GPSTk Exception : " << e; oflog << "GPSTk Exception : " << e; } catch (...) { cerr << "Unknown error in DDBase. Abort." << endl; oflog << "Unknown error in DDBase. Abort." << endl; } // close files oflog.close(); return -1; } // end main()
int ReadStatsFile(string statsfile) { try { ifstream sifs; sifs.open(statsfile.c_str()); if (!sifs) return -5; else { lofs << "Opened stats file for input " << statsfile << endl; bool wtd; const int BUFF_SIZE=1024; char buffer[BUFF_SIZE]; string line; vector<string> fields; int i; while (sifs.getline(buffer,BUFF_SIZE)) { line = buffer; StringUtils::stripTrailing(line,'\r'); fields.clear(); for (i=0; i<StringUtils::numWords(line); i++) { fields.push_back(StringUtils::word(line,i)); } if (fields[0] == string("STAT")) { i = StringUtils::asInt(fields[1]); if (fields[9] == string("Y")) wtd = true; else wtd = false; HGridStats[i].Load( (unsigned int)(StringUtils::asInt(fields[4])), StringUtils::asDouble(fields[5]), // min StringUtils::asDouble(fields[6]), // max StringUtils::asDouble(fields[7]), // ave StringUtils::asDouble(fields[8]), // var wtd, StringUtils::asDouble(fields[10]) // norm ); if (fields[16] == string("Y")) wtd = true; else wtd = false; NGridStats[i].Load( (unsigned int)(StringUtils::asInt(fields[11])), StringUtils::asDouble(fields[12]), // min StringUtils::asDouble(fields[13]), // max StringUtils::asDouble(fields[14]), // ave StringUtils::asDouble(fields[15]), // var wtd, StringUtils::asDouble(fields[17]) // norm ); } else if (fields[0] == string("WORSTN")) { IworstN = StringUtils::asInt(fields[1]); TworstN.setGPSfullweek(StringUtils::asInt(fields[2]), StringUtils::asDouble(fields[3])); WorstN = StringUtils::asDouble(fields[6]); NtrofN = StringUtils::asInt(fields[7]); } else if (fields[0] == string("WORSTH")) { IworstH = StringUtils::asInt(fields[1]); TworstH.setGPSfullweek(StringUtils::asInt(fields[2]), StringUtils::asDouble(fields[3])); WorstH = StringUtils::asDouble(fields[6]); NpeakH = StringUtils::asInt(fields[7]); } else if (fields[0] == string("WORSTP")) { IworstP = StringUtils::asInt(fields[1]); TworstP.setGPSfullweek(StringUtils::asInt(fields[2]), StringUtils::asDouble(fields[3])); WorstP = StringUtils::asDouble(fields[6]); NpeakP = StringUtils::asInt(fields[7]); } } // end loop over lines in file } sifs.close(); return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } }
/** Edit the store by deleting all entries before(after) * the given min(max) times. If tmin is later than tmax, * the two times are switched. * @param tmin DayTime desired earliest store time. * @param tmax DayTime desired latest store time. */ void edit(const DayTime& tmin, const DayTime& tmax) throw() { edit(int(tmin.MJD()+0.5),int(tmax.MJD()+1.5)); }
//------------------------------------------------------------------------------------ // called from DDBase.cpp int OutputRawData(void) throw(Exception) { try { if(CI.Verbose) oflog << "BEGIN OutputRawData()" << endl; if(CI.OutputRawFile.empty()) return 0; int i; DayTime tt; map<string,Station>::const_iterator it; map<GSatID,RawData>::const_iterator jt; format f133(13,3),f52(5,2); // open an output file for RAW data ofstream rawofs; rawofs.open(CI.OutputRawFile.c_str(),ios::out); if(rawofs.is_open()) { oflog << "Opened file " << CI.OutputRawFile << " for raw data output.." << endl; rawofs << "# " << Title << endl; rawofs << "RAW site sat week sec_wk count L1_cyc L2_cyc" << " P1_m P2_m ER_m EL AZ\n"; } else { // TD error msg return -1; } // loop over stations for(it=Stations.begin(); it != Stations.end(); it++) { // loop over satellites for(jt=it->second.RawDataBuffers.begin(); jt != it->second.RawDataBuffers.end(); jt++) { // loop over epochs for(i=0; i<jt->second.count.size(); i++) { tt = FirstEpoch + jt->second.count[i]*CI.DataInterval; rawofs << "RAW " << it->first << " " << jt->first << " " << tt.printf("%4F %10.3g") << " " << setw(5) << jt->second.count[i] << " " << f133 << jt->second.L1[i] << " " << f133 << jt->second.L2[i] << " " << f133 << jt->second.P1[i] << " " << f133 << jt->second.P2[i] << " " << f133 << jt->second.ER[i] << " " << f52 << jt->second.elev[i] << " " << f52 << jt->second.az[i] << endl; } // end loop over epochs } // loop over satellites } // loop over stations // close output file rawofs.close(); return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } } // end OutputRawData()
//------------------------------------------------------------------------------------ int InterpolateAndOutput(void) throw(Exception) { // interpolate positions and output to rinex try { bool Lagrange; int i,ipts; double PDOP,GDOP,rms,err,dt,Dt,delt,xx,yy,zz,tt; DayTime t0,ttag; RinexObsData psdata; vector<double> times,X,Y,Z,T; map<DayTime,PosInfo>::iterator itb,ite,itB,itE,itr; // if no previous epoch, nothing to do if(PrevEpoch==DayTime::BEGINNING_OF_TIME) return 0; // find 4 positions on each side of CurrEpoch-1/2dt ite = TimePositionMap.lower_bound(CurrEpoch); if(ite == TimePositionMap.end()) return 0; // no position; get it next time if(ite->first - LastInterpolated < 0) return 0; // already done itb = ite; if(itb == TimePositionMap.begin()) { //PIC.oflog << "Warning: cannot interpolate at " << CurrEpoch //<< ": before beginning of data" << endl; PIC.oflog << "Echo position at first epoch " << CurrEpoch.printf("%04Y/%02m/%02d %02H:%02M:%6.3f = %4F %.3g") << endl; // create the aux header // use data from the begin time RinexPositionComments(psdata,CurrEpoch, itb->second.N, itb->second.X, itb->second.Y, itb->second.Z, itb->second.T, itb->second.PDOP, itb->second.GDOP, itb->second.rms); // write it out ofstr << psdata; return 0; } itb--; // itb and ite are now on either side of the times at which to interpolate if(PIC.Debug) PIC.oflog << "Interpolate : " << itb->first.printf("%02H:%02M:%04.1f") << " to " << ite->first.printf("%02H:%02M:%04.1f") << " : (" << (ite->first - itb->first) << " sec)" << endl; // now expand them out, up to 3 more epochs, watching for gaps TD: 3*DT input itB = itb; itE = ite; for(i=0; i<3; i++) { if(itB == TimePositionMap.begin() || (i==0 && itE->first-itB->first > 3*PIC.DT)) break; // increase the end time ttag = itE->first; itE++; if(itE == TimePositionMap.end() || itE->first-ttag > 3*PIC.DT) { itE--; break; } // decrease the begin time ttag = itB->first; itB--; if(ttag-itB->first > 3*PIC.DT) { itE--; itB++; break; } } // fill the arrays for interpolation t0 = itB->first; ipts = 1; itr = itB; if(PIC.Debug) PIC.oflog << "Data for interpolation:\n"; while(1) { if(PIC.Debug) PIC.oflog << " " << ipts << " " << itr->first.printf("%02M:%04.1f") << fixed << setprecision(3) << " " << setw(6) << (itr->first-t0) << " " << setw(13) << itr->second.X << " " << setw(13) << itr->second.Y << " " << setw(13) << itr->second.Z << ((itr==itb || itr==ite) ? " *":"") << endl; times.push_back(itr->first - t0); // sec X.push_back(itr->second.X); // m Y.push_back(itr->second.Y); Z.push_back(itr->second.Z); T.push_back(itr->second.T); if(itr == itE) break; itr++; ipts++; } // compute the time intervals involved ttag = itb->first; Dt = ite->first - ttag; // time interval over which interpolating if(Dt > 3*PIC.DT) { PIC.oflog << "Warning: cannot interpolate at " << CurrEpoch << ": large gap = " << Dt << " seconds." << endl; return 0; } dt = PIC.DT/double(PIC.irate); // is there enough data to do Lagrange interpolation? // fall back to linear interpolation if have to, but not over long periods if(ipts < 2 || (ipts==2 && Dt>3*PIC.DT)) { PIC.oflog << "Warning: cannot interpolate at " << CurrEpoch << ": not enough data" << endl; return 0; // not enough data } Lagrange = (ipts == 2 ? false : true); // number of interpolations needed to cover Dt, plus 1 endpt ipts = int(0.5+Dt/dt); PIC.oflog << "Dt dt and ipts are " << Dt << " " << dt << " " << ipts << CurrEpoch.printf(" at %04Y/%02m/%02d %02H:%02M:%6.3f = %4F %.3g") << endl; // loop over the interpolation times you want delt = itb->first - t0; // time since first data point for(i=0; i<ipts; i++) { ttag += dt; // itb->first was done last epoch delt += dt; // use 1. known position if i==ipts-1 (last epoch, ite) // 2. Lagrange if you have more than 1 data on each side // 3. linear interpolation xx = (i==ipts-1 ? ite->second.X : (Lagrange ? LagrangeInterpolation(times,X,delt,err) : X[0]+(X[1]-X[0])*delt/Dt)); yy = (i==ipts-1 ? ite->second.Y : (Lagrange ? LagrangeInterpolation(times,Y,delt,err) : Y[0]+(Y[1]-Y[0])*delt/Dt)); zz = (i==ipts-1 ? ite->second.Z : (Lagrange ? LagrangeInterpolation(times,Z,delt,err) : Z[0]+(Z[1]-Z[0])*delt/Dt)); tt = (i==ipts-1 ? ite->second.T : (Lagrange ? LagrangeInterpolation(times,T,delt,err) : T[0]+(T[1]-T[0])*delt/Dt)); // create the aux header // use N,DOPs,RMS of _end_ time for all interpolated times RinexPositionComments(psdata,ttag, ite->second.N, xx,yy,zz,tt, ite->second.PDOP, ite->second.GDOP, ite->second.rms); // write it out ofstr << psdata; if(i != ipts-1) Ninterps++; LastInterpolated = ttag; } return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } }
//------------------------------------------------------------------------------------ int OutputDDData(void) throw(Exception) { try { if(CI.Verbose) oflog << "BEGIN OutputDDData()" << endl; if(CI.OutputDDDFile.empty()) return 0; int i; double wlb; DayTime tt; map<DDid,DDData>::const_iterator it; format f166(16,6); // open an output file for DDD data ofstream dddofs; dddofs.open(CI.OutputDDDFile.c_str(),ios::out); if(dddofs.is_open()) { oflog << "Opened file " << CI.OutputDDDFile << " for DD data output." << endl; dddofs << "# " << Title << endl; dddofs << "DDD sit1 sit2 sat ref week sec_wk DDL1_m " << "DDL2_m DDER_m resL1_m resL2_m"; if(CI.Frequency == 3) dddofs << " WLbias_m"; dddofs << endl; } else { // TD error msg return -1; } // loop over DDids for(it=DDDataMap.begin(); it != DDDataMap.end(); it++) { // loop over epochs for(i=0; i<it->second.count.size(); i++) { tt = FirstEpoch + it->second.count[i]*CI.DataInterval; if(CI.Frequency == 3) wlb = wl1p * it->second.DDL1[i] // wide lane range minus phase + wl2p * it->second.DDL2[i] // = WL phase - NL range - wl1r * it->second.DDP1[i] - wl2r * it->second.DDP2[i]; dddofs << "DDD " << it->first << " " << tt.printf("%4F %10.3g") << " " << f166 << it->second.DDL1[i] << " " << f166 << it->second.DDL2[i] << " " << f166 << it->second.DDER[i] << " " << f166 << it->second.DDL1[i] - it->second.DDER[i] << " " << f166 << it->second.DDL2[i] - it->second.DDER[i]; if(CI.Frequency == 3) dddofs << " " << f166 << wlb; dddofs << endl; } } dddofs.close(); return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } } // end OutputDDData()
//------------------------------------------------------------------------------------ // called from EditDDs.cpp int OutputRawDData(const DDid& ddid, const DDData& dddata, const vector<int>& mark) throw(Exception) { try { bool TripleOut=true; // output triple differences as well if(CI.OutputRawDDFile.empty()) return 0; static ofstream rddofs; // allow caller to close the file... if(mark.size() == 0) { if(rddofs.is_open()) rddofs.close(); return 0; } if(!rddofs.is_open()) { // first call : open the file if(CI.Verbose) oflog << "BEGIN OutputRawDData()" << endl; rddofs.open(CI.OutputRawDDFile.c_str(),ios::out); if(rddofs.is_open()) { oflog << "Opened file " << CI.OutputRawDDFile << " for raw DD data output." << endl; rddofs << "# " << Title << endl; rddofs << "RDD sit1 sit2 sat ref week sec_wk flag DDL1_m" << " " << "DDL2_m DDER_m resL1_m resL2_m"; if(CI.Frequency == 3) rddofs << " WLbias_m"; rddofs << endl; if(TripleOut) rddofs << "RTD sit1 sit2 sat ref week sec_wk flag TDL1_m" << " TDL2_m TDER_m" << endl; } else { // TD error msg return -1; } } int i; double wlb; DayTime tt; format f166(16,6); // loop over epochs for(i=0; i<dddata.count.size(); i++) { tt = FirstEpoch + dddata.count[i]*CI.DataInterval; if(CI.Frequency == 3) wlb = wl1p * dddata.DDL1[i] // wide lane range minus phase + wl2p * dddata.DDL2[i] // = WL phase - NL range - wl1r * dddata.DDP1[i] - wl2r * dddata.DDP2[i]; rddofs << "RDD " << ddid << " " << tt.printf("%4F %10.3g") << " " << setw(2) << mark[i] << " " << f166 << dddata.DDL1[i] << " " << f166 << dddata.DDL2[i] << " " << f166 << dddata.DDER[i] << " " << f166 << dddata.DDL1[i] - dddata.DDER[i] << " " << f166 << dddata.DDL2[i] - dddata.DDER[i]; if(CI.Frequency == 3) rddofs << " " << f166 << wlb; rddofs << endl; if(TripleOut && i>0) { // wlb is a dummy here, = delta time for this triple diff wlb = (dddata.count[i]-dddata.count[i-1])*CI.DataInterval; rddofs << "RTD " << ddid << " " << tt.printf("%4F %10.3g") << " " << setw(2) << 10*mark[i]+mark[i-1] << " " << f166 << (dddata.DDL1[i]-dddata.DDL1[i-1])/wlb << " " << f166 << (dddata.DDL2[i]-dddata.DDL2[i-1])/wlb << " " << f166 << (dddata.DDER[i]-dddata.DDER[i-1])/wlb << endl; } } return 0; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } } // end OutputRawDData()
WxObservation WxObsData::getWxObservation(const DayTime& t, unsigned iv, bool interpolate) const throw(ObjectNotFound) { if (obs.empty()) { ObjectNotFound e("No WxObservation available near time " + t.printf("%02H:%02M:%02S on day %03j of %4Y")); GPSTK_THROW(e); } // get the first object after time t; WxObsMap::const_iterator after = obs.upper_bound(t); if (after == obs.begin()) { const WxObservation& wxa = after->second; if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv))) { // only after point fits return wxa; } else { ObjectNotFound e("No WxObservation available near time " + t.printf("%02H:%02M:%02S on day %03j of %4Y")); GPSTK_THROW(e); } } // get the first object at or before time t; WxObsMap::const_iterator before = after; before--; if (after == obs.end()) { const WxObservation& wxb = before->second; if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv))) { // only before point fits return wxb; } else { ObjectNotFound e("No WeatherData available near time " + t.printf("%02H:%02M:%02S on day %03j of %4Y")); GPSTK_THROW(e); } } else { const WxObservation& wxa = after->second; const WxObservation& wxb = before->second; if (interpolate) { if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv))) { if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv))) { // both points fit, linearly interpolate and create // a WeatherData object with those values double dtw = wxa.t - wxb.t; double dt = t - wxb.t; double slope = (wxa.pressure - wxb.pressure) / dtw; double pressure = slope * dt + wxb.pressure; slope = (wxa.humidity - wxb.humidity) / dtw; double humidity = slope * dt + wxb.humidity; slope = (wxa.temperature - wxb.temperature) / dtw; double temp = slope * dt + wxb.temperature; WxObservation wx(t, temp, pressure, humidity); return wx; } else { // only before point fits return wxb; } } else if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv))) { // only after point fits return wxa; } else { ObjectNotFound e("No WeatherData available near time " + t.printf("%02H:%02M:%02S on day %03j of %4Y")); GPSTK_THROW(e); } } else { if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv))) { if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv))) { // both points fit, return closer point, or // before point if at same distance double diffa = wxa.t - t; double diffb = t - wxb.t; return(diffa < diffb ? wxa : wxb); } else { // only before point fits return wxb; } } else if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv))) { // only after point fits return wxa; } else { ObjectNotFound e("No WeatherData available near time " + t.printf("%02H:%02M:%02S on day %03j of %4Y")); GPSTK_THROW(e); } } } }
// Method to print solution values void example9::printSolution( ofstream& outfile, const SolverLMS& solver, const DayTime& time, const ComputeDOP& cDOP, bool useNEU, int numSats, double dryTropo, int precision ) { // Prepare for printing outfile << fixed << setprecision( precision ); // Print results outfile << time.year() << " "; // Year - #1 outfile << time.DOY() << " "; // DayOfYear - #2 outfile << time.DOYsecond() << " "; // SecondsOfDay - #3 if( useNEU ) { outfile << solver.getSolution(TypeID::dLat) << " "; // dLat - #4 outfile << solver.getSolution(TypeID::dLon) << " "; // dLon - #5 outfile << solver.getSolution(TypeID::dH) << " "; // dH - #6 // We add 0.1 meters to 'wetMap' because 'NeillTropModel' sets a // nominal value of 0.1 m. Also to get the total we have to add the // dry tropospheric delay value // ztd - #7 outfile << solver.getSolution(TypeID::wetMap) + 0.1 + dryTropo << " "; outfile << solver.getVariance(TypeID::dLat) << " "; // Cov dLat - #8 outfile << solver.getVariance(TypeID::dLon) << " "; // Cov dLon - #9 outfile << solver.getVariance(TypeID::dH) << " "; // Cov dH - #10 outfile << solver.getVariance(TypeID::wetMap) << " "; // Cov ztd - #11 } else { outfile << solver.getSolution(TypeID::dx) << " "; // dx - #4 outfile << solver.getSolution(TypeID::dy) << " "; // dy - #5 outfile << solver.getSolution(TypeID::dz) << " "; // dz - #6 // We add 0.1 meters to 'wetMap' because 'NeillTropModel' sets a // nominal value of 0.1 m. Also to get the total we have to add the // dry tropospheric delay value // ztd - #7 outfile << solver.getSolution(TypeID::wetMap) + 0.1 + dryTropo << " "; outfile << solver.getVariance(TypeID::dx) << " "; // Cov dx - #8 outfile << solver.getVariance(TypeID::dy) << " "; // Cov dy - #9 outfile << solver.getVariance(TypeID::dz) << " "; // Cov dz - #10 outfile << solver.getVariance(TypeID::wetMap) << " "; // Cov ztd - #11 } outfile << numSats << " "; // Number of satellites - #12 outfile << cDOP.getGDOP() << " "; // GDOP - #13 outfile << cDOP.getPDOP() << " "; // PDOP - #14 outfile << cDOP.getTDOP() << " "; // TDOP - #15 outfile << cDOP.getHDOP() << " "; // HDOP - #16 outfile << cDOP.getVDOP() << " "; // VDOP - #17 // Add end-of-line outfile << endl; return; } // End of method 'example9::printSolution()'
int main(int argc, char* argv[]) { try { // if no options are given on command line, print syntax and quit if (argc < 2 || string(argv[1]) == "-h" || string(argv[1]) == "--help") { cout << "Program CalcDOPs reads an FIC, FICA or a Rinex Nav file" << endl << "Usage: CalcDOPs -i <inputfile> input file for day to be calculated (required)" << endl << " -p <inputfile> input file for previous day (optional, ephemeris mode only)" << endl << " -o <outputfile> grid output file [DOPs.out]" << endl << " -sf <outputfile> stats output file [DOPs.stat]" << endl << " -tf <outputfile> time steps output file [DOPs.times]" << endl << " -l <outputfile> log output file [DOPs.log]" << endl << " -rs read from stats file" << endl << " -a work in almanac mode [ephemeris mode is default]" << endl << " -w <week> -s <sow> starting time tag" << endl << " -x <prn> exclude satellite PRN" << endl << " -t <dt> time spacing" << endl << " -na do North America only" << endl << " -d dump grid results at each time step (time-intensive)" << endl << " -h, --help output options info and exit" << endl << " -v print version info and exit" << endl << endl; return 0; } int i, j, ii; // parse command line i = 1; while (i < argc) { if (string(argv[i]) == "-i" ) inputfile = string(argv[++i]); else if (string(argv[i]) == "-p" ) previnputfile = string(argv[++i]); else if (string(argv[i]) == "-o" ) outputfile = string(argv[++i]); else if (string(argv[i]) == "-l" ) logfile = string(argv[++i]); else if (string(argv[i]) == "-tf") timesfile = string(argv[++i]); else if (string(argv[i]) == "-a" ) ephmode = false; else if (string(argv[i]) == "-w" ) week = atoi(argv[++i]); else if (string(argv[i]) == "-s" ) sow = atof(argv[++i]); else if (string(argv[i]) == "-x" ) ExPRN.push_back(atoi(argv[++i])); else if (string(argv[i]) == "-t" ) dt = atof(argv[++i]); else if (string(argv[i]) == "-sf") statsfile = string(argv[++i]); else if (string(argv[i]) == "-rs") readStats = true; else if (string(argv[i]) == "-na") NAonly = true; else if (string(argv[i]) == "-d" ) dumpeach = true; else if (string(argv[i]) == "-v" ) { cout << "CalcDOPs version " << fixed << setprecision(1) << setw(3) << version << endl; return 0; } else cout << "Unrecognized option: " << argv[i] << endl; i++; } lofs.open(logfile.c_str(),ios_base::out); if (!lofs) return -8; tofs.open(timesfile.c_str(),ios_base::out); if (!tofs) return -8; // reassurance print lofs << "Program visible with:" << endl << "current-day input file " << inputfile << endl; if ( previnputfile != "" ) lofs << "and previous-day input file " << previnputfile << endl; lofs << "and output file " << outputfile << endl; if (week > 0) lofs << " Input time tag: " << week << " " << sow << endl; if (ExPRN.size() > 0) { lofs << " Exclude satellite PRNs"; for(i=0; i<ExPRN.size(); i++) lofs << " " << ExPRN[i]; lofs << "." << endl; } // compute the number of time steps from the time spacing nt = int(86400.0/dt); // 86400 = 60*60*24 = sec/day // open and read the previous day's input data file first, if specified and in Eph mode if ( previnputfile != "" && ephmode ) { lofs << "Reading in previous-day input file..." << endl; i = ReadDataFile(previnputfile); if (i) { if (i == -1) lofs << "Previous-day input file does not exist. Abort." << endl; if (i == -2) lofs << "Cannot identify previous-day file type. Abort." << endl; return i; } } // open and read the current day's input data file lofs << "Reading in current-day input file..." << endl; i = ReadDataFile(inputfile); if (i) { if (i == -1) lofs << "Current-day input file does not exist. Abort." << endl; if (i == -2) lofs << "Cannot identify current-day file type. Abort." << endl; return i; } // build the spatial grid, and store it in vector<GridData> Grid; BuildGrid(); // get a list of the available satellite PRNs and the initial timetag bool ok; DayTime tt, starttime; bool initialTimeSet = false; if ( ephmode ) // ephemeris mode { try { DayTime earliest = ges.getInitialTime(); DayTime latest = ges.getFinalTime(); // DayTime start = latest - gpstk::DayTime::SEC_DAY/2; /* make sure you're in the right day */ DayTime start = latest - 6*3600.0; /* go back 6 h: covers any 4 h ephemeris going into the next day */ tt = DayTime( start.year(), start.month(), start.day(), 0, 0, 0.0 ); starttime = tt; lofs << " Initial time tag is " << tt.printf("%4F %8.1g") << endl; initialTimeSet = true; } catch(InvalidRequest) { i = -100; lofs << "Initial Time or Final Time missing. Abort." << endl; return i; } for (i=1; i<33; i++) { for (ok=true,j=0; j<ExPRN.size(); j++) { if (ExPRN[j] == i) { ok=false; break; } } if (!ok) continue; // skip this satellite Sats.push_back(i); // save this satellite } } else // almanac mode (original version) { DayTime start(DayTime::BEGINNING_OF_TIME); // Declare and initialize to something guaranteed to be early. for (i=1; i<33; i++) // # of SVs hard-wired to 32 { if (aomap.find(i) == aomap.end()) continue; // satellite not found in almanac for (ok=true,j=0; j<ExPRN.size(); j++) { if (ExPRN[j] == i) { ok=false; break; } } if (!ok) continue; // skip this satellite if not ok Sats.push_back(i); // save this satellite otherwise // store latest transmit time tag of the set. if (aomap[i].getTransmitTime()>start) start = aomap[i].getTransmitTime(); } // Set starting time to beginning of day in which majority of almanac was collected. tt = DayTime( start.year(), start.month(), start.day(), 0, 0, 0.0 ); starttime = tt; lofs << " Initial time tag is " << tt.printf("%4F %8.1g") << endl; initialTimeSet = true; } if (Sats.size() < 4) { lofs << "Fewer than 4 satellite almanacs are available - abort." << endl; return -3; } // allocate Stats objects for each grid point's DOPs GGridStats = new Stats<double>[Grid.size()]; PGridStats = new Stats<double>[Grid.size()]; HGridStats = new Stats<double>[Grid.size()]; VGridStats = new Stats<double>[Grid.size()]; TGridStats = new Stats<double>[Grid.size()]; NGridStats = new Stats<double>[Grid.size()]; BadPDOP = (double*)calloc(Grid.size(),sizeof(double)); if (!GGridStats || !PGridStats || !HGridStats || !VGridStats || !TGridStats || !NGridStats ) { lofs << "Failed to allocate GridStats" << endl; return -4; } // initialize storage of 'worsts' and 'peaks' IworstN = IworstG = IworstP = IworstH = IworstV = IworstT = -1; // indexes of worst Number and worst DOPs NtrofN = NpeakG = NpeakP = NpeakH = NpeakV = NpeakT = 0; // number of cells with DOP > 10, # with < 5 sats // if reading a stats file (-rs), initialize stats using data from a file if (readStats) { i = ReadStatsFile(statsfile); if (i) { lofs << "Could not open stats file for input. Abort." << endl; return i; } } // compute away dlon = 360.0/double(MaxNLon); for (j=0; j<nt; j++) // LOOP OVER TIMES { SVs.clear(); // clear SV position array for (i=0; i<Sats.size(); i++) // LOOP OVER SVs -- get positions at each time step { if (ephmode) // ephemeris mode { SatID sid(Sats[i],SatID::systemGPS); try { if (ges.getSatHealth(sid,tt)!=0) continue; SVPVT = ges.getXvt(sid,tt); } catch(InvalidRequest& e) { continue; } SV.setECEF(SVPVT.x[0],SVPVT.x[1],SVPVT.x[2]); // get SV position SVs.push_back(SV); // add to the vector } else // almanac mode { SVPVT = aomap[Sats[i]].svXvt(tt); SV.setECEF(SVPVT.x[0],SVPVT.x[1],SVPVT.x[2]); // get SV position SVs.push_back(SV); // add to the vector } } // zero worst-site DOPs (worst #SVs to large #) for this time step StepWorstG = StepWorstP = StepWorstH = StepWorstV = StepWorstT = 0.; StepWorstN = 10000.; for (i=0; i<Grid.size(); i++) // LOOP OVER GRID POSITIONS { if ( j == 0 ) // set up grid position vector only on first time step { // transform XYZT to UENT: R*Vector(XYZT) = Vector(UENT) double ca,sa,co,so; Position Rx(Grid[i].lat,Grid[i].lon,0.0,Position::Geodetic); // grid position ca = cos(Rx.geodeticLatitude()*DEG_TO_RAD); sa = sin(Rx.geodeticLatitude()*DEG_TO_RAD); co = cos(Rx.longitude()*DEG_TO_RAD); so = sin(Rx.longitude()*DEG_TO_RAD); M4 Rtemp; Rtemp(0,0) = ca*co ; Rtemp(0,1) = ca*so ; Rtemp(0,2) = sa ; Rtemp(0,3) = 0.0; Rtemp(1,0) = -so ; Rtemp(1,1) = co ; Rtemp(1,2) = 0.0; Rtemp(1,3) = 0.0; Rtemp(2,0) = -sa*co; Rtemp(2,1) = -sa*so; Rtemp(2,2) = ca ; Rtemp(2,3) = 0.0; Rtemp(3,0) = 0.0 ; Rtemp(3,1) = 0.0 ; Rtemp(3,2) = 0.0; Rtemp(3,3) = 1.0; Rmat.push_back(Rtemp); // add this grid point's R matrix to the stack } ComputeDOPs(tt,Grid[i],SVs,Rmat[i]); // compute DOPs BadPDOP[i] = BadPDOP[i] + Grid[i].bdop; // adds up each grid pt.'s BDOP over all times // BDOP for a single pt. is 0 or 1 for PDOP <= v. > 6 // add to stats -- each GridStats object ends up holding all times for a grid point GGridStats[i].Add(Grid[i].gdop); PGridStats[i].Add(Grid[i].pdop); HGridStats[i].Add(Grid[i].hdop); VGridStats[i].Add(Grid[i].vdop); TGridStats[i].Add(Grid[i].tdop); NGridStats[i].Add(Grid[i].nsvs); // save the worst and the peaks if (Grid[i].gdop > StepWorstG) { StepWorstG = Grid[i].gdop; } if (Grid[i].pdop > StepWorstP) { StepWorstP = Grid[i].pdop; } if (Grid[i].hdop > StepWorstH) { StepWorstH = Grid[i].hdop; } if (Grid[i].vdop > StepWorstV) { StepWorstV = Grid[i].vdop; } if (Grid[i].tdop > StepWorstT) { StepWorstT = Grid[i].tdop; } if (Grid[i].nsvs < StepWorstN) { StepWorstN = Grid[i].nsvs; } if (IworstG == -1 || Grid[i].gdop > WorstG) { IworstG = i; WorstG = Grid[i].gdop; TworstG = tt; } if (IworstP == -1 || Grid[i].pdop > WorstP) { IworstP = i; WorstP = Grid[i].pdop; TworstP = tt; } if (IworstH == -1 || Grid[i].hdop > WorstH) { IworstH = i; WorstH = Grid[i].hdop; TworstH = tt; } if (IworstV == -1 || Grid[i].vdop > WorstV) { IworstV = i; WorstV = Grid[i].vdop; TworstV = tt; } if (IworstT == -1 || Grid[i].tdop > WorstT) { IworstT = i; WorstT = Grid[i].tdop; TworstT = tt; } if (IworstN == -1 || Grid[i].nsvs < WorstN) { IworstN = i; WorstN = Grid[i].nsvs; TworstN = tt; } if (Grid[i].nsvs < 5) NtrofN++; if (Grid[i].pdop > 10.) { NpeakP++; lofs << "PDS " << NpeakP << " " << setw(4) << j+1 // time << fixed << setprecision(2) << " " << setw(7) << Grid[i].lon << " " << setw(7) << Grid[i].lat << endl; } if (Grid[i].hdop > 10.) { NpeakH++; lofs << "HDS " << NpeakH << " " << setw(4) << j+1 // time << fixed << setprecision(2) << " " << setw(7) << Grid[i].lon << " " << setw(7) << Grid[i].lat << endl; } } // end loop over grid // write timestep results to timesfile tofs << " " << tt.printf("%4F %8.1g") << " " << " " << setw(7) << StepWorstG << " " << setw(7) << StepWorstP << " " << setw(7) << StepWorstH << " " << setw(7) << StepWorstV << " " << setw(7) << StepWorstT << " " << setw(6) << StepWorstN << endl; // dump grid results to file for each time step if enabled if (dumpeach) { stringstream ss; ss << j; dumpfile = outputfile + ".t-" + ss.str(); cout << dumpfile << endl; ii = DumpGrid(tt, dumpfile); if (ii) { lofs << "Could not dump grid file for writing. Abort." << endl; return i; } } // record worst-site DOPs at each time step WGTimeStats.push_back(StepWorstG); WPTimeStats.push_back(StepWorstP); WHTimeStats.push_back(StepWorstH); WVTimeStats.push_back(StepWorstV); WTTimeStats.push_back(StepWorstT); WNTimeStats.push_back(StepWorstN); tt += dt; // increment time tag } // end loop over times // get day's average of worst-site (grid) DOPs for (i=0; i<nt; i++) { AvgWorstSiteDOP.wgdop += WGTimeStats[i]; AvgWorstSiteDOP.wpdop += WPTimeStats[i]; AvgWorstSiteDOP.whdop += WHTimeStats[i]; AvgWorstSiteDOP.wvdop += WVTimeStats[i]; AvgWorstSiteDOP.wtdop += WTTimeStats[i]; AvgWorstSiteDOP.wnsvs += WNTimeStats[i]; } AvgWorstSiteDOP.wgdop /= nt; AvgWorstSiteDOP.wpdop /= nt; AvgWorstSiteDOP.whdop /= nt; AvgWorstSiteDOP.wvdop /= nt; AvgWorstSiteDOP.wtdop /= nt; AvgWorstSiteDOP.wnsvs /= nt; // output the grid itself and the stats - for use later i = OutputGrid(outputfile); // output average and worst-site DOP results over the grid if (i) { lofs << "Could not output file for writing. Abort." << endl; return i; } i = WriteStatsFile(statsfile); if (i) { lofs << "Could not open stats file for output. Abort." << endl; return i; } // clean up delete[] GGridStats; delete[] PGridStats; delete[] HGridStats; delete[] VGridStats; delete[] TGridStats; delete[] NGridStats; lofs.close(); } catch(Exception& e) { lofs << "Caught an exception" << endl << e << endl; } return 0; }