ProblemSatFilter.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ProblemSatFilter.cpp 2528 2011-03-10 16:57:48Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010, 2011
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "ProblemSatFilter.hpp"
00032 #include <fstream>
00033 #include "StringUtils.hpp"
00034 
00035 
00036 namespace gpstk
00037 {
00038 
00039    using namespace std;
00040 
00041       // Index initially assigned to this class
00042    int ProblemSatFilter::classIndex = 1100000;
00043 
00044 
00045       // Returns an index identifying this object.
00046    int ProblemSatFilter::getIndex() const
00047    { return index; }
00048 
00049 
00050       // Returns a string identifying this object.
00051    std::string ProblemSatFilter::getClassName() const
00052    { return "ProblemSatFilter"; }
00053 
00054 
00055       /* Returns a satTypeValueMap object, adding the new data generated
00056        *  when calling this object.
00057        *
00058        * @param epoch     Time of observations.
00059        * @param gData     Data object holding the data.
00060        */
00061    satTypeValueMap& ProblemSatFilter::Process( const DayTime& epoch,
00062                                                 satTypeValueMap& gData )
00063       throw(ProcessingException)
00064    {
00065 
00066       try
00067       {
00068 
00069          SatIDSet satRejectedSet;
00070    
00071             // Loop through all the satellites
00072          satTypeValueMap::iterator it;
00073          for (it = gData.begin(); it != gData.end(); ++it) 
00074          {
00075             if( isBadSat(epoch,it->first)) satRejectedSet.insert(it->first);
00076          }
00077 
00078             // Remove satellites with missing data
00079          gData.removeSatID(satRejectedSet);
00080 
00081          return gData;
00082 
00083       }
00084       catch(Exception& u)
00085       {
00086             // Throw an exception if something unexpected happens
00087          ProcessingException e( getClassName() + ":"
00088                                 + StringUtils::asString( getIndex() ) + ":"
00089                                 + u.what() );
00090 
00091          GPSTK_THROW(e);
00092 
00093       }
00094 
00095    }  // End of 'ProblemSatFilter::Process()'
00096 
00097 
00098       /* Returns a gnnsRinex object, adding the new data generated when
00099        *  calling this object.
00100        *
00101        * @param gData    Data object holding the data.
00102        */
00103    gnssRinex& ProblemSatFilter::Process(gnssRinex& gData)
00104       throw(ProcessingException)
00105    {
00106 
00107       try
00108       {
00109 
00110          Process(gData.header.epoch, gData.body);
00111 
00112          return gData;
00113 
00114       }
00115       catch(Exception& u)
00116       {
00117             // Throw an exception if something unexpected happens
00118          ProcessingException e( getClassName() + ":"
00119                                 + StringUtils::asString( getIndex() ) + ":"
00120                                 + u.what() );
00121 
00122          GPSTK_THROW(e);
00123 
00124       }
00125 
00126    }  // End of 'ProblemSatFilter::Process()'
00127 
00128 
00129    int ProblemSatFilter::loadSatelliteProblemFile(const string& crxFile)
00130    {
00131       ifstream istrm(crxFile.c_str());
00132       if(istrm.bad()) return -1;
00133 
00134       string buffer;
00135       
00136       // let's skip the first 6 lines
00137       for(int i=0;i<6;i++) getline(istrm,buffer);
00138 
00139       long counter(0);
00140 
00141       while( getline(istrm,buffer) )
00142       {
00143          string data(buffer);
00144          StringUtils::stripTrailing(data);
00145 
00146          StringUtils::strip(buffer);
00147          if (buffer.length()<1) break;
00148          
00149        
00150          int satellite(0), problem(0), action(0);
00151          stringstream ss(data);
00152          ss >> satellite >> problem >> action;
00153          
00154          int s[6]={0.0};
00155          for(int i=0;i<6;i++) ss >> s[i];
00156 
00157          DayTime startEpoch(s[0],s[1],s[2],s[3],s[4],double(s[5]));
00158          DayTime endEpoch(startEpoch);
00159          if( data.length()>70 )
00160          {
00161             for(int i=0;i<6;i++) ss >> s[i];
00162             endEpoch.setYMDHMS(s[0],s[1],s[2],s[3],s[4],double(s[5]));
00163          }
00164          
00165          int spiltFlag = 0;
00166 
00167          string temp = StringUtils::stripLeading(data);
00168          if(temp[0]=='+') spiltFlag = 1;
00169          if(temp[0]=='-') spiltFlag =-1;
00170          
00171          // We only handle GPS satellites
00172          if( std::abs(satellite) <= 32 )
00173          {
00174             SatID sat(std::abs(satellite),SatID::systemGPS);
00175             
00176             SatDataMap::iterator it = satDataMap.find(sat);
00177             if(it==satDataMap.end())
00178             {
00179                satDataMap[sat] = SatDataList();
00180             }
00181             
00182             SatDataList& satDataList = satDataMap[sat];
00183             
00184             SatData satData;
00185             satData.spiltFlag = spiltFlag;
00186             satData.problemFlag = problem;
00187             satData.actionFlag = action;
00188             satData.startEpoch = startEpoch;
00189             satData.endEpoch = endEpoch;
00190 
00191             satDataList.push_back(satData);
00192          }
00193         
00194          counter++;
00195       }
00196 
00197 
00198       istrm.close();
00199 
00200       return 0;
00201    }
00202 
00203    bool ProblemSatFilter::isBadSat(const DayTime& time,const SatID& sat)
00204    {
00205       SatDataMap::iterator it = satDataMap.find(sat);
00206       if( it == satDataMap.end() ) return false;
00207 
00208       SatDataList& dataList = satDataMap[sat];
00209 
00210       for( SatDataList::iterator itt = dataList.begin();
00211          itt != dataList.end();
00212          ++itt)
00213       {
00214          if( time >= itt->startEpoch && time <= itt->endEpoch )
00215          {
00216             if( (itt->actionFlag == 2) || 
00217                 (itt->problemFlag== 1) ||
00218                 (itt->problemFlag== 2) ||
00219                 (itt->problemFlag== 3)   ) { return true; }
00220 
00221          } 
00222 
00223       }  // for( SatDataList::iterator...
00224 
00225       return false;
00226 
00227    }  // End of method 'ProblemSatFilter::isBadSat('
00228 
00229 } // End of namespace gpstk

Generated on Tue May 22 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1