SatPass.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: SatPass.hpp 2293 2010-02-12 18:14:16Z btolman $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00030 #ifndef GPSTK_SATELLITE_PASS_INCLUDE
00031 #define GPSTK_SATELLITE_PASS_INCLUDE
00032 
00033 #include <vector>
00034 #include <map>
00035 
00036 #include "DayTime.hpp"
00037 #include "GSatID.hpp"
00038 #include "RinexObsHeader.hpp"
00039 #include "RinexObsData.hpp"
00040 #include "Exception.hpp"
00041 
00042 namespace gpstk {
00043 
00051 class SatPass {
00052 public:
00053    // ------------------ configuration --------------------------------
00054 
00055    // public member functions -----------------------------------------
00056 
00062    SatPass(GSatID sat, double dt) throw();
00063 
00074    SatPass(GSatID sat, double dt, std::vector<std::string> obstypes) throw();
00075 
00076    // d'tor, copy c'tor are built by compiler; so is operator= but don't use it!
00077    SatPass& operator=(const SatPass& right) throw();
00078 
00079    // Add data to the arrays at timetag tt; calls must be made in time order.
00080    // Caller sets the flag to either BAD or OK later using flag().
00081 
00092    int addData(const DayTime tt, std::vector<std::string>& obstypes,
00093                                   std::vector<double>& data) throw(Exception);
00094 
00107    int addData(const DayTime tt, std::vector<std::string>& obstypes,
00108                                   std::vector<double>& data,
00109                                   std::vector<unsigned short>& lli,
00110                                   std::vector<unsigned short>& ssi,
00111                                   unsigned short flag=SatPass::OK)
00112       throw(Exception);
00113 
00122    int addData(const RinexObsData& robs) throw();
00123 
00142    void smooth(bool smoothPR, bool smoothPH, std::string& msg) throw(Exception);
00143 
00144    // -------------------------- get and set routines --------------------------
00145 
00146    // can change ssi, lli, data, but not times,sat,dt,ngood,count
00147    // get and set flag so you can update ngood
00148    // lvalue for the data or SSI/LLI arrays of this SatPass at index i
00149 
00151    int& status(void) throw() { return Status; }
00152 
00157    double& data(unsigned int i, std::string type) throw(Exception);
00158 
00163    double& timeoffset(unsigned int i) throw(Exception);
00164 
00169    unsigned short& LLI(unsigned int i, std::string type) throw(Exception);
00170 
00175    unsigned short& SSI(unsigned int i, std::string type) throw(Exception);
00176 
00177    // -------------------------------- set routines ----------------------------
00178 
00182    static double setMaxGap(const double gap) { maxGap = gap; return maxGap; }
00183 
00187    void setOutputFormat(std::string fmt) { outFormat = fmt; };
00188 
00192    void setFlag(unsigned int i, unsigned short flag) throw(Exception);
00193 
00194    // -------------------------------- get routines ----------------------------
00195 
00198    double getMaxGap(void) const throw() { return maxGap; }
00199 
00202    std::vector<std::string> getObsTypes(void) throw() {
00203       std::vector<std::string> v;
00204       for(int i=0; i<labelForIndex.size(); i++) v.push_back(labelForIndex[i]);
00205       return v;
00206    }
00207 
00211    unsigned short getFlag(unsigned int i) throw(Exception);
00212 
00214    DayTime getFirstTime(void) const throw() { return firstTime; }
00215    
00219    //void resetFirstTime(DayTime& tt) throw()
00220    //   { firstTime = tt; }
00221    //void resetLastTime(DayTime& tt) throw()
00222    //   { lastTime = tt; }
00223 
00225    DayTime getLastTime(void) const throw() { return lastTime; }
00226 
00228    DayTime getFirstGoodTime(void) const throw() {
00229       for(int j=0; j<spdvector.size(); j++) if(spdvector[j].flag & OK) {
00230          return time(j);
00231       }
00232       return DayTime::END_OF_TIME;
00233    }
00234 
00236    DayTime getLastGoodTime(void) const throw() {
00237       for(int j=spdvector.size()-1; j>=0; j--) if(spdvector[j].flag & OK) {
00238          return time(j);
00239       }
00240       return DayTime::BEGINNING_OF_TIME;
00241    }
00242 
00245    GSatID getSat(void) const throw() { return sat; }
00246 
00249    double getDT(void) const throw() { return dt; }
00250 
00253    int getNgood(void) const throw() { return ngood; }
00254 
00257    unsigned int size(void) const throw() { return spdvector.size(); }
00258 
00263    unsigned int getCount(unsigned int i) const throw(Exception);
00264 
00265    // -------------------------------- utils ---------------------------------
00266 
00268    void clear(void) throw() { spdvector.clear(); }
00269 
00273    DayTime time(unsigned int i) const throw(Exception);
00274 
00279    bool includesTime(const DayTime& tt) const throw();
00280 
00284    bool split(int N, SatPass &newSP);
00285 
00294    void decimate(const int N, DayTime refTime=DayTime::BEGINNING_OF_TIME)
00295       throw(Exception);
00296 
00301    void dump(std::ostream& os, std::string msg1, std::string msg2=std::string())
00302       throw();
00303 
00305    bool operator<(const SatPass& right) const
00306       { return firstTime < right.firstTime; }
00307 
00308    // other ---------------------------------------------------------
00309 
00315    friend std::ostream& operator<<(std::ostream& os, SatPass& sp);
00316 
00317    // public member data -----------------------------------------------
00318 
00320    static const unsigned short BAD;
00321 
00325    static const unsigned short OK;
00326 
00329    static const unsigned short LL1;
00330 
00333    static const unsigned short LL2;
00334 
00337    static const unsigned short LL3;
00338 
00340    static double maxGap;
00341 
00344    static std::string outFormat;
00345 
00346 protected:
00350    int countForTime(const DayTime& tt) const throw(Exception)
00351       { return int((tt-firstTime)/dt + 0.5); }
00352 
00353    // --------------- SatPassData data structure for internal use only ----------
00354    //
00355    struct SatPassData {
00356 
00357       // ---------------------- member data ----------------------------------
00358 
00361       unsigned short flag;
00363       unsigned int ndt;
00365       double toffset;
00367       std::vector<double> data;
00370       std::vector<unsigned short> lli,ssi;
00371 
00372       // ---------------------- private member functions ---------------------
00373 
00376       SatPassData(unsigned short n=4) : flag(SatPass::OK), ndt(0), toffset(0.0)
00377       {
00378          data = std::vector<double>(n,0.0);
00379          lli = std::vector<unsigned short>(n,0);
00380          ssi = std::vector<unsigned short>(n,0);
00381       }
00382 
00383       // d'tor, copy c'tor and operator= are built by compiler,
00384       // but operator= will not work correctly, b/c a deep copy is needed.
00385       SatPassData& operator=(const SatPassData& right) throw()
00386       {
00387          if(&right != this) {
00388             flag = right.flag;
00389             ndt = right.ndt;
00390             toffset = right.toffset;
00391             data.resize(right.data.size());
00392             lli.resize(right.lli.size());
00393             ssi.resize(right.ssi.size());
00394             int i;
00395             for(i=0; i<right.data.size(); i++) data[i] = right.data[i];
00396             for(i=0; i<right.lli.size(); i++) lli[i] = right.lli[i];
00397             for(i=0; i<right.ssi.size(); i++) ssi[i] = right.ssi[i];
00398          }
00399 
00400          return *this;
00401       }
00402 
00403    }; // end struct SatPassData
00404 
00405    // --------------- private member data -----------------------------
00409    int Status;
00410 
00412    double dt;
00413 
00415    GSatID sat;
00416 
00418    std::map<std::string,unsigned int> indexForLabel;
00419    std::map<unsigned int,std::string> labelForIndex;
00420 
00421       // above determined at construction; the rest determined by input data
00422 
00424    DayTime firstTime,lastTime;
00425 
00427    unsigned int ngood;
00428 
00430    std::vector<SatPassData> spdvector;
00431 
00432    // --------------- private member functions ------------------------
00433 
00435    void init(GSatID sat, double dt, std::vector<std::string> obstypes) throw();
00436 
00441    int push_back(const DayTime tt, SatPassData& spd) throw();
00442 
00444    struct SatPassData getData(unsigned int i) const throw(Exception);
00445 
00446    // --------------- friend functions --------------------------------
00447 
00449    friend void sort(std::vector<SatPass>& SPList) throw();
00450 
00473    friend int SatPassFromRinexFiles(std::vector<std::string>& filenames,
00474                                     std::vector<std::string>& obstypes,
00475                                     double dt,
00476                                     std::vector<SatPass>& SPList,
00477                gpstk::DayTime beginTime=gpstk::DayTime::BEGINNING_OF_TIME,
00478                gpstk::DayTime endTime=gpstk::DayTime::END_OF_TIME)
00479       throw(Exception);
00480 
00485    friend int SatPassToRinexFile(std::string filename,
00486                                  RinexObsHeader& header,
00487                                  std::vector<SatPass>& SPList)
00488       throw(Exception);
00489 
00492    friend class SatPassIterator;
00493 
00494 }; // end class SatPass
00495 
00496 
00499 class SatPassIterator {
00500 public:
00512    explicit SatPassIterator(std::vector<SatPass>& splist) throw(Exception);
00513 
00522    int next(std::map<unsigned int, unsigned int>& indexMap) throw(Exception);
00523 
00532    int next(RinexObsData& robs) throw(Exception);
00533 
00535    void reset(void) throw();
00536 
00538    DayTime getFirstTime(void) throw() { return FirstTime; }
00539 
00541    DayTime getLastTime(void) throw() { return LastTime; }
00542 
00544    DayTime getFirstGoodTime(void) const throw() {
00545       DayTime ttag = LastTime;
00546       for(int i=0; i<SPList.size(); i++)
00547          if(SPList[i].getFirstGoodTime() < ttag)
00548             ttag = SPList[i].getFirstGoodTime();
00549       return ttag;
00550    }
00551 
00553    DayTime getLastGoodTime(void) const throw() {
00554       DayTime ttag = FirstTime;
00555       for(int i=0; i<SPList.size(); i++)
00556          if(SPList[i].getLastGoodTime() > ttag)
00557             ttag = SPList[i].getLastGoodTime();
00558       return ttag;
00559    }
00560 
00562    double getDT(void) throw() { return DT; }
00563 
00567    std::map<unsigned int,unsigned int> getIndexes(void) throw()
00568       { return nextIndexMap; }
00569 
00570 private:
00571    SatPassIterator(const SatPassIterator&);              // DO NOT implement
00572    SatPassIterator& operator=(const SatPassIterator&);   // DO NOT implement
00573 
00575    int currentN;                    // current time = FirstTime + currentN*DT
00576 
00579    double DT;
00580 
00583    DayTime FirstTime,LastTime;
00584 
00586    std::map<GSatID,int> listIndex;
00587 
00590    std::map<GSatID,int> dataIndex;
00591 
00593    std::map<GSatID,int> countOffset;
00594 
00598    std::vector<int> indexStatus;
00599 
00601    std::vector<SatPass>& SPList;
00602 
00605    std::map<unsigned int,unsigned int> nextIndexMap;
00606 
00607 }; // end class SatPassIterator
00608 
00613 std::ostream& operator<<(std::ostream& os, gpstk::SatPass& sp);
00614 
00615 }  // end namespace gpstk
00616 
00617 // -----------------------------------------------------------------------------------
00618 #endif // GPSTK_SATELLITE_PASS_INCLUDE

Generated on Wed Feb 8 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1