Beispiel #1
0
//=============================================================================
// General test for the SP3EphemerisStore
// Makes sure SP3EphemerisStore can be instantiated and can load
// a file; also ensures that nonexistent files throw an exception
//=============================================================================
   int SP3ESTest(void)
   {
      TUDEF( "SP3EphemerisStore", "Constructor" );

         // Verify the consturctor builds the SP3EphemerisStore object
      try
      {
         SP3EphemerisStore store;
         TUPASS("SP3EphemerisStore object successfully created");
      }
      catch (...)
      {
         TUFAIL("SP3EphemerisStore object could not be created");
      }

      SP3EphemerisStore store;

         // Verify opening an empty file throws an error
      try
      {
         store.loadFile(inputNotaFile);
         TUFAIL("Opening an empty file did not throw an exception");
      }
      catch (Exception& e)
      {
         TUPASS("Opening an empty file threw the correct exception");
      }
      catch (...)
      {
         TUFAIL("Opening an empty file caused an unexpected exception");
      }

         // Verify opening a file works with no errors
      try
      {
/*
  fstream smoo;
  smoo.open(inputSP3Data.c_str(),std::ios::in);
  testFramework.assert(smoo, "plain file open fail", __LINE__);
  smoo.close();
  cerr << "-------------------------" << endl;
*/
         store.loadFile(inputSP3Data);
//         cerr << "-------------------------" << endl;
         TUPASS("Opening a valid file works with no exceptions");
      }
      catch (...)
      {
//         cerr << "-------------------------" << endl;
         TUFAIL("Exception thrown when opening a valid file");
      }

         // Write the dump of the loaded file
      ofstream DumpData;
      DumpData.open (outputDataDump.c_str());
      store.dump(DumpData,1);
      DumpData.close();

      return testFramework.countFails();
   }
Beispiel #2
0
gpstk::CommonTime compSatVis::setStartTime()
{
   CommonTime retDT = GPSWeekSecond( 621, 0.0 );     // 12/1/1991
   CommonTime initialTime;
   CommonTime finalTime;
   
   switch(navFileType)
   {
      case FIC_EPH:
      case RINEX_NAV:
         initialTime = BCEphList.getInitialTime();
         finalTime   = BCEphList.getFinalTime();
         break;
            
      case FIC_ALM:
         initialTime = BCAlmList.getInitialTime();
         finalTime   = BCAlmList.getFinalTime();
         break;

      case Yuma_ALM:
         initialTime = YumaAlmStore.getInitialTime();
         finalTime   = YumaAlmStore.getFinalTime();
         break;

      case SEM_ALM:
         initialTime = SEMAlmStore.getInitialTime();
         finalTime   = SEMAlmStore.getFinalTime();
         break;

         // If loading "day at a time" files, will need 
         // three days to cover middle day.  We need to 
         // find the middle of whatever period was loaded
         // and back up to the beginning of that day.
      case SP3:
      {
         initialTime = SP3EphList.getInitialTime();
         finalTime = SP3EphList.getFinalTime();
         break;
      }   
   }
   double diff = finalTime - initialTime;
   retDT = initialTime;
   retDT += diff/2.0;
   retDT = YDSTime( static_cast<YDSTime>(retDT).year, static_cast<YDSTime>(retDT).doy, 0.0 );
   return(retDT);
}        
Beispiel #3
0
//=============================================================================
// Test for getFinalTime
// Tests getFinalTime method in SP3EphemerisStore by ensuring that
// the method outputs the final time stamp in an SP3 file
//=============================================================================
   int getFinalTimeTest (void)
   {
      TUDEF( "SP3EphemerisStore", "getFinalTime" );

      try
      {
         SP3EphemerisStore store;
         store.loadFile(inputSP3Data);

         CommonTime computedFinalTime = store.getFinalTime();

         CivilTime knownFinalTime_civ(1997,4,6,23,45,0);
         CommonTime knownFinalTime = knownFinalTime_civ.convertToCommonTime();

            // Check that the function returns the initial time from the file
         TUASSERTE(CommonTime, knownFinalTime, computedFinalTime);
      }
      catch (...)
      {
         TUFAIL("Unexpected exception");
      }

      return testFramework.countFails();
   }
Beispiel #4
0
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
int FillEphemerisStore(const vector<string>& files, SP3EphemerisStore& PE,
                                                     GPSEphemerisStore& BCE)
{
   try
   {
      int nread = 0;
      Rinex3NavHeader rnh;
      Rinex3NavData rne;
      for(size_t nfile = 0; nfile < files.size(); nfile++) {
         if(files[nfile].empty()) {
            Exception e("File name is empty");
            GPSTK_THROW(e);
         }

         if(isRinex3NavFile(files[nfile]) || isRinexNavFile(files[nfile])) {
            Rinex3NavStream instrm(files[nfile].c_str());
            instrm.exceptions(fstream::failbit);
            try {
               instrm >> rnh;
               while (instrm >> rne) {
                  // check health...
                  if(rne.health == 0)
                     BCE.addEphemeris(rne);
               }
               nread++;
            }
            catch(Exception& e) {
               GPSTK_RETHROW(e);
            }
         }

         else if(isSP3File(files[nfile])) {
            try {
               PE.loadFile(files[nfile]);
               nread++;
            }
            catch(Exception& e) { GPSTK_RETHROW(e); }
         }
         else {
            Exception e("File " + files[nfile]
                  + " is neither Rinex Nav nor SP3 file.");
            GPSTK_THROW(e);
         }
      }
Beispiel #5
0
void compSatVis::computeVisibility( gpstk::CommonTime currT )
{
   gpstk::Position SVpos[gpstk::MAX_PRN+1];
   bool SVAvail[gpstk::MAX_PRN+1];
   Xvt SVxvt;
   
      // Compute SV positions for this epoch
   int PRNID;
   for (PRNID=1;PRNID<=gpstk::MAX_PRN;++PRNID)
   {
      SVAvail[PRNID] = false;
      try
      {
         SatID satid(PRNID,SatID::systemGPS);
         switch(navFileType)
         {
            case FIC_EPH:
            case RINEX_NAV:
               SVxvt = BCEphList.getXvt( satid, currT );
               break;
            
            case FIC_ALM:
               SVxvt = BCAlmList.getXvt( satid, currT );
               break;
            
            case Yuma_ALM:
               SVxvt = YumaAlmStore.getXvt( satid, currT );
               break;
 
            case SEM_ALM:
               SVxvt = SEMAlmStore.getXvt( satid, currT );
               break;
            
            case SP3:
               SVxvt = SP3EphList.getXvt( satid, currT );
               break;
               
            default:
               cerr << "Unknown navigation file type in computeVisibility()." << endl;
               cerr << "Fatal error. compSatVis will halt." << endl;
               exit(1);
         }
         SVpos[PRNID] = SVxvt.x; 
         SVAvail[PRNID] = true;
      }
      catch(InvalidRequest& e)
      { 
         continue;
      }
   }
   
      // If first time through, print the detail hearder if required.
   if (detailPrint && currT==startT)
   {
      fprintf(logfp," Number of Stations visible to each SV by epoch\n");
      fprintf(logfp,"  PRN, ");
      for (int pi=1;pi<=gpstk::MAX_PRN;++pi)
      {
         if (SVAvail[pi]) fprintf(logfp," %4d,",pi);
      }
      fprintf(logfp,"   Max,   Min\n");
   }
   
   if (detailPrint) fprintf(logfp,"%s, ",printTime(currT,"%02H:%02M").c_str());

      // Now count number of Stations visible to each SV
   int maxNum = 0;
   int minNum = stationPositions.size() + 1; 
   StaPosList::const_iterator splCI;
   DiscreteVisibleCounts& dvc0 = dvcList.find(0)->second;
   
   for (PRNID=1;PRNID<=gpstk::MAX_PRN;++PRNID)
   {
      if (!SVAvail[PRNID]) continue;
      int numVis = 0;
      for (splCI =stationPositions.begin();
           splCI!=stationPositions.end();
           ++splCI)
      {
         Position staPos = splCI->second;
         double elv = staPos.elvAngle( SVpos[PRNID] );
         if (elv>=minimumElevationAngle) numVis++;
      }
      if (detailPrint) fprintf(logfp,"   %2d,",numVis);
      if (numVis>maxNum) maxNum = numVis;
      if (numVis<minNum) minNum = numVis;
      
      StaStatsList::iterator sslI = staStatsList.find( PRNID );
      if (sslI==staStatsList.end())
      {
         cerr << "Missing statistics object for satellite " << PRNID << endl;
         cerr << "Fatal error.  compSatVis will termination." << endl;
      }
      StaStats& ss = sslI->second;
      ss.addEpochInfo( numVis, epochCount );
      statsOverAllPRNs.addEpochInfo( numVis, epochCount );
      DiscreteVisibleCounts& dvc = dvcList.find(PRNID)->second;
      dvc.addCount(numVis);
      dvc0.addCount(numVis);
   }
   if (detailPrint) fprintf(logfp,"    %2d,    %2d\n",maxNum,minNum);
}
Beispiel #6
0
void compSatVis::printNavFileReferenceTime(FILE* logfp)
{
   string tform2 = "%02m/%02d/%02y DOY %03j, GPS Week %F, DOW %w, %02H:%02M:%02S";
   CommonTime t;
   
      // If the user did not specify a start time for the evaulation, find the
      // epoch time of the navigation data set and work from that.
      // In the case of almanac data, the "initial time" is derived from the 
      // earliest almanac reference time minus a half week.  Therefore, we
      // add the halfweek back in.  
   switch(navFileType)
   {
         // For ephemeris, initial time is earliest beginning of effectivty.
      case FIC_EPH:
      case RINEX_NAV:
	 t = BCEphList.getInitialTime();
	 t += HALFWEEK;
         fprintf(logfp,"  Ephemeris effectivity\n");
         fprintf(logfp,"     Earliest             : %s\n",
                 printTime(t,tform2).c_str());
	 t = BCEphList.getFinalTime();
	 t -= HALFWEEK;
         fprintf(logfp,"     Latest               : %s\n",
                 printTime(t,tform2).c_str());
         break;
            
      case FIC_ALM:
         t = BCAlmList.getInitialTime();
         t += HALFWEEK;
         fprintf(logfp,"  Almanac reference time\n");
         fprintf(logfp,"     Earliest             : %s\n",
                       printTime(t,tform2).c_str());
         t = BCAlmList.getFinalTime();
         t -= HALFWEEK;
         fprintf(logfp,"     Latest               : %s\n",
                       printTime(t,tform2).c_str());
         break;

      case Yuma_ALM:
         t = YumaAlmStore.getInitialTime();
         t += HALFWEEK;
         fprintf(logfp,"  Almanac reference time\n");
         fprintf(logfp,"     Earliest             : %s\n",
                       printTime(t,tform2).c_str());
         t = YumaAlmStore.getFinalTime();
         t -= HALFWEEK;
         fprintf(logfp,"     Latest               : %s\n",
                       printTime(t,tform2).c_str());
         break;

      case SEM_ALM:
         t = SEMAlmStore.getInitialTime();
         t += HALFWEEK;
         fprintf(logfp,"  Almanac reference time\n");
         fprintf(logfp,"     Earliest             : %s\n",
                       printTime(t,tform2).c_str());
         t = SEMAlmStore.getFinalTime();
         t -= HALFWEEK;
         fprintf(logfp,"     Latest               : %s\n",
                       printTime(t,tform2).c_str());
         break;
         
      case SP3:
      {
         CommonTime begin = SP3EphList.getInitialTime();
         CommonTime end = SP3EphList.getFinalTime();
         fprintf(logfp,"  Ephemeris effectivity\n");
         fprintf(logfp,"     Earliest             : %s\n",
                 printTime(begin,tform2).c_str());
         fprintf(logfp,"     Latest               : %s\n",
                 printTime(end,tform2).c_str());
         break;
      }   
   }
   return;
}
Beispiel #7
0
//=============================================================================
// Test for getVelocity
// Tests getPosition method in SP3EphemerisStore by comparing the outputs
// of the method to known values in an SP3 files with position and
// velocity values
//=============================================================================
   int getVelocityTest (void)
   {
      TUDEF( "SP3EphemerisStore", "getVelocity" );

      try
      {
         SP3EphemerisStore Store;
         Store.loadFile(inputAPCData);

         const short PRN1 = 1;
         const short PRN31 = 31;

         CivilTime testTime_civ(2001,7,22,2,0,0);
         CommonTime testTime = testTime_civ.convertToCommonTime();

         SatID sid1(PRN1,SatID::systemGPS);
         SatID sid31(PRN31,SatID::systemGPS);

         Triple computedVelocity_1 = Store.getVelocity(sid1,testTime);
         Triple computedVelocity_31 = Store.getVelocity(sid31,testTime);

         Triple knownVelocity_1(1541.6040306,-2000.8516260,-1256.4479944);
         Triple knownVelocity_31(1165.3672035,-1344.4254143,2399.1497704);

         double relativeError;
         std::stringstream testMessageStream;
         std::string testMessageP2,
            testMessageP1 = "getVelocity obtained the wrong velocity in the ";
            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 1
            //--------------------------------------------------------------------
         testMessageP2 = " direction for SatID 1";
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError = fabs(knownVelocity_1[i]  - computedVelocity_1[i]) /fabs(
               computedVelocity_1[i] );
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }

            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 1
            //--------------------------------------------------------------------
         testMessageP2 = " direction for SatID 31";
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError = fabs(knownVelocity_31[i] - computedVelocity_31[i])/fabs(
               computedVelocity_31[i]);
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }
      }
      catch (...)
      {
         TUFAIL("Unexpected exception");
      }

      return testFramework.countFails();
   }
Beispiel #8
0
//=============================================================================
// Test for getPosition
// Tests getPosition method in SP3EphemerisStore by comparing the outputs
// of the method to known values in two SP3 files--one with position and
// velocity values and one with only position values
//=============================================================================
   int getPositionTest (void)
   {
      TUDEF( "SP3EphemerisStore", "getPosition" );

      try
      {
         SP3EphemerisStore igsStore;
         igsStore.loadFile(inputSP3Data);

         const short PRN1 = 1;
         const short PRN31 = 31;

         CivilTime igsTime_civ(1997,4,6,2,0,0);
         CommonTime igsTime = igsTime_civ.convertToCommonTime();

         SatID sid1(PRN1,SatID::systemGPS);
         SatID sid31(PRN31,SatID::systemGPS);

         Triple computedPosition_igs1  = igsStore.getPosition(sid1,igsTime);
         Triple computedPosition_igs31 = igsStore.getPosition(sid31,igsTime);

         Triple knownPosition_igs1(-17432922.132,6688018.407,-18768291.053);
         Triple knownPosition_igs31(-5075919.490,25101160.691,-6633797.696);

         double relativeError;
         std::stringstream testMessageStream;
         std::string testMessageP1 = "getPosition obtained the wrong position in the ";
         std::string testMessageP2 = " direction for SatID 1";
            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 1
            //--------------------------------------------------------------------
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError  = fabs(knownPosition_igs1[i]  - computedPosition_igs1[i]) /fabs(
               knownPosition_igs1[i] );
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }

            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 31
            //--------------------------------------------------------------------
         testMessageP2 = " direction for SatID 31";
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError  = fabs(knownPosition_igs31[i]  -
                                  computedPosition_igs31[i]) /fabs(knownPosition_igs31[i] );
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }

         SP3EphemerisStore apcStore;
         apcStore.loadFile(inputAPCData);

         CivilTime apcTime_civ(2001,7,22,2,0,0);
         CommonTime apcTime = apcTime_civ.convertToCommonTime();

         Triple computedPosition_apc1 = apcStore.getPosition(sid1,apcTime);
         Triple computedPosition_apc31 = apcStore.getPosition(sid31,apcTime);

         Triple knownPosition_apc1(-5327654.053,-16633919.811,20164748.602);
         Triple knownPosition_apc31(2170451.938,-22428932.839,-14059088.503);

            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 1
            //--------------------------------------------------------------------
         testMessageP2 = " direction for SatID 1";
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError = fabs(knownPosition_apc1[i]  - computedPosition_apc1[i]) /fabs(
               knownPosition_apc1[i] );
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }

            //--------------------------------------------------------------------
            // Check that the computed position matches the known value for SatID 31
            //--------------------------------------------------------------------
         testMessageP2 = " direction for SatID 31";
         for (int i = 0; i < 3; i++)
         {
            testMessageStream << testMessageP1 << i << testMessageP2;
            relativeError = fabs(knownPosition_apc31[i]  -
                                 computedPosition_apc31[i]) /fabs(knownPosition_apc31[i] );
            testFramework.assert( relativeError < epsilon , testMessageStream.str() ,
                                  __LINE__);
            testMessageStream.str(std::string());
         }
      }
      catch (...)
      {
         TUFAIL("Unexpected exception");
      }

      return testFramework.countFails();
   }
Beispiel #9
0
//=============================================================================
// Test for getXvt.
// Tests the getXvt method in SP3EphemerisStore by comparing known
// results with the method's output for various time stamps in an
// SP3 file; also ensures nonexistent SatIDs throw an exception
//=============================================================================
   int getXvtTest (void)
   {
      TUDEF( "SP3EphemerisStore", "getXvt" );

      try
      {
         SP3EphemerisStore store;
         store.loadFile(inputSP3Data);

         stringstream outputStream1;
         stringstream outputStream15;
         stringstream outputStream31;

         const short PRN0 = 0; // Nonexistent in SP3 file
         const short PRN1 = 1;
         const short PRN15 = 15;
         const short PRN31 = 31;
         const short PRN32 = 32; // Nonexistent in SP3 file

         SatID sid0(PRN0,SatID::systemGPS);
         SatID sid1(PRN1,SatID::systemGPS);
         SatID sid15(PRN15,SatID::systemGPS);
         SatID sid31(PRN31,SatID::systemGPS);
         SatID sid32(PRN32,SatID::systemGPS);

         CivilTime eTime_civ(1997,4,6,6,15,0); // Time stamp of one epoch
         CommonTime eTime = eTime_civ.convertToCommonTime();
         CivilTime bTime_civ(1997,4,6,0,0,0); // Time stamp of first epoch
         CommonTime bTime = bTime_civ.convertToCommonTime();

         try
         {
               // Verify that an InvalidRequest exception is thrown when SatID is not in the data
            try
            {
               store.getXvt(sid0,bTime);
               TUFAIL("No exception thrown when getXvt looks for an invalid"
                      " SatID");
            }
            catch (InvalidRequest& e)
            {
               TUPASS("Expected exception thrown when getXvt looks for an invalid"
                      " SatID");
            }
            catch (...)
            {
               TUFAIL("Unexpected exception thrown when getXvt looks for an"
                      " invalid SatID");
            }

               // Verify that an InvalidRequest exception is thrown when SatID is not in the data
            try
            {
               store.getXvt(sid32,bTime);
               TUFAIL("No exception thrown when getXvt looks for an invalid"
                      " SatID");
            }
            catch (InvalidRequest& e)
            {
               TUPASS("Expected exception thrown when getXvt looks for an invalid"
                      " SatID");
            }
            catch (...)
            {
               TUFAIL("Unexpected exception thrown when getXvt looks for an"
                      " invalid SatID");
            }

               // Verify that no exception is thrown for SatID in the data set
            try
            {
               store.getXvt(sid1,eTime);
               TUPASS("No exception thrown when getXvt looks for a valid SatID");
            }
            catch (...)
            {
               TUFAIL("Exception thrown when getXvt looks for a valid SatID");
            }

            outputStream1 << store.getXvt(sid1,eTime);
            outputStream15 << store.getXvt(sid15,eTime);
            outputStream31 << store.getXvt(sid31,eTime);
         }

         catch (Exception& e)
         {
            cout << e;
         }

            //--------------------------------------------------------------------
            // Were the values set to expectation using the explicit constructor?
            //--------------------------------------------------------------------
         TUASSERTE(std::string, inputComparisonOutput1, outputStream1.str());
         TUASSERTE(std::string, inputComparisonOutput15, outputStream15.str());
         TUASSERTE(std::string, inputComparisonOutput31, outputStream31.str());
      }
      catch (...)
      {
         TUFAIL("Unexpected exception");
      }

      return testFramework.countFails();
   }
Beispiel #10
0
int main(int argc, char *argv[])
{
   if (argc<2) {
      cout << "Usage: petest <SP3-format files ...>\n";
      return -1;
   }

   try
   {

      bool firstEpochFound=true;
      DayTime firstTime;
      DayTime lastTime;
      SatID firstSat;
         
      int i,ip,it,nf=0,np=0,nt=0;
      SP3EphemerisStore EphList;
      for(i=1; i<argc; i++) {
         SP3Header header;
         SP3Data data;
         
         // you can't open, close, and reopen a file w/o abort on second open...
         SP3Stream pefile;
         pefile.exceptions(ifstream::failbit);
         cout << "Reading SP3 file " << argv[i] << "." << endl;
         pefile.open(argv[i],ios::in);

         pefile >> header;
         data.version = header.version;
         
         //cout << "Dump header:\n";
         //header.dump(cout);
         //cout << endl;

         ip = it = 0;
         DayTime t(DayTime::BEGINNING_OF_TIME);

         while(pefile >> data) {
            if (firstEpochFound)
            {  
               firstSat = data.sat;
               firstTime = data.time;
               lastTime = firstTime;
               
               firstEpochFound=false;
            }

            if (data.time > lastTime) lastTime = data.time;
            
            if(data.time > t) {
               //cout << "Epoch " << data.time << endl;
               t = data.time;
               it++; nt++;
            }
            //data.dump(cout);
            ip++; np++;
         }
         cout << "\nDone with file " << argv[i] << ": read "
              << ip << " P/V records and " << it << " epochs." << endl;
         pefile.close();
         nf++;

         // add to store
         EphList.loadFile(string(argv[i]));
      }
      
      cout << "\nDone with " << nf << " files: read "
           << np << " P/V records and " << nt << " epochs." << endl;

      //EphList.dump(2);

      unsigned long ref;
      // choose a time tag within the data....
      DayTime tt = firstTime + (lastTime-firstTime)/2.;
      SatID tsat = firstSat;
      Xvt PVT;
      for(i=0; i<300; i++) {
         tt += 30.0;
         PVT = EphList.getXvt(tsat,tt);

         if (true) 
            cout << "LI " << tt << " P " << fixed
                 << setw(13) << setprecision(6) << PVT.x[0] << " "
                 << setw(13) << setprecision(6) << PVT.x[1] << " "
                 << setw(13) << setprecision(6) << PVT.x[2] << " "
                 << setw(13) << setprecision(6) << PVT.dtime
                 << " V "
                 << setw(13) << setprecision(6) << PVT.v[0] << " "
                 << setw(13) << setprecision(6) << PVT.v[1] << " "
                 << setw(13) << setprecision(6) << PVT.v[2] << " "
                 << setw(13) << setprecision(6) << PVT.ddtime
                 << endl;
      }
      
   }
   catch (Exception& e)
   {
      cout << e;
      exit(-1);
   }
   catch (...)
   {
      cout << "Caught an unknown exception" << endl;
      exit(-1);
   }

   return 0;
}
Beispiel #11
0
//------------------------------------------------------------------------------------
// Configure(1)
// open and read navigation files
// open and read headers of all observation files
int Initialize(void) throw(Exception)
{
try {
   size_t i;
   // global pEph will point to one of these
   static GPSEphemerisStore BCEphList;
   static SP3EphemerisStore SP3EphList;

   if(CI.Verbose) oflog << "BEGIN Configure(1)"
      << " at total time " << fixed << setprecision(3)
      << double(clock()-totaltime)/double(CLOCKS_PER_SEC) << " seconds."
      << endl;
   if(CI.Frequency == 1) wave = wl1;
   if(CI.Frequency == 2) wave = wl2;
      // NB wave should never be used for L3 -- see warning in CommandInput.cpp
   else if(CI.Frequency == 3) wave = wl1;

      // open nav files, if any, and read EphemerisStore into EphLists
   if(CI.NavFileNames.size() > 0) {
      if(!CI.NavPath.empty())
         for(i=0; i<CI.NavFileNames.size(); i++)
            CI.NavFileNames[i] = CI.NavPath + "/" + CI.NavFileNames[i];

      // fill ephemeris store -- this routine in RinexUtilities.cpp
      FillEphemerisStore(CI.NavFileNames, SP3EphList, BCEphList);
   }

      // read all headers and store information in Station object
   ReadAllObsHeaders();

      // use the information gathered in ReadAllObsHeaders to determine DT
      // if the user did not specify --DT, set it
      // else if the --DT the user chose is too small, reset it
      // else leave --DT alone
   double DT=-1.0;
   for(i=0; i<ObsFileList.size(); i++) {
      if(ObsFileList[i].dt > DT)
         DT = ObsFileList[i].dt;
      if(ObsFileList[i].firstTime > CI.BegTime)
         CI.BegTime = ObsFileList[i].firstTime;
   }
   if(CI.DataInterval == -1) {
      CI.DataInterval = DT;
      if(CI.Verbose) oflog << "DDBase has determined the data interval (--DT) to be "
         << CI.DataInterval << " seconds." << endl;
   }
   else if(CI.DataInterval < DT) {
      CI.DataInterval = DT;
      oflog << "Warning - DDBase has changed the data interval (--DT) to "
         << CI.DataInterval << " seconds." << endl;
   }

      // dump SP3 store to log
   if(SP3EphList.size()) {
      if(CI.Verbose) SP3EphList.dump(oflog,0);
   }
   else if(CI.Verbose) oflog << "SP3 Ephemeris store is empty" << endl;

      // dump BCE store to log
   if(BCEphList.size()) {
         // this causes the CorrectedEphemerisRange routines to pick the
         // closest TOE in either future or past of the epoch, rather
         // than the closest in the past -- see GPSEphemerisStore.hpp
      BCEphList.SearchNear();

      if(CI.Debug) BCEphList.dump(oflog,1);
      else if(CI.Verbose) BCEphList.dump(oflog,0);
   }
   else if(CI.Verbose) oflog << "BC Ephemeris store is empty" << endl;

      // assign pointer
      // NB SP3 takes precedence
   if(SP3EphList.size())     pEph = &SP3EphList;
   else if(BCEphList.size()) pEph = &BCEphList;
   else {
      cerr << "Initialize ERROR: no ephemeris. Abort." << endl;
      oflog << "Initialize ERROR: no ephemeris. Abort." << endl;
      return 1;
   }

      // open all EOP files and fill the EOPstore
   if(!CI.EOPPath.empty())
      for(i=0; i<CI.EOPFileNames.size(); i++)
         CI.EOPFileNames[i] = CI.EOPPath + "/" + CI.EOPFileNames[i];

   if(CI.EOPFileNames.size() > 0) {
      for(i=0; i<CI.EOPFileNames.size(); i++)
         EOPList.addFile(CI.EOPFileNames[i]);
   }
   else {
      try {
         EOPList.addIERSFile("finals.daily");
      }
      catch(FileMissingException& fme) {
         string msg("DDBase was unable to find any Earth Orientation parameters:\n"
           " either add option --EOPFile <file> or put file 'finals.daily' in the"
           " current directory.\n  (http://maia.usno.navy.mil/ser7/finals.daily)\n");
         cerr << msg;
         oflog << msg;
         GPSTK_RETHROW(fme);
      }
   }

   if(EOPList.size()) {
      if(CI.Debug) EOPList.dump(1,oflog);
      else if(CI.Verbose) EOPList.dump(0,oflog);
   }
   else oflog << "Warning - no Earth Orientation Parameters were input\n";

      // add path to output files
   if(!CI.OutPath.empty()) {
      if(!CI.OutputClkFile.empty())
         CI.OutputClkFile = CI.OutPath + "/" + CI.OutputClkFile;
      if(!CI.OutputDDDFile.empty())
         CI.OutputDDDFile = CI.OutPath + "/" + CI.OutputDDDFile;
      if(!CI.OutputTDDFile.empty())
         CI.OutputTDDFile = CI.OutPath + "/" + CI.OutputTDDFile;
      if(!CI.OutputRawFile.empty())
         CI.OutputRawFile = CI.OutPath + "/" + CI.OutputRawFile;
      if(!CI.OutputRawDDFile.empty())
         CI.OutputRawDDFile = CI.OutPath + "/" + CI.OutputRawDDFile;
      if(!CI.OutputPRSFile.empty())
         CI.OutputPRSFile = CI.OutPath + "/" + CI.OutputPRSFile;
      if(!CI.OutputDDRFile.empty())
         CI.OutputDDRFile = CI.OutPath + "/" + CI.OutputDDRFile;
   }

      // assign trop model for RAIM (model for DD est assigned in Configure(2))
      // NB using another, like Saastamoinen, here, is problematic because it
      // requires height, latitude and DOY input, [ this because RAIM calls
      // CI.pTropModel->correction(elevation) ], and that info is different for
      // different sites and not all available.
   CI.pTropModel = &TropModelSimple;
      // TD per site
   CI.pTropModel->setWeather(CI.DefaultTemp,CI.DefaultPress,CI.DefaultRHumid);

      // Define first and last epochs
   FirstEpoch = CommonTime::BEGINNING_OF_TIME;
   LastEpoch = CommonTime::END_OF_TIME;

   return 0;
}
catch(Exception& e) { GPSTK_RETHROW(e); }
catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
}