📄 rinexeditor.cpp
字号:
// callback before editing input header iret = BeforeEditHeader(rhin); if(iret) return -6; // edit header EditHeader(rhin,rhout); if(REVerbose) *oflog << "Edit header done" << endl; // callback after calling EditHeader (pass output header) iret = AfterEditHeader(rhout); if(iret) return -7; // ----------------------------------------------------------- // if header is to be filled, write to a temporary file TrueOutputFile = OutputFile; if(FillOptionalHeader) { OutputFile = GetTempFileName(); if(OutputFile.empty()) { cerr << "Could not create temporary file name - abort\n"; if(REVerbose) *oflog << "Could not create temporary file name - abort\n"; return -5; } // some OSs create the file when you get the name... remove(OutputFile.c_str()); if(!OutputDir.empty()) OutputFile = OutputDir + string("/") + OutputFile; TempFile = OutputFile; } // ----------------------------------------------------------- // open output file ROFout.open(OutputFile.c_str(), ios::out); if(!ROFout) { cerr << "RinexEditor::EditFile could not open output file " << OutputFile << endl; if(REVerbose) *oflog << "RinexEditor::EditFile could not open output file " << OutputFile << endl; return -1; } ROFout.exceptions(ios::failbit); Noutput = 0; } // end if this is the first input file // -------------------------------------------------------------- // loop over epochs, reading input and writing to output while (1) { // read next observation epoch try { ROFin >> roin; } catch(gpstk::FFStreamError& e) { cerr << "RinexEditor::EditFile caught an FFStreamError while reading obs:\n" << e << endl; if(REVerbose) *oflog << "RinexEditor::EditFile caught an FFStreamError while reading obs:\n" << e << endl; return -2; } catch(gpstk::Exception& e) { cerr << "RinexEditor::EditFile caught an exception while reading obs:\n" << e << endl; if(REVerbose) *oflog << "RinexEditor::EditFile caught an exception while reading obs:\n" << e << endl; return -2; } // was read successful? if(!ROFin) { // no if(REVerbose) *oflog << "Reached EOF on " << InputFile << endl; if(nfile == Inputfiles.size()-1) iret = -1; else break; } else { // yes, edit the obs data if(REDebug) { *oflog << "Epoch: " << roin.time << ", Flag " << roin.epochFlag << ", clk " << roin.clockOffset << endl; roin.dump(*oflog); } // callback after reading input obs // and before calling EditObs (pass input obs) iret = BeforeEditObs(roin); if(iret) { iret=-8; break; } iret = EditObs(roin,roout); // Return -2 error // -1 time limit reached // 0 DO NOT write the output obs ROOut // 1 DO NOT write the output obs ROOut, // but close and re-open the output file // 2 DO write the output obs ROOut // 3 DO write the output obs ROOut, // but first close and re-open the output file if(REDebug) { *oflog << "EditObs returned " << iret << endl; roout.dump(*oflog); } } if(iret == -2) break; // error => abort if(iret == -1 || iret == 1 || iret == 3) { // new output file // close this output file ROFout.close(); // fill the optional header records if(FillOptionalHeader) { if(Noutput > 0) { if(FillHeaderAndReplaceFile(TempFile,TrueOutputFile) != 0) { cerr << "Failed to fill header and replace file - abort\n"; if(REVerbose) *oflog << "Failed to fill header and replace file - abort\n"; return -4; } else if(REVerbose) *oflog << "Added header to " << TempFile << " and put in " << TrueOutputFile << endl; } if(iret != -1) { // not EOF => going on to another file TrueOutputFile = OutputFile; OutputFile = GetTempFileName(); if(OutputFile.empty()) { cerr << "Could not create temporary file name - abort\n"; if(REVerbose) *oflog << "Could not create temporary file name - abort\n"; return -5; } // some OSs create the file when you get the name... remove(OutputFile.c_str()); if(!OutputDir.empty()) OutputFile = OutputDir + string("/") + OutputFile; TempFile = OutputFile; if(REVerbose) *oflog << "New temp file is " << TempFile << ", and true output file is " << TrueOutputFile << endl; } } // end if FillOptionalHeader else { TrueOutputFile = OutputFile; } if(iret == -1) { // quit if(REVerbose) *oflog << "Finished processing obs file " << InputFile << endl; iret = 0; break; } // open the new output file ROFout.open(OutputFile.c_str(), ios::out); Noutput = 0; if(REVerbose) *oflog << "New output file " << TrueOutputFile << " (really " << OutputFile << ") at time " << roin.time << endl; } // end if new output file // write to output if(iret > 1) { // not EOF nor error if(Noutput == 0) { rhout.firstObs = roout.time; // callback before writing out header (pass output header) iret = BeforeWritingHeader(rhout); if(iret) return -9; ROFout << rhout; if(REVerbose) { *oflog << "Dump output header (iret is " << iret << "):\n"; rhout.dump(*oflog); } // prepare for next file RHOut = rhout; table.clear(); for(int i=0; i<9; i++) ndt[i]=-1; } // callback just before writing output obs (pass reference to output obs) // return value of BeforeWritingObs determines what is written: // if return <0 abort // 0 write nothing // 1 write the obs data structure (note that the caller may set // roout.epochFlag to determine what is output : 0,1 are data, // while 2,3,4 or 5, is for in-line header auxHeader only) // >1 write BOTH header data (in auxHeader, setting // epochFlag=return) AND obs data roout.auxHeader.clear(); iret = BeforeWritingObs(roout); if(iret < 0) return -10; if(iret > 1) { // write auxiliary header info first int flag=roout.epochFlag, nsvs=roout.numSvs; roout.epochFlag = iret; roout.numSvs = roout.auxHeader.NumberHeaderRecordsToBeWritten(); // write out the header records ROFout << roout; Noutput++; // prepare to write obs roout.epochFlag = flag; roout.numSvs = nsvs; } // add count of valid obs to table for header // -- have to do it here b/c BeforeWritingObs has just filled it if(FillOptionalHeader) { int k,n=RHOut.obsTypeList.size(); RinexObsData::RinexSatMap::const_iterator pit; RinexObsData::RinexObsTypeMap::const_iterator pjt; for(pit=roout.obs.begin(); pit != roout.obs.end(); ++pit) { vector<TableData>::iterator ptab; ptab = find(table.begin(),table.end(),TableData(pit->first,n)); if(ptab == table.end()) { table.push_back(TableData(pit->first,n)); ptab = find(table.begin(),table.end(),TableData(pit->first,n)); } for(pjt=pit->second.begin(); pjt!=pit->second.end(); pjt++) { for(k=0; k<n; k++) if(RHOut.obsTypeList[k] == pjt->first) break; if(pjt->second.data != 0.0) ptab->nobs[k]++; } } } // now write out the obs if(REDebug) { *oflog << "Write this obs to output:\n"; roout.dump(*oflog); } ROFout << roout; Noutput++; } } // end while loop over epochs if(REDebug) *oflog << "Close input file" << endl; ROFin.clear(); ROFin.close(); } // end loop over input file names return iret;}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); }}//------------------------------------------------------------------------------------vector<string> RinexEditor::CommandList(void) throw(Exception){try { string str,comma(","); vector<string> strs; deque<REditCmd>::iterator jt; for(jt=Cmds.begin(); jt != Cmds.end(); jt++) { str = REditCmd::typeLabel[jt->type] + comma + (jt->sign < 0 ? string("-1") : (jt->sign > 0 ? string("1") : string("0"))) + comma + jt->SV.toString() + comma + asString(jt->inOT) + comma + jt->field + comma + asString(jt->bias,3) + comma + jt->time.printf("%4Y/%02m/%02d,%02H:%02M:%.4f") ; strs.push_back(str); } return strs;}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); }}//------------------------------------------------------------------------------------void DisplayRinexEditUsage(ostream& os) throw(){ os <<" Rinex Editor commands:\n"" ===================================================================================\n"" Commands consist of an identifier and a comma-delimited data field; they may be\n"" separated by space(s) '--id <data>' (two minuses) or not '-id<data>' (one minus).\n"" Examples are '--IF myFile' or '-IFmyFile'; '--HDc msg' or '--HD cmsg' or '-HDcmsg';\n"" --BZ or -BZ; '--DD +<SV,OT,t>' or '--DD+ <SV,OT,t>' or '-DD+<SV,OT,t>'.\n"" The data field contains no whitespace and sub-fields are comma-delimited.\n"" <SV> is a RINEX 'system & id' identifier, e.g. G27 (= GPS PRN 27);\n"" satellite system alone denotes 'all satellites this system', e.g. 'R' (GLONASS).\n"" <OT> is a RINEX observation type, e.g. L1 or P2, and is case sensitive.\n"" <time> is either <GPSweek,GPSsecOfWeek> or <year,mon,day,hour,min,second>.\n""\n"" File I/O:\n"" ---------\n"" -IF<file> Input RINEX observation file name [may be repeated] (required)\n"" -ID<dir> Directory in which to find input file\n"" -OF<file> Output RINEX file name (required, or -OF<file>,<time>)\n"" -OF<f>,<time> At RINEX epoch <time>, close output file and open another named <f>\n"" -OD<dir> Directory in which to put output file(s)\n""\n"" Output RINEX header:\n"" --------------------\n"" -HDf If present, fill optional records in the output RINEX header\n"//" (NB EditObs() and EditFile() will do this, but NOT EditHeader().)\n"" -HDp<program> Set output RINEX header 'program' field\n"" -HDr<run_by> Set output RINEX header 'run by' field\n"" -HDo<observer> Set output RINEX header 'observer' field\n"" -HDa<agency> Set output RINEX header 'agency' field\n"" -HDx<x,y,z> Set output RINEX header 'position' field to ECEF position (x,y,z)\n"" -HDm<marker> Set output RINEX header 'marker' field\n"" -HDn<number> Set output RINEX header 'number' field\n"" -HDc<comment> Add comment to output RINEX header (more than one allowed).\n"" -HDdc Delete all comments in output RINEX header\n"" (NB -HDdc cannot delete comments created by *subsequent* -HDc commands)\n""\n"" Output RINEX observation types (also see 'Specific edit commands' below):\n"" -------------------------------------------------------------------------\n"" -AO<OT> Add observation type OT to header and observation data\n"" -DO<OT> Delete observation type OT entirely (including in header)\n""\n"" Time-related edit commands:\n"" ---------------------------\n"" -TB<time> Begin time: reject data before this time (also used for decimation)\n"" -TE<time> End time: reject data after this time\n"" -TT<dt> Tolerance in comparing times, in seconds (default=1ms)\n"" -TN<dt> Decimate data to epochs = Begin + integer*dt (within tolerance)\n""\n"" Specific edit commands:\n"" -----------------------\n"" (Generally each '+' command (e.g DA+<time>) has a corresponding '-' command,\n"" and vice-versa; if not, end-of-file or beginning-of-file is assumed.\n"" Note that one-time commands are applied AFTER other commands of the same type.)\n""\n"" Delete commands:\n"" -DA+<time> Delete all data beginning at this time\n"" -DA-<time> Stop deleting data at this time\n"" -DO<OT> Delete observation type OT entirely (including in header)\n"" -DS<SV> Delete all data for satellite SV entirely (SV may be system only)\n"" -DS<SV>,<time> Delete all data for satellite SV at this single time only\n"" -DS+<SV>,<time> Delete all data for satellite SV beginning at this time\n"" -DS-<SV>,<time> Stop deleting all data for satellite SV at this time\n"" -DD<SV,OT,t> Delete a single RINEX datum(SV,OT,t) at time <t>\n"" -DD+<SV,OT,t> Delete all (SV,OT) data, beginning at time <t>\n"" -DD-<SV,OT,t> Stop deleting all (SV,OT) data at time <t>\n"" (NB deleting data for one OT means setting it to zero - as RINEX requires)\n""\n"" Set commands:\n"" -SD<SV,OT,t,d> Set data(SV,OT,t) to <d> at time <t>\n"" -SS<SV,OT,t,s> Set ssi(SV,OT,t) to <s> at time <t>\n"" -SL+<SV,OT,t,l> Set all lli(SV,OT,t) to <l> at time <t>\n"" -SL-<SV,OT,t,l> Stop setting lli(SV,OT,t) to <l> at time <t> (',<l>' is optional)\n"" -SL<SV,OT,t,l> Set lli(SV,OT,t) to <l> at the single time <t> only\n""\n"" Bias commands:\n"" (NB. BD commands apply only when data is non-zero, unless -BZ appears)\n"" -BZ Apply BD commands even when data is zero (i.e. 'missing')\n"" -BD<SV,OT,t,d> Add the value of <d> to data(SV,OT,t) at time <t>\n"" -BD+<SV,OT,t,d> Add value <d> to data(SV,OT) beginning at time <t>\n"" -BD-<SV,OT,t,d> Stop adding <d> to data(SV,OT) at time <t> (',<d>' optional)\n"" -BS<SV,OT,t,s> Add the value of <s> to ssi(SV,OT,t) at time <t>\n"" -BL<SV,OT,t,l> Add the value of <l> to lli(SV,OT,t) at time <t>\n""\n End of Rinex Editor commands.\n"" ===================================================================================\n" ; os << endl;}//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -