00001 #pragma ident "$Id: DataStructures.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 "DataStructures.hpp"
00032
00033 using namespace gpstk::StringUtils;
00034 using namespace std;
00035
00036
00037 namespace gpstk
00038 {
00039
00040
00042
00043
00044
00045
00046 TypeIDSet typeValueMap::getTypeID() const
00047 {
00048
00049 TypeIDSet typeSet;
00050
00051 for( typeValueMap::const_iterator pos = (*this).begin();
00052 pos != (*this).end();
00053 ++pos )
00054 {
00055 typeSet.insert( (*pos).first );
00056 }
00057
00058 return typeSet;
00059
00060 }
00061
00062
00063
00064
00065
00066 typeValueMap typeValueMap::extractTypeID(const TypeID& type) const
00067 {
00068
00069 TypeIDSet typeSet;
00070 typeSet.insert(type);
00071
00072 return extractTypeID(typeSet);
00073
00074 }
00075
00076
00077
00078
00079
00080
00081 typeValueMap typeValueMap::extractTypeID(const TypeIDSet& typeSet) const
00082 {
00083
00084 typeValueMap tvMap;
00085
00086 for( TypeIDSet::const_iterator pos = typeSet.begin();
00087 pos != typeSet.end();
00088 ++pos )
00089 {
00090
00091 typeValueMap::const_iterator itObs( (*this).find(*pos) );
00092 if( itObs != (*this).end() )
00093 {
00094 tvMap[ (*itObs).first ] = (*itObs).second;
00095 };
00096 }
00097
00098 return tvMap;
00099
00100 }
00101
00102
00103
00104
00105
00106 typeValueMap& typeValueMap::keepOnlyTypeID(const TypeID& type)
00107 {
00108
00109 TypeIDSet typeSet;
00110 typeSet.insert(type);
00111
00112 return (keepOnlyTypeID(typeSet));
00113
00114 }
00115
00116
00117
00118
00119
00120
00121 typeValueMap& typeValueMap::keepOnlyTypeID(const TypeIDSet& typeSet)
00122 {
00123
00124 typeValueMap tvMap( (*this).extractTypeID(typeSet) );
00125 (*this) = tvMap;
00126
00127 return (*this);
00128
00129 }
00130
00131
00132
00133
00134
00135
00136 typeValueMap& typeValueMap::removeTypeID(const TypeIDSet& typeSet)
00137 {
00138
00139 for( TypeIDSet::const_iterator pos = typeSet.begin();
00140 pos != typeSet.end();
00141 ++pos )
00142 {
00143 (*this).erase(*pos);
00144 }
00145
00146 return (*this);
00147
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 double typeValueMap::getValue(const TypeID& type) const
00157 throw(TypeIDNotFound)
00158 {
00159
00160 typeValueMap::const_iterator itObs( (*this).find(type) );
00161 if ( itObs != (*this).end() )
00162 {
00163 return (*itObs).second;
00164 }
00165 else
00166 {
00167 GPSTK_THROW(TypeIDNotFound("TypeID not found in map"));
00168 }
00169
00170 }
00171
00172
00173
00174
00175
00176
00177 double& typeValueMap::operator()(const TypeID& type)
00178 throw(TypeIDNotFound)
00179 {
00180
00181 typeValueMap::iterator itObs ( (*this).find(type) );
00182
00183 if ( itObs != (*this).end() )
00184 {
00185 return (*itObs).second;
00186 }
00187 else
00188 {
00189 GPSTK_THROW(TypeIDNotFound("TypeID not found in map"));
00190 }
00191
00192 }
00193
00194
00195
00197
00198
00199
00200 SatIDSet satValueMap::getSatID() const
00201 {
00202
00203 SatIDSet satSet;
00204
00205 for( satValueMap::const_iterator pos = (*this).begin();
00206 pos != (*this).end();
00207 ++pos )
00208 {
00209 satSet.insert( (*pos).first );
00210 }
00211
00212 return satSet;
00213
00214 }
00215
00216
00217
00218
00219 Vector<SatID> satValueMap::getVectorOfSatID() const
00220 {
00221
00222 std::vector<SatID> temp;
00223
00224 for( satValueMap::const_iterator pos = (*this).begin();
00225 pos != (*this).end();
00226 ++pos )
00227 {
00228 temp.push_back( (*pos).first );
00229 }
00230
00231 Vector<SatID> result;
00232 result = temp;
00233
00234 return result;
00235
00236 }
00237
00238
00239
00240
00241
00242 satValueMap satValueMap::extractSatID(const SatID& satellite) const
00243 {
00244
00245 SatIDSet satSet;
00246 satSet.insert(satellite);
00247
00248 return extractSatID(satSet);
00249
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 satValueMap satValueMap::extractSatID( const int& p,
00259 const SatID::SatelliteSystem& s ) const
00260 {
00261
00262 SatID tempSatellite(p, s);
00263
00264 return extractSatID(tempSatellite);
00265
00266 }
00267
00268
00269
00270
00271
00272
00273 satValueMap satValueMap::extractSatID(const SatIDSet& satSet) const
00274 {
00275
00276 satValueMap svMap;
00277
00278 for( SatIDSet::const_iterator pos = satSet.begin();
00279 pos != satSet.end();
00280 ++pos )
00281 {
00282 satValueMap::const_iterator itObs( (*this).find(*pos) );
00283
00284 if( itObs != (*this).end() )
00285 {
00286 svMap[ (*itObs).first ] = (*itObs).second;
00287 };
00288 }
00289
00290 return svMap;
00291
00292 }
00293
00294
00295
00296
00297
00298 satValueMap& satValueMap::keepOnlySatID(const SatID& satellite)
00299 {
00300
00301 SatIDSet satSet;
00302 satSet.insert(satellite);
00303
00304 return keepOnlySatID(satSet);
00305
00306 }
00307
00308
00309
00310
00311
00312
00313 satValueMap& satValueMap::keepOnlySatID( const int& p,
00314 const SatID::SatelliteSystem& s )
00315 {
00316
00317 SatID tempSatellite(p, s);
00318
00319 return keepOnlySatID(tempSatellite);
00320
00321 }
00322
00323
00324
00325
00326
00327 satValueMap& satValueMap::keepOnlySatID(const SatIDSet& satSet)
00328 {
00329
00330 satValueMap svMap = extractSatID(satSet);
00331 (*this) = svMap;
00332
00333 return (*this);
00334
00335 }
00336
00337
00338
00339
00340
00341
00342 satValueMap& satValueMap::removeSatID(const SatIDSet& satSet)
00343 {
00344
00345 for( SatIDSet::const_iterator pos = satSet.begin();
00346 pos != satSet.end();
00347 ++pos )
00348 {
00349 (*this).erase(*pos);
00350 }
00351
00352 return (*this);
00353
00354 }
00355
00356
00357
00358
00359
00360
00361
00362 double satValueMap::getValue(const SatID& satellite) const
00363 throw(SatIDNotFound)
00364 {
00365
00366 satValueMap::const_iterator itObs( (*this).find(satellite) );
00367 if ( itObs != (*this).end() )
00368 {
00369 return (*itObs).second;
00370 }
00371 else
00372 {
00373 GPSTK_THROW(SatIDNotFound("SatID not found in map"));
00374 }
00375
00376 }
00377
00378
00379
00380
00381
00382
00383 double& satValueMap::operator()(const SatID& satellite)
00384 throw(SatIDNotFound)
00385 {
00386
00387 satValueMap::iterator itObs( (*this).find(satellite) );
00388
00389 if ( itObs != (*this).end() )
00390 {
00391 return (*itObs).second;
00392 }
00393 else
00394 {
00395 GPSTK_THROW(SatIDNotFound("SatID not found in map"));
00396 }
00397
00398 }
00399
00400
00401
00403
00404
00405
00406
00407
00408
00409 size_t satTypeValueMap::numElements() const
00410 {
00411
00412 size_t numEle(0);
00413
00414 for( satTypeValueMap::const_iterator it = (*this).begin();
00415 it != (*this).end();
00416 ++it )
00417 {
00418 numEle = numEle + (*it).second.size();
00419 }
00420
00421 return numEle;
00422
00423 }
00424
00425
00426
00427
00428 SatIDSet satTypeValueMap::getSatID() const
00429 {
00430
00431 SatIDSet satSet;
00432
00433 for( satTypeValueMap::const_iterator pos = (*this).begin();
00434 pos != (*this).end();
00435 ++pos )
00436 {
00437 satSet.insert( (*pos).first );
00438 }
00439
00440 return satSet;
00441
00442 }
00443
00444
00445
00446
00447 Vector<SatID> satTypeValueMap::getVectorOfSatID() const
00448 {
00449
00450 std::vector<SatID> temp;
00451
00452 for( satTypeValueMap::const_iterator pos = (*this).begin();
00453 pos != (*this).end();
00454 ++pos )
00455 {
00456 temp.push_back( (*pos).first );
00457 }
00458
00459 Vector<SatID> result;
00460 result = temp;
00461
00462 return result;
00463
00464 }
00465
00466
00467
00468
00469
00470 TypeIDSet satTypeValueMap::getTypeID() const
00471 {
00472
00473 TypeIDSet typeSet;
00474
00475 for( satTypeValueMap::const_iterator pos = (*this).begin();
00476 pos != (*this).end();
00477 ++pos )
00478 {
00479
00480 for( typeValueMap::const_iterator it = (*pos).second.begin();
00481 it != (*pos).second.end();
00482 ++it )
00483 {
00484 typeSet.insert( (*it).first );
00485 }
00486
00487 }
00488
00489 return typeSet;
00490
00491 }
00492
00493
00494
00495
00496
00497 satTypeValueMap satTypeValueMap::extractSatID(const SatID& satellite) const
00498 {
00499
00500 SatIDSet satSet;
00501 satSet.insert(satellite);
00502
00503 return extractSatID(satSet);
00504
00505 }
00506
00507
00508
00509
00510
00511
00512
00513 satTypeValueMap satTypeValueMap::extractSatID( const int& p,
00514 const SatID::SatelliteSystem& s) const
00515 {
00516
00517 SatID tempSatellite(p, s);
00518
00519 return extractSatID(tempSatellite);
00520
00521 }
00522
00523
00524
00525
00526
00527
00528 satTypeValueMap satTypeValueMap::extractSatID(const SatIDSet& satSet) const
00529 {
00530
00531 satTypeValueMap stvMap;
00532
00533 for( SatIDSet::const_iterator pos = satSet.begin();
00534 pos != satSet.end();
00535 ++pos )
00536 {
00537 satTypeValueMap::const_iterator itObs( (*this).find(*pos) );
00538 if( itObs != (*this).end() )
00539 {
00540 stvMap[ (*itObs).first ] = (*itObs).second;
00541 };
00542 }
00543
00544 return stvMap;
00545
00546 }
00547
00548
00549
00550
00551
00552 satTypeValueMap& satTypeValueMap::keepOnlySatID(const SatID& satellite)
00553 {
00554
00555 SatIDSet satSet;
00556 satSet.insert(satellite);
00557
00558 return keepOnlySatID(satSet);
00559
00560 }
00561
00562
00563
00564
00565
00566
00567 satTypeValueMap& satTypeValueMap::keepOnlySatID( const int& p,
00568 const SatID::SatelliteSystem& s )
00569 {
00570
00571 SatID tempSatellite(p, s);
00572
00573 return keepOnlySatID(tempSatellite);
00574
00575 }
00576
00577
00578
00579
00580
00581 satTypeValueMap& satTypeValueMap::keepOnlySatID(const SatIDSet& satSet)
00582 {
00583
00584 satTypeValueMap stvMap( extractSatID(satSet) );
00585 (*this) = stvMap;
00586
00587 return (*this);
00588
00589 }
00590
00591
00592
00593
00594
00595 satTypeValueMap satTypeValueMap::extractTypeID(const TypeID& type) const
00596 {
00597
00598 TypeIDSet typeSet;
00599 typeSet.insert(type);
00600
00601 return extractTypeID(typeSet);
00602
00603 }
00604
00605
00606
00607
00608
00609
00610 satTypeValueMap satTypeValueMap::extractTypeID(const TypeIDSet& typeSet)
00611 const
00612 {
00613
00614 satTypeValueMap theMap;
00615
00616 for( satTypeValueMap::const_iterator it = (*this).begin();
00617 it != (*this).end();
00618 ++it )
00619 {
00620
00621 typeValueMap tvMap( (*it).second.extractTypeID(typeSet) );
00622 if( tvMap.size() > 0 )
00623 {
00624 theMap[(*it).first] = tvMap;
00625 };
00626
00627 };
00628
00629 return theMap;
00630
00631 }
00632
00633
00634
00635
00636
00637 satTypeValueMap& satTypeValueMap::keepOnlyTypeID(const TypeID& type)
00638 {
00639
00640 TypeIDSet typeSet;
00641 typeSet.insert(type);
00642
00643 return keepOnlyTypeID(typeSet);
00644
00645 }
00646
00647
00648
00649
00650
00651
00652 satTypeValueMap& satTypeValueMap::keepOnlyTypeID(const TypeIDSet& typeSet)
00653 {
00654
00655 satTypeValueMap stvMap( extractTypeID(typeSet) );
00656 (*this) = stvMap;
00657
00658 return (*this);
00659
00660 }
00661
00662
00663
00664
00665
00666
00667 satTypeValueMap& satTypeValueMap::removeSatID(const SatIDSet& satSet)
00668 {
00669
00670 for( SatIDSet::const_iterator pos = satSet.begin();
00671 pos != satSet.end();
00672 ++pos )
00673 {
00674 (*this).erase(*pos);
00675 }
00676
00677 return (*this);
00678
00679 }
00680
00681
00682
00683
00684
00685 satTypeValueMap& satTypeValueMap::removeTypeID(const TypeID& type)
00686 {
00687
00688 for( satTypeValueMap::iterator it = (*this).begin();
00689 it != (*this).end();
00690 ++it )
00691 {
00692 (*it).second.removeTypeID(type);
00693 }
00694
00695 return (*this);
00696
00697 }
00698
00699
00700
00701
00702
00703
00704 satTypeValueMap& satTypeValueMap::removeTypeID(const TypeIDSet& typeSet)
00705 {
00706
00707 for( TypeIDSet::const_iterator pos = typeSet.begin();
00708 pos != typeSet.end();
00709 ++pos )
00710 {
00711 removeTypeID(*pos);
00712 }
00713
00714 return (*this);
00715
00716 }
00717
00718
00719
00720
00721
00722
00723 Vector<double> satTypeValueMap::getVectorOfTypeID(const TypeID& type) const
00724 {
00725
00726
00727 std::vector<double> temp;
00728
00729 for( satTypeValueMap::const_iterator it = (*this).begin();
00730 it != (*this).end();
00731 ++it )
00732 {
00733
00734 typeValueMap::const_iterator itObs( (*it).second.find(type) );
00735 if ( itObs != (*it).second.end() )
00736 {
00737 temp.push_back( (*itObs).second );
00738 }
00739 else
00740 {
00741 temp.push_back( 0.0 );
00742 }
00743
00744 }
00745
00746
00747 Vector<double> result;
00748
00749
00750 result = temp;
00751
00752 return result;
00753
00754 }
00755
00756
00757
00758
00759
00760 Matrix<double> satTypeValueMap::getMatrixOfTypes(const TypeIDSet& typeSet)
00761 const
00762 {
00763
00764
00765 Matrix<double> tempMat( (*this).numSats(), typeSet.size(), 0.0 );
00766
00767 size_t numRow(0), numCol(0);
00768
00769 for( satTypeValueMap::const_iterator it = (*this).begin();
00770 it != (*this).end();
00771 ++it )
00772 {
00773 numCol=0;
00774
00775 for( TypeIDSet::const_iterator pos = typeSet.begin();
00776 pos != typeSet.end();
00777 ++pos )
00778 {
00779
00780 typeValueMap::const_iterator itObs( (*it).second.find(*pos) );
00781 if( itObs != (*it).second.end() )
00782 {
00783 tempMat(numRow, numCol) = (*itObs).second;
00784 }
00785
00786 ++numCol;
00787 }
00788
00789 ++numRow;
00790
00791 }
00792
00793 return tempMat;
00794
00795 }
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814 satTypeValueMap& satTypeValueMap::insertTypeIDVector( const TypeID& type,
00815 const Vector<double> dataVector )
00816 throw(NumberOfSatsMismatch)
00817 {
00818
00819 if( dataVector.size() == (*this).numSats() )
00820 {
00821 size_t pos = 0;
00822
00823 for( satTypeValueMap::iterator it = (*this).begin();
00824 it != (*this).end();
00825 ++it )
00826 {
00827 (*it).second[type] = dataVector[pos];
00828 ++pos;
00829 }
00830
00831 return (*this);
00832
00833 }
00834 else
00835 {
00836 GPSTK_THROW( NumberOfSatsMismatch(" Number of data values in vector \
00837 and number of satellites do not match") );
00838 }
00839
00840 }
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863 satTypeValueMap& satTypeValueMap::insertMatrix( const TypeIDSet& typeSet,
00864 const Matrix<double> dataMatrix )
00865 throw(NumberOfSatsMismatch, NumberOfTypesMismatch)
00866 {
00867
00868 if( dataMatrix.rows() != (*this).numSats() )
00869 {
00870 GPSTK_THROW( NumberOfSatsMismatch("Number of rows in matrix and \
00871 number of satellites do not match") );
00872 }
00873
00874 if( dataMatrix.cols() == typeSet.size() )
00875 {
00876
00877 size_t pos(0);
00878
00879 for( satTypeValueMap::iterator it = (*this).begin();
00880 it != (*this).end();
00881 ++it )
00882 {
00883
00884 size_t idx(0);
00885
00886 for( TypeIDSet::const_iterator itSet = typeSet.begin();
00887 itSet != typeSet.end();
00888 ++itSet )
00889 {
00890 (*it).second[(*itSet)] = dataMatrix(pos,idx);
00891 ++idx;
00892 }
00893
00894 ++pos;
00895
00896 }
00897
00898 return (*this);
00899
00900 }
00901 else
00902 {
00903 GPSTK_THROW( NumberOfTypesMismatch("Number of data values per row \
00904 in matrix and number of types do not match") );
00905 }
00906
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 double satTypeValueMap::getValue( const SatID& satellite,
00918 const TypeID& type ) const
00919 throw( SatIDNotFound, TypeIDNotFound )
00920 {
00921
00922 satTypeValueMap::const_iterator itObs( (*this).find(satellite) );
00923 if( itObs != (*this).end() )
00924 {
00925 return (*itObs).second.getValue( type );
00926 }
00927 else
00928 {
00929 GPSTK_THROW(SatIDNotFound("SatID not found in map"));
00930 }
00931
00932 }
00933
00934
00935
00936
00937
00938 typeValueMap& satTypeValueMap::operator()(const SatID& satellite)
00939 throw(SatIDNotFound)
00940 {
00941
00942 satTypeValueMap::iterator itObs( (*this).find(satellite) );
00943 if( itObs != (*this).end() )
00944 {
00945 return (*itObs).second;
00946 }
00947 else
00948 {
00949 GPSTK_THROW(SatIDNotFound("SatID not found in map"));
00950 }
00951
00952 }
00953
00954
00955
00956
00958
00959
00960
00961
00962 gnssSatValue gnssSatValue::extractSatID(const SatID& satellite) const
00963 {
00964
00965 gnssSatValue result;
00966 result.header = (*this).header;
00967 result.body = (*this).body.extractSatID(satellite);
00968
00969 return result;
00970
00971 }
00972
00973
00974
00975
00976
00977
00978
00979 gnssSatValue gnssSatValue::extractSatID( const int& p,
00980 const SatID::SatelliteSystem& s ) const
00981 {
00982
00983 SatID tempSatellite(p, s);
00984
00985 return extractSatID(tempSatellite);
00986
00987 }
00988
00989
00990
00991
00992
00993
00994 gnssSatValue gnssSatValue::extractSatID(const SatIDSet& satSet) const
00995 {
00996
00997 gnssSatValue result;
00998 result.header = (*this).header;
00999 result.body = (*this).body.extractSatID(satSet);
01000
01001 return result;
01002
01003 }
01004
01005
01006
01007
01008
01009 gnssSatValue& gnssSatValue::keepOnlySatID(const SatID& satellite)
01010 {
01011
01012 SatIDSet satSet;
01013 satSet.insert(satellite);
01014
01015 return keepOnlySatID(satSet);
01016
01017 }
01018
01019
01020
01021
01022
01023
01024 gnssSatValue& gnssSatValue::keepOnlySatID( const int& p,
01025 const SatID::SatelliteSystem& s )
01026 {
01027
01028 SatID tempSatellite(p, s);
01029
01030 return keepOnlySatID(tempSatellite);
01031
01032 }
01033
01034
01035
01036
01037
01038 gnssSatValue& gnssSatValue::keepOnlySatID(const SatIDSet& satSet)
01039 {
01040
01041 satValueMap svMap ( (*this).body.extractSatID(satSet) );
01042 (*this).body = svMap;
01043
01044 return (*this);
01045
01046 }
01047
01048
01049
01050
01051
01052
01053 gnssSatValue& gnssSatValue::removeSatID(const SatIDSet& satSet)
01054 {
01055
01056 for( SatIDSet::const_iterator pos = satSet.begin();
01057 pos != satSet.end();
01058 ++pos )
01059 {
01060 (*this).body.erase(*pos);
01061 }
01062
01063 return (*this);
01064
01065 }
01066
01067
01068
01069
01071
01072
01073
01074
01075 gnssTypeValue gnssTypeValue::extractTypeID(const TypeID& type) const
01076 {
01077
01078 gnssTypeValue result;
01079 result.header = (*this).header;
01080 result.body = (*this).body.extractTypeID(type);
01081
01082 return result;
01083
01084 }
01085
01086
01087
01088
01089
01090
01091 gnssTypeValue gnssTypeValue::extractTypeID(const TypeIDSet& typeSet) const
01092 {
01093
01094 gnssTypeValue result;
01095 result.header = (*this).header;
01096 result.body = (*this).body.extractTypeID(typeSet);
01097
01098 return result;
01099
01100 }
01101
01102
01103
01104
01105
01106 gnssTypeValue& gnssTypeValue::keepOnlyTypeID(const TypeID& type)
01107 {
01108
01109 TypeIDSet typeSet;
01110 typeSet.insert(type);
01111
01112 return keepOnlyTypeID(typeSet);
01113
01114 }
01115
01116
01117
01118
01119
01120
01121 gnssTypeValue& gnssTypeValue::keepOnlyTypeID(const TypeIDSet& typeSet)
01122 {
01123
01124 typeValueMap tvMap( (*this).body.extractTypeID(typeSet) );
01125 (*this).body = tvMap;
01126
01127 return (*this);
01128
01129 }
01130
01131
01132
01133
01134
01135
01136 gnssTypeValue& gnssTypeValue::removeTypeID(const TypeIDSet& typeSet)
01137 {
01138
01139 for( TypeIDSet::const_iterator pos = typeSet.begin();
01140 pos != typeSet.end();
01141 ++pos )
01142 {
01143 (*this).body.erase(*pos);
01144 }
01145
01146 return (*this);
01147
01148 }
01149
01150
01151
01152
01154
01155
01156
01157
01158 gnssSatTypeValue gnssSatTypeValue::extractSatID(const SatID& satellite)
01159 const
01160 {
01161
01162 gnssSatTypeValue result;
01163 result.header = (*this).header;
01164 result.body = (*this).body.extractSatID(satellite);
01165
01166 return result;
01167
01168 }
01169
01170
01171
01172
01173
01174
01175
01176 gnssSatTypeValue gnssSatTypeValue::extractSatID( const int& p,
01177 const SatID::SatelliteSystem& s ) const
01178 {
01179
01180 SatID tempSatellite(p, s);
01181
01182 return extractSatID(tempSatellite);
01183
01184 }
01185
01186
01187
01188
01189
01190
01191 gnssSatTypeValue gnssSatTypeValue::extractSatID(const SatIDSet& satSet) const
01192 {
01193
01194 gnssSatTypeValue result;
01195 result.header = (*this).header;
01196 result.body = (*this).body.extractSatID(satSet);
01197
01198 return result;
01199
01200 }
01201
01202
01203
01204
01205
01206 gnssSatTypeValue& gnssSatTypeValue::keepOnlySatID(const SatID& satellite)
01207 {
01208
01209 SatIDSet satSet;
01210 satSet.insert(satellite);
01211
01212 return keepOnlySatID(satSet);
01213
01214 }
01215
01216
01217
01218
01219
01220
01221 gnssSatTypeValue& gnssSatTypeValue::keepOnlySatID( const int& p,
01222 const SatID::SatelliteSystem& s )
01223 {
01224
01225 SatID tempSatellite(p, s);
01226
01227 return keepOnlySatID(tempSatellite);
01228
01229 }
01230
01231
01232
01233
01234
01235 gnssSatTypeValue& gnssSatTypeValue::keepOnlySatID(const SatIDSet& satSet)
01236 {
01237
01238 satTypeValueMap stvMap( (*this).body.extractSatID(satSet) );
01239 (*this).body = stvMap;
01240
01241 return (*this);
01242
01243 }
01244
01245
01246
01247
01248
01249 gnssSatTypeValue gnssSatTypeValue::extractTypeID(const TypeID& type) const
01250 {
01251
01252 gnssSatTypeValue result;
01253 result.header = (*this).header;
01254 result.body = (*this).body.extractTypeID(type);
01255
01256 return result;
01257
01258 }
01259
01260
01261
01262
01263
01264
01265 gnssSatTypeValue gnssSatTypeValue::extractTypeID(const TypeIDSet& typeSet)
01266 const
01267 {
01268
01269 gnssSatTypeValue result;
01270 result.header = (*this).header;
01271 result.body = (*this).body.extractTypeID(typeSet);
01272
01273 return result;
01274
01275 }
01276
01277
01278
01279
01280
01281 gnssSatTypeValue& gnssSatTypeValue::keepOnlyTypeID(const TypeID& type)
01282 {
01283
01284 TypeIDSet typeSet;
01285 typeSet.insert(type);
01286
01287 return keepOnlyTypeID(typeSet);
01288
01289 }
01290
01291
01292
01293
01294
01295
01296 gnssSatTypeValue& gnssSatTypeValue::keepOnlyTypeID(const TypeIDSet& typeSet)
01297 {
01298
01299 satTypeValueMap stvMap( (*this).body.extractTypeID(typeSet) );
01300 (*this).body = stvMap;
01301
01302 return (*this);
01303
01304 }
01305
01306
01307
01308
01309
01310
01311 gnssSatTypeValue& gnssSatTypeValue::removeSatID(const SatIDSet& satSet)
01312 {
01313
01314 for( SatIDSet::const_iterator pos = satSet.begin();
01315 pos != satSet.end();
01316 ++pos )
01317 {
01318 (*this).body.erase(*pos);
01319 }
01320
01321 return (*this);
01322
01323 }
01324
01325
01326
01327
01328
01329
01330 gnssSatTypeValue& gnssSatTypeValue::removeTypeID(const TypeIDSet& typeSet)
01331 {
01332
01333 for( TypeIDSet::const_iterator pos = typeSet.begin();
01334 pos != typeSet.end();
01335 ++pos )
01336 {
01337 (*this).body.removeTypeID(*pos);
01338 }
01339
01340 return (*this);
01341
01342 }
01343
01344
01345
01346
01348
01349
01350
01351
01352 gnssRinex gnssRinex::extractSatID(const SatID& satellite) const
01353 {
01354
01355 gnssRinex result;
01356 result.header = (*this).header;
01357 result.body = (*this).body.extractSatID(satellite);
01358
01359 return result;
01360
01361 }
01362
01363
01364
01365
01366
01367
01368
01369 gnssRinex gnssRinex::extractSatID( const int& p,
01370 const SatID::SatelliteSystem& s ) const
01371 {
01372
01373 SatID tempSatellite(p, s);
01374
01375 return extractSatID(tempSatellite);
01376
01377 }
01378
01379
01380
01381
01382
01383
01384 gnssRinex gnssRinex::extractSatID(const SatIDSet& satSet) const
01385 {
01386
01387 gnssRinex result;
01388 result.header = (*this).header;
01389 result.body = (*this).body.extractSatID(satSet);
01390
01391 return result;
01392
01393 }
01394
01395
01396
01397
01398
01399 gnssRinex& gnssRinex::keepOnlySatID(const SatID& satellite)
01400 {
01401
01402 SatIDSet satSet;
01403 satSet.insert(satellite);
01404
01405 return keepOnlySatID(satSet);
01406
01407 }
01408
01409
01410
01411
01412
01413
01414 gnssRinex& gnssRinex::keepOnlySatID( const int& p,
01415 const SatID::SatelliteSystem& s )
01416 {
01417
01418 SatID tempSatellite(p, s);
01419
01420 return keepOnlySatID(tempSatellite);
01421
01422 }
01423
01424
01425
01426
01427
01428 gnssRinex& gnssRinex::keepOnlySatID(const SatIDSet& satSet)
01429 {
01430
01431 satTypeValueMap stvMap( (*this).body.extractSatID(satSet) );
01432 (*this).body = stvMap;
01433
01434 return (*this);
01435
01436 }
01437
01438
01439
01440
01441
01442 gnssRinex gnssRinex::extractTypeID(const TypeID& type) const
01443 {
01444
01445 gnssRinex result;
01446 result.header = (*this).header;
01447 result.body = (*this).body.extractTypeID(type);
01448
01449 return result;
01450
01451 }
01452
01453
01454
01455
01456
01457
01458 gnssRinex gnssRinex::extractTypeID(const TypeIDSet& typeSet) const
01459 {
01460
01461 gnssRinex result;
01462 result.header = (*this).header;
01463 result.body = (*this).body.extractTypeID(typeSet);
01464
01465 return result;
01466
01467 }
01468
01469
01470
01471
01472
01473 gnssRinex& gnssRinex::keepOnlyTypeID(const TypeID& type)
01474 {
01475
01476 TypeIDSet typeSet;
01477 typeSet.insert(type);
01478
01479 return keepOnlyTypeID(typeSet);
01480
01481 }
01482
01483
01484
01485
01486
01487
01488 gnssRinex& gnssRinex::keepOnlyTypeID(const TypeIDSet& typeSet)
01489 {
01490
01491 satTypeValueMap stvMap( (*this).body.extractTypeID(typeSet) );
01492 (*this).body = stvMap;
01493
01494 return (*this);
01495
01496 }
01497
01498
01499
01500
01501
01502 gnssRinex& gnssRinex::keepOnlySatSystem(const SatID::SatelliteSystem satSys)
01503 {
01504 satTypeValueMap stvMap( (*this).body );
01505
01506 SatIDSet satRejectedSet;
01507 for(satTypeValueMap::iterator it = stvMap.begin();
01508 it != stvMap.end();
01509 ++it)
01510 {
01511 if( it->first.system != satSys ) satRejectedSet.insert( it->first );
01512 }
01513 stvMap.removeSatID(satRejectedSet);
01514
01515
01516 (*this).body = stvMap;
01517
01518 return (*this);
01519 }
01520
01521
01522
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534 double sourceDataMap::getValue( const SourceID& source,
01535 const SatID& satellite,
01536 const TypeID& type ) const
01537 throw( SourceIDNotFound, SatIDNotFound, TypeIDNotFound )
01538 {
01539
01540
01541 sourceDataMap::const_iterator itObs( (*this).find(source) );
01542 if( itObs != (*this).end() )
01543 {
01544 return (*itObs).second.getValue( satellite, type );
01545 }
01546 else
01547 {
01548 GPSTK_THROW(SourceIDNotFound("SourceID not found in map"));
01549 }
01550
01551 }
01552
01553
01554
01555
01556
01557
01558
01559
01560 SourceIDSet sourceDataMap::getSourceIDSet( void ) const
01561 {
01562
01563
01564 SourceIDSet toReturn;
01565
01566
01567 for( sourceDataMap::const_iterator sdmIter = (*this).begin();
01568 sdmIter != (*this).end();
01569 ++sdmIter )
01570 {
01571
01572
01573 toReturn.insert( (*sdmIter).first );
01574
01575 }
01576
01577 return toReturn;
01578
01579 }
01580
01581
01582
01583
01584
01585
01586
01587
01588 SatIDSet sourceDataMap::getSatIDSet( void ) const
01589 {
01590
01591
01592 SatIDSet toReturn;
01593
01594
01595 for( sourceDataMap::const_iterator sdmIter = (*this).begin();
01596 sdmIter != (*this).end();
01597 ++sdmIter )
01598 {
01599
01600
01601 for( satTypeValueMap::const_iterator stvmIter =
01602 (*sdmIter).second.begin();
01603 stvmIter != (*sdmIter).second.end();
01604 stvmIter++ )
01605 {
01606
01607
01608 toReturn.insert( (*stvmIter).first );
01609
01610 }
01611
01612 }
01613
01614 return toReturn;
01615
01616 }
01617
01618
01619
01620
01621
01622
01623
01624 gnssDataMap& gnssDataMap::addGnssSatTypeValue( const gnssSatTypeValue& gds )
01625 {
01626
01627
01628 sourceDataMap sdMap;
01629
01630
01631 sdMap[ gds.header.source ] = gds.body;
01632
01633
01634 (*this).insert( pair<const CommonTime, sourceDataMap>( gds.header.epoch, sdMap ) );
01635
01636
01637 return (*this);
01638
01639 }
01640
01641
01642
01643
01644
01645
01646
01647 gnssDataMap& gnssDataMap::addGnssRinex( const gnssRinex& gds )
01648 {
01649
01650
01651 sourceDataMap sdMap;
01652
01653
01654 sdMap[ gds.header.source ] = gds.body;
01655
01656
01657 (*this).insert( pair<const CommonTime, sourceDataMap>( gds.header.epoch, sdMap ) );
01658
01659
01660 return (*this);
01661
01662 }
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673 gnssRinex gnssDataMap::getGnssRinex( const SourceID& source ) const
01674 {
01675
01676
01677 gnssDataMap gdMap( (*this).frontEpoch() );
01678
01679
01680 gnssRinex toReturn;
01681
01682
01683 bool found(false);
01684
01685
01686 for( gnssDataMap::const_iterator it = gdMap.begin();
01687 it != gdMap.end() && !found;
01688 ++it )
01689 {
01690
01691
01692 sourceDataMap::const_iterator iter( (*it).second.find( source ) );
01693 if( iter != (*it).second.end() )
01694 {
01695 toReturn.body = (*iter).second;
01696 toReturn.header.source = (*iter).first;
01697 toReturn.header.epoch = (*it).first;
01698 toReturn.header.epochFlag = 0;
01699 found = true;
01700 }
01701
01702 }
01703
01704
01705 return toReturn;
01706
01707 }
01708
01709
01710
01711
01712
01713
01714
01715 gnssDataMap& gnssDataMap::addGnssDataMap( const gnssDataMap& gds )
01716 {
01717
01718 for( gnssDataMap::const_iterator it = gds.begin();
01719 it != gds.end();
01720 ++it )
01721 {
01722 const CommonTime& time(it->first);
01723 const sourceDataMap& sourceMap(it->second);
01724
01725 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
01726 itsrc != sourceMap.end();
01727 ++itsrc)
01728 {
01729 gnssSatTypeValue stv;
01730 stv.header.epoch = time;
01731 stv.header.source = itsrc->first;
01732 stv.body = itsrc->second;
01733
01734 addGnssSatTypeValue(stv);
01735
01736 }
01737
01738 }
01739
01740 return (*this);
01741 }
01742
01743
01744
01745 gnssDataMap gnssDataMap::front( void ) const
01746 {
01747
01748
01749 gnssDataMap toReturn;
01750
01751
01752 if( !( (*this).empty() ) )
01753 {
01754
01755
01756 gnssDataMap::const_iterator firstIt( (*this).begin() );
01757
01758
01759 toReturn.insert(*firstIt);
01760
01761 }
01762
01763 return toReturn;
01764
01765 }
01766
01767
01768
01769
01770 void gnssDataMap::pop_front( void )
01771 {
01772
01773
01774 if( !( (*this).empty() ) )
01775 {
01776
01777
01778 gnssDataMap::iterator pos( (*this).begin() );
01779
01780
01781 (*this).erase( pos++ );
01782
01783 }
01784
01785 return;
01786
01787 }
01788
01789
01790
01791
01792
01793 gnssDataMap gnssDataMap::frontEpoch( void ) const
01794 {
01795
01796
01797 gnssDataMap toReturn;
01798
01799
01800 if( !( (*this).empty() ) )
01801 {
01802
01803
01804 CommonTime firstEpoch( (*(*this).begin()).first );
01805
01806
01807
01808 gnssDataMap::const_iterator endPos(
01809 (*this).upper_bound(firstEpoch+tolerance) );
01810
01811
01812 for( gnssDataMap::const_iterator it = (*this).begin();
01813 it != endPos;
01814 ++it )
01815 {
01816 toReturn.insert( (*it) );
01817 }
01818
01819 }
01820
01821 return toReturn;
01822
01823 }
01824
01825
01826
01827
01828
01829
01830 void gnssDataMap::pop_front_epoch( void )
01831 {
01832
01833
01834 if( !( (*this).empty() ) )
01835 {
01836
01837
01838 CommonTime firstEpoch( (*(*this).begin()).first );
01839
01840
01841
01842 gnssDataMap::iterator endPos(
01843 (*this).upper_bound(firstEpoch+tolerance) );
01844
01845
01846 for( gnssDataMap::iterator pos = (*this).begin();
01847 pos != endPos; )
01848 {
01849
01850
01851
01852 (*this).erase( pos++ );
01853 }
01854
01855 }
01856
01857 return;
01858
01859 }
01860
01861
01862
01863
01864 gnssDataMap gnssDataMap::back( void ) const
01865 {
01866
01867
01868 gnssDataMap toReturn;
01869
01870
01871 if( !( (*this).empty() ) )
01872 {
01873
01874
01875 gnssDataMap::const_reverse_iterator lastIt( (*this).rbegin() );
01876
01877
01878 toReturn.insert(*lastIt);
01879
01880 }
01881
01882 return toReturn;
01883
01884 }
01885
01886
01887
01888
01889 void gnssDataMap::pop_back( void )
01890 {
01891
01892
01893 if( !( (*this).empty() ) )
01894 {
01895
01896
01897 gnssDataMap::iterator pos( (*this).end() );
01898
01899
01900 (*this).erase( --pos );
01901
01902 }
01903
01904 return;
01905
01906 }
01907
01908
01909
01910
01911
01912 gnssDataMap gnssDataMap::backEpoch( void ) const
01913 {
01914
01915
01916 gnssDataMap toReturn;
01917
01918
01919 if( !( (*this).empty() ) )
01920 {
01921
01922
01923 CommonTime lastEpoch( (*(--(*this).end())).first );
01924
01925
01926
01927 gnssDataMap::const_iterator beginPos(
01928 (*this).lower_bound(lastEpoch-tolerance) );
01929
01930
01931 for( gnssDataMap::const_iterator it = beginPos;
01932 it != (*this).end();
01933 ++it )
01934 {
01935 toReturn.insert( (*it) );
01936 }
01937
01938 }
01939
01940 return toReturn;
01941
01942 }
01943
01944
01945
01946
01947
01948
01949 void gnssDataMap::pop_back_epoch( void )
01950 {
01951
01952
01953 if( !( (*this).empty() ) )
01954 {
01955
01956
01957 CommonTime lastEpoch( (*(--(*this).end())).first );
01958
01959
01960
01961 gnssDataMap::iterator beginPos(
01962 (*this).lower_bound(lastEpoch-tolerance) );
01963
01964
01965 for( gnssDataMap::iterator pos = beginPos;
01966 pos != (*this).end(); )
01967 {
01968
01969
01970
01971 (*this).erase( pos++ );
01972 }
01973
01974 }
01975
01976 return;
01977
01978 }
01979
01980
01981
01982
01983
01984
01985
01986
01987 gnssDataMap gnssDataMap::getDataFromEpoch( const CommonTime& epoch ) const
01988 throw( CommonTimeNotFound )
01989 {
01990
01991
01992 gnssDataMap toReturn;
01993
01994
01995 if( !( (*this).empty() ) )
01996 {
01997
01998
01999
02000 gnssDataMap::const_iterator beginPos(
02001 (*this).lower_bound(epoch-tolerance) );
02002
02003
02004
02005 gnssDataMap::const_iterator endPos(
02006 (*this).upper_bound(epoch+tolerance) );
02007
02008
02009 for( gnssDataMap::const_iterator it = beginPos;
02010 it != endPos;
02011 ++it )
02012 {
02013 toReturn.insert( (*it) );
02014 }
02015
02016 }
02017 else
02018 {
02019 GPSTK_THROW(CommonTimeNotFound("Data map is empty"));
02020 }
02021
02022
02023 if( toReturn.empty() )
02024 {
02025 GPSTK_THROW(CommonTimeNotFound("Epoch not found"));
02026 }
02027
02028 return toReturn;
02029
02030 }
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045 double gnssDataMap::getValue( const CommonTime& epoch,
02046 const SourceID& source,
02047 const SatID& satellite,
02048 const TypeID& type ) const
02049 throw( CommonTimeNotFound, ValueNotFound )
02050 {
02051
02052
02053 gnssDataMap gdMap( getDataFromEpoch(epoch) );
02054
02055
02056 double toReturn;
02057
02058
02059 bool found(false);
02060
02061
02062 for( gnssDataMap::const_iterator it = gdMap.begin();
02063 it != gdMap.end() && !found;
02064 ++it )
02065 {
02066
02067 try
02068 {
02069 toReturn = (*it).second.getValue( source, satellite, type );
02070 found = true;
02071 }
02072 catch(...)
02073 {
02074 continue;
02075 }
02076
02077 }
02078
02079
02080 if( !found )
02081 {
02082 GPSTK_THROW(ValueNotFound("Value not found"));
02083 }
02084
02085 return toReturn;
02086
02087 }
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101 double gnssDataMap::getValue( const SourceID& source,
02102 const SatID& satellite,
02103 const TypeID& type ) const
02104 throw( ValueNotFound )
02105 {
02106
02107
02108 gnssDataMap gdMap( frontEpoch() );
02109
02110
02111 double toReturn;
02112
02113
02114 bool found(false);
02115
02116
02117 for( gnssDataMap::const_iterator it = gdMap.begin();
02118 it != gdMap.end() && !found;
02119 ++it )
02120 {
02121
02122 try
02123 {
02124 toReturn = (*it).second.getValue( source, satellite, type );
02125 found = true;
02126 }
02127 catch(...)
02128 {
02129 continue;
02130 }
02131
02132 }
02133
02134
02135 if( !found )
02136 {
02137 GPSTK_THROW(ValueNotFound("Value not found"));
02138 }
02139
02140 return toReturn;
02141
02142 }
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155 gnssDataMap& gnssDataMap::insertValue( const CommonTime& epoch,
02156 const SourceID& source,
02157 const SatID& satellite,
02158 const TypeID& type,
02159 double value )
02160 throw( CommonTimeNotFound, ValueNotFound )
02161 {
02162
02163
02164 if( !( (*this).empty() ) )
02165 {
02166
02167
02168
02169 gnssDataMap::iterator beginPos( (*this).lower_bound(epoch-tolerance) );
02170
02171
02172
02173 gnssDataMap::iterator endPos( (*this).upper_bound(epoch+tolerance) );
02174
02175
02176 if( beginPos != endPos )
02177 {
02178
02179
02180 bool found(false);
02181
02182
02183 for( gnssDataMap::iterator it = beginPos;
02184 it != endPos && !found;
02185 ++it )
02186 {
02187
02188
02189 sourceDataMap::iterator it2( (*it).second.find(source) );
02190
02191 if( it2 != (*it).second.end() )
02192 {
02193
02194
02195 satTypeValueMap::iterator it3((*it2).second.find(satellite));
02196
02197 if( it3 != (*it2).second.end() )
02198 {
02199
02200
02201 (*it3).second[ type ] = value;
02202
02203
02204 found = true;
02205
02206 }
02207
02208 }
02209
02210 }
02211
02212
02213 if( !found )
02214 {
02215 GPSTK_THROW( ValueNotFound("No proper place to insert value"));
02216 }
02217
02218 }
02219 else
02220 {
02221
02222 GPSTK_THROW(CommonTimeNotFound("Epoch not found within tolerance"));
02223 }
02224
02225 }
02226 else
02227 {
02228 GPSTK_THROW(CommonTimeNotFound("Data map is empty"));
02229 }
02230
02231 return (*this);
02232
02233 }
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245 gnssDataMap& gnssDataMap::insertValue( const SourceID& source,
02246 const SatID& satellite,
02247 const TypeID& type,
02248 double value )
02249 throw( ValueNotFound )
02250 {
02251
02252
02253 bool found(false);
02254
02255
02256 for( gnssDataMap::iterator it = (*this).begin();
02257 it != (*this).end() && !found;
02258 ++it )
02259 {
02260
02261
02262 sourceDataMap::iterator it2( (*it).second.find(source) );
02263
02264 if( it2 != (*it).second.end() )
02265 {
02266
02267
02268 satTypeValueMap::iterator it3( (*it2).second.find(satellite) );
02269
02270 if( it3 != (*it2).second.end() )
02271 {
02272
02273
02274 (*it3).second[ type ] = value;
02275
02276
02277 found = true;
02278
02279 }
02280
02281 }
02282
02283 }
02284
02285
02286 if( !found )
02287 {
02288 GPSTK_THROW( ValueNotFound("No proper place to insert value"));
02289 }
02290
02291 return (*this);
02292
02293 }
02294
02295
02296
02297
02298
02299
02300
02301
02302 SourceIDSet gnssDataMap::getSourceIDSet( void ) const
02303 {
02304
02305
02306 SourceIDSet toReturn;
02307
02308
02309 for( gnssDataMap::const_iterator it = (*this).begin();
02310 it != (*this).end();
02311 ++it )
02312 {
02313
02314
02315 for( sourceDataMap::const_iterator sdmIter = (*it).second.begin();
02316 sdmIter != (*it).second.end();
02317 ++sdmIter )
02318 {
02319
02320
02321 toReturn.insert( (*sdmIter).first );
02322
02323 }
02324
02325 }
02326
02327 return toReturn;
02328
02329 }
02330
02331
02332
02333
02334
02335
02336
02337
02338 SatIDSet gnssDataMap::getSatIDSet( void ) const
02339 {
02340
02341
02342 SatIDSet toReturn;
02343
02344
02345 for( gnssDataMap::const_iterator it = (*this).begin();
02346 it != (*this).end();
02347 ++it )
02348 {
02349
02350
02351 for( sourceDataMap::const_iterator sdmIter = (*it).second.begin();
02352 sdmIter != (*it).second.end();
02353 ++sdmIter )
02354 {
02355
02356
02357 for( satTypeValueMap::const_iterator stvmIter =
02358 (*sdmIter).second.begin();
02359 stvmIter != (*sdmIter).second.end();
02360 stvmIter++ )
02361 {
02362
02363
02364 toReturn.insert( (*stvmIter).first );
02365
02366 }
02367
02368 }
02369
02370 }
02371
02372 return toReturn;
02373
02374 }
02375
02376
02377
02378
02379 std::ostream& gnssDataMap::dump( std::ostream& s,
02380 int mode ) const
02381 {
02382
02383
02384 for( gnssDataMap::const_iterator it = (*this).begin();
02385 it != (*this).end();
02386 ++it )
02387 {
02388
02389
02390 for( sourceDataMap::const_iterator sdmIter = (*it).second.begin();
02391 sdmIter != (*it).second.end();
02392 ++sdmIter )
02393 {
02394
02395
02396 for( satTypeValueMap::const_iterator stvmIter =
02397 (*sdmIter).second.begin();
02398 stvmIter != (*sdmIter).second.end();
02399 stvmIter++ )
02400 {
02401
02402
02403 YDSTime time( (*it).first );
02404
02405 s << time.year << " "
02406 << time.doy << " "
02407 << time.sod << " ";
02408
02409
02410 s << (*sdmIter).first << " ";
02411
02412
02413 s << (*stvmIter).first << " ";
02414
02415
02416 for( typeValueMap::const_iterator itObs =
02417 (*stvmIter).second.begin();
02418 itObs != (*stvmIter).second.end();
02419 itObs++ )
02420 {
02421
02422 s << (*itObs).first << " "
02423 << (*itObs).second << " ";
02424
02425 }
02426
02427
02428 s << endl;
02429
02430 }
02431
02432 }
02433
02434 }
02435
02436
02437 return s;
02438
02439 }
02440
02441
02442
02443
02444
02445 gnssDataMap gnssDataMap::extractSourceID(const SourceID& source)
02446 {
02447 SourceIDSet sourceSet;
02448 sourceSet.insert(source);
02449
02450 return extractSourceID(sourceSet);
02451
02452 }
02453
02454
02455
02459 gnssDataMap gnssDataMap::extractSourceID(const SourceIDSet& sourceSet)
02460 {
02461 gnssDataMap dataMap;
02462
02463
02464 for( gnssDataMap::const_iterator it = this->begin();
02465 it != this->end();
02466 ++it )
02467 {
02468 const CommonTime& time(it->first);
02469 const sourceDataMap& sourceMap(it->second);
02470
02471 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02472 itsrc != sourceMap.end();
02473 ++itsrc)
02474 {
02475 SourceIDSet::const_iterator itsrc2 = sourceSet.find(itsrc->first);
02476 if(itsrc2!=sourceSet.end())
02477 {
02478 gnssSatTypeValue gds;
02479 gds.header.epoch = time;
02480 gds.header.source = itsrc->first;
02481 gds.body = itsrc->second;
02482
02483 dataMap.addGnssSatTypeValue(gds);
02484 }
02485
02486 }
02487
02488 }
02489
02490 return dataMap;
02491
02492 }
02493
02494
02495
02496
02497 gnssDataMap& gnssDataMap::keepOnlySourceID(const SourceID& source)
02498 {
02499 (*this) = extractSourceID(source);
02500 return (*this);
02501 }
02502
02503
02504
02505
02506
02507 gnssDataMap& gnssDataMap::keepOnlySourceID(const SourceIDSet& sourceSet)
02508 {
02509 (*this) = extractSourceID(sourceSet);
02510 return (*this);
02511 }
02512
02513
02514
02515
02516 gnssDataMap& gnssDataMap::removeSourceID(const SourceID& source)
02517 {
02518 SourceIDSet sourceSet;
02519 sourceSet.insert(source);
02520
02521 return removeSourceID(sourceSet);
02522 }
02523
02524
02525
02526
02527
02528 gnssDataMap& gnssDataMap::removeSourceID(const SourceIDSet& sourceSet)
02529 {
02530 gnssDataMap dataMap;
02531
02532
02533 for( gnssDataMap::const_iterator it = this->begin();
02534 it != this->end();
02535 ++it )
02536 {
02537 const CommonTime& time(it->first);
02538 const sourceDataMap& sourceMap(it->second);
02539
02540 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02541 itsrc != sourceMap.end();
02542 ++itsrc)
02543 {
02544 SourceIDSet::const_iterator itsrc2 = sourceSet.find(itsrc->first);
02545 if(itsrc2==sourceSet.end())
02546 {
02547 gnssSatTypeValue gds;
02548 gds.header.epoch = time;
02549 gds.header.source = itsrc->first;
02550 gds.body = itsrc->second;
02551
02552 dataMap.addGnssSatTypeValue(gds);
02553 }
02554
02555 }
02556
02557 }
02558
02559 (*this) = dataMap;
02560
02561 return (*this);
02562
02563 }
02564
02565
02566
02567
02568 gnssDataMap gnssDataMap::extractSatID(const SatID& sat)
02569 {
02570 SatIDSet satSet;
02571 satSet.insert(sat);
02572
02573 return extractSatID(satSet);
02574 }
02575
02576
02577
02578
02579
02580 gnssDataMap gnssDataMap::extractSatID(const SatIDSet& satSet)
02581 {
02582 gnssDataMap dataMap;
02583
02584
02585 for( gnssDataMap::const_iterator it = this->begin();
02586 it != this->end();
02587 ++it )
02588 {
02589 const CommonTime& time(it->first);
02590 const sourceDataMap& sourceMap(it->second);
02591
02592 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02593 itsrc != sourceMap.end();
02594 ++itsrc)
02595 {
02596 gnssSatTypeValue gds;
02597 gds.header.epoch = time;
02598 gds.header.source = itsrc->first;
02599 gds.body = itsrc->second;
02600
02601 gds.body.keepOnlySatID(satSet);
02602
02603 dataMap.addGnssSatTypeValue(gds);
02604
02605 }
02606
02607 }
02608
02609 return dataMap;
02610
02611 }
02612
02613
02614
02615
02616 gnssDataMap& gnssDataMap::keepOnlySatID(const SatID& sat)
02617 {
02618 (*this) = extractSatID(sat);
02619 return (*this);
02620 }
02621
02622
02623
02624
02625
02626 gnssDataMap& gnssDataMap::keepOnlySatID(const SatIDSet& satSet)
02627 {
02628 (*this) = extractSatID(satSet);
02629 return (*this);
02630 }
02631
02632
02633
02634 gnssDataMap& gnssDataMap::removeSatID(const SatID& sat)
02635 {
02636 SatIDSet satSet;
02637 satSet.insert(sat);
02638
02639 return removeSatID(satSet);
02640 }
02641
02642
02643
02644
02645
02646 gnssDataMap& gnssDataMap::removeSatID(const SatIDSet& satSet)
02647 {
02648 gnssDataMap dataMap;
02649
02650
02651 for( gnssDataMap::const_iterator it = this->begin();
02652 it != this->end();
02653 ++it )
02654 {
02655 const CommonTime& time(it->first);
02656 const sourceDataMap& sourceMap(it->second);
02657
02658 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02659 itsrc != sourceMap.end();
02660 ++itsrc)
02661 {
02662 gnssSatTypeValue gds;
02663 gds.header.epoch = time;
02664 gds.header.source = itsrc->first;
02665 gds.body = itsrc->second;
02666
02667 gds.body.removeSatID(satSet);
02668
02669 dataMap.addGnssSatTypeValue(gds);
02670
02671 }
02672
02673 }
02674
02675 (*this) = dataMap;
02676
02677 return (*this);
02678
02679 }
02680
02681
02682
02685 gnssDataMap gnssDataMap::extractTypeID(const TypeID& type)
02686 {
02687 TypeIDSet typeSet;
02688 typeSet.insert(type);
02689
02690 return extractTypeID(typeSet);
02691 }
02692
02693
02694
02695
02696
02697 gnssDataMap gnssDataMap::extractTypeID(const TypeIDSet& typeSet)
02698 {
02699 gnssDataMap dataMap;
02700
02701
02702 for( gnssDataMap::const_iterator it = this->begin();
02703 it != this->end();
02704 ++it )
02705 {
02706 const CommonTime& time(it->first);
02707 const sourceDataMap& sourceMap(it->second);
02708
02709 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02710 itsrc != sourceMap.end();
02711 ++itsrc)
02712 {
02713 gnssSatTypeValue gds;
02714 gds.header.epoch = time;
02715 gds.header.source = itsrc->first;
02716 gds.body = itsrc->second;
02717
02718 gds.body.keepOnlyTypeID(typeSet);
02719
02720 dataMap.addGnssSatTypeValue(gds);
02721
02722 }
02723
02724 }
02725
02726 return dataMap;
02727 }
02728
02729
02730
02731
02732 gnssDataMap& gnssDataMap::keepOnlyTypeID(const TypeID& type)
02733 {
02734 (*this) = extractTypeID(type);
02735 return (*this);
02736 }
02737
02738
02739
02740
02741
02742 gnssDataMap& gnssDataMap::keepOnlyTypeID(const TypeIDSet& typeSet)
02743 {
02744 (*this) = extractTypeID(typeSet);
02745 return (*this);
02746 }
02747
02748
02749
02750
02751 gnssDataMap& gnssDataMap::removeTypeID(const TypeID& type)
02752 {
02753 TypeIDSet typeSet;
02754 typeSet.insert(type);
02755
02756 return removeTypeID(typeSet);
02757 }
02758
02759
02760
02761
02762
02763 gnssDataMap& gnssDataMap::removeTypeID(const TypeIDSet& typeSet)
02764 {
02765 gnssDataMap dataMap;
02766
02767
02768 for( gnssDataMap::const_iterator it = this->begin();
02769 it != this->end();
02770 ++it )
02771 {
02772 const CommonTime& time(it->first);
02773 const sourceDataMap& sourceMap(it->second);
02774
02775 for(sourceDataMap::const_iterator itsrc = sourceMap.begin();
02776 itsrc != sourceMap.end();
02777 ++itsrc)
02778 {
02779 gnssSatTypeValue gds;
02780 gds.header.epoch = time;
02781 gds.header.source = itsrc->first;
02782 gds.body = itsrc->second;
02783
02784 gds.body.removeTypeID(typeSet);
02785
02786 dataMap.addGnssSatTypeValue(gds);
02787
02788 }
02789
02790 }
02791
02792 (*this) = dataMap;
02793
02794 return (*this);
02795
02796 }
02797
02798
02799
02800
02801
02802
02803
02804
02805 gnssDataMap& gnssDataMap::edit(CommonTime tmin, CommonTime tmax )
02806 {
02807 gnssDataMap dataMap;
02808
02809 while(!this->empty())
02810 {
02811 gnssDataMap gds = this->frontEpoch();
02812
02813 CommonTime time(gds.begin()->first);
02814 if( (time>=tmin) && (time<=tmax) ) dataMap.addGnssDataMap(gds);
02815
02816 this->pop_front_epoch();
02817 }
02818
02819 (*this) = dataMap;
02820
02821 return (*this);
02822 }
02823
02824
02825 void gnssDataMap::loadObsFile(std::string obsFile)
02826 {
02827 try
02828 {
02829 RinexObsStream rin(obsFile);
02830 rin.exceptions(ios::failbit);
02831
02832 gnssRinex gRin;
02833 while( rin >> gRin )
02834 {
02835 this->addGnssRinex(gRin);
02836 }
02837
02838 rin.close();
02839 }
02840 catch(...)
02841 {
02842 Exception e("Failed to load obs file '"+obsFile+"'.");
02843 GPSTK_THROW(e);
02844 }
02845
02846 }
02847
02848
02850
02851
02852
02853
02854 std::ostream& satTypeValueMap::dump( std::ostream& s,
02855 int mode ) const
02856 {
02857
02858 for( satTypeValueMap::const_iterator it = (*this).begin();
02859 it!= (*this).end();
02860 it++ )
02861 {
02862
02863
02864 s << (*it).first << " ";
02865
02866 for( typeValueMap::const_iterator itObs = (*it).second.begin();
02867 itObs != (*it).second.end();
02868 itObs++ )
02869 {
02870
02871 if (mode==1)
02872 {
02873 s << (*itObs).first << " ";
02874 }
02875
02876 s << (*itObs).second << " ";
02877
02878 }
02879
02880 s << endl;
02881
02882 }
02883
02884
02885 return s;
02886
02887 }
02888
02889
02890
02891
02892 std::ostream& operator<<( std::ostream& s,
02893 const satTypeValueMap& stvMap )
02894 {
02895
02896 stvMap.dump(s);
02897 return s;
02898
02899 }
02900
02901
02902
02903
02904 std::ostream& operator<<( std::ostream& s,
02905 const gnssDataMap& gdsMap)
02906 {
02907
02908 gdsMap.dump(s);
02909 return s;
02910
02911 }
02912
02913
02914
02915 std::istream& operator>>( std::istream& i, gnssRinex& f )
02916 {
02917
02918 if( RinexObsStream::IsRinexObsStream(i) )
02919 {
02920 try
02921 {
02922 RinexObsStream& strm = dynamic_cast<RinexObsStream&>(i);
02923
02924
02925 if(!strm.headerRead) strm >> strm.header;
02926
02927
02928 RinexObsHeader& roh = strm.header;
02929
02930 RinexObsData rod;
02931 strm >> rod;
02932
02933
02934 f.header.source.type = SatIDsystem2SourceIDtype(roh.system);
02935 f.header.source.sourceName = roh.markerName;
02936 f.header.antennaType = roh.antType;
02937 f.header.antennaPosition = roh.antennaPosition;
02938 f.header.epochFlag = rod.epochFlag;
02939 f.header.epoch = rod.time;
02940
02941 f.body = satTypeValueMapFromRinexObsData(roh, rod);
02942
02943 return i;
02944 }
02945 catch (...)
02946 {
02947 return i;
02948 }
02949 }
02950 if( Rinex3ObsStream::IsRinex3ObsStream(i) )
02951 {
02952 Rinex3ObsStream& strm = dynamic_cast<Rinex3ObsStream&>(i);
02953
02954
02955 if(!strm.headerRead) strm >> strm.header;
02956
02957
02958 Rinex3ObsHeader& roh = strm.header;
02959
02960 Rinex3ObsData rod;
02961 strm >> rod;
02962
02963
02964 f.header.source.type = SatIDsystem2SourceIDtype(roh.fileSysSat);
02965 f.header.source.sourceName = roh.markerName;
02966 f.header.antennaType = roh.antType;
02967 f.header.antennaPosition = roh.antennaPosition;
02968 f.header.epochFlag = rod.epochFlag;
02969 f.header.epoch = rod.time;
02970
02971 f.body = satTypeValueMapFromRinex3ObsData(roh, rod);
02972
02973 return i;
02974 }
02975
02976 return i;
02977
02978 }
02979
02980
02981
02982 std::ostream& operator<<( std::ostream& s,
02983 gnssRinex& f )
02984 throw(FFStreamError, gpstk::StringUtils::StringException)
02985 {
02986 FFStream* ffs = dynamic_cast<FFStream*>(&s);
02987 if(ffs)
02988 {
02989 try
02990 {
02991 RinexObsStream& strm = dynamic_cast<RinexObsStream&>(*ffs);
02992
02993
02994 RinexObsHeader& hdr = strm.header;
02995
02996 RinexObsData rod;
02997
02998 rod.time = f.header.epoch;
02999 rod.epochFlag = f.header.epochFlag;
03000 rod.numSvs = f.numSats();
03001 rod.clockOffset = 0.0;
03002 rod.auxHeader = hdr;
03003
03004 SatIDSet satSet = f.getSatID();
03005 for(SatIDSet::iterator itSat = satSet.begin();
03006 itSat != satSet.end();
03007 ++itSat)
03008 {
03009 vector<RinexObsHeader::RinexObsType>::iterator obsTypeItr =
03010 hdr.obsTypeList.begin();
03011
03012 while (obsTypeItr != strm.header.obsTypeList.end())
03013 {
03014 TypeID type = ConvertToTypeID( *obsTypeItr,
03015 RinexSatID(itSat->id,itSat->system));
03016
03017 RinexObsData::RinexDatum data;
03018 data.data = f.body[*itSat][type];
03019 data.ssi = 0;
03020 data.lli = 0;
03021
03022 if( (type == TypeID::P1) || (type == TypeID::L1) )
03023 {
03024 if(type == TypeID::L1)
03025 {
03026 data.data /= L1_WAVELENGTH_GAL;
03027 data.ssi = f.body[*itSat][TypeID::SSI1];
03028 }
03029
03030 data.lli = f.body[*itSat][TypeID::LLI1];
03031 }
03032
03033 if( (type == TypeID::P2) || (type == TypeID::L2))
03034 {
03035 if(type == TypeID::L2)
03036 {
03037 data.data /= L2_WAVELENGTH_GPS;
03038 data.ssi = f.body[*itSat][TypeID::SSI2];
03039 }
03040
03041 data.lli = f.body[*itSat][TypeID::LLI2];
03042 }
03043
03044 if( (type == TypeID::C5) || (type == TypeID::L5))
03045 {
03046 if(type == TypeID::L5)
03047 {
03048 data.data /= L5_WAVELENGTH_GAL;
03049 data.ssi = f.body[*itSat][TypeID::SSI5];
03050 }
03051
03052 data.lli = f.body[*itSat][TypeID::LLI5];
03053 }
03054
03055 if( (type == TypeID::C6) || (type == TypeID::L6) )
03056 {
03057 if(type == TypeID::L6)
03058 {
03059 data.data /= L6_WAVELENGTH_GAL;
03060 data.ssi = f.body[*itSat][TypeID::SSI6];
03061 }
03062
03063 data.lli = f.body[*itSat][TypeID::LLI6];
03064 }
03065
03066 if( (type == TypeID::C7) || (type == TypeID::L7) )
03067 {
03068 if(type == TypeID::L7)
03069 {
03070 data.data /= L7_WAVELENGTH_GAL;
03071 data.ssi = f.body[*itSat][TypeID::SSI7];
03072 }
03073
03074 data.lli = f.body[*itSat][TypeID::LLI7];
03075 }
03076
03077 if( (type == TypeID::C8) || (type == TypeID::L8))
03078 {
03079 if(type == TypeID::L8)
03080 {
03081 data.data /= L8_WAVELENGTH_GAL;
03082 data.ssi = f.body[*itSat][TypeID::SSI8];
03083 }
03084
03085 data.lli = f.body[*itSat][TypeID::LLI8];
03086 }
03087
03088 if( (type == TypeID::D1) ||
03089 (type == TypeID::S1) ||
03090 (type == TypeID::C1) )
03091 {
03092 data.lli = f.body[*itSat][TypeID::LLI1];
03093 }
03094
03095 if( (type == TypeID::D2) || (type == TypeID::S2) )
03096 {
03097 data.lli = f.body[*itSat][TypeID::LLI2];
03098 }
03099
03100
03101 rod.obs[*itSat][*obsTypeItr] = data;
03102
03103 obsTypeItr++;
03104 }
03105 }
03106
03107 strm << rod;
03108
03109 return s;
03110
03111 }
03118
03119
03120 catch (EndOfFile& e)
03121 {
03122 return s;
03123 }
03124 catch (...)
03125 {
03126 return s;
03127 }
03128
03129 }
03130 else
03131 {
03132 FFStreamError e("operator<< stream argument must be an FFStream");
03133 GPSTK_THROW(e);
03134 }
03135
03136 }
03137
03138
03139
03140
03141 SourceID::SourceType SatIDsystem2SourceIDtype(const SatID& sid)
03142 {
03143
03144
03145 switch(sid.system)
03146 {
03147 case SatID::systemGPS:
03148 return SourceID::GPS;
03149 break;
03150 case SatID::systemGalileo:
03151 return SourceID::Galileo;
03152 break;
03153 case SatID::systemGlonass:
03154 return SourceID::Glonass;
03155 break;
03156 case SatID::systemGeosync:
03157 return SourceID::Geosync;
03158 break;
03159 case SatID::systemLEO:
03160 return SourceID::LEO;
03161 break;
03162 case SatID::systemTransit:
03163 return SourceID::Transit;
03164 break;
03165 case SatID::systemMixed:
03166 return SourceID::Mixed;
03167 break;
03168 default:
03169 return SourceID::Unknown;
03170 }
03171
03172 }
03173
03174
03175
03176
03177
03179
03180 satTypeValueMap satTypeValueMapFromRinexObsData(
03181 const RinexObsHeader& roh, const RinexObsData& rod)
03182 {
03183
03184
03185 satTypeValueMap theMap;
03186
03187
03188
03189
03190 for( RinexObsData::RinexSatMap::const_iterator it = rod.obs.begin();
03191 it!= rod.obs.end();
03192 ++it )
03193 {
03194
03195
03196
03197
03198 RinexObsData::RinexObsTypeMap otmap = (*it).second;
03199 SatID sat = (*it).first;
03200
03201 typeValueMap tvMap;
03202
03203
03204 for( RinexObsData::RinexObsTypeMap::const_iterator itObs = otmap.begin();
03205 itObs!= otmap.end();
03206 ++itObs )
03207 {
03208
03209 RinexSatID rsat(sat.id,sat.system);
03210
03211 TypeID type = ConvertToTypeID( itObs->first, rsat);
03212
03213 const bool isPhase = IsCarrierPhase(itObs->first);
03214 const int n = GetCarrierBand(itObs->first);
03215
03216 if(isPhase)
03217 {
03218
03219 tvMap[ type ] = (*itObs).second.data*getWavelength(rsat,n);
03220
03221
03222 if(n==1)
03223 {
03224 tvMap[TypeID::LLI1] = (*itObs).second.lli;
03225 tvMap[TypeID::SSI1] = (*itObs).second.ssi;
03226 }
03227 else if(n==2)
03228 {
03229 tvMap[TypeID::LLI2] = (*itObs).second.lli;
03230 tvMap[TypeID::SSI2] = (*itObs).second.ssi;
03231 }
03232 else if(n==5)
03233 {
03234 tvMap[TypeID::LLI5] = (*itObs).second.lli;
03235 tvMap[TypeID::SSI5] = (*itObs).second.ssi;
03236 }
03237 else if(n==6)
03238 {
03239 tvMap[TypeID::LLI6] = (*itObs).second.lli;
03240 tvMap[TypeID::SSI6] = (*itObs).second.ssi;
03241 }
03242 else if(n==7)
03243 {
03244 tvMap[TypeID::LLI7] = (*itObs).second.lli;
03245 tvMap[TypeID::SSI7] = (*itObs).second.ssi;
03246 }
03247 else if(n==8)
03248 {
03249 tvMap[TypeID::LLI8] = (*itObs).second.lli;
03250 tvMap[TypeID::SSI8] = (*itObs).second.ssi;
03251 }
03252 }
03253 else
03254 {
03255 tvMap[ type ] = (*itObs).second.data;
03256 }
03257
03258 }
03259
03260 theMap[sat] = tvMap;
03261 }
03262
03263 return theMap;
03264
03265 }
03266
03267
03268
03269
03270
03271
03272 satTypeValueMap satTypeValueMapFromRinex3ObsData(
03273 const Rinex3ObsHeader& roh, const Rinex3ObsData& rod )
03274 {
03275
03276 satTypeValueMap theMap;
03277
03278 Rinex3ObsData::DataMap::const_iterator it;
03279 for(it=rod.obs.begin(); it != rod.obs.end(); it++)
03280 {
03281 RinexSatID sat(it->first);
03282
03283 typeValueMap tvMap;
03284
03285 map<std::string,std::vector<RinexObsID> > mapObsTypes(roh.mapObsTypes);
03286 const vector<RinexObsID> types = mapObsTypes[sat.toString().substr(0,1)];
03287 for(int i=0; i<types.size(); i++)
03288 {
03289 TypeID type = ConvertToTypeID(types[i],sat);
03290
03291 const int n = GetCarrierBand(types[i]);
03292
03293 if(types[i].type==ObsID::otPhase)
03294 {
03295
03296 tvMap[type] = it->second[i].data*getWavelength(sat,n);
03297
03298
03299 if(n==1)
03300 {
03301 tvMap[TypeID::LLI1] = it->second[i].lli;
03302 tvMap[TypeID::SSI1] = it->second[i].ssi;
03303 }
03304 else if(n==2)
03305 {
03306 tvMap[TypeID::LLI2] = it->second[i].lli;
03307 tvMap[TypeID::SSI2] = it->second[i].ssi;
03308 }
03309 else if(n==5)
03310 {
03311 tvMap[TypeID::LLI5] = it->second[i].lli;
03312 tvMap[TypeID::SSI5] = it->second[i].ssi;
03313 }
03314 else if(n==6)
03315 {
03316 tvMap[TypeID::LLI6] = it->second[i].lli;
03317 tvMap[TypeID::SSI6] = it->second[i].ssi;
03318 }
03319 else if(n==7)
03320 {
03321 tvMap[TypeID::LLI7] = it->second[i].lli;
03322 tvMap[TypeID::SSI7] = it->second[i].ssi;
03323 }
03324 else if(n==8)
03325 {
03326 tvMap[TypeID::LLI8] = it->second[i].lli;
03327 tvMap[TypeID::SSI8] = it->second[i].ssi;
03328 }
03329 }
03330 else
03331 {
03332 tvMap[ type ] = it->second[i].data;
03333 }
03334 }
03335
03336 theMap[sat] = tvMap;
03337 }
03338
03339 return theMap;
03340 }
03341
03342 }