00001 #pragma ident "$Id: $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "NetworkObsStreams.hpp"
00032 #include "RinexObsHeader.hpp"
00033
00034
00035 namespace gpstk
00036 {
00037
00038
00039 bool NetworkObsStreams::addRinexObsFile(const std::string& obsFile)
00040 {
00041
00042 ObsData oData;
00043 oData.obsFile = obsFile;
00044
00045 try
00046 {
00047
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
00058 oData.pObsStream->exceptions(std::ios::failbit);
00059 oData.pObsStream->open(oData.obsFile, std::ios::in);
00060
00061
00062 RinexObsHeader obsHeader;
00063 (*oData.pObsStream) >> obsHeader;
00064
00065
00066 gnssRinex gRin;
00067 obsHeader >> gRin;
00068
00069 oData.obsSource = gRin.header.source;
00070
00071 oData.pSynchro->setReferenceSource(*oData.pObsStream);
00072
00073
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
00086
00087
00088
00089 delete oData.pObsStream;
00090 oData.pObsStream = (RinexObsStream*)0;
00091
00092 return false;
00093 }
00094
00095 }
00096
00097
00098
00099
00100 bool NetworkObsStreams::readEpochData(gnssDataMap& gdsMap)
00101 throw(SynchronizeException)
00102 {
00103
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 }
00147
00148 return true;
00149
00150 }
00151
00152
00153 return false;
00154
00155 }
00156
00157
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 }
00184
00185
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
00204
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 }
00214
00215 }
00216
00217
00218
00219