Exemplo n.º 1
0
//------------------------------------------------------------------------------------
int OpenFiles(void) throw(Exception)
{
try {
   string filename;
   if(InputDirectory.empty())
      filename = NovatelFile;
   else
      filename = InputDirectory + string("/") + NovatelFile;
   instr.open(filename.c_str(),ios::in | ios::binary);
   if(!instr.is_open()) {
      cerr << "Failed to open input file " << NovatelFile << endl;
      return -1;
   }
   if(verbose) cout << "Opened input file " << NovatelFile << endl;
   instr.exceptions(fstream::failbit);

   TempFileName = GetTempFileName();
   rostr.open(TempFileName.c_str(),ios::out);
   if(!rostr.is_open()) {
      cerr << "Failed to open temporary output file " << TempFileName << endl;
      return -2;
   }
   rostr.exceptions(fstream::failbit);

   rnstr.open(RinexNavFile.c_str(),ios::out);
   if(!rnstr.is_open()) {
      cerr << "Failed to open output nav file " << RinexNavFile << endl;
      return -3;
   }
   if(verbose) cout << "Opened output nav file " << RinexNavFile << endl;
   rnstr.exceptions(fstream::failbit);

   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); }
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------------
// Returns 0 when successful.
int main(int argc, char *argv[])
{
   if (argc<2)
   {
      cout <<
"Usage: NavMerge [options] <RINEX nav file name(s)>\n"
"  Options are:\n"
"    [-o|--out] <file>     Output RINEX navigation file name. If omitted, a data summary is displayed.\n"
"    [-tb|--begTime] <tb>  Output data only if epoch is within 4 hours of the interval (tb,te).\n"
"    [-te|--endTime] <te>    If one of (te,tb) is omitted, they are made equal.\n"
"                            Times are either 'year,mon,day,hr,min,sec' or 'GPSweek,secOfWeek'\n"
"  NB. NavMerge corrects data for output when GPS full week number is inconsistent with epoch time.\n"
      ;

      return -1;
   }

   try
   {
      int i;
      string arg,filename,outfile,YMDformat("%Y,%m,%d,%H,%M,%f"),GPSformat("%F,%g");
      DayTime tb,te;

      te = tb = DayTime::BEGINNING_OF_TIME;

      i = 1;
      while(i < argc) {
         arg = string(argv[i]);
         if(arg == "--out" || arg.substr(0,2) == "-o") {
            if(arg == "--out") {
               argv[i][0] = '\0';
               if(++i == argc) { BadArg(arg); break; }
               outfile = string(argv[i]);
            }
            else
               outfile = arg.substr(2);
            cout << "Output file name is " << outfile << endl;
            argv[i][0] = '\0';
         }
         else if(arg == "--begTime" || arg == "-tb" || arg.substr(0,3) == "-tb") {
            if(arg.substr(0,3) == "-tb" && arg.size() > 3)
               arg = arg.substr(3);
            else {
               argv[i][0] = '\0';
               if(++i == argc) { BadArg(arg); break; }
               arg = string(argv[i]);
            }

            if(numWords(arg,',') == 2)
               tb.setToString(arg,GPSformat);
            else if(numWords(arg,',') == 6)
               tb.setToString(arg,YMDformat);
            else
               cout << "Unable to understand timetag option: " << arg << endl;
            argv[i][0] = '\0';
         }
         else if(arg == "--endTime" || arg == "-te" || arg.substr(0,3) == "-te") {
            if(arg.substr(0,3) == "-te" && arg.size() > 3)
               arg = arg.substr(3);
            else {
               argv[i][0] = '\0';
               if(++i == argc) { BadArg(arg); break; }
               arg = string(argv[i]);
            }

            if(numWords(arg,',') == 2)
               te.setToString(arg,GPSformat);
            else if(numWords(arg,',') == 6)
               te.setToString(arg,YMDformat);
            else
               cout << "Unable to understand timetag option: " << arg << endl;
            argv[i][0] = '\0';
         }

         i++;
      }

      if(te != DayTime::BEGINNING_OF_TIME &&
         tb == DayTime::BEGINNING_OF_TIME) tb = te;
      else
      if(tb != DayTime::BEGINNING_OF_TIME &&
         te == DayTime::BEGINNING_OF_TIME) te = tb;
      if(tb > te) { DayTime tt=tb; tb=te; te=tt; }

      if(tb != DayTime::BEGINNING_OF_TIME)
         cout << "Time limits are " << tb.printf(YMDformat)
               << " - " << te.printf(YMDformat) << endl;

      RinexNavHeader rnh,rnhout;
      RinexNavData rne;
      GPSEphemerisStore EphStore;
      RinexNavStream RNFileOut;

      if(outfile != string("")) {
         RNFileOut.open(outfile.c_str(),ios::out);
         RNFileOut.exceptions(fstream::failbit);
         rnhout.version = 2.1;
         rnhout.valid |= RinexNavHeader::versionValid;
         rnhout.fileType = string("NAVIGATION");
         rnhout.fileProgram = string("NavMerge");
         rnhout.fileAgency = string("ARL:UT/SGL/GPSTK");
         rnhout.valid |= RinexNavHeader::runByValid;
         rnhout.commentList.clear();
         rnhout.valid |= RinexNavHeader::commentValid;
         rnhout.valid |= RinexNavHeader::endValid;
      }

      int na=1,n=0,nf;
      while(na < argc) {
         filename = string(argv[na]);
         if(filename == string("")) { na++; continue; }

         try {
            RinexNavStream RNFileIn(filename.c_str());
            if(!RNFileIn) {
               cout << "Could not open file " << filename << endl;
               na++;
               continue;
            }
            RNFileIn.exceptions(fstream::failbit);
      
            RNFileIn >> rnh;
            if(rnh.valid & RinexNavHeader::ionAlphaValid) {
               for(i=0; i<4; i++) rnhout.ionAlpha[i]=rnh.ionAlpha[i];
               rnhout.valid |= RinexNavHeader::ionAlphaValid;
            }
            if(rnh.valid & RinexNavHeader::ionBetaValid) {
               for(i=0; i<4; i++) rnhout.ionBeta[i]=rnh.ionBeta[i];
               rnhout.valid |= RinexNavHeader::ionBetaValid;
            }
            if(rnh.valid & RinexNavHeader::deltaUTCValid) {
               rnhout.A0 = rnh.A0;
               rnhout.A1 = rnh.A1;
               rnhout.UTCRefWeek = rnh.UTCRefWeek;
               rnhout.UTCRefTime = rnh.UTCRefTime;
               rnhout.valid |= RinexNavHeader::deltaUTCValid;
            }
            if(rnh.valid & RinexNavHeader::leapSecondsValid) {
               rnhout.leapSeconds = rnh.leapSeconds;
               rnhout.valid |= RinexNavHeader::leapSecondsValid;
            }

            nf = 0;
            while (RNFileIn >> rne)
            {
               nf++;
               n++;
               // check that week number (associated with HOW) is consistent with TOC.
               // (NB. in Rinex nav file, the week number is associated with the TOE;
               // RinexNavData converts it to associate with the HOW)
               int wkTOC,wk;
               wk = rne.weeknum;                // 'weeknum' associated with HOW
               wkTOC = rne.time.GPSfullweek();  // 'time' comes from epoch line
               if(ABS(wk-wkTOC) > 1) {          // HOW and TOC should be w/in 1 week
                  double dt = double(wk-wkTOC)/1024.0;
                  dt += (dt < 0.0 ? -0.5 : 0.5);
                  wk -= int(dt) * 1024;
                  if(ABS(wk-wkTOC) > 1) {
                     cout << "WARNING: Ephemeris in " << filename
                        << " for satellite G"
                        << setw(2) << setfill('0') << rne.PRNID << setfill(' ')
                        << " at time " << rne.time
                        << " has inconsistent week number " << rne.weeknum << endl;
                  }
                  else {
                     cout << "NavMerge corrected the week in G"
                        << setw(2) << setfill('0') << rne.PRNID << setfill(' ')
                        << " " << rne.time
                        << " " << filename << endl;
                     rne.weeknum = wk;
                  }
               }
                  // if healthy, add to the store
               if(rne.health == 0) EphStore.addEphemeris(rne);
            }
         }
         catch(Exception& e) {
            cout << "Exception: " << e << endl;
         }
         na++;
         cout << "Read " << setw(4) << nf << " ephemerides from file "
            << filename << endl;
      }
      cout << "Read " << setw(4) << n << " total ephemerides." << endl;

         // pull out all the ephemerides
      list<EngEphemeris> EphList;
      i = EphStore.addToList(EphList);

      if(outfile != string("")) {
            // write the output header
         RNFileOut << rnhout;

            // write out all the ephemerides
         list<EngEphemeris>::iterator it=EphList.begin();
         n=0;
         while(it != EphList.end()) {
            rne = RinexNavData(*it);
            if(tb == DayTime::BEGINNING_OF_TIME ||
               (rne.time - tb > -14400.0 && rne.time - te < 14400.0))
            {
               n++;
               RNFileOut << rne;
            }
            it++;
         }
         cout << "Wrote " << setw(3) << n << " unique ephemerides to file "
            << outfile << endl;
      }
      else {
         EphStore.dump(cout,1);
      }

      return 0;
   }
   catch(Exception& e) { cout << e; }
   catch (...) { cout << "unknown error.  Done." << endl; }
   return 1;

   return 0;
}