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 oData.obsSource.type = SatIDsystem2SourceIDtype(obsHeader.system);
00067 oData.obsSource.sourceName = obsHeader.markerName;
00068
00069 oData.pSynchro->setReferenceSource(*oData.pObsStream);
00070
00071
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
00084
00085
00086
00087 delete oData.pObsStream;
00088 oData.pObsStream = (RinexObsStream*)0;
00089
00090 return false;
00091 }
00092
00093 }
00094
00095
00096
00097
00098 bool NetworkObsStreams::readEpochData(gnssDataMap& gdsMap)
00099 throw(SynchronizeException)
00100 {
00101
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 }
00145
00146 return true;
00147
00148 }
00149
00150
00151 return false;
00152
00153 }
00154
00155
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 }
00182
00183
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
00202
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 }
00212
00213 }
00214
00215
00216
00217