Example #1
0
MPSim::~MPSim()
{
   DayTime endTime;
   logStream << "Execution end at: " << endTime.printf(epochFormat) << endl;
   logStream << "Total execution time: " << endTime - startTime << " seconds" 
	     << endl;
}
Example #2
0
      // 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;
      };
Example #3
0
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;
}
Example #4
0
//------------------------------------------------------------------------------------
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()
Example #5
0
//------------------------------------------------------------------------------------
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()
Example #6
0
/// 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;
}
Example #7
0
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;      
  }
Example #8
0
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); }
}
Example #9
0
//------------------------------------------------------------------------------------
// 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()
Example #10
0
//------------------------------------------------------------------------------------
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()
Example #11
0
//------------------------------------------------------------------------------------
// 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()
Example #12
0
   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);
            }
         }
      }
   }
Example #13
0
//------------------------------------------------------------------------------------
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); }
}
Example #14
0
//------------------------------------------------------------------------------------
int Timetable(void) throw(Exception)
{
try {
   if(CI.Verbose) oflog << "BEGIN Timetable()"
      << " at total time " << fixed << setprecision(3)
      << double(clock()-totaltime)/double(CLOCKS_PER_SEC) << " seconds."
      << endl;

   int ib,iret;
   list<TTSegment>::iterator ttit;

   if(CI.TimeTableFile.size() > 0) {
      iret = ReadTimeTable();
   }
   else if(CI.RefSat.id != -1) {         // user says use this sat only
      // loop over baselines
      for(ib=0; ib<Baselines.size(); ib++) {
         TTSegment ts;
         ts.site1 = word(Baselines[ib],0,'-');
         ts.site2 = word(Baselines[ib],1,'-');
         ts.sat = CI.RefSat;
         ts.start = ts.first = 0;
         ts.end = ts.last = maxCount;
         ts.minelev = ts.maxelev = 0.0;
         ts.length = ts.end - ts.start + 1;
         TimeTable.push_back(ts);
         iret = 0;
      }
   }
   else {
      // loop over baselines
      for(ib=0; ib<Baselines.size(); ib++) {
         iret = ComputeBaselineTimeTable(Baselines[ib]);
         if(iret) break;
      }  // end loop over baselines
   }

   if(iret == 0) {
      // write out timetable to log
      // REF site site sat week use_first use_last data_start data_end
      DayTime tt;
      GSatID sat;
      oflog << "Here is the time table (" << TimeTable.size() << ")" << endl;
      if(CI.Screen)
         cout << "Time table (" << TimeTable.size() << "):" << endl;
      oflog << "# " << Title << endl;
      oflog << "# REF site site sat week use_first use_last data_start data_end\n";
      if(CI.Screen)
         cout << "# REF site site sat week use_first use_last data_start data_end\n";
      for(ttit=TimeTable.begin(); ttit != TimeTable.end(); ttit++) {
         oflog << "REF " << ttit->site1 << " " << ttit->site2 << " " << ttit->sat;
         if(CI.Screen)
            cout << "REF " << ttit->site1 << " " << ttit->site2 << " " << ttit->sat;
         tt = FirstEpoch + CI.DataInterval * ttit->first;
         oflog << tt.printf(" %4F %10.3g");        // TD week rollover!
         if(CI.Screen)
            cout << tt.printf(" %4F %10.3g");        // TD week rollover!
         tt = FirstEpoch + CI.DataInterval * ttit->last;
         oflog << tt.printf(" %10.3g");
         if(CI.Screen)
            cout << tt.printf(" %10.3g");
         tt = FirstEpoch + CI.DataInterval * ttit->start;
         oflog << tt.printf(" %10.3g");
         if(CI.Screen)
            cout << tt.printf(" %10.3g");
         tt = FirstEpoch + CI.DataInterval * ttit->end;
         oflog << tt.printf(" %10.3g");
         if(CI.Screen)
            cout << tt.printf(" %10.3g");
         // TD? ttit->minelev, ttit->maxelev, ttit->length, ttit->metric()
         oflog << " " << fixed << setw(4) << setprecision(1) << ttit->minelev;
         if(CI.Screen)
            cout << " " << fixed << setw(4) << setprecision(1) << ttit->minelev;
         oflog << " " << fixed << setw(4) << setprecision(1) << ttit->maxelev;
         if(CI.Screen)
            cout << " " << fixed << setw(4) << setprecision(1) << ttit->maxelev;
         // write the number of counts for this ref
         oflog << " " << setw(5) << ttit->length;
         if(CI.Screen)
            cout << " " << setw(5) << ttit->length;
         oflog << endl;
         if(CI.Screen)
            cout << endl;

         // for next time
         sat = ttit->sat;
      }
      oflog << "End of time table." << endl;
      if(CI.Screen)
         cout << "End of time table." << endl;
   }

   return iret;

   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 Timetable()
Example #15
0
 void RinexNavHeader::reallyPutRecord(FFStream& ffs) const 
    throw(std::exception, FFStreamError, StringException)
 {
    RinexNavStream& strm = dynamic_cast<RinexNavStream&>(ffs);
    
    strm.header = (*this);
    
    unsigned long allValid;
    if (version == 2.0)        allValid = allValid20;
    else if (version == 2.1)   allValid = allValid21;
    else if (version == 2.11)  allValid = allValid211;
    else
    {
       FFStreamError err("Unknown RINEX version: " + asString(version,3));
       err.addText("Make sure to set the version correctly.");
       GPSTK_THROW(err);
    }
    
    if ((valid & allValid) != allValid)
    {
       FFStreamError err("Incomplete or invalid header.");
       err.addText("Make sure you set all header valid bits for all of the available data.");
       GPSTK_THROW(err);
    }
    
    string line;
    
    if (valid & versionValid)
    {
       line  = rightJustify(asString(version,3), 10);
       line += string(10, ' ');
       line += string("NAVIGATION"); //leftJustify(fileType, 20);
       line += string(30, ' ');
       line += versionString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & runByValid) 
    {
       line  = leftJustify(fileProgram,20);
       line += leftJustify(fileAgency,20);
       DayTime dt;
       dt.setLocalTime();
       string dat = dt.printf("%02m/%02d/%04Y %02H:%02M:%02S");
       line += leftJustify(dat, 20);
       line += runByString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & commentValid)
    {
       vector<string>::const_iterator itr = commentList.begin();
       while (itr != commentList.end())
       {
          line  = leftJustify((*itr), 60);
          line += commentString;
          strm << line << endl;
          strm.lineNumber++;
          itr++;
       }
    }
    if (valid & ionAlphaValid)
    {
       line  = string(2, ' ');
       for (int i = 0; i < 4; i++)
       {
          line += rightJustify(doub2for(ionAlpha[i], 12, 2),12);  // should be 12.4
       }
       line += string(10, ' ');
       line += ionAlphaString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & ionBetaValid)
    {
       line  = string(2, ' ');
       for (int i = 0; i < 4; i++)
       {
          line += rightJustify(doub2for(ionBeta[i], 12, 2),12);
       }
       line += string(10, ' ');
       line += ionBetaString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & deltaUTCValid)
    {
       line  = string(3, ' ');
       //line += string(2, ' ');
       line += doub2for(A0, 19, 2);
       line += doub2for(A1, 19, 2);
       line += rightJustify(asString(UTCRefTime),9);
       line += rightJustify(asString(UTCRefWeek),9);               
       line += string(1, ' ');
       line += deltaUTCString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & leapSecondsValid)
    {
       line  = rightJustify(asString(leapSeconds), 6);
       line += string(54, ' ');
       line += leapSecondsString;
       strm << line << endl;
       strm.lineNumber++;
    }
    if (valid & endValid)
    {
       line  = string(60,' ');
       line += endOfHeader;
       strm << line << endl;
       strm.lineNumber++;
    }
    
 }
Example #16
0
//------------------------------------------------------------------------------------
int EditDDSlips(const DDid& ddid, DDData& dddata, int frequency) throw(Exception)
{
try {
   int i,j,k,n,m,tdcount,tddt,ii,iter;
   double slip,fslip,tol;
   vector<int> slipindex;
   vector<double> td,slipsize;
   DayTime tt;
   TwoSampleStats<double> tsstats;

      // -------------------------------------- define td tolerance for slips
   const int iter_limit = 3;       // this allows iter_limit-1 slips to be fixed
   const double tolerance = 0.5;         // cycles
   // 3.4 const double tol = 0.5;        // cycles -- TD make input
   // 3.2 revert tol = 0.9;        // cycles
//#define turnoffslips 1

      // iterate
   for(iter=1; iter<=iter_limit; iter++) {
      if(iter == 1) tol = tolerance;
      if(iter >  1) tol = 0.6 * tolerance;
      td.clear();
      slipsize.clear();
      slipindex.clear();
      tsstats.Reset();

         // -------------------------------------- find slips
         // compute triple differences
         // j is the index of the previous good point
      for(k=0,j=-1,i=0; i<dddata.count.size(); i++) {
         if(mark[i] == 0) {
            //oflog << "Data 1 marked at count " << dddata.count[i] << endl;
            continue;
         }
         if(j == -1) { j = i; continue; }
         //tdcount = dddata.count[i];
         tt = FirstEpoch + CI.DataInterval * dddata.count[i];
         tddt = dddata.count[i]-dddata.count[j];
         td.push_back(
            (frequency == 1 ? dddata.DDL1[i] - dddata.DDL1[j]
                            : dddata.DDL2[i] - dddata.DDL2[j]  )
               - (dddata.DDER[i] - dddata.DDER[j])
         );
         tsstats.Add(dddata.count[i],td[k]);
            // slip in cycles
         slip = td[k]/(frequency == 1 ? wl1 : wl2);
            // fractional part of slip
         fslip = fabs(fmod(slip,1.0));
         if(fslip > 0.5) fslip = 1.0-fslip;
#ifndef turnoffslips
            // look for slips
            // if frac > 0.2, call it a slip anyway and hope it will be combined
         if(fabs(slip) > tol) {  // || fslip > 0.2) 
            oflog << " Warning - DD " << ddid << " L" << frequency << fixed
               << " slip " << setprecision(3) << setw(8) << slip << " cycles, at "
               << tt.printf(" %4F %10.3g = %Y/%02m/%02d %2H:%02M:%6.3f")
               << " = count " << dddata.count[i] << " on iteration " << iter
               << endl;

               // first see if it can be combined with previous slip
            n = slipindex.size();
            if(n>0 && dddata.count[i]-dddata.count[slipindex[n-1]] < CI.MaxGap)  {
                  // combine these slips
               slipsize[n-1] += slip;
                  // mark all points from old slip to pt before this as bad
               for(m=slipindex[n-1]; m<i; m++) {
                  mark[m] = 0;
                  ngood--;
                  nbad++;
               }
               slipindex[n-1] = i;
               oflog << " Warning - DD " << ddid << " L" << frequency << fixed
                     << " last two slips combined (iter " << iter << ")"
                     << endl;
            }
            else {
               slipindex.push_back(i);
               slipsize.push_back(slip);
            }
         }
#endif
         if(tddofs) {
            tddofs << "TDS " << ddid << " L" << frequency << fixed
               << " " << iter
               << " " << setw(4) << dddata.count[i]
               << " " << tt.printf("%4F %10.3g")
               << " " << setw(3) << tddt << setprecision(6)
               << " " << setw(11) << td[k]
               << " " << setw(11) << slip << setprecision(3)
               << " " << setw(8) << fslip
               << endl; }

         k++;
         j = i;
      } // end for loop over dddata to compute TDs

         // if too small, delete the whole pass
      if(td.size() < 10) return -1;

         // print stats to log
      if(CI.Verbose) {
         double median,mad,mest;
         vector<double> weights;
         weights.resize(td.size());
         mad = Robust::MedianAbsoluteDeviation(&td[0], td.size(), median);
         mest = Robust::MEstimate(&td[0], td.size(), median, mad, &weights[0]);

         oflog << " TUR " << ddid << " L" << frequency << fixed << setprecision(3)
            << " " << iter
            << " " << setw(5) << tsstats.N()
            << " " << setw(7) << tsstats.AverageY()
            << " " << setw(7) << tsstats.StdDevY()
            << " " << setw(7) << tsstats.SigmaYX()
            << "  " << setw(7) << median
            << " " << setw(7) << mest
            << " " << setw(7) << mad
            << endl;
      }

         // if no slips found, normal return
      if(slipindex.size() == 0) return 0;
         // if on last iteration, don't bother to fix...
      if(iter == iter_limit) break;
         // TD check for too many slips -> reject the whole pass

      //if(CI.Verbose) for(i=0; i<slipindex.size(); i++)
      //   oflog << "Slip " << " L" << frequency << setprecision(3) << slipsize[i]
      //      << " found at count " << dddata.count[slipindex[i]] << endl;

         // -------------------------------------- remove slips
         // add a dummy..
      slipindex.push_back(99999);

         // ii is slip count, k is current correction in cycles,
         // j is index of previous good point
      for(k=0,j=-1,ii=0,i=0; i<dddata.count.size(); i++) {
         if(mark[i] == 0) {
            //oflog << "Data 2 marked at " << dddata.count[i] << endl;
            continue;
         }
         tt = FirstEpoch + CI.DataInterval * dddata.count[i];
            // fix
         if(i == slipindex[ii]) {     // new slip on this count
            k += int(slipsize[ii] + (slipsize[ii]>0 ? 0.5 : -0.5));
            if(CI.Verbose) oflog << " Fix L" << frequency << " slip at count "
               << dddata.count[i]
               << " " << tt.printf("%4F %10.3g")
               << " total mag " << k << " iteration " << iter
               << endl;
            ii++;
         }
            // fix double differences using accumulated net slip
         if(k != 0) {
            if(frequency == 1) dddata.DDL1[i] -= k * wl1;
            else               dddata.DDL2[i] -= k * wl2;
         }
            // output the slip-edited DDs and TDs
         if(tddofs) {
            tddofs << "SED " << ddid << fixed
               << " L" << frequency
               << " " << iter
               << " " << setw(4) << dddata.count[i]
               << " " << tt.printf("%4F %10.3g")
               << " " << setw(11) << setprecision(6)           // DD in m
               << (frequency == 1 ?  dddata.DDL1[i] : dddata.DDL2[i])
                     - dddata.DDER[i]
               << " " << setw(11)
               << (j == -1 ? 0.0 :                             // TD in m
                     (frequency == 1 ?  dddata.DDL1[i] - dddata.DDL1[j] :
                                        dddata.DDL2[i] - dddata.DDL2[j])
                        - (dddata.DDER[i] - dddata.DDER[j])
                  )
               << endl;

            j = i;

         }  // end output

      }  // end for loop over data to fix slips

   } // end for loop over iterations

      // failed - return non-zero to delete the whole segment
   oflog << " Warning - Delete " << ddid << " L" << frequency
      << ": unable to fix slips" << endl;

   return -1;
}
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); }
}
Example #17
0
//------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
try {
   clock_t totaltime;            // for timing
   totaltime = clock();

   // locals
   int i,iret=0;
   DayTime CurrEpoch;         // defaults to current local time
   SolarSystem SSEphemeris;

   // program name, title and version
   PrgmName = string("testSSEph");
   Title = PrgmName + ", test program for JPL ephemeris, version "
      + Version + ", " + CurrEpoch.printf("Run %04Y/%02m/%02d at %02H:%02M:%02S");

   // default command line input
   bool verbose=false,debug=false;
   string inputFilename,testFilename,logFilename;

   // parse the command line input
   for(i=0; i<argc; i++) {
      string word = string(argv[i]);
      if(argc == 1 || word == "-h" || word == "--help") {
         cout << "Program " << PrgmName
            << " reads a binary JPL planetary ephemeris file, created by "
            << "convertSSEph,\n  and a test file, downloaded from the JPL ftp site, "
            << "containing times and planets\n  with JPL-generated ephemeris "
            << "coordinate values. The coordinates are computed using\n  the binary "
            << "file and the SolarSystem class, and compared with the JPL values;\n  "
            << "any difference larger than 10^-13 is noted with the word 'Failure' "
            << "at EOL.\n  Note that some large coordinate values may differ at the "
            << "level of 10^-13 because the\n  size of double precision is barely "
            << "able to hold that much precision; compare the\n  computed value "
            << "with the JPL value (copied as a string) in the output file.\n"
            << "\n Usage: " << PrgmName << " [options]\n Options are:\n"
            << "   --log <file>   name of optional log file (otherwise stderr)\n"
            << "   --file <file>  name of binary SS ephemeris file\n"
            << "   --test <file>  name of JPL test file (e.g. testpo.403)\n"
            << "   --verbose      print info to the log file.\n"
            << "   --debug        print debugging info to the log file.\n"
            << "   --help         print this and quit.\n"
            ;
         return 0;
      }
      else if(i == 0) continue;
      else if(word == "-d" || word == "--debug") debug = true;
      else if(word == "-v" || word == "--verbose") verbose = true;
      else if(word == "--log") logFilename = string(argv[++i]);
      else if(word == "--file") inputFilename = string(argv[++i]);
      else if(word == "--test") testFilename = string(argv[++i]);
   }

   // test input
   if(inputFilename.empty()) {
      LOG(ERROR) << "Must specify an input binary file name";
      return -1;
   }
   if(testFilename.empty()) {
      LOG(ERROR) << "Must specify an input test file name";
      return -1;
   }

   if(!logFilename.empty()) {
      // choose the log file
      logstrm.open(logFilename.c_str(),ios_base::out);
      ConfigureLOG::Stream() = &logstrm;
      // if not the above, output is to stderr

      cout << Title << endl;
      cout << "Output is logged to file " << logFilename << endl;
   }

      // set the maximum level to be logged
   ConfigureLOG::ReportLevels() = ConfigureLOG::ReportTimeTags() = true;
   if(debug)
      ConfigureLOG::ReportingLevel() = ConfigureLOG::FromString("DEBUG");
   else if(verbose)
      ConfigureLOG::ReportingLevel() = ConfigureLOG::FromString("VERBOSE");
   else
      ConfigureLOG::ReportingLevel() = ConfigureLOG::FromString("INFO");
      // = any of ERROR,WARNING,INFO,VERBOSE,DEBUG,DEBUGn (n=1,2,3,4,5,6,7)
   //cout << "Reporting in main is "
   //   << ConfigureLOG::ToString(ConfigureLOG::ReportingLevel()) << endl;

   // display title in the log file
   LOG(INFO) << Title;

   // now read the binary file, and read selected records
   // use the binary to test using the JPL file testpo.<EPH#>
   LOG(VERBOSE) << "Initialize with file " << inputFilename;
   SSEphemeris.initializeWithBinaryFile(inputFilename);
   LOG(VERBOSE) << "End Initialize";
   LOG(INFO) << "Ephemeris number is " << SSEphemeris.JPLNumber();

   bool foundEOT=false;
   int target,center,coord;
   double JD,PV[6],value,diff;
   SolarSystem::Planet Target,Center;
   ifstream istrm;

   istrm.open(testFilename.c_str(),ios::in);
   if(!istrm.is_open()) {
      LOG(ERROR) << "Could not open test file " << testFilename;
   }
   else while(1) {
      string line,word;
      getline(istrm,line);
      stripTrailing(line,'\r');
      strip(line);
      if(line.empty())
         ;
      else if(line == string("EOT"))
         foundEOT = true;
      else if(!foundEOT)
         ;
      else {
         word = stripFirstWord(line);     // DEPHEM
         word = stripFirstWord(line);     // date in YYYY.MM.DD form
         JD = for2doub(stripFirstWord(line));
         target = asInt(stripFirstWord(line));
         center = asInt(stripFirstWord(line));
         coord = asInt(stripFirstWord(line)) - 1;  // my coords are 0-5, theirs 1-6
         word = stripFirstWord(line);
         value = for2doub(word);
         word = rightJustify(word,25);

         Target = SolarSystem::Planet(target);
         Center = SolarSystem::Planet(center);
         iret = SSEphemeris.computeState(JD, Target, Center, PV, false);
         if(iret == -1 || iret == -2) continue;   // time is not in file

         diff = fabs(PV[coord]-value);
         LOG(INFO) << fixed << setprecision(1) << setw(9) << JD
            << " " << setw(2) << target //<< " " << setw(2) << Target
            << " " << setw(2) << center //<< " " << setw(2) << Center
            << " " << setw(1) << coord+1
            << " " << scientific << setprecision(5) << setw(13) << diff
            << " " << word
            << " " << fixed << setprecision(20) << setw(25) << PV[coord]
            << " " << iret
            << (diff > 1.e-13 ? " Failure" : "")
            ;
      }

      if(istrm.eof() || !istrm.good()) break;
   }

   if(iret) LOG(INFO) << PrgmName << " terminating with error code " << iret
      << ", which means " <<
      (iret == 0 ? "OK" : 
      (iret == -1 ? "last time in file was before first time in ephemeris" :
      (iret == -2 ? "time is beyond end time of ephemeris" :
      (iret == -3 ? "file reading failed" : "ephemeris file is corrupted")))) ;

      // compute run time
   totaltime = clock()-totaltime;
   LOG(INFO) << PrgmName << " timing: " << fixed << setprecision(9)
      << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds.";
   if(LOGstrm != cout) cout << PrgmName << " timing: " << fixed << setprecision(9)
      << double(totaltime)/double(CLOCKS_PER_SEC) << " seconds." << endl;

   return iret;
}
catch(Exception& e) {
   LOG(ERROR) << "GPSTk Exception : " << e.what();
}
catch (...) {
   LOG(ERROR) << "Unknown error in " << PrgmName << ".  Abort." << endl;
}
   return -1;
}   // end main()
Example #18
0
   void RinexMetHeader::reallyPutRecord(FFStream& ffs) const
      throw(std::exception, FFStreamError,
            gpstk::StringUtils::StringException)
   {
      RinexMetStream& strm = dynamic_cast<RinexMetStream&>(ffs);
      
         // since they want to output this header, let's store
         // it internally for use by the data
      strm.header = (*this);
      
         // i'm casting out const here to set the correct required valid bits.
         // deal with it =P
	 

      unsigned long allValid;
      if (version == 2.0)        allValid = allValid20;
      else if (version == 2.1)   allValid = allValid21;
      else
      {
         FFStreamError err("Unknown RINEX version: " + asString(version,2));
         err.addText("Make sure to set the version correctly.");
         GPSTK_THROW(err);
      }
      
      if ((valid & allValid) != allValid)
      {
         string errstr("Incomplete or invalid header: missing: ");
         errstr += bitString(allValid & ~valid);
         FFStreamError err(errstr);
         err.addText("Make sure you set all header valid bits for all of the available data.");
         GPSTK_THROW(err);
      }
      
      string line;
         // line by line, let's do this.
      if (valid & versionValid)
      {
         line  = rightJustify(asString(version,2), 9);
         line += string(11, ' ');
         line += leftJustify(fileType, 40);
         line += versionString;
         strm << line << endl;
         strm.lineNumber++;
      }
      if (valid & runByValid)
      {
         line  = leftJustify(fileProgram,20);
         line += leftJustify(fileAgency,20);
         DayTime dt;
         dt.setLocalTime();
         string dat = dt.printf("%02m/%02d/%04Y %02H:%02M:%02S");
         line += leftJustify(dat, 20);
         line += runByString;
         strm << line << endl;
         strm.lineNumber++;
      }
      if (valid & commentValid)
      {
         vector<string>::const_iterator itr = commentList.begin();
         while (itr != commentList.end())
         {
            line  = leftJustify((*itr), 60);
            line += commentString;
            strm << line << endl;
            strm.lineNumber++;
            itr++;
         }
      }
      if (valid & markerNameValid)
      {
         line  = leftJustify(markerName, 60);
         line += markerNameString;
         strm << line << endl;
         strm.lineNumber++;
      }
      if (valid & markerNumberValid)
      {
         line  = leftJustify(markerNumber, 60);
         line += markerNumberString;
         strm << line << endl;
         strm.lineNumber++;
      }
      if (valid & obsTypeValid)
      {
         line  = rightJustify(asString(obsTypeList.size()),6);
         vector<RinexMetType>::const_iterator itr = obsTypeList.begin();
         size_t numWritten = 0;
         while (itr != obsTypeList.end())
         {
            numWritten++;
               // stupid continuation lines =P
            if ((numWritten % (maxObsPerLine+1)) == 0)
            {
               line += obsTypeString;
               strm << line << endl;
               strm.lineNumber++;
               line = string(6,' ');
            }
            line += rightJustify(convertObsType(*itr), 6);
            itr++;
         }
            // pad the line out to 60 chrs and add label
         line += string(60 - line.size(), ' ');
         line += obsTypeString;
         strm << line << endl;
         strm.lineNumber++;
      }
      if (valid & sensorTypeValid)
      {
            // only write out the sensor types that are 
            // in the obsTypeList
         vector<sensorType>::const_iterator itr = sensorTypeList.begin();
         while (itr != sensorTypeList.end())
         {
            if (std::find(obsTypeList.begin(), obsTypeList.end(),
                          (*itr).obsType) != obsTypeList.end())
            {
               line  = leftJustify((*itr).model, 20);
               line += leftJustify((*itr).type, 20);
               line += string(6, ' ');
               line += rightJustify(asString((*itr).accuracy,1),7);
               line += string(4, ' ');
               line += convertObsType((*itr).obsType);
               line += string(1, ' ');
               line += sensorTypeString;
               strm << line << endl;
               strm.lineNumber++;
            }
            itr++;
         }
      }
      if (valid & sensorPosValid)
      {
            // only write out the sensor positions that are 
            // in the obsTypeList
         vector<sensorPosType>::const_iterator itr = sensorPosList.begin();
         while (itr != sensorPosList.end())
         {
            if (std::find(obsTypeList.begin(), obsTypeList.end(),
                     (*itr).obsType) != obsTypeList.end())
            {
               line  = rightJustify(asString((*itr).position[0],4),14);
               line += rightJustify(asString((*itr).position[1],4),14);
               line += rightJustify(asString((*itr).position[2],4),14);
               line += rightJustify(asString((*itr).height,4),14);
               line += string(1, ' ');
               line += convertObsType((*itr).obsType);
               line += string(1, ' ');
               line += sensorPosString;
               strm << line << endl;
               strm.lineNumber++;
            }
            itr++;
         }
      }
      if (valid & endValid)
      {
         line  = string(60, ' ');
         line += endOfHeader;
         strm << line << endl;
         strm.lineNumber++;
      }
   }     
