RinexObsFilterOperators.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: RinexObsFilterOperators.hpp 2150 2009-10-26 15:39:25Z renfroba $"
00002 
00003 
00004 
00010 #ifndef GPSTK_RINEXOBSFILTEROPERATORS_HPP
00011 #define GPSTK_RINEXOBSFILTEROPERATORS_HPP
00012 
00013 //============================================================================
00014 //
00015 //  This file is part of GPSTk, the GPS Toolkit.
00016 //
00017 //  The GPSTk is free software; you can redistribute it and/or modify
00018 //  it under the terms of the GNU Lesser General Public License as published
00019 //  by the Free Software Foundation; either version 2.1 of the License, or
00020 //  any later version.
00021 //
00022 //  The GPSTk is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU Lesser General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU Lesser General Public
00028 //  License along with GPSTk; if not, write to the Free Software Foundation,
00029 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030 //  
00031 //  Copyright 2004, The University of Texas at Austin
00032 //
00033 //============================================================================
00034 
00035 //============================================================================
00036 //
00037 //This software developed by Applied Research Laboratories at the University of
00038 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00039 //Department of Defense. The U.S. Government retains all rights to use,
00040 //duplicate, distribute, disclose, or release this software. 
00041 //
00042 //Pursuant to DoD Directive 523024 
00043 //
00044 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00045 //                           release, distribution is unlimited.
00046 //
00047 //=============================================================================
00048 
00049 
00050 
00051 
00052 
00053 
00054 #include "FileFilter.hpp"
00055 #include "RinexObsData.hpp"
00056 #include "RinexObsHeader.hpp"
00057 
00058 #include <set>
00059 #include <algorithm>
00060 
00061 namespace gpstk
00062 {
00065 
00068    struct RinexObsDataOperatorLessThanFull : 
00069       public std::binary_function<gpstk::RinexObsData, 
00070          gpstk::RinexObsData, bool>
00071    {
00072    public:
00076       RinexObsDataOperatorLessThanFull
00077       (const std::set<gpstk::RinexObsHeader::RinexObsType>& rohset)
00078             : obsSet(rohset)
00079          {}
00080 
00081       bool operator()(const gpstk::RinexObsData& l,
00082                       const gpstk::RinexObsData& r) const
00083          {
00084                // compare the times, offsets, then only those elements
00085                // that are common to both.  this ignores the flags
00086                // that are set to 0
00087             if (l.time < r.time)
00088                return true;
00089             else if (l.time == r.time)
00090             {
00091                if (l.epochFlag < r.epochFlag)
00092                   return true;
00093                else if (l.epochFlag == r.epochFlag)
00094                {
00095                   if (l.clockOffset < r.clockOffset)
00096                      return true;
00097                   else if (l.clockOffset > r.clockOffset)
00098                      return false;
00099                }
00100                else
00101                   return false;
00102             }
00103             else
00104                return false;
00105          
00106                // for the obs, first check that they're the same size
00107                // i.e. - contain the same number of PRNs
00108             if (l.obs.size() < r.obs.size())
00109                return true;
00110 
00111             if (l.obs.size() > r.obs.size())
00112                return false;
00113 
00114                // then check that each PRN has the same data for each of the 
00115                // shared fields
00116             gpstk::RinexObsData::RinexSatMap::const_iterator lItr = 
00117                l.obs.begin(), rItr;
00118          
00119             gpstk::SatID sat;
00120 
00121             while (lItr != l.obs.end())
00122             {
00123                sat = (*lItr).first;
00124                rItr = r.obs.find(sat);
00125                if (rItr == r.obs.end())
00126                   return false;
00127          
00128                gpstk::RinexObsData::RinexObsTypeMap 
00129                   lObs = (*lItr).second, 
00130                   rObs = (*rItr).second;
00131 
00132                std::set<gpstk::RinexObsHeader::RinexObsType>::const_iterator obsItr = 
00133                   obsSet.begin();
00134          
00135                while (obsItr != obsSet.end())
00136                {
00137                   gpstk::RinexObsData::RinexDatum lData, rData;
00138                   lData = lObs[*obsItr];
00139                   rData = rObs[*obsItr];
00140 
00141                   if (lData.data < rData.data)
00142                      return true;
00143                
00144                   if ( (lData.lli != 0) && (rData.lli != 0) )
00145                      if (lData.lli < rData.lli)
00146                         return true;
00147                
00148                   if ( (lData.ssi != 0) && (rData.ssi != 0) )
00149                      if (lData.ssi < rData.ssi)
00150                         return true;
00151                
00152                   obsItr++;
00153                }
00154 
00155                lItr++;
00156             }
00157 
00158                // the data is either == or > at this point
00159             return false;
00160          }
00161 
00162    private:
00163       std::set<gpstk::RinexObsHeader::RinexObsType> obsSet;
00164    };
00165 
00170    struct RinexObsDataOperatorLessThanSimple : 
00171       public std::binary_function<gpstk::RinexObsData, 
00172          gpstk::RinexObsData, bool>
00173    {
00174    public:
00175       bool operator()(const gpstk::RinexObsData& l,
00176                       const gpstk::RinexObsData& r) const
00177          {
00178             if (l.time < r.time)
00179                return true;
00180             else if (l.time == r.time)
00181             {
00182                if (l.epochFlag < r.epochFlag)
00183                   return true;
00184             }
00185             return false;
00186          }
00187    };
00188 
00191    struct RinexObsDataOperatorEqualsSimple : 
00192       public std::binary_function<gpstk::RinexObsData, 
00193          gpstk::RinexObsData, bool>
00194    {
00195    public:
00196       bool operator()(const gpstk::RinexObsData& l,
00197                       const gpstk::RinexObsData& r) const
00198          {
00199             if (l.time == r.time &&
00200                 l.epochFlag == r.epochFlag)
00201                return true;
00202             return false;
00203          }
00204    };
00205 
00213    struct RinexObsHeaderTouchHeaderMerge :
00214       public std::unary_function<gpstk::RinexObsHeader, bool>
00215    {
00216    public:
00217       RinexObsHeaderTouchHeaderMerge()
00218             : firstHeader(true)
00219          {}
00220 
00221       bool operator()(const gpstk::RinexObsHeader& l)
00222          {
00223             if (firstHeader)
00224             {
00225                theHeader = l;
00226                firstHeader = false;
00227             }
00228             else
00229             {
00230                std::set<gpstk::RinexObsHeader::RinexObsType> thisObsSet, 
00231                   tempObsSet;
00232                std::set<std::string> commentSet;
00233                obsSet.clear();
00234 
00235                   // insert the comments to the set
00236                   // and let the set take care of uniqueness
00237                copy(theHeader.commentList.begin(),
00238                     theHeader.commentList.end(),
00239                     inserter(commentSet, commentSet.begin()));
00240                copy(l.commentList.begin(),
00241                     l.commentList.end(),
00242                     inserter(commentSet, commentSet.begin()));
00243                   // then copy the comments back into theHeader
00244                theHeader.commentList.clear();
00245                copy(commentSet.begin(), commentSet.end(),
00246                     inserter(theHeader.commentList,
00247                              theHeader.commentList.begin()));
00248 
00249                   // find the set intersection of the obs types
00250                copy(theHeader.obsTypeList.begin(),
00251                     theHeader.obsTypeList.end(),
00252                     inserter(thisObsSet, thisObsSet.begin()));
00253                copy(l.obsTypeList.begin(),
00254                     l.obsTypeList.end(),
00255                     inserter(tempObsSet, tempObsSet.begin()));
00256                set_intersection(thisObsSet.begin(), thisObsSet.end(),
00257                                 tempObsSet.begin(), tempObsSet.end(),
00258                                 inserter(obsSet, obsSet.begin()));
00259                   // then copy the obsTypes back into theHeader
00260                theHeader.obsTypeList.clear();
00261                copy(obsSet.begin(), obsSet.end(),
00262                     inserter(theHeader.obsTypeList, 
00263                              theHeader.obsTypeList.begin()));
00264             }
00265             return true;
00266          }
00267 
00268       bool firstHeader;
00269       gpstk::RinexObsHeader theHeader;
00270       std::set<gpstk::RinexObsHeader::RinexObsType> obsSet;
00271    };
00272 
00274 
00275 }
00276 
00277 
00278 #endif

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