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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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             // Try to get the SourceID of the receiver 
00066          gnssRinex gRin;
00067          obsHeader >> gRin;
00068 
00069          oData.obsSource = gRin.header.source;
00070 
00071          oData.pSynchro->setReferenceSource(*oData.pObsStream);
00072 
00073             // Now, we should store the data for the receiver
00074          allStreamData.push_back(oData);
00075 
00076          mapSourceStream[oData.obsSource] = oData.pObsStream;
00077          mapSourceSynchro[oData.obsSource] = oData.pSynchro;
00078 
00079          referenceSource = gRin.header.source;
00080 
00081          return true;
00082       }
00083       catch(...)
00084       {
00085          // Problem opening the file
00086          // Maybe it doesn't exist or you don't have proper read permissions
00087 
00088          // We have to deallocate the memory here
00089          delete oData.pObsStream;
00090          oData.pObsStream = (RinexObsStream*)0;
00091 
00092          return false;
00093       }
00094 
00095    }  // End of method 'NetworkObsStreams::addRinexObsFile()'
00096 
00097       // Get epoch data of the network
00098       // @gdsMap  Object hold epoch observation data of the network
00099       // @return  Is there more epoch data for the network 
00100    bool NetworkObsStreams::readEpochData(gnssDataMap& gdsMap)
00101       throw(SynchronizeException)
00102    {
00103       // First, We clear the data map
00104       gdsMap.clear();
00105 
00106 
00107       RinexObsStream* pRefObsStream = mapSourceStream[referenceSource];
00108 
00109       gnssRinex gRef;
00110   
00111       if( (*pRefObsStream) >> gRef )
00112       {
00113          gdsMap.addGnssRinex(gRef);
00114 
00115          std::map<SourceID, RinexObsStream*>::iterator it;
00116          for( it = mapSourceStream.begin();
00117               it != mapSourceStream.end();
00118             ++it)
00119          {
00120             if( it->first == referenceSource) continue;
00121 
00122             Synchronize* synchro = mapSourceSynchro[it->first];
00123             synchro->setRoverData(gRef);
00124 
00125             gnssRinex gRin;
00126 
00127             try
00128             {
00129                gRin >> (*synchro);
00130                gdsMap.addGnssRinex(gRin);
00131             }
00132             catch(...)
00133             {
00134                if(synchronizeException)
00135                {
00136                   std::stringstream ss;
00137                   ss << "Exception when try to synchronize at epoch: "
00138                      << gRef.header.epoch << std::endl;
00139 
00140                   SynchronizeException e(ss.str());
00141 
00142                   GPSTK_THROW(e);
00143                }
00144             }
00145 
00146          }  // End of 'for(std::map<SourceID, RinexObsStream*>::iterator it;
00147          
00148          return true;
00149 
00150       }  // End of 'if( (*pRefObsStream) >> gRef )'
00151 
00152 
00153       return false;
00154 
00155    }  // End of method 'NetworkObsStreams::readEpochData()'
00156 
00157       // do some clean operation 
00158    void NetworkObsStreams::cleanUp()
00159    {
00160       mapSourceStream.clear();
00161 
00162       std::list<ObsData>::iterator it;
00163       for( it = allStreamData.begin();
00164            it != allStreamData.end();
00165          ++it)
00166       {
00167          if(it->pObsStream)
00168          {
00169             it->pObsStream->close();
00170             delete it->pObsStream;
00171             it->pObsStream = (RinexObsStream*)0;
00172          }
00173          
00174          if(it->pSynchro)
00175          {
00176             delete it->pSynchro;
00177             it->pSynchro = (Synchronize*)0;
00178          }
00179       }
00180 
00181       allStreamData.clear();
00182 
00183    }  // End of method 'NetworkObsStreams::cleanUp()'
00184 
00185       // Get the SourceID of the rinex observation file
00186    SourceID NetworkObsStreams::sourceIDOfRinexObsFile(std::string obsFile)
00187    {
00188       try
00189       {
00190          RinexObsStream rin;
00191          rin.exceptions(std::ios::failbit);
00192          rin.open(obsFile, std::ios::in);
00193  
00194          gnssRinex gRin;
00195          rin >> gRin;
00196 
00197          rin.close();
00198          
00199          return gRin.header.source;
00200       }
00201       catch(...)
00202       {
00203          // Problem opening the file
00204          // Maybe it doesn't exist or you don't have proper read permissions
00205 
00206          Exception e("Problem opening the file "
00207             + obsFile 
00208             + "Maybe it doesn't exist or you don't have proper read permissions");
00209 
00210          GPSTK_THROW(e);
00211       }
00212 
00213    }  // End of method 'NetworkObsStreams::sourceIDOfRinexObsFile'
00214 
00215 }  // End of namespace gpstk
00216 
00217 
00218 
00219 

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