GDSUtils.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: $"
00002 
00008 #ifndef GPSTK_GDSUTILS_HPP
00009 #define GPSTK_GDSUTILS_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 //  Wei Yan - Chinese Academy of Sciences . 2011
00030 //
00031 //============================================================================
00032 
00033 #include <fstream>
00034 
00035 #include "DataStructures.hpp"
00036 
00037 namespace gpstk
00038 {
00043    template<class DataType>
00044    struct DataBin
00045    {
00046       DataType data;
00047 
00048       DataBin() {}
00049 
00050       DataBin(const DataType& d) : data(d) {}
00051       
00052       DataBin(const DataType& d,std::ostream& s) : data(d) { write(s); }
00053       
00054       DataBin(std::istream& s) { read(s); }
00055       
00056       DataType get() { return data; }
00057 
00058       void set(const DataType& d) { data = d;}
00059 
00060       DataBin operator=(const DataBin& right)
00061       { data = right.data; return (*this); }
00062 
00063       virtual void write(std::ostream& s)
00064       { s.write((char*)&data,sizeof(DataType));}
00065 
00066       virtual void read(std::istream& s)
00067       { s.read((char*)&data,sizeof(DataType));}
00068    };
00069  
00070    struct StringBin : DataBin<std::string>
00071    {
00072       StringBin() : DataBin(){}
00073 
00074       StringBin(const std::string& str) : DataBin(str){}
00075 
00076       StringBin(const std::string& str,std::ostream& s) 
00077          : DataBin(str) { write(s); }
00078 
00079       StringBin(std::istream& s) { read(s); }
00080 
00081       void write(std::ostream& s)
00082       {          
00083          DataBin<size_t> sizeBin(data.length(),s);
00084          
00085          s.write(&data[0],sizeof(char)*sizeBin.get());
00086       }
00087 
00088       void read(std::istream& s)
00089       { 
00090          DataBin<size_t> sizeBin(s);
00091 
00092          data.resize(sizeBin.get(),' ');
00093          s.read(&data[0],sizeof(char)*sizeBin.get());
00094       }
00095    };
00096 
00097    struct TypeIDBin : DataBin<TypeID>
00098    {
00099       TypeIDBin() : DataBin(){}
00100 
00101       TypeIDBin(const TypeID& type) : DataBin(type){}
00102 
00103       TypeIDBin(const TypeID& type,std::ostream& s) 
00104          : DataBin(type) { write(s); }
00105 
00106       TypeIDBin(std::istream& s) { read(s); }
00107 
00108       void write(std::ostream& s)
00109       { 
00110          DataBin<TypeID::ValueType> dBin(data.type,s);
00111       }
00112    
00113       void read(std::istream& s)
00114       { 
00115          DataBin<TypeID::ValueType> dBin(s);
00116          
00117          data.type = dBin.get();
00118       }
00119    };
00120 
00121    struct SourceIDBin : DataBin<SourceID>
00122    {
00123       SourceIDBin() : DataBin(){}
00124 
00125       SourceIDBin(const SourceID& source) : DataBin(source){}
00126 
00127       SourceIDBin(const SourceID& source,std::ostream& s) 
00128          : DataBin(source) { write(s); }
00129 
00130       SourceIDBin(std::istream& s) { read(s); }
00131 
00132       void write(std::ostream& s)
00133       { 
00134          DataBin<SourceID::SourceType> typeBin(data.type,s);
00135          StringBin nameBin(data.sourceName,s);
00136       }
00137 
00138       void read(std::istream& s)
00139       { 
00140          DataBin<SourceID::SourceType> typeBin(s);
00141          StringBin nameBin(s);
00142 
00143          data.type = typeBin.get();
00144          data.sourceName = nameBin.get();
00145       }
00146    };
00147 
00148    struct SatIDBin : DataBin<SatID>
00149    {
00150       SatIDBin() : DataBin(){}
00151 
00152       SatIDBin(const SatID& sat) : DataBin(sat){}
00153 
00154       SatIDBin(const SatID& sat,std::ostream& s) : DataBin(sat) { write(s); }
00155 
00156       SatIDBin(std::istream& s) { read(s); }
00157 
00158       void write(std::ostream& s)
00159       {  
00160          DataBin<int> idBin(data.id,s);
00161          DataBin<SatID::SatelliteSystem> sysBin(data.system,s);
00162       }
00163 
00164       void read(std::istream& s)
00165       { 
00166          DataBin<int> idBin(s);
00167          DataBin<SatID::SatelliteSystem> sysBin(s);
00168          
00169          data.id = idBin.get();
00170          data.system = sysBin.get();
00171       }
00172    };
00173 
00174 
00175    struct DayTimeBin : DataBin<DayTime>
00176    {
00177       DayTimeBin() : DataBin(){}
00178 
00179       DayTimeBin(const DayTime& time) : DataBin(time){}
00180 
00181       DayTimeBin(const DayTime& time,std::ostream& s) 
00182          : DataBin(time) { write(s); }
00183 
00184       DayTimeBin(std::istream& s) { read(s); }
00185 
00186       void write(std::ostream& s)
00187       { 
00188          DataBin<int> yearBin(data.year(),s);
00189          DataBin<int> monthBin(data.month(),s);
00190          DataBin<int> dayBin(data.day(),s);
00191          DataBin<int> hourBin(data.hour(),s);
00192          DataBin<int> minuteBin(data.minute(),s);
00193          DataBin<double> secondBin(data.second(),s);
00194       }
00195 
00196       void read(std::istream& s)
00197       { 
00198          DataBin<int> yearBin(s);
00199          DataBin<int> monthBin(s);
00200          DataBin<int> dayBin(s);
00201          DataBin<int> hourBin(s);
00202          DataBin<int> minuteBin(s);
00203          DataBin<double> secondBin(s);
00204 
00205          data = DayTime(yearBin.get(),monthBin.get(),dayBin.get(),
00206                         hourBin.get(),minuteBin.get(),secondBin.get());
00207       }
00208    };
00209 
00210    struct typeValueMapBin : DataBin<typeValueMap>
00211    {
00212       typeValueMapBin() : DataBin(){}
00213 
00214       typeValueMapBin(const typeValueMap& tvMap) : DataBin(tvMap){}
00215 
00216       typeValueMapBin(const typeValueMap& tvMap,std::ostream& s)
00217          : DataBin(tvMap) { write(s); }
00218 
00219       typeValueMapBin(std::istream& s) { read(s); }
00220 
00221       void write(std::ostream& s)
00222       { 
00223          DataBin<size_t> sizeBin(data.size(),s);
00224 
00225          for( typeValueMap::const_iterator it = data.begin();
00226               it != data.end();
00227               ++it )
00228          {
00229             TypeIDBin typeb(it->first,s);
00230             DataBin<double> valueb(it->second,s);
00231          }
00232       }
00233 
00234       void read(std::istream& s)
00235       { 
00236          data.clear();
00237 
00238          DataBin<size_t> sizeBin(s);
00239 
00240          for(size_t i=0; i<sizeBin.get(); i++)
00241          {
00242             TypeIDBin typeb(s);
00243             DataBin<double> valueb(s);
00244 
00245             data[typeb.get()] = valueb.get();
00246          }
00247       }
00248    };
00249 
00250 
00251    struct satTypeValueMapBin : DataBin<satTypeValueMap>
00252    {
00253       satTypeValueMapBin() : DataBin(){}
00254 
00255       satTypeValueMapBin(const satTypeValueMap& stvMap) : DataBin(stvMap){}
00256 
00257       satTypeValueMapBin(const satTypeValueMap& stvMap,std::ostream& s) 
00258          : DataBin(stvMap) { write(s); }
00259 
00260       satTypeValueMapBin(std::istream& s) { read(s); }
00261 
00262       void write(std::ostream& s)
00263       { 
00264          DataBin<size_t> sizeBin(data.size(),s);
00265        
00266          for( satTypeValueMap::const_iterator it = data.begin();
00267               it != data.end();
00268               ++it )
00269          {
00270             SatIDBin satBin(it->first,s);
00271             typeValueMapBin tvMapBin(it->second,s);
00272          }
00273       }
00274 
00275       void read(std::istream& s)
00276       { 
00277          data.clear();
00278 
00279          DataBin<size_t> sizeBin(s);
00280 
00281          for(size_t i=0; i<sizeBin.get(); i++)
00282          {
00283             SatIDBin satBin(s);
00284             typeValueMapBin tvMapBin(s);
00285 
00286             data[satBin.get()] = tvMapBin.get();
00287          }
00288       }
00289    };
00290 
00291    struct sourceDataMapBin : DataBin<sourceDataMap>
00292    {
00293       sourceDataMapBin() : DataBin(){}
00294 
00295       sourceDataMapBin(const sourceDataMap& sdMap) : DataBin(sdMap){}
00296 
00297       sourceDataMapBin(const sourceDataMap& sdMap,std::ostream& s) 
00298          : DataBin(sdMap) { write(s); }
00299 
00300       sourceDataMapBin(std::istream& s) { read(s); }
00301 
00302       void write(std::ostream& s)
00303       { 
00304          DataBin<size_t> sizeBin(data.size(),s);
00305 
00306          sourceDataMap::const_iterator it;
00307          for( it = data.begin(); it != data.end(); it++ )
00308          {
00309             SourceIDBin sourceBin(it->first);
00310             satTypeValueMapBin stvMapBin(it->second);
00311 
00312             sourceBin.write(s);
00313             stvMapBin.write(s);
00314          }
00315       }
00316 
00317       void read(std::istream& s)
00318       { 
00319          data.clear();
00320 
00321          DataBin<size_t> sizeBin(s);
00322 
00323          for(size_t i=0; i<sizeBin.get(); i++)
00324          {
00325             SourceIDBin sourceBin(s);
00326             satTypeValueMapBin stvMapBin(s);
00327 
00328             data[sourceBin.get()] = stvMapBin.get();
00329          }
00330       }
00331    };
00332 
00333    struct gnssDataMapBin : DataBin<gnssDataMap>
00334    {
00335       gnssDataMapBin() : DataBin(){}
00336 
00337       gnssDataMapBin(const gnssDataMap& gdMap) : DataBin(gdMap){}
00338 
00339       gnssDataMapBin(const gnssDataMap& gdMap,std::ostream& s) 
00340          : DataBin(gdMap) { write(s); }
00341 
00342       gnssDataMapBin(std::istream& s) { read(s); }
00343 
00344       void write(std::ostream& s)
00345       {
00346          DataBin<size_t> sizeBin(data.size(),s);
00347 
00348          gnssDataMap::const_iterator it;
00349          for(it=data.begin();it!=data.end();it++)
00350          {
00351             DayTimeBin timeBin(it->first,s);
00352             sourceDataMapBin sdMapBin(it->second,s); 
00353          }
00354       }
00355 
00356       void read(std::istream& s)
00357       {
00358          data.clear();
00359 
00360          DataBin<size_t> sizeBin(s);
00361 
00362          for(size_t i=0; i<sizeBin.get(); i++)
00363          {
00364             DayTimeBin timeBin(s);
00365             sourceDataMapBin sdMapBin(s);
00366 
00367             data.insert(std::pair<const DayTime,sourceDataMap>(timeBin.get(),
00368                                                                sdMapBin.get()));
00369          }
00370       }
00371    };
00372 
00374    void saveGnssDataMap(const gnssDataMap& gdsMap,const std::string& file)
00375    {
00376       ofstream ofs(file.c_str(),ios::binary);
00377 
00378       gnssDataMapBin gdsMapBin(gdsMap,ofs);
00379 
00380       return;
00381    }
00382 
00384    gnssDataMap loadGnssDataMap(const std::string& file)
00385    {
00386       ifstream ifs(file.c_str(),ios::binary);
00387 
00388       gnssDataMapBin gdsMapBin(ifs);
00389 
00390       return gdsMapBin.get();
00391    }
00392 
00394    void dumpGnssDataMap(const gnssDataMap& gdsMap,const std::string& file)
00395    {
00396       ofstream s(file.c_str());
00397       s<<fixed;
00398 
00399       const string timeFormat = "%04Y %02m %02d %02H %02M %06.3f";
00400       const string indentSpace = StringUtils::leftJustify("",4);
00401 
00402       gnssDataMap dataMap(gdsMap);
00403 
00404       while(!dataMap.empty())
00405       {
00406          gnssDataMap data = dataMap.frontEpoch();
00407 
00408          DayTime time(data.begin()->first);
00409 
00410          s << StringUtils::leftJustify(time.printf(timeFormat),23) << " {" << endl;
00411 
00412          gnssDataMap::const_iterator it;
00413          for(it=data.begin();it!=data.end();it++)
00414          {
00415             const sourceDataMap& sourceMap(it->second);
00416             for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00417                 itsrc != sourceMap.end();
00418                 ++itsrc)
00419             {
00420                SourceID source(itsrc->first);
00421                s << indentSpace <<"receiver: "<< source << " {" << endl;
00422                
00423                const satTypeValueMap& stvMap(itsrc->second);
00424                for(satTypeValueMap::const_iterator itsat = stvMap.begin();
00425                    itsat != stvMap.end();
00426                    ++ itsat)
00427                {
00428                   SatID satellite(itsat->first);
00429                   s << indentSpace << indentSpace <<"satellite: "<< satellite <<" {"<<endl;
00430 
00431                   const typeValueMap& tvMap(itsat->second);
00432                   for(typeValueMap::const_iterator ittyp=tvMap.begin();
00433                       ittyp != tvMap.end();
00434                       ++ittyp)
00435                   {
00436                      s << indentSpace<<indentSpace<<indentSpace;
00437                      s << setw(10) << ittyp->first << " " 
00438                        << setw(18)<< setprecision(6) << ittyp->second << endl;
00439                   }
00440                   
00441                   s << indentSpace << indentSpace << "}" << endl;
00442                   
00443                }  // loop in the satellite
00444 
00445                s << indentSpace <<"}"<<endl;
00446 
00447             }  // loop in the sources
00448 
00449          }  // loop in the epoches
00450          
00451          s << "}" << endl;    // Epoch
00452 
00453          dataMap.pop_front_epoch();
00454       }
00455 
00456       s.close();
00457    }
00458 
00459    gnssDataMap mergeGnssDataMap(const gnssDataMap& gdsMap1,
00460                                 const gnssDataMap& gdsMap2 )
00461    {
00462       gnssDataMap gdsMap(gdsMap1);
00463 
00464       // Iterate through all items in the gnssDataMap
00465       for( gnssDataMap::const_iterator it = gdsMap2.begin();
00466            it != gdsMap2.end();
00467            ++it )
00468       {
00469          const DayTime& time(it->first);
00470          const sourceDataMap& sourceMap(it->second);
00471 
00472          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00473              itsrc != sourceMap.end();
00474              ++itsrc)
00475          {
00476             gnssSatTypeValue gds;
00477             gds.header.epoch = time;
00478             gds.header.source = itsrc->first;
00479             gds.body = itsrc->second;
00480 
00481             gdsMap.addGnssSatTypeValue(gds);
00482 
00483          }  // loop in the sources
00484 
00485       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00486 
00487       return gdsMap;
00488    }
00489 
00490    // source id
00491 
00492    gnssDataMap extractSourceID(const gnssDataMap& gdsMap,
00493                                const SourceIDSet& sourceSet)
00494    {
00495       gnssDataMap dataMap;
00496 
00497       // Iterate through all items in the gnssDataMap
00498       for( gnssDataMap::const_iterator it = gdsMap.begin();
00499            it != gdsMap.end();
00500            ++it )
00501       {
00502          const DayTime& time(it->first);
00503          const sourceDataMap& sourceMap(it->second);
00504 
00505          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00506              itsrc != sourceMap.end();
00507              ++itsrc)
00508          {
00509             SourceIDSet::const_iterator itsrc2 = sourceSet.find(itsrc->first);
00510             if(itsrc2!=sourceSet.end())
00511             {
00512                gnssSatTypeValue gds;
00513                gds.header.epoch = time;
00514                gds.header.source = itsrc->first;
00515                gds.body = itsrc->second;
00516 
00517                dataMap.addGnssSatTypeValue(gds);
00518             }
00519 
00520          }  // loop in the sources
00521 
00522       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00523 
00524       return dataMap;
00525    }
00526 
00527    gnssDataMap extractSourceID(const gnssDataMap& gdsMap,
00528       const SourceID& source)
00529    {
00530       SourceIDSet sourceSet;
00531       sourceSet.insert(source);
00532 
00533       return extractSourceID(gdsMap,sourceSet);
00534    }
00535 
00536    gnssDataMap keepOnlySourceID(gnssDataMap& gdsMap,
00537                                 const SourceIDSet& sourceSet)
00538    {
00539       gdsMap = extractSourceID(gdsMap,sourceSet);
00540       return gdsMap;
00541    }
00542 
00543    gnssDataMap keepOnlySourceID(gnssDataMap& gdsMap,
00544                                 const SourceID& source)
00545    {
00546       gdsMap = extractSourceID(gdsMap,source);
00547       return gdsMap;
00548    }
00549 
00550    gnssDataMap removeSourceID(const gnssDataMap& gdsMap,
00551                               const SourceIDSet& sourceSet)
00552    {
00553       gnssDataMap dataMap;
00554 
00555       // Iterate through all items in the gnssDataMap
00556       for( gnssDataMap::const_iterator it = gdsMap.begin();
00557            it != gdsMap.end();
00558            ++it )
00559       {
00560          const DayTime& time(it->first);
00561          const sourceDataMap& sourceMap(it->second);
00562 
00563          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00564              itsrc != sourceMap.end();
00565              ++itsrc)
00566          {
00567             SourceIDSet::const_iterator itsrc2 = sourceSet.find(itsrc->first);
00568             if(itsrc2==sourceSet.end())
00569             {
00570                gnssSatTypeValue gds;
00571                gds.header.epoch = time;
00572                gds.header.source = itsrc->first;
00573                gds.body = itsrc->second;
00574 
00575                dataMap.addGnssSatTypeValue(gds);
00576             }
00577 
00578          }  // loop in the sources
00579 
00580       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00581 
00582       return dataMap;
00583    }
00584 
00585    gnssDataMap removeSourceID(const gnssDataMap& gdsMap,
00586                               const SourceID& source)
00587    {
00588       SourceIDSet sourceSet;
00589       sourceSet.insert(source);
00590 
00591       return removeSourceID(gdsMap,sourceSet);
00592    }
00593 
00594    // sat id
00595    gnssDataMap extractSatID(const gnssDataMap& gdsMap,
00596                             const SatIDSet& satSet)
00597    {
00598       gnssDataMap dataMap;
00599 
00600       // Iterate through all items in the gnssDataMap
00601       for( gnssDataMap::const_iterator it = gdsMap.begin();
00602            it != gdsMap.end();
00603            ++it )
00604       {
00605          const DayTime& time(it->first);
00606          const sourceDataMap& sourceMap(it->second);
00607 
00608          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00609              itsrc != sourceMap.end();
00610              ++itsrc)
00611          {
00612             gnssSatTypeValue gds;
00613             gds.header.epoch = time;
00614             gds.header.source = itsrc->first;
00615             gds.body = itsrc->second;
00616 
00617             gds.body.keepOnlySatID(satSet);
00618 
00619             dataMap.addGnssSatTypeValue(gds);
00620 
00621          }  // loop in the sources
00622 
00623       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00624 
00625       return dataMap;
00626    }
00627 
00628    gnssDataMap extractSatID(const gnssDataMap& gdsMap,
00629                             const SatID& sat)
00630    {
00631       SatIDSet satSet;
00632       satSet.insert(sat);
00633       
00634       return extractSatID(gdsMap,satSet);
00635    }
00636 
00637    gnssDataMap keepOnlySatID(gnssDataMap& gdsMap,
00638                              const SatID& sat)
00639    {
00640       gdsMap =  extractSatID(gdsMap,sat);
00641       return gdsMap;
00642    }
00643 
00644    gnssDataMap keepOnlySatID(gnssDataMap& gdsMap,
00645                              const SatIDSet& satSet)
00646    {
00647       gdsMap = extractSatID(gdsMap,satSet);
00648       return gdsMap;
00649    }
00650   
00651    gnssDataMap removeSatID(const gnssDataMap& gdsMap,
00652                            const SatIDSet& satSet)
00653    {
00654       gnssDataMap dataMap;
00655 
00656       // Iterate through all items in the gnssDataMap
00657       for( gnssDataMap::const_iterator it = gdsMap.begin();
00658            it != gdsMap.end();
00659            ++it )
00660       {
00661          const DayTime& time(it->first);
00662          const sourceDataMap& sourceMap(it->second);
00663 
00664          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00665              itsrc != sourceMap.end();
00666              ++itsrc)
00667          {
00668             gnssSatTypeValue gds;
00669             gds.header.epoch = time;
00670             gds.header.source = itsrc->first;
00671             gds.body = itsrc->second;
00672 
00673             gds.body.removeSatID(satSet);
00674 
00675             dataMap.addGnssSatTypeValue(gds);
00676 
00677          }  // loop in the sources
00678 
00679       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00680 
00681       return dataMap;
00682    }
00683 
00684    gnssDataMap removeSatID(const gnssDataMap& gdsMap,
00685                            const SatID& sat)
00686    {
00687       SatIDSet satSet;
00688       satSet.insert(sat);
00689 
00690       return removeSatID(gdsMap,satSet);
00691    }
00692 
00693    // type id
00694    gnssDataMap extractTypeID(const gnssDataMap& gdsMap,
00695                              const TypeIDSet& typeSet)
00696    {
00697       gnssDataMap dataMap;
00698 
00699       // Iterate through all items in the gnssDataMap
00700       for( gnssDataMap::const_iterator it = gdsMap.begin();
00701            it != gdsMap.end();
00702            ++it )
00703       {
00704          const DayTime& time(it->first);
00705          const sourceDataMap& sourceMap(it->second);
00706 
00707          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00708              itsrc != sourceMap.end();
00709              ++itsrc)
00710          {
00711             gnssSatTypeValue gds;
00712             gds.header.epoch = time;
00713             gds.header.source = itsrc->first;
00714             gds.body = itsrc->second;
00715 
00716             gds.body.keepOnlyTypeID(typeSet);
00717 
00718             dataMap.addGnssSatTypeValue(gds);
00719 
00720          }  // loop in the sources
00721 
00722       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00723 
00724       return dataMap;
00725    }
00726 
00727    gnssDataMap extractTypeID(const gnssDataMap& gdsMap,
00728                              const TypeID& type)
00729    {
00730       TypeIDSet typeSet;
00731       typeSet.insert(type);
00732 
00733       return extractTypeID(gdsMap,typeSet);
00734    }
00735 
00736    gnssDataMap keepOnlyTypeID(gnssDataMap& gdsMap,
00737                               const TypeIDSet& typeSet)
00738    {
00739       gdsMap = extractTypeID(gdsMap,typeSet);
00740       return gdsMap;
00741    }
00742 
00743    gnssDataMap keepOnlyTypeID(gnssDataMap& gdsMap,
00744                               const TypeID& type)
00745    {
00746       gdsMap = extractTypeID(gdsMap,type);
00747       return gdsMap;
00748    }
00749 
00750    gnssDataMap removeTypeID(const gnssDataMap& gdsMap,
00751                             const TypeIDSet& typeSet)
00752    {
00753       gnssDataMap dataMap;
00754 
00755       // Iterate through all items in the gnssDataMap
00756       for( gnssDataMap::const_iterator it = gdsMap.begin();
00757            it != gdsMap.end();
00758            ++it )
00759       {
00760          const DayTime& time(it->first);
00761          const sourceDataMap& sourceMap(it->second);
00762 
00763          for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
00764              itsrc != sourceMap.end();
00765              ++itsrc)
00766          {
00767             gnssSatTypeValue gds;
00768             gds.header.epoch = time;
00769             gds.header.source = itsrc->first;
00770             gds.body = itsrc->second;
00771 
00772             gds.body.removeTypeID(typeSet);
00773 
00774             dataMap.addGnssSatTypeValue(gds);
00775 
00776          }  // loop in the sources
00777 
00778       }  // End of 'for( gnssDataMap::const_iterator it = gdMap.begin(); ...'
00779 
00780       return dataMap;
00781    }
00782 
00783    gnssDataMap removeTypeID(const gnssDataMap& gdsMap,
00784                             const TypeID& type)
00785    {
00786       TypeIDSet typeSet;
00787       typeSet.insert(type);
00788 
00789       return removeTypeID(gdsMap,typeSet);
00790    }
00791 
00793    // temp testing code
00794    
00795    void testSave()
00796    {
00797       gnssDataMap gdsMap;
00798 
00799       DayTime time0(2010,12,31,0,0,0.0);
00800       for(int i=0;i<1;i++)
00801       {
00802          gnssRinex gRin;
00803 
00804          gRin.header.epoch = time0 + i*30.0;
00805          
00806          gRin.body[SatID(1,SatID::systemGPS)][TypeID::P1] = 100.0;
00807          gRin.body[SatID(2,SatID::systemGPS)][TypeID::P1] = 200.0;
00808 
00809          gRin.body[SatID(1,SatID::systemGPS)][TypeID::P2] = 200.0;
00810          gRin.body[SatID(2,SatID::systemGPS)][TypeID::P2] = 400.0;
00811 
00812          gRin.header.source = SourceID(SourceID::GPS,"test1");
00813          gdsMap.addGnssRinex(gRin);
00814 
00815          gRin.header.source = SourceID(SourceID::GPS,"test2");
00816          gdsMap.addGnssRinex(gRin);
00817 
00818          gRin.header.source = SourceID(SourceID::GPS,"test3");
00819          gdsMap.addGnssRinex(gRin);
00820       }
00821       
00822       saveGnssDataMap(gdsMap,"test.bin");
00823 
00824    }
00825 
00826    void testLoad()
00827    {
00828       gnssDataMap gdsMap = loadGnssDataMap("test.bin");
00829 
00830       SourceIDSet sourceSet;
00831       sourceSet.insert(SourceID(SourceID::GPS,"test1"));
00832 
00833       SatIDSet satSet;
00834       satSet.insert(SatID(1,SatID::systemGPS));
00835 
00836       TypeIDSet typeSet;
00837       typeSet.insert(TypeID::P1);
00838 
00839       gdsMap.keepOnlySourceID(sourceSet);
00840       gdsMap.keepOnlySatID(satSet);
00841       gdsMap.keepOnlyTypeID(typeSet);
00842 
00843       dumpGnssDataMap(gdsMap,"test.txt");
00844 
00845       int a = 0;
00846    }
00847 
00848 }   // End of namespace gpstk
00849 
00850 
00851 #endif  //GPSTK_GDSUTILS_HPP
00852 

Generated on Thu May 23 03:31:07 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1