RinexMetFilterOperators.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: RinexMetFilterOperators.hpp 438 2007-03-21 17:22:21Z btolman $"
00002 
00003 
00004 
00010 #ifndef GPSTK_RINEXMETFILTEROPERATORS_HPP
00011 #define GPSTK_RINEXMETFILTEROPERATORS_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 "DayTime.hpp"
00055 #include "FileFilter.hpp"
00056 #include "RinexMetData.hpp"
00057 #include "RinexMetHeader.hpp"
00058 
00059 #include <set>
00060 
00061 namespace gpstk
00062 {
00065 
00066    typedef std::unary_function<gpstk::RinexMetHeader, bool> RinexMetDataUnaryOperator;
00067    typedef std::binary_function<gpstk::RinexMetData, gpstk::RinexMetData, bool> RinexMetDataBinaryOperator;
00068 
00071    struct RinexMetDataOperatorLessThanFull : 
00072       public RinexMetDataBinaryOperator
00073    {
00074    public:
00078       RinexMetDataOperatorLessThanFull
00079       (const std::set<gpstk::RinexMetHeader::RinexMetType>& rmhset)
00080             : obsSet(rmhset)
00081          {}
00082 
00083       bool operator()(const gpstk::RinexMetData& l,
00084                       const gpstk::RinexMetData& r) const
00085          {
00086                // compare the times, offsets, then only those elements
00087                // that are common to both.  this ignores the flags
00088                // that are set to 0
00089             if (l.time < r.time)
00090                return true;
00091             else if (l.time != r.time)
00092                return false;
00093             
00094                // then check that each observation has the same data
00095                // for each item in the set of common observations
00096             gpstk::RinexMetData::RinexMetMap::const_iterator 
00097                lItr, rItr;
00098             std::set<gpstk::RinexMetHeader::RinexMetType>::const_iterator
00099                obsItr = obsSet.begin();
00100          
00101             while (obsItr != obsSet.end())
00102             {
00103                rItr = r.data.find(*obsItr);
00104                if (rItr == r.data.end())
00105                   return false;
00106 
00107                lItr = l.data.find(*obsItr);
00108                if (lItr == l.data.end())
00109                   return false;
00110 
00111                if ((*lItr).second < (*rItr).second)
00112                   return true;
00113                if ((*lItr).second > (*rItr).second)
00114                   return false;
00115 
00116                obsItr++;
00117             }
00118 
00119                // the data is either == or > at this point
00120             return false;
00121          }
00122 
00123    private:
00124       std::set<gpstk::RinexMetHeader::RinexMetType> obsSet;
00125    };
00126 
00128    struct RinexMetDataOperatorLessThanSimple : 
00129       public RinexMetDataBinaryOperator
00130    {
00131    public:
00132       bool operator()(const gpstk::RinexMetData& l,
00133                       const gpstk::RinexMetData& r) const
00134          {
00135             if (l.time < r.time)
00136                return true;
00137             return false;
00138          }
00139    };
00140 
00142    struct RinexMetDataOperatorEqualsSimple : 
00143       public RinexMetDataBinaryOperator
00144    {
00145    public:
00146       bool operator()(const gpstk::RinexMetData& l,
00147                       const gpstk::RinexMetData& r) const
00148          {
00149             if (l.time == r.time)
00150                return true;
00151             return false;
00152          }
00153    };
00154 
00162    struct RinexMetHeaderTouchHeaderMerge :
00163       public RinexMetDataUnaryOperator
00164    {
00165    public:
00166       RinexMetHeaderTouchHeaderMerge()
00167             : firstHeader(true)
00168          {}
00169 
00170       bool operator()(const gpstk::RinexMetHeader& l)
00171          {
00172             if (firstHeader)
00173             {
00174                theHeader = l;
00175                firstHeader = false;
00176             }
00177             else
00178             {
00179                std::set<gpstk::RinexMetHeader::RinexMetType> thisMetSet, 
00180                   tempMetSet;
00181                std::set<std::string> commentSet;
00182                obsSet.clear();
00183 
00184                   // insert the comments to the set
00185                   // and let the set take care of uniqueness
00186                copy(theHeader.commentList.begin(),
00187                     theHeader.commentList.end(),
00188                     inserter(commentSet, commentSet.begin()));
00189                copy(l.commentList.begin(),
00190                     l.commentList.end(),
00191                     inserter(commentSet, commentSet.begin()));
00192                   // then copy the comments back into theHeader
00193                theHeader.commentList.clear();
00194                copy(commentSet.begin(), commentSet.end(),
00195                     inserter(theHeader.commentList,
00196                              theHeader.commentList.begin()));
00197 
00198                   // find the set intersection of the obs types
00199                copy(theHeader.obsTypeList.begin(),
00200                     theHeader.obsTypeList.end(),
00201                     inserter(thisMetSet, thisMetSet.begin()));
00202                copy(l.obsTypeList.begin(),
00203                     l.obsTypeList.end(),
00204                     inserter(tempMetSet, tempMetSet.begin()));
00205                set_intersection(thisMetSet.begin(), thisMetSet.end(),
00206                                 tempMetSet.begin(), tempMetSet.end(),
00207                                 inserter(obsSet, obsSet.begin()));
00208                   // then copy the obsTypes back into theHeader
00209                theHeader.obsTypeList.clear();
00210                copy(obsSet.begin(), obsSet.end(),
00211                     inserter(theHeader.obsTypeList, 
00212                              theHeader.obsTypeList.begin()));
00213             }
00214             return true;
00215          }
00216 
00217       bool firstHeader;
00218       gpstk::RinexMetHeader theHeader;
00219       std::set<gpstk::RinexMetHeader::RinexMetType> obsSet;
00220    };
00221 
00222 
00224    struct RinexMetDataFilterTime : public RinexMetDataUnaryOperator
00225    {
00226    public:
00227       RinexMetDataFilterTime(const gpstk::DayTime& startTime,
00228                              const gpstk::DayTime& endTime)
00229             : start(startTime), end(endTime)
00230       {}
00231       
00232       bool operator() (const gpstk::RinexMetData& l) const
00233       {
00234          if ( (l.time < start) ||
00235               (l.time >= end))
00236             return true;
00237          return false;
00238       }
00239       
00240    private:
00241       gpstk::DayTime start, end;
00242    };
00243 
00245 
00246 }
00247 
00248 
00249 #endif

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