NetworkObsStreams.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00025 //
00026 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "NetworkObsStreams.hpp"
00032 #include "RinexObsHeader.hpp"
00033 
00034 
00035 namespace gpstk
00036 {
00037       // Add a rinex obs file to the network
00038       // @obsFile Rinex observation file name
00039    bool NetworkObsStreams::addRinexObsFile(const std::string& obsFile)
00040    {
00041          // object to hold the data
00042       ObsData oData;
00043       oData.obsFile = obsFile;
00044 
00045       try
00046       {
00047             // allocate memory
00048          oData.pObsStream = new RinexObsStream();
00049          oData.pSynchro = new Synchronize();
00050          if(!oData.pObsStream || !oData.pSynchro)
00051          {
00052             if(oData.pObsStream) delete oData.pObsStream;
00053             if(oData.pSynchro) delete oData.pSynchro;
00054 
00055             return false;
00056          }
00057             // Open the file
00058          oData.pObsStream->exceptions(std::ios::failbit);
00059          oData.pObsStream->open(oData.obsFile, std::ios::in);
00060 
00061             // We reader the header of the obs file
00062          RinexObsHeader obsHeader;
00063          (*oData.pObsStream) >> obsHeader;
00064 
00065 
00066          oData.obsSource.type = SatIDsystem2SourceIDtype(obsHeader.system);
00067          oData.obsSource.sourceName = obsHeader.markerName;
00068 
00069          oData.pSynchro->setReferenceSource(*oData.pObsStream);
00070 
00071             // Now, we should store the data for the receiver
00072          allStreamData.push_back(oData);
00073 
00074          mapSourceStream[oData.obsSource] = oData.pObsStream;
00075          mapSourceSynchro[oData.obsSource] = oData.pSynchro;
00076 
00077          referenceSource = oData.obsSource;
00078 
00079          return true;
00080       }
00081       catch(...)
00082       {
00083          // Problem opening the file
00084          // Maybe it doesn't exist or you don't have proper read permissions
00085 
00086          // We have to deallocate the memory here
00087          delete oData.pObsStream;
00088          oData.pObsStream = (RinexObsStream*)0;
00089 
00090          return false;
00091       }
00092 
00093    }  // End of method 'NetworkObsStreams::addRinexObsFile()'
00094 
00095       // Get epoch data of the network
00096       // @gdsMap  Object hold epoch observation data of the network
00097       // @return  Is there more epoch data for the network 
00098    bool NetworkObsStreams::readEpochData(gnssDataMap& gdsMap)
00099       throw(SynchronizeException)
00100    {
00101       // First, We clear the data map
00102       gdsMap.clear();
00103 
00104 
00105       RinexObsStream* pRefObsStream = mapSourceStream[referenceSource];
00106 
00107       gnssRinex gRef;
00108   
00109       if( (*pRefObsStream) >> gRef )
00110       {
00111          gdsMap.addGnssRinex(gRef);
00112 
00113          std::map<SourceID, RinexObsStream*>::iterator it;
00114          for( it = mapSourceStream.begin();
00115               it != mapSourceStream.end();
00116             ++it)
00117          {
00118             if( it->first == referenceSource) continue;
00119 
00120             Synchronize* synchro = mapSourceSynchro[it->first];
00121             synchro->setRoverData(gRef);
00122 
00123             gnssRinex gRin;
00124 
00125             try
00126             {
00127                gRin >> (*synchro);
00128                gdsMap.addGnssRinex(gRin);
00129             }
00130             catch(...)
00131             {
00132                if(synchronizeException)
00133                {
00134                   std::stringstream ss;
00135                   ss << "Exception when try to synchronize at epoch: "
00136                      << gRef.header.epoch << std::endl;
00137 
00138                   SynchronizeException e(ss.str());
00139 
00140                   GPSTK_THROW(e);
00141                }
00142             }
00143 
00144          }  // End of 'for(std::map<SourceID, RinexObsStream*>::iterator it;
00145          
00146          return true;
00147 
00148       }  // End of 'if( (*pRefObsStream) >> gRef )'
00149 
00150 
00151       return false;
00152 
00153    }  // End of method 'NetworkObsStreams::readEpochData()'
00154 
00155       // do some clean operation 
00156    void NetworkObsStreams::cleanUp()
00157    {
00158       mapSourceStream.clear();
00159 
00160       std::list<ObsData>::iterator it;
00161       for( it = allStreamData.begin();
00162            it != allStreamData.end();
00163          ++it)
00164       {
00165          if(it->pObsStream)
00166          {
00167             it->pObsStream->close();
00168             delete it->pObsStream;
00169             it->pObsStream = (RinexObsStream*)0;
00170          }
00171          
00172          if(it->pSynchro)
00173          {
00174             delete it->pSynchro;
00175             it->pSynchro = (Synchronize*)0;
00176          }
00177       }
00178 
00179       allStreamData.clear();
00180 
00181    }  // End of method 'NetworkObsStreams::cleanUp()'
00182 
00183       // Get the SourceID of the rinex observation file
00184    SourceID NetworkObsStreams::sourceIDOfRinexObsFile(std::string obsFile)
00185    {
00186       try
00187       {
00188          RinexObsStream rin;
00189          rin.exceptions(std::ios::failbit);
00190          rin.open(obsFile, std::ios::in);
00191  
00192          gnssRinex gRin;
00193          rin >> gRin;
00194 
00195          rin.close();
00196          
00197          return gRin.header.source;
00198       }
00199       catch(...)
00200       {
00201          // Problem opening the file
00202          // Maybe it doesn't exist or you don't have proper read permissions
00203 
00204          Exception e("Problem opening the file "
00205             + obsFile 
00206             + "Maybe it doesn't exist or you don't have proper read permissions");
00207 
00208          GPSTK_THROW(e);
00209       }
00210 
00211    }  // End of method 'NetworkObsStreams::sourceIDOfRinexObsFile'
00212 
00213 }  // End of namespace gpstk
00214 
00215 
00216 
00217 

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