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 "Differentiator.hpp"
00032
00033
00034 namespace gpstk
00035 {
00036
00037
00038 int Differentiator::classIndex = 9900000;
00039
00040
00041
00042 int Differentiator::getIndex() const
00043 { return index; }
00044
00045
00046
00047
00048 std::string Differentiator::getClassName() const
00049 { return "Differentiator"; }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 Differentiator::Differentiator( const TypeID& inType,
00062 const TypeID& outType,
00063 double samplingPeriod,
00064 double tol,
00065 bool useArc )
00066 : inputType(inType), outputType(outType), useSatArcs(useArc),
00067 watchCSFlag(TypeID::CSL1)
00068 {
00069
00070 setSamplingPeriod(samplingPeriod);
00071 setTolerance(tol);
00072 setIndex();
00073
00074 }
00075
00076
00077
00078
00079
00080
00081
00082 Differentiator& Differentiator::setSamplingPeriod(double samplingPeriod)
00083 {
00084
00085
00086 if (samplingPeriod > 0.0)
00087 {
00088 Ts = samplingPeriod;
00089 }
00090 else
00091 {
00092 Ts = 1.0;
00093 }
00094
00095
00096 delay = Ts * 5.0;
00097
00098 return (*this);
00099
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 Differentiator& Differentiator::setTolerance(double tol)
00109 {
00110
00111
00112 if (tol > 0.0)
00113 {
00114 tolerance = tol;
00115 }
00116 else
00117 {
00118 tolerance = 0.005;
00119 }
00120
00121 return (*this);
00122
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 double Differentiator::getValue( const SourceID& source,
00134 const SatID& satellite ) const
00135 throw( SourceIDNotFound, SatIDNotFound )
00136 {
00137
00138
00139 std::map<SourceID, std::map<SatID, double> >::const_iterator itObs(
00140 svDerivativesMap.find(source) );
00141 if( itObs != svDerivativesMap.end() )
00142 {
00143
00144
00145 std::map<SatID, double>::const_iterator itSat(
00146 (*itObs).second.find(satellite) );
00147 if( itSat != (*itObs).second.end() )
00148 {
00149 return (*itSat).second;
00150 }
00151 else
00152 {
00153 GPSTK_THROW(SatIDNotFound("SatID not found in map"));
00154 }
00155
00156 }
00157 else
00158 {
00159 GPSTK_THROW(SourceIDNotFound("SourceID not found in map"));
00160 }
00161
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 void Differentiator::Compute( const DayTime& epoch,
00174 const SourceID& source,
00175 const satTypeValueMap& gData )
00176 throw(ProcessingException)
00177 {
00178
00179
00180 svDerivativesMap.clear();
00181
00182 try
00183 {
00184
00185
00186 for( satTypeValueMap::const_iterator it = gData.begin();
00187 it != gData.end();
00188 ++it )
00189 {
00190
00191
00192 double value(0.0);
00193
00194 try
00195 {
00196
00197 value = (*it).second.getValue(inputType);
00198 }
00199 catch(...)
00200 {
00201
00202
00203 continue;
00204
00205 }
00206
00207
00208 std::map<SatID, filterData>::const_iterator itDat(
00209 svData[ source ].find( (*it).first ) );
00210 if( itDat == svData[source].end() )
00211 {
00212
00213
00214 filterData fData;
00215
00216
00217 fData.filter.setT(Ts);
00218
00219
00220 svData[ source ][ (*it).first ] = fData;
00221
00222 }
00223
00224
00225
00226 bool csflag(false);
00227
00228
00229
00230 if(useSatArcs)
00231 {
00232
00233 double arcN(0.0);
00234
00235 try
00236 {
00237
00238
00239 arcN = (*it).second.getValue(TypeID::satArc);
00240
00241 }
00242 catch(...)
00243 {
00244
00245
00246 continue;
00247
00248 }
00249
00250
00251
00252 if( svData[ source ][ (*it).first ].arcNumber != arcN )
00253 {
00254
00255
00256 csflag = true;
00257
00258
00259 svData[ source ][(*it).first].arcNumber = arcN;
00260 }
00261
00262 }
00263 else
00264 {
00265
00266 double flag(0.0);
00267
00268 try
00269 {
00270
00271
00272 flag = (*it).second.getValue(watchCSFlag);
00273
00274 }
00275 catch(...)
00276 {
00277
00278
00279 continue;
00280
00281 }
00282
00283
00284 if( flag > 0.0)
00285 {
00286
00287 csflag = true;
00288 }
00289
00290 }
00291
00292
00293
00294 double tDiff( std::abs(epoch -
00295 svData[ source ][ (*it).first ].previousEpoch) );
00296
00297
00298
00299
00300 if( ( csflag ) ||
00301 ( std::abs( tDiff - Ts ) > tolerance ) )
00302 {
00303
00304
00305 svData[ source ][ (*it).first ].filter.Reset();
00306 }
00307
00308
00309 svData[ source ][ (*it).first ].previousEpoch = epoch;
00310
00311
00312 double result( svData[source][(*it).first].filter.Compute(value) );
00313
00314
00315 if( svData[ source ][ (*it).first ].filter.isValid() )
00316 {
00317 svDerivativesMap[ source ][ (*it).first ] = result;
00318 }
00319
00320 }
00321
00322
00323 return;
00324
00325 }
00326 catch(Exception& u)
00327 {
00328
00329 ProcessingException e( getClassName() + ":"
00330 + StringUtils::asString( getIndex() ) + ":"
00331 + u.what() );
00332
00333 GPSTK_THROW(e);
00334
00335 }
00336
00337 }
00338
00339
00340
00341
00342
00343
00344
00345
00346 gnssSatTypeValue& Differentiator::Process(gnssSatTypeValue& gData)
00347 throw(ProcessingException)
00348 {
00349
00350 try
00351 {
00352
00353 Compute(gData.header.epoch, gData.header.source, gData.body);
00354
00355 return gData;
00356
00357 }
00358 catch(Exception& u)
00359 {
00360
00361 ProcessingException e( getClassName() + ":"
00362 + StringUtils::asString( getIndex() ) + ":"
00363 + u.what() );
00364
00365 GPSTK_THROW(e);
00366
00367 }
00368
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378 gnssRinex& Differentiator::Process(gnssRinex& gData)
00379 throw(ProcessingException)
00380 {
00381
00382 try
00383 {
00384
00385 Compute(gData.header.epoch, gData.header.source, gData.body);
00386
00387 return gData;
00388
00389 }
00390 catch(Exception& u)
00391 {
00392
00393 ProcessingException e( getClassName() + ":"
00394 + StringUtils::asString( getIndex() ) + ":"
00395 + u.what() );
00396
00397 GPSTK_THROW(e);
00398
00399 }
00400
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410 gnssDataMap& Differentiator::Process(gnssDataMap& gData)
00411 throw(ProcessingException)
00412 {
00413
00414 try
00415 {
00416
00417
00418 for( gnssDataMap::iterator itGdata = gData.begin();
00419 itGdata != gData.end();
00420 ++itGdata )
00421 {
00422
00423
00424 DayTime workEpoch( (*itGdata).first );
00425
00426
00427 SourceIDSet sourceSet( (*itGdata).second.getSourceIDSet() );
00428
00429
00430 for( SourceIDSet::const_iterator itSource = sourceSet.begin();
00431 itSource != sourceSet.end();
00432 ++itSource )
00433 {
00434
00435
00436 Compute( workEpoch,
00437 (*itSource),
00438 (*itGdata).second[ (*itSource) ] );
00439
00440
00441 for( std::map<SatID, double>::const_iterator
00442 itSat = svDerivativesMap[ (*itSource) ].begin();
00443 itSat != svDerivativesMap[ (*itSource) ].end();
00444 ++itSat )
00445 {
00446
00447 double value( svDerivativesMap[(*itSource)][(*itSat).first] );
00448
00449
00450 try
00451 {
00452
00453
00454 gData.insertValue( (workEpoch - delay),
00455 (*itSource),
00456 (*itSat).first,
00457 outputType,
00458 value );
00459
00460 }
00461 catch(...)
00462 {
00463
00464
00465 continue;
00466 }
00467
00468 }
00469
00470 }
00471
00472 }
00473
00474
00475 return gData;
00476
00477 }
00478 catch(Exception& u)
00479 {
00480
00481 ProcessingException e( getClassName() + ":"
00482 + StringUtils::asString( getIndex() ) + ":"
00483 + u.what() );
00484
00485 GPSTK_THROW(e);
00486
00487 }
00488
00489 }
00490
00491
00492
00493 }