⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rinexeditor.cpp

📁 GPS数据预处理软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            case REditCmd::DS:               if(Cmds[0].sign > 0 && index(DelSV,Cmds[0].SV) == -1)                  DelSV.push_back(Cmds[0].SV);               if(Cmds[0].sign < 0) {                  if(find(DelSV.begin(),DelSV.end(),Cmds[0].SV) != DelSV.end())                     DelSV.erase(find(DelSV.begin(),DelSV.end(),Cmds[0].SV));               }               if(Cmds[0].sign == 0 && fabs(dt) < TimeTol)                  OneTimeCmds.push_back(Cmds[0]);               if(Cmds[0].sign != 0 && REDebug) {                  *oflog << "DS: DelSV is";                  for(int itemp=0; itemp<DelSV.size(); itemp++)                     *oflog << " " << DelSV[itemp];                  *oflog << endl;               }               break;            case REditCmd::DD:            case REditCmd::SS:            case REditCmd::SL:            case REditCmd::SD:            case REditCmd::BD:            case REditCmd::BS:            case REditCmd::BL:               if(Cmds[0].sign > 0)                  CurrentCmds.push_back(Cmds[0]);               if(Cmds[0].sign < 0) {                  vector<REditCmd>::iterator it;                  it = find(CurrentCmds.begin(), CurrentCmds.end(),Cmds[0]);                  if(it != CurrentCmds.end()) CurrentCmds.erase(it);               }               if(Cmds[0].sign == 0 && fabs(dt) < TimeTol)                  OneTimeCmds.push_back(Cmds[0]);               break;            default:               if(REDebug) Cmds[0].Dump(*oflog,                     Cmds[0].time.printf("%4Y/%2m/%2d %2H:%2M:%.4f")                     + string(": This command not implemented! : "));               break;         }   // end switch(type)            // delete this command         if(REDebug) Cmds[0].Dump(*oflog,               Cmds[0].time.printf("%4Y/%2m/%2d %2H:%2M:%.4f")               + string(": Delete (old) : "));         Cmds.pop_front();      }      else break;              // this command (and all others) is in future   }      // clear out anything old   ROOut.obs.clear();      // if not writing out, return here   if(Skip && !NewFile) return 0;   if(Skip && NewFile) return 1;      // copy data over to new obs structure   RinexObsData::RinexDatum datum;                       // place holder and zero   datum.data = 0.0;   datum.lli = datum.ssi = 0;   RinexObsData::RinexObsTypeMap otmap;           // place holder for ROOut.obs.second   for(int j=0; j<RHOut.obsTypeList.size(); j++)  // loop over obstypes (out) in otmap      otmap.insert(std::map<RinexObsHeader::RinexObsType,         RinexObsData::RinexDatum>::value_type(RHOut.obsTypeList[j],datum) );      // loop over prns, create otmap and then insert it with the correct sat   int nsvs=0;   RinexObsData::RinexSatMap::iterator it;   RinexObsData::RinexObsTypeMap::iterator jt,kt;   for(it=ROIn.obs.begin(); it != ROIn.obs.end(); ++it) {      // loop over prn=it->first, ObsTypeMap=it->second      if(find(DelSV.begin(),DelSV.end(),it->first) != DelSV.end()) {         if(REDebug) *oflog << "Deleted sat " << it->first            << " at " << ROIn.time << endl;         continue;      }      RinexSatID p(-1,it->first.system);      if(find(DelSV.begin(),DelSV.end(),p) != DelSV.end()) continue;      for(int j=0; j<RHOut.obsTypeList.size(); j++) { // loop over obstypes         jt = otmap.find(RHOut.obsTypeList[j]);  // jt points to ObsTypeMap output         kt = it->second.find(RHOut.obsTypeList[j]);  // kt points to ObsTypeMap input         if(kt==it->second.end())                        // not found            jt->second = datum;         else            jt->second = kt->second;      }      // TD should test for all zero data -> delete this SV.      ROOut.obs.insert(std::map<SatID,         RinexObsData::RinexObsTypeMap>::value_type(it->first,otmap) );   }  // end loop over sats   ROOut.time = ROIn.time;   if(!NewFile) {      PrevEpoch = CurrEpoch;      CurrEpoch = ROOut.time;   }   ROOut.clockOffset = ROIn.clockOffset;   ROOut.epochFlag = ROIn.epochFlag;      // apply current commands   vector<REditCmd>::iterator cit;                    // iterator for commands   for(cit=CurrentCmds.begin(); cit != CurrentCmds.end(); cit++) {      if(REDebug) cit->Dump(*oflog,string("Current : "));         // for SV=system only, start at beginning, else start with command SV      for(it = ROOut.obs.begin(); it != ROOut.obs.end(); it++) {            // skip if the sat is not a match         if(cit->SV.system != it->first.system ||            (cit->SV.id > -1 && cit->SV.id != it->first.id)) continue;            // find the command obs type in the data         jt = it->second.find(RinexObsHeader::convertObsType(cit->field));            // if its there, edit it         if(jt != it->second.end()) {            if(cit->type == REditCmd::DD) jt->second.data = 0.0;            if(cit->type == REditCmd::SS) jt->second.ssi =               (int(cit->bias) < 0 ? 0 : (int(cit->bias) > 9 ? 9 : int(cit->bias)));            if(cit->type == REditCmd::SL) jt->second.lli = int(cit->bias);               (int(cit->bias) < 0 ? 0 : (int(cit->bias) > 9 ? 9 : int(cit->bias)));            if(cit->type == REditCmd::BD) {               if(BiasZeroData || fabs(jt->second.data) > 0.001)                  jt->second.data += cit->bias;            }            if(cit->type == REditCmd::BS) {               jt->second.ssi += int(cit->bias);               if(jt->second.ssi < 0) jt->second.ssi = 0;               if(jt->second.ssi > 9) jt->second.ssi = 9;            }            if(cit->type == REditCmd::BL) {               jt->second.lli += int(cit->bias);               if(jt->second.lli < 0) jt->second.lli = 0;               if(jt->second.lli > 9) jt->second.lli = 9;            }         }      }  // end loop over satellites   }  // end loop over current commands      // apply one-time commands .. iterate in reverse so you can erase as you go   vector<REditCmd>::reverse_iterator irt;   RinexObsData::RinexSatMap::reverse_iterator roit;  // reverse iterator for obs data   for(irt=OneTimeCmds.rbegin(); irt != OneTimeCmds.rend(); irt++) {      if(REDebug) irt->Dump(*oflog,string("1-time : "));         // for SV=system only, start at beginning, else start with command SV      for(roit = ROOut.obs.rbegin(); roit != ROOut.obs.rend(); ) {            // skip if not a match         if(irt->SV.system != roit->first.system ||            (irt->SV.id > -1 && irt->SV.id != roit->first.id)) { roit++; continue; }            // DS : delete SV altogether         if(irt->type == REditCmd::DS) ROOut.obs.erase(roit->first);         else {               // find the command obs type in the data            jt=roit->second.find(RinexObsHeader::convertObsType(irt->field));            if(jt != roit->second.end()) {               if(irt->type == REditCmd::DD) jt->second.data = 0.0;               if(irt->type == REditCmd::SD) jt->second.data = irt->bias;               if(irt->type == REditCmd::SS)                  (int(irt->bias) < 0 ? 0 : (int(irt->bias) > 9 ? 9 : int(irt->bias)));               if(irt->type == REditCmd::SL)                  (int(irt->bias) < 0 ? 0 : (int(irt->bias) > 9 ? 9 : int(irt->bias)));               if(irt->type == REditCmd::BD) {                  if(BiasZeroData || fabs(jt->second.data) > 0.001)                     jt->second.data += irt->bias;               }               if(irt->type == REditCmd::BS) {                  jt->second.ssi += int(irt->bias);                  if(jt->second.ssi < 0) jt->second.ssi = 0;                  if(jt->second.ssi > 9) jt->second.ssi = 9;               }               if(irt->type == REditCmd::BL) {                  jt->second.lli += int(irt->bias);                  if(jt->second.lli < 0) jt->second.lli = 0;                  if(jt->second.lli > 9) jt->second.lli = 9;               }            }            roit++;         }      }  // end loop over satellites         // delete this command      OneTimeCmds.pop_back();   }  // end loop over one-time commands   ROOut.numSvs = ROOut.obs.size();      // update estimate of dt   if(FillOptionalHeader) {      if(PrevEpoch.year() != 1) {         dt = CurrEpoch-PrevEpoch;         for(int i=0; i<9; i++) {            if(ndt[i] <= 0) { bestdt[i]=dt; ndt[i]=1; break; }            if(fabs(dt-bestdt[i]) < 0.0001) { ndt[i]++; break; }            if(i == 8) {               int k = 0;               int nleast=ndt[k];               for(int j=1; j<9; j++) if(ndt[j] <= nleast) {                  k=j; nleast=ndt[j];               }               ndt[k]=1; bestdt[k]=dt;            }         }      }   }   if(NewFile) return 3;   return 2;}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); }}//------------------------------------------------------------------------------------// use remove(newname) to delete itstring GetTempFileName(void) throw(Exception){try {#ifdef _MSC_VER   char newname[L_tmpnam];   if(!tmpnam(newname)) {#else   char newname[]="RETemp.XXXXXX";   if(mkstemp(newname)==-1) {#endif      return string("");   }   return string(newname);}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); }}//------------------------------------------------------------------------------------// assumes TempFile has been written with RHOut, and info is in config// Return 0 or -1 if could not open/delete filesint RinexEditor::FillHeaderAndReplaceFile(string& TempFile, string& TrueOutputFile)   throw(Exception){try {   int i,j;      // compute interval   for(i=1,j=0; i<9; i++) if(ndt[i]>ndt[j]) j=i;   double dt = bestdt[j];      // modify the header   RHOut.version = 2.1; RHOut.valid |= RinexObsHeader::versionValid;   RHOut.interval = dt; RHOut.valid |= RinexObsHeader::intervalValid;   RHOut.lastObs = CurrEpoch; RHOut.valid |= RinexObsHeader::lastTimeValid;      // now the table   RHOut.numSVs = table.size(); RHOut.valid |= RinexObsHeader::numSatsValid;   RHOut.numObsForSat.clear();   vector<TableData>::iterator tit;   for(tit=table.begin(); tit!=table.end(); ++tit) {      RHOut.numObsForSat.insert(map<SatID,            vector<int> >::value_type(tit->prn,tit->nobs));   }   RHOut.valid |= RinexObsHeader::prnObsValid;      // callback   i = BeforeWritingFilledHeader(RHOut);   if(i) return -2;      // here you need to validate the RHOut header      // now re-open the file and replace the header   RinexObsHeader rhjunk;   RinexObsStream ROutStr(TrueOutputFile.c_str(), ios::out);   RinexObsStream InAgain(TempFile.c_str());   InAgain.exceptions(ios::failbit);   InAgain >> rhjunk;   ROutStr << RHOut;   RinexObsData robs;   while(InAgain >> robs) {      if(robs.time < BegTime) continue;      if(robs.time > EndTime) break;      ROutStr << robs;   }   InAgain.close();   ROutStr.close();      // delete the temporary   if(remove(TempFile.c_str()) != 0) {      *oflog << "Error: Could not remove existing temp file: " << TempFile << endl;      return -1;   }   else if(REVerbose) *oflog << "Removed temporary file " << TempFile << 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); }}//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------// Return -1 failed to open file//        -2 failed to read input file correctly (includes file not an obs file)//        -4 failed to fill header and replace original file//        -5 could not create temporary file//        -6 callback to BeforeEditHeader returned error//        -7 callback to AfterEditHeader returned error//        -8 callback to BeforeEditObs returned error//        -9 callback to BeforeWritingHeader returned error//       -10 callback to BeforeWritingObs returned error// will replace header after filling using temp fileint RinexEditor::EditFile(void) throw(Exception){try {   int iret,Noutput;   RinexObsHeader rhin,rhout;   RinexObsData roin,roout;   string TrueOutputFile,TempFile;   RinexObsStream ROFin;   RinexObsStream ROFout;   if(REVerbose) *oflog << "EditFile: Reading " << Inputfiles.size()      << " input files, and Writing " << OutputFile << endl;      // --------------------------------------------------------------      // loop over input files   for(int nfile=0; nfile < Inputfiles.size(); nfile++) {   InputFile = Inputfiles[nfile];      // --------------------------------------------------------------      // open input file   ROFin.open(InputFile.c_str(), ios::in);   if(!ROFin) {      if(REVerbose) *oflog << "RinexEditor::EditFile could not open input file "         << InputFile << endl;      cerr << "RinexEditor::EditFile could not open input file " << InputFile << endl;      if(REVerbose) *oflog << "RinexEditor::EditFile could not open input file "         << InputFile << endl;      return -1;   }   ROFin.exceptions(ios::failbit);   if(REDebug) *oflog << "Opened input file " << InputFile << endl;      // --------------------------------------------------------------      // read header   try {      ROFin >> rhin;   }   catch(gpstk::FFStreamError& e) {      cerr << "Caught an FFStreamError while reading header:\n" << e.getText(0)         << endl;      if(REVerbose) *oflog << "Caught an FFStreamError while reading header:\n"         << e.getText(0) << endl;      return -2;   }   catch(gpstk::Exception& e) {      cerr << "Caught an exception while reading header:\n" << e.getText(0) << endl;      if(REVerbose) *oflog << "Caught an exception while reading header:\n"         << e.getText(0) << endl;      return -2;   }   if(REDebug) *oflog << "Read input header" << endl;      // dump header   if(REVerbose) {      *oflog << "Input header:\n";      rhin.dump(*oflog);   }      // --------------------------------------------------------------      // Edit header and open output file - do this only once   if(nfile == 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -