00001 #pragma ident "$Id: GloEphemerisStore.cpp 3319 2012-09-19 16:58:10Z prestonherrmann $"
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 "GloEphemerisStore.hpp"
00032 #include "TimeString.hpp"
00033
00034 using namespace std;
00035
00036 namespace gpstk
00037 {
00038
00039
00040
00041 bool GloEphemerisStore::addEphemeris(const Rinex3NavData& data)
00042 throw()
00043 {
00044
00045
00046 if( (data.health == 0) || (!checkHealthFlag) )
00047 {
00048
00049 GloEphemeris gloEphem(data);
00050
00051 CommonTime t( data.time);
00052 t.setTimeSystem(TimeSystem::GLO);
00053
00054 SatID sat( data.sat );
00055 pe[sat][t] = gloEphem;
00056
00057 if (t < initialTime)
00058 initialTime = t;
00059 else if (t > finalTime)
00060 finalTime = t;
00061
00062 return true;
00063
00064 }
00065
00066 return false;
00067
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 Xvt GloEphemerisStore::getXvt( const SatID& sat,
00085 const CommonTime& epoch ) const
00086 throw( InvalidRequest )
00087 {
00088
00089 if(epoch.getTimeSystem() != initialTime.getTimeSystem())
00090 {
00091 InvalidRequest e(string("Requested time system is not GLONASS time"));
00092 GPSTK_THROW(e);
00093 }
00094
00095
00096
00097 if ( epoch < (initialTime - 900.0) ||
00098 epoch >= (finalTime + 900.0) )
00099 {
00100 InvalidRequest e( "Requested time is out of boundaries for satellite "
00101 + StringUtils::asString(sat) );
00102 GPSTK_THROW(e);
00103 }
00104
00105
00106 GloEphMap::const_iterator svmap = pe.find(sat);
00107
00108
00109 if (svmap == pe.end())
00110 {
00111 InvalidRequest e( "Ephemeris for satellite "
00112 + StringUtils::asString(sat) + " not found." );
00113 GPSTK_THROW(e);
00114 }
00115
00116
00117 const TimeGloMap& sem = svmap->second;
00118
00119
00120 TimeGloMap::const_iterator i = sem.lower_bound(epoch);;
00121
00122
00123 Xvt sv;
00124
00125
00126
00127
00128 if ( i == sem.end() )
00129 {
00130 i = --i;
00131 }
00132
00133
00134 if ( ( i->first > (epoch+900.0) ) && ( i != sem.begin() ) )
00135 {
00136 i = --i;
00137 }
00138
00139
00140
00141 if ( epoch < (i->first - 900.0) ||
00142 epoch >= (i->first + 900.0) )
00143 {
00144 InvalidRequest e( "Requested time is out of boundaries for satellite "
00145 + StringUtils::asString(sat) );
00146 GPSTK_THROW(e);
00147 }
00148
00149
00150 GloEphemeris data( i->second );
00151
00152
00153 sv = data.svXvt( epoch );
00154
00155
00156 return sv;
00157
00158 };
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void GloEphemerisStore::dump( std::ostream& s, short detail ) const
00171 throw()
00172 {
00173 static const string fmt("%4F %10.3g = %04Y/%02m/%02d %02H:%02M:%02S %P");
00174 s << "Dump of GloEphemerisStore:\n";
00175
00176 if (detail == 0 )
00177 {
00178 s << " Span is " << (initialTime == CommonTime::END_OF_TIME
00179 ? "End_time" : printTime(initialTime, fmt))
00180 << " to " << (finalTime == CommonTime::BEGINNING_OF_TIME
00181 ? "Begin_time" : printTime(finalTime, fmt))
00182 << " with " << pe.size() << " entries."
00183 << std::endl;
00184 }
00185 else
00186 {
00187 if (pe.size()) s << "Dump every record:\nweek sow = year/mn/dy hr:mi:sc Sys Sat "
00188 << "X Y Z "
00189 << "VX VY VZ "
00190 << "AX AY AZ "
00191 << "TauN GammaN MFtime Hlth fNo AgeInfo\n";
00192
00193
00194 for( GloEphMap::const_iterator it = pe.begin();
00195 it != pe.end();
00196 ++it )
00197 {
00198
00199
00200 for( TimeGloMap::const_iterator tgmIter = (*it).second.begin();
00201 tgmIter != (*it).second.end();
00202 ++tgmIter )
00203 {
00204
00205
00206 s << printTime(tgmIter->first,fmt) << " ";
00207
00208
00209 s << RinexSatID((*it).first) << " ";
00210
00211
00212 GloEphemeris data( (*tgmIter).second );
00213
00214 Triple a( data.getAcc() );
00215
00216 s << scientific << setprecision(12);
00217 s << setw(19) << data.x[0] << " "
00218 << setw(19) << data.x[1] << " "
00219 << setw(19) << data.x[2] << " "
00220 << setw(19) << data.v[0] << " "
00221 << setw(19) << data.v[1] << " "
00222 << setw(19) << data.v[2] << " "
00223 << setw(19) << a[0] << " "
00224 << setw(19) << a[1] << " "
00225 << setw(19) << a[2] << " "
00226 << setw(19) << data.getTauN() << " "
00227 << setw(19) << data.getGammaN() << " "
00228 << setw(6) << data.getMFtime() << " "
00229 << setw(3) << data.getHealth() << " "
00230 << setw(3) << data.getfreqNum() << " "
00231 << setprecision(2) << setw(5) << data.getAgeOfInfo();
00232
00233
00234 s << endl;
00235
00236 }
00237
00238 }
00239
00240 s << " End of GloEphemerisStore data." << std::endl << std::endl;
00241
00242 }
00243
00244 };
00245
00246
00247
00248
00249
00250
00251
00252 void GloEphemerisStore::edit( const CommonTime& tmin,
00253 const CommonTime& tmax )
00254 throw()
00255 {
00256
00257
00258 GloEphMap bak;
00259
00260
00261 initialTime = CommonTime::END_OF_TIME;
00262 finalTime = CommonTime::BEGINNING_OF_TIME;
00263
00264
00265 for( GloEphMap::const_iterator it = pe.begin();
00266 it != pe.end();
00267 ++it )
00268 {
00269
00270
00271 for( TimeGloMap::const_iterator tgmIter = (*it).second.begin();
00272 tgmIter != (*it).second.end();
00273 ++tgmIter )
00274 {
00275
00276 CommonTime t( (*tgmIter).first );
00277
00278
00279 if( ( tmin <= t ) && ( t <= tmax ) )
00280 {
00281
00282
00283 GloEphemeris data( (*tgmIter).second );
00284
00285 SatID sat( (*it).first );
00286 bak[sat][t] = data;
00287
00288
00289 if (t < initialTime)
00290 initialTime = t;
00291 else if (t > finalTime)
00292 finalTime = t;
00293
00294 }
00295
00296 }
00297
00298 }
00299
00300
00301 pe = bak;
00302
00303 return;
00304
00305 };
00306
00307
00308
00309
00310
00311
00312 CommonTime GloEphemerisStore::getInitialTime() const
00313 throw(InvalidRequest)
00314 {
00315
00316
00317 if( pe.empty() )
00318 {
00319 InvalidRequest e( "GloEphemerisStore object has no data." );
00320 GPSTK_THROW(e);
00321 }
00322
00323 return initialTime;
00324
00325 };
00326
00327
00328
00329
00330
00331
00332 CommonTime GloEphemerisStore::getFinalTime() const
00333 throw(InvalidRequest)
00334 {
00335
00336
00337 if( pe.empty() )
00338 {
00339 InvalidRequest e( "GloEphemerisStore object has no data." );
00340 GPSTK_THROW(e);
00341 }
00342
00343 return finalTime;
00344
00345 };
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 const GloEphemeris& GloEphemerisStore::findEphemeris( const SatID& sat,
00357 const CommonTime& epoch ) const
00358 throw( InvalidRequest )
00359 {
00360
00361
00362
00363 if ( epoch < (initialTime - 900.0) ||
00364 epoch >= (finalTime + 900.0) )
00365 {
00366 InvalidRequest e( "Requested time is out of boundaries for satellite "
00367 + StringUtils::asString(sat) );
00368 GPSTK_THROW(e);
00369 }
00370
00371
00372 GloEphMap::const_iterator svmap = pe.find(sat);
00373
00374
00375 if (svmap == pe.end())
00376 {
00377 InvalidRequest e( "Ephemeris for satellite "
00378 + StringUtils::asString(sat) + " not found." );
00379 GPSTK_THROW(e);
00380 }
00381
00382
00383 const TimeGloMap& sem = svmap->second;
00384
00385
00386 TimeGloMap::const_iterator i = sem.lower_bound(epoch);
00387
00388
00389
00390
00391 if ( i == sem.end() )
00392 {
00393 i = --i;
00394 }
00395
00396
00397 if ( ( i->first > (epoch+900.0) ) && ( i != sem.begin() ) )
00398 {
00399 i = --i;
00400 }
00401
00402
00403
00404 if ( epoch < (i->first - 900.0) ||
00405 epoch >= (i->first + 900.0) )
00406 {
00407 InvalidRequest e( "Requested time is out of boundaries for satellite "
00408 + StringUtils::asString(sat) );
00409 GPSTK_THROW(e);
00410 }
00411
00412
00413 return ( i->second );
00414
00415 };
00416
00417
00418
00419 bool GloEphemerisStore::isPresent(const SatID& id) const throw()
00420 {
00421
00422
00423 GloEphMap::const_iterator svmap = pe.find(id);
00424
00425
00426 if (svmap == pe.end())
00427 {
00428 return false;
00429 }
00430 else
00431 {
00432 return true;
00433 }
00434
00435 };
00436
00437
00438 int GloEphemerisStore::addToList(std::list<GloEphemeris>& v) const
00439 throw()
00440 {
00441 int n = 0;
00442 for(GloEphMap::const_iterator it = pe.begin(); it != pe.end(); ++it )
00443 {
00444 for(TimeGloMap::const_iterator tgmIter = (*it).second.begin();
00445 tgmIter != (*it).second.end(); ++tgmIter )
00446 {
00447 v.push_back(tgmIter->second);
00448 n++;
00449 }
00450 }
00451 return n;
00452 }
00453
00454
00455 }