Example #19
0
//------------------------------------------------------------------------------------
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()
Example #20
0
int WriteStatsFile(string statsfile)
{
try
{
   ofstream sofs;

   sofs.open(statsfile.c_str(),ios_base::out);
   if (!sofs) return -7;
   else
   {
      bool wtd;
      double W,f;
      int i;
      for (i=0; i<Grid.size(); i++)
      {
         W = 1.0;

         // for completeness, if stats are weighted (they are not in this program's output),
         // they have to be re-normalized....
         wtd = HGridStats[i].Weighted();
         if (wtd)
         {
            W = HGridStats[i].Normalization();
            f = W / double(HGridStats[i].N());
         }
         // write the unweighted stats to the file
         sofs << " " << setw(5) << i
            << fixed << setprecision(2)
            << " " << setw(7) << Grid[i].lon << " " << setw(6) << Grid[i].lat
            << setprecision(10)
            << " " << setw( 4) << HGridStats[i].N()
            << " " << setw(12) << HGridStats[i].Minimum()
            << " " << setw(12) << HGridStats[i].Maximum();
         if (wtd)
         {
            sofs << " " << setw(12) << HGridStats[i].Average()*f
                 << " " << setw(12) << HGridStats[i].Variance()*f*f*f*f
                 << " Y";           // this says 'are they weighted?' (see Stats.hpp in GPS-Tk)
         }
         else
         {
            sofs << " " << setw(12) << HGridStats[i].Average()
                 << " " << setw(12) << HGridStats[i].Variance()
                 << " N";
         }
         sofs << " " << setw(12) << W;
   
         wtd = NGridStats[i].Weighted();
         if (wtd)
         {
            W = NGridStats[i].Normalization();
            f = W / double(NGridStats[i].N());
         }
         sofs << setprecision(10)
            << " " << setw( 4) << NGridStats[i].N()
            << " " << setw(12) << NGridStats[i].Minimum()
            << " " << setw(12) << NGridStats[i].Maximum();
         if (wtd)
         {
            sofs << " " << setw(12) << NGridStats[i].Average()*f
                 << " " << setw(12) << NGridStats[i].Variance()*f*f*f*f
                 << " Y";
         }
         else
         {
            sofs << " " << setw(12) << NGridStats[i].Average()
                 << " " << setw(12) << NGridStats[i].Variance()
                 << " N";
         }
         sofs << " " << setw(12) << W
              << endl;
      }

      // output absolute worst-site DOPs

      sofs << "Abs WORSTN"
           << " " << setw(5) << IworstN
           << TworstN.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstN].lon
           << " " << setw(7) << Grid[IworstN].lat
           << " " << setw(5) << WorstN
           << " " << setw(5) << NtrofN
           << endl;
      sofs << "Abs WORSTG"
           << " " << setw(5) << IworstG
           << TworstG.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstG].lon
           << " " << setw(7) << Grid[IworstG].lat
           << " " << setw(5) << WorstG
           << " " << setw(5) << NpeakG
           << endl;
      sofs << "Abs WORSTP"
           << " " << setw(5) << IworstP
           << TworstP.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstP].lon
           << " " << setw(7) << Grid[IworstP].lat
           << " " << setw(5) << WorstP
           << " " << setw(5) << NpeakP
           << endl;
      sofs << "Abs WORSTH"
           << " " << setw(5) << IworstH
           << TworstH.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstH].lon
           << " " << setw(7) << Grid[IworstH].lat
           << " " << setw(5) << WorstH
           << " " << setw(5) << NpeakH
           << endl;
      sofs << "Abs WORSTV"
           << " " << setw(5) << IworstV
           << TworstV.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstV].lon
           << " " << setw(7) << Grid[IworstV].lat
           << " " << setw(5) << WorstV
           << " " << setw(5) << NpeakV
           << endl;
      sofs << "Abs WORSTT"
           << " " << setw(5) << IworstT
           << TworstT.printf(" %4F %8.1g")
           << fixed << setprecision(2)
           << " " << setw(7) << Grid[IworstT].lon
           << " " << setw(7) << Grid[IworstT].lat
           << " " << setw(5) << WorstT
           << " " << setw(5) << NpeakT
           << endl;

      // output worst-site DOPs averaged over the day (avg. of worst-site values @ each timept.)

      sofs << "Avg WORSTN "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.wnsvs << endl;
      sofs << "Avg WORSTG "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.wgdop << endl;
      sofs << "Avg WORSTP "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.wpdop << endl;
      sofs << "Avg WORSTH "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.whdop << endl;
      sofs << "Avg WORSTV "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.wvdop << endl;
      sofs << "Avg WORSTT "
           << fixed << setprecision(2) << setw(5) << AvgWorstSiteDOP.wtdop << endl;

   }
   sofs.close();
   
return 0;
}
catch(Exception& e) { GPSTK_RETHROW(e); }
}
Example #21
0
void NavSum::process()
{
   try
   {
   ofstream out;
   out.open(outputFileOption.getValue()[0].c_str());
   if (out.fail())
   {
      cout << "Opening output file " << outputFileOption.getValue()[0] 
           << " failed." << endl
           << "   navsum is ending..." << endl
           << endl;
      return;
   }

      // filter the data...  first by block number, then by PRN
   FileFilterFrame<FICStream, FICData> data(inputFileOption.getValue()[0]);
   if (!blockFilterList.empty())
      data.filter(FICDataFilterBlock(blockFilterList));
   if (!prnFilterList.empty())
      data.filter(FICDataFilterPRN(prnFilterList));
      
   out << "Block#       PRN or                Transmit            !        Toe/Toa" << endl;
   out << "in set Type   SVID   mm/dd/yy DOY hh:mm:ss Week    SOW ! mm/dd/yy DOY HH:MM:SS" << endl;
   std::string xmitFmt("%02m/%02d/%02y %03j %02H:%02M:%02S %4F %6.0g");
   std::string epochFmt("%02m/%02d/%02y %03j %02H:%02M:%02S");
   DayTime XMitT;
   DayTime EpochT;
   uint32_t temp;
   int PRNID; 
   int xmitPRN;
   int xMitWeek;
   int EpochWeek;
   char line[100];
   string linestr;
      
   int count = 0;
   list<FICData>& ficlist = data.getData();
   list<FICData>::iterator itr = ficlist.begin();
   while (itr != ficlist.end())
   {
		FICData& r = *itr;
      count++;
      int blockType = r.blockNum;
      double diff = 0.0;
      double Toe = 0.0;
      double HOW = 0.0;
      double xMitSOW = 0.0;
      double iMitSOW = 0;
      long IODC = 0;
      int fit = 0;
      switch (blockType)
      {
			case 9:
				PRNID = (short) r.f[19];
				HOW = r.f[2];
				Toe = r.f[33];
				xMitWeek = (int) r.f[5];
				IODC = ((long) r.f[9]) / 2048;
				fit = (int) r.f[34];
				EpochWeek = xMitWeek;
				diff = Toe - HOW;
				if (diff < -1.0 * (double) DayTime::HALFWEEK) EpochWeek++;
				if (diff > (double) DayTime::HALFWEEK) xMitWeek--;
				XMitT = DayTime( xMitWeek, HOW-6.0 );
				EpochT = DayTime( EpochWeek, Toe );
				sprintf(line," %5d  %3d    %02d    %s ! %s 0x%03lX %1d",
					count,blockType,PRNID,
					XMitT.printf(xmitFmt).c_str(),
					EpochT.printf(epochFmt).c_str(),
					IODC,
					fit);
				linestr = string(line);
				out << linestr << endl;
				totalsByBlock[BLK9]++;
				totalsByPRN[PRNID][BLK9]++;
				break;
               
			case 109:
				PRNID = (int) r.i[1];
				xMitWeek = (int) r.i[0];
				temp = (uint32_t) r.i[3];
				XMitT = buildXMitTime( temp, xMitWeek );
				sprintf(line," %5d  %3d    %02d    %s !",
					count,blockType,PRNID,
					XMitT.printf(xmitFmt).c_str() );
				linestr = string(line);
				out << linestr << endl;
				totalsByBlock[BLK109]++;
				totalsByPRN[PRNID][BLK109]++;
				break;
               
			case 62:
				PRNID = r.i[3];
				xMitWeek = (int) r.i[5];
				EpochWeek = (int) r.i[0];
				iMitSOW = r.i[1];
				if (iMitSOW<0)
				{
					iMitSOW += gpstk::DayTime::FULLWEEK;
					xMitWeek--;
				}
				xMitSOW = (double) iMitSOW;
				XMitT = DayTime( xMitWeek, xMitSOW );
				if (PRNID>0 && PRNID<33)
				{
					EpochT = DayTime( EpochWeek, r.f[8] );
					sprintf(line," %5d  %3d    %02d    %s ! %s",
						count,blockType,PRNID,
						XMitT.printf(xmitFmt).c_str(),
						EpochT.printf(epochFmt).c_str() );
				}
				else
				{
					sprintf(line," %5d  %3d    %02d    %s !",
						count,blockType,PRNID,
						XMitT.printf(xmitFmt).c_str() );
				}
				linestr = string(line);
				out << linestr << endl;
				totalsByBlock[BLK62]++;
				totalsBySVID[PRNID][BLK62]++;
				break;
               
			case 162:
				PRNID = r.i[0];
				xMitWeek = r.i[14];
				EpochWeek = r.i[13];
				temp = (uint32_t) r.i[2];
				xmitPRN = r.i[11];
				XMitT = buildXMitTime( temp, xMitWeek );
				sprintf(line," %5d  %3d    %02d    %s !                        %02d",
					count,blockType,PRNID,
					XMitT.printf(xmitFmt).c_str(),
					xmitPRN);
				linestr = string(line);
				out << linestr << endl;
				totalsByBlock[BLK162]++;
				totalsBySVID[PRNID][BLK162]++;
				break;
		}
         
		itr++;
   }
   printSummary( out );
   }
   catch (Exception& exc)
   {
      cerr << exc;
      exit(1);
   }
   catch (...)
   {
      cerr << "Caught unknown exception" << endl;
      exit(1);
   }
}