📄 rinexeditor.cpp
字号:
#pragma ident "$Id: RinexEditor.cpp 660 2007-06-29 13:41:47Z btolman $"//============================================================================//// This file is part of GPSTk, the GPS Toolkit.//// The GPSTk is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published// by the Free Software Foundation; either version 2.1 of the License, or// any later version.//// The GPSTk is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with GPSTk; if not, write to the Free Software Foundation,// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA// // Copyright 2004, The University of Texas at Austin////============================================================================/** * @file RinexEditor.cpp * Edit Rinex observation files. * class REditCmd encapsulates commands passed to the Rinex Editor *///------------------------------------------------------------------------------------// TD Do better at catching exceptions//------------------------------------------------------------------------------------#include <vector>#include <algorithm>#include <time.h>#include <stdlib.h> // for mkstemp#include <iostream>#include "RinexEditor.hpp"#include "MathBase.hpp"#include "StringUtils.hpp"#include "RinexObsStream.hpp"#include "RinexUtilities.hpp"using namespace std;using namespace gpstk;using namespace StringUtils;//------------------------------------------------------------------------------------string RinexEditVersion; // see below in Initialize()std::map<REditCmd::TYPE, std::string> REditCmd::typeLabel;//------------------------------------------------------------------------------------// InitializeREditCmd::Initialize REditCmdInitializer;REditCmd::Initialize::Initialize(){ RinexEditVersion = string("3.5 6/21/2007"); typeLabel[INVALID] = string("INVALID"); typeLabel[IF] = string("IF"); typeLabel[OF] = string("OF"); typeLabel[ID] = string("ID"); typeLabel[OD] = string("OD"); typeLabel[HD] = string("HD"); typeLabel[TN] = string("TN"); typeLabel[TB] = string("TB"); typeLabel[TE] = string("TE"); typeLabel[TT] = string("TT"); typeLabel[AO] = string("AO"); typeLabel[DA] = string("DA"); typeLabel[DO] = string("DO"); typeLabel[DS] = string("DS"); typeLabel[DD] = string("DD"); typeLabel[SD] = string("SD"); typeLabel[SS] = string("SS"); typeLabel[SL] = string("SL"); typeLabel[BD] = string("BD"); typeLabel[BS] = string("BS"); typeLabel[BL] = string("BL"); typeLabel[BZ] = string("BZ");}//------------------------------------------------------------------------------------// find the index of first occurance of item t (of type T) in vector<T> v;// i.e. v[index]=t Return -1 if t is not found.template<class T> int index(const std::vector<T> v, const T& t) { for(int i=0; i<v.size(); i++) { if(v[i] == t) return i; } return -1;}//------------------------------------------------------------------------------------string RinexEditor::getRinexEditVersion(void) { return RinexEditVersion; }//------------------------------------------------------------------------------------// REditCmd member functions//------------------------------------------------------------------------------------// constructor from a string, pass by value to avoid changing originalREditCmd::REditCmd(string s, ostream *oflog) throw(Exception){try { type = INVALID; // ignore leading '-'s while(s.size() && (s[0]=='-' || (s[0]==' '||s[0]=='\t'))) s.erase(0,1); if(s.size() < 2) return; // separate type and the rest string tag=s.substr(0,2); field = s.substr(2,s.size()-2); // first identify the type map<TYPE,string>::const_iterator it; for(it=typeLabel.begin(); it != typeLabel.end(); it++) { if(tag == it->second) { type = it->first; break; } } // defaults bias = -99.99; SV = RinexSatID(33,SatID::systemGPS); sign = 0; inOT = -1; time = DayTime::BEGINNING_OF_TIME; // bail if invalid if(type==INVALID) return; // BZ needs nothing more if(type==BZ) return; // break field into subfields if(field.size() == 0) { type = INVALID; return; } vector<string> subfield; string::size_type pos; while(field.size() > 0) { pos = field.find(","); if(pos==string::npos) pos=field.size(); if(pos==0) subfield.push_back(" "); else subfield.push_back(field.substr(0,pos)); if(pos >= field.size()) break; field.erase(0,pos+1); }; // TN just needs time spacing if(type==TN) { bias = asDouble(subfield[0]); // validate? return; } // TT just needs delta time if(type==TT) { bias = asDouble(subfield[0]); // validate? return; } // get (optional) sign if(type==DA || type==DS || type==DD || type==SL || type==BD) { if(subfield[0][0]=='+') { sign=+1; subfield[0].erase(0,1); } if(subfield[0][0]=='-') { sign=-1; subfield[0].erase(0,1); } } // field = filename, OT, or header info if(type==IF || type==OF || type==ID || type==OD || type==HD || type==AO || type==DO) { field = subfield[0]; if(type==HD) { // inOT = int(first character) char c=field[0]; inOT = int(toupper(c)); if(inOT!='F' && inOT!='P' && inOT!='R' && inOT!='O' && inOT!='A' && inOT!='M' && inOT!='N' && inOT!='C' && inOT!='D' && inOT!='X') { type=INVALID; return; } if(inOT == 'X') { if(subfield.size() < 3) { type=INVALID; return; } field += ";" + subfield[1] + ";" + subfield[2]; } field.erase(0,1); } if(type!=OF || subfield.size()==1) return; subfield.erase(subfield.begin()); } else field = string(" "); // get an SV if(type >= DS) { SV.fromString(subfield[0]); //if(REDebug) *oflog << "REC: PRN is " << SV << endl; // allow all commands from DS on to have SV = (system,-1) // where id==-1 means 'all SV of this system' //if((type==DS || type==SL) && SV.id == -1) ; // ok //else if(SV.system == SatID::systemGPS && (SV.id<=0 || SV.id>32)) // { type=INVALID; return; } if(type==DS && subfield.size()==1) return; subfield.erase(subfield.begin()); } // get an OT if(type >= DD) { field = subfield[0]; // TD have a bool valid(string) function or bool valid(RinexObsType) RinexObsHeader::RinexObsType rot=RinexObsHeader::convertObsType(field); if(rot.type==string("UN")) { type=INVALID; return; } //if(REDebug) *oflog << "REC: processed OT is " << rot.type << endl; subfield.erase(subfield.begin()); } // get a time if(subfield.size()==2 || subfield.size()==3) { time.setGPSfullweek(asInt(subfield[0]), asDouble(subfield[1])); } if(subfield.size()==6 || subfield.size()==7) { time.setYMDHMS(asInt(subfield[0]), asInt(subfield[1]), asInt(subfield[2]), asInt(subfield[3]), asInt(subfield[4]), asDouble(subfield[5])); } //if(REDebug) *oflog << "REC: time is " //<< time.printf("%4Y/%2m/%2d %2H:%2M:%.4f") << endl; // test validity? // bias if(type >= SD) { //if(REDebug) *oflog << "REC: bias field is " << subfield.back() << endl; bias = asDouble(subfield.back().c_str()); //if(REDebug) *oflog << "REC: bias is " << bias << endl; }}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 REditCmd::REditCmd(string)//------------------------------------------------------------------------------------REditCmd::~REditCmd(void){}//------------------------------------------------------------------------------------void REditCmd::Dump(ostream& os, string msg) throw(Exception){try { if(msg.size()) os << msg; os << " type=" << typeLabel[type] << ", sign=" << sign << ", SV=" << SV.toString() << ", inOT=" << inOT << ", field=" << field << ", bias=" << fixed << setprecision(3) << bias << ", time = " << time.printf("%4Y/%2m/%2d %2H:%2M:%.4f") << endl;}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); }}//------------------------------------------------------------------------------------// RinexEditor member functions//------------------------------------------------------------------------------------RinexEditor::RinexEditor(void){ Decimate = 0.0; TimeTol = 0.001; BegTime = DayTime::BEGINNING_OF_TIME; EndTime = DayTime::END_OF_TIME; REVerbose = REDebug = BiasZeroData = FillOptionalHeader = HDDeleteOldComments = false; Skip = false; IVLast = IVInterval = IVTable = false; for(int i=0; i<9; i++) ndt[i]=-1; oflog = &cout;}//------------------------------------------------------------------------------------RinexEditor::~RinexEditor(void){ Cmds.erase(Cmds.begin(),Cmds.end()); OneTimeCmds.erase(OneTimeCmds.begin(),OneTimeCmds.end()); CurrentCmds.erase(CurrentCmds.begin(),CurrentCmds.end());}//------------------------------------------------------------------------------------// Return 0 ok, -1 no input file name, -2 no output file nameint RinexEditor::ParseCommands(void) throw(Exception){try { bool flag; int i,iret=0; // first scan command list for BZ,HDf,TN,TT,TB,TE,IF,OF,ID,OD for(i=0; i<Cmds.size(); i++) { if(REDebug) Cmds[i].Dump(*oflog,string("parse this command")); switch(Cmds[i].type) { case REditCmd::TN: Decimate = Cmds[i].bias; IVInterval = true; //if(REDebug) Cmds[i].Dump(*oflog,string("set TN with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::TT: TimeTol = Cmds[i].bias; if(REDebug) Cmds[i].Dump(*oflog,string("set TT with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::TB: BegTime = Cmds[i].time; IVTable = true; //if(REDebug) Cmds[i].Dump(*oflog,string("set TB with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::TE: EndTime = Cmds[i].time; IVLast = IVTable = true; //if(REDebug) Cmds[i].Dump(*oflog,string("set TE with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::IF: //InputFile = Cmds[i].field; Inputfiles.push_back(Cmds[i].field); //if(REDebug) Cmds[i].Dump(*oflog,string("set IF with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::OF: if(Cmds[i].time == DayTime::BEGINNING_OF_TIME) { OutputFile = Cmds[i].field; //if(REDebug) Cmds[i].Dump(*oflog,string("set OF with this cmd")); Cmds[i].type = REditCmd::INVALID; } break; case REditCmd::ID: InputDir = Cmds[i].field; //if(REDebug) Cmds[i].Dump(*oflog,string("set ID with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::OD: OutputDir = Cmds[i].field; //if(REDebug) Cmds[i].Dump(*oflog,string("set OD with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::BZ: BiasZeroData = true; //if(REDebug) Cmds[i].Dump(*oflog,string("set BZ with this cmd")); Cmds[i].type = REditCmd::INVALID; break; case REditCmd::HD: flag = true; switch(Cmds[i].inOT) { case int('F'): FillOptionalHeader=true; break; case int('D'): HDDeleteOldComments=true; break; case int('P'): HDProgram=Cmds[i].field; break; case int('X'): HDPosition=Cmds[i].field; break; case int('R'): HDRunBy=Cmds[i].field; break; case int('O'): HDObserver=Cmds[i].field; break; case int('A'): HDAgency=Cmds[i].field; break; case int('M'): HDMarker=Cmds[i].field; break; case int('N'): HDNumber=Cmds[i].field; break; case int('C'): HDComments.push_back(Cmds[i].field); break; default: flag=false; break; } if(flag) { if(REDebug) Cmds[i].Dump(*oflog,string("set HD rec with this cmd"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -