Rinex3ObsFilterOperators.hpp

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

Generated on Sun May 19 03:31:12 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1