RinexMetFilterOperators.hpp

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

Generated on Sat May 18 03:31:09 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1