MinSfTest.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: MinSfTest.cpp 1895 2009-05-12 19:34:29Z afarris $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2009, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 // gpstk
00026 #include "FileFilterFrame.hpp"
00027 #include "BasicFramework.hpp"
00028 #include "StringUtils.hpp"
00029 #include "FICStream.hpp"
00030 #include "FICHeader.hpp"
00031 #include "FICData.hpp"
00032 #include "FICFilterOperators.hpp"
00033 #include "BCEphemerisStore.hpp"
00034 #include "EngEphemeris.hpp"
00035 
00036 using namespace std;
00037 using namespace gpstk;
00038 
00039 class MinSfTest : public gpstk::BasicFramework
00040 {
00041 public:
00042    MinSfTest(const std::string& applName,
00043               const std::string& applDesc) throw();
00044    ~MinSfTest() {}
00045    virtual bool initialize(int argc, char *argv[]) throw();
00046 protected:
00047    virtual void process();
00048    gpstk::CommandOptionWithAnyArg inputOption;
00049    gpstk::CommandOptionWithAnyArg outputOption;
00050    std::list<long> blocklist;
00051    
00052    BCEphemerisStore bc109;
00053    BCEphemerisStore minRaw;
00054    std::ofstream fp;
00055    
00056    void testXvt( short PRN, gpstk::DayTime dt );
00057 };
00058 
00059 int main( int argc, char*argv[] )
00060 {
00061    try
00062    {
00063       MinSfTest fc("MinSfTest", "Process one (or more) FIC files.");
00064       if (!fc.initialize(argc, argv)) return(false);
00065       fc.run();
00066    }
00067    catch(gpstk::Exception& exc)
00068    {
00069       cout << exc << endl;
00070       return 1;
00071    }
00072    catch(...)
00073    {
00074       cout << "Caught an unnamed exception. Exiting.";
00075       return 1;
00076    }
00077    return 0;
00078 }
00079 
00080 MinSfTest::MinSfTest(const std::string& applName, 
00081                        const std::string& applDesc) throw()
00082           :BasicFramework(applName, applDesc),
00083            inputOption('i', "input-file", "The name of the FIC file to raead.", true),
00084            outputOption('o', "output-file", "The name of the output file to write.", true)
00085 {
00086    inputOption.setMaxCount(1);
00087    outputOption.setMaxCount(1);
00088 }
00089 
00090 bool MinSfTest::initialize(int argc, char *argv[])
00091    throw()
00092 {
00093    if (!BasicFramework::initialize(argc, argv)) return false;
00094    if (debugLevel)
00095    {
00096       cout << "Input File:  " << inputOption.getValue().front() << endl;
00097       cout << "Output File: " << outputOption.getValue().front() << endl;
00098    }
00099    return true;   
00100 }
00101 
00102 void MinSfTest::process()
00103 {
00104    if (debugLevel)
00105       cout << "Setting up input file: " 
00106            <<  inputOption.getValue().front() << endl;
00107    FileFilterFrame<FICStream, FICData>
00108       input(inputOption.getValue().front());
00109    
00110    printf(" input.getDataCount() after init: %d\n", input.getDataCount());
00111    if(debugLevel)
00112       cout << "Setting up output file: "
00113            << outputOption.getValue().front() << endl;
00114            
00115    fp.open( outputOption.getValue().front().c_str() );
00116    if ( !fp.is_open() )
00117    {
00118       printf(" Failed to open output file.\n");
00119       exit(1);
00120    }
00121            
00122       // filter the FIC data for the requested vlock(s)
00123    std::list<long> blockList;
00124    blockList.push_back(109);
00125    input.filter(FICDataFilterBlock(blockList));
00126    input.sort(FICDataOperatorLessThanBlock109());
00127    input.unique(FICDataUniqueBlock109());
00128    
00129       //some hand waving for the data conversion
00130    if(debugLevel)
00131       cout << "Reading the input data." << endl;
00132    list<FICData>& ficList = input.getData();
00133    list<FICData>::iterator itr = ficList.begin();
00134    
00135    DayTime earliest( DayTime::END_OF_TIME );
00136    DayTime latest( DayTime::BEGINNING_OF_TIME );
00137    int count = 0;
00138    int numMismatches = 0;
00139    int numMismatchEph = 0; 
00140    while (itr != ficList.end())
00141    {
00142       EngEphemeris ee(*itr);
00143 
00144       bc109.addEphemeris( ee );
00145 
00146       DayTime ct = ee.getEpochTime();
00147       if (ct>latest) latest = ct;
00148       if (ct<earliest) earliest = ct;
00149       
00150          // Following code simulates a situation where only words 3-10
00151          // and the estimated time of receipt are available.
00152       DayTime timeOfReceipt = ee.getTransmitTime();
00153       FICData& fic = *itr;
00154       long sf1min[8];
00155       long sf2min[8];
00156       long sf3min[8];
00157       int wrdCnt = 8;
00158       int i;
00159       for (i=0; i<wrdCnt; ++i) sf1min[i] = fic.i[4+i];   
00160       for (i=0; i<wrdCnt; ++i) sf2min[i] = fic.i[14+i];   
00161       for (i=0; i<wrdCnt; ++i) sf3min[i] = fic.i[24+i];  
00162 
00163       EngEphemeris eeMin;
00164       short PRNID = (short) fic.i[1];
00165       eeMin.addIncompleteSF1Thru3( sf1min, sf2min, sf3min,
00166              (long) timeOfReceipt.GPSsecond(), timeOfReceipt.GPSfullweek(),
00167              PRNID, 0 );
00168       minRaw.addEphemeris( eeMin );
00169       
00170          // Compare non-orbit portions of the two objects
00171       bool mismatch = false;
00172       for (int i=1; i<=3; ++i)
00173       {
00174          if (!ee.isData(i) || !eeMin.isData(i))
00175          {
00176             mismatch = true;
00177             fp << "ERROR: not all subframes are claimed available.";
00178          }
00179       }
00180       
00181       if (ee.getIODC()!=eeMin.getIODC()) 
00182       {
00183          mismatch = true;
00184          fp << "ERROR: IODCs do not match."; 
00185       }
00186       if (ee.getIODE()!=eeMin.getIODE()) 
00187       {
00188          mismatch = true;
00189          fp << "ERROR: IODCs do not match."; 
00190       }
00191       if (ee.getFitInterval() != eeMin.getFitInterval() )
00192       {
00193          mismatch = true;
00194          fp << "ERROR: fit intervals do not match.";
00195       }
00196       if (ee.getCodeFlags()!=eeMin.getCodeFlags() )
00197       {
00198          mismatch = true;
00199          fp << "ERROR: code flags do not match.";
00200       }
00201       if (ee.getL2Pdata()!=eeMin.getL2Pdata() )
00202       {
00203          mismatch = true;
00204          fp << "ERROR: L2P data flags do not match.";
00205       }
00206       if (ee.getAccuracy()!=eeMin.getAccuracy() )
00207       {
00208          mismatch = true;
00209          fp << "ERROR: accuracy values do not match.";
00210       }
00211       if (ee.getAccFlag()!=eeMin.getAccFlag() )
00212       {
00213          mismatch = true;
00214          fp << "ERROR: accuracy flags do not match.";
00215       }
00216       if (ee.getHealth()!=eeMin.getHealth() )
00217       {
00218          mismatch = true;
00219          fp << "ERROR: health values do not match.";
00220       }
00221       if (ee.getFitInt()!=eeMin.getFitInt() )
00222       {
00223          mismatch = true;
00224          fp << "ERROR: Fit interval values do not match.";
00225       }
00226 
00227       if (mismatch)
00228       {
00229          fp << " PRNID: " << PRNID << ", IODC: 0x " << hex << ee.getIODC() << dec << endl;
00230          numMismatches++;
00231       }
00232       
00233       itr++;
00234       count++;
00235    }
00236    cout << "Number of Block 109 records read: " << count << endl;
00237    if (numMismatches!=0)
00238    {
00239       printf("Errors detected.  Some ephemerides did not match in both forms.\n");
00240       printf("Number of mismatches: %d\n",numMismatches);
00241    }
00242    fp << "Number of mismatches detected: " << numMismatches << endl;
00243    if (debugLevel) cout << "done." << endl;
00244    
00245 
00246       // Generate test positions for PRN 1 and PRN 31 at
00247       // earliest epoch, latest epoch, and middle of the time span.
00248    try
00249    {
00250       double timeDuration = latest - earliest;
00251       DayTime middle( earliest );
00252       middle += (timeDuration/2);
00253 
00254       short IODC109 = -1;
00255       short IODCMin = -1;
00256       short PRNID = 1;
00257       printf("--- PRN 1 Examples ---\n");
00258       printf("\nEarliest time\n");
00259       fp << "--- PRN 1 Examples ---" << endl;
00260       fp << endl << "Earliest time" << endl;
00261       testXvt( PRNID, earliest );
00262       printf("\nMiddle time\n");
00263       fp << endl << "Middle time" << endl;
00264       testXvt( PRNID, middle );
00265       printf("\nLatest time\n");
00266       fp << endl << "Latest time" << endl;
00267       testXvt( PRNID, latest );
00268 
00269       PRNID = 31;      
00270       printf("\n--- PRN 31 Examples ---\n");
00271       printf("\nEarliest time\n");
00272       fp << endl << "--- PRN 31 Examples ---" << endl;
00273       fp << endl << "Earliest time" << endl;
00274       testXvt( PRNID, earliest );
00275       printf("\nMiddle time\n");
00276       fp << endl << "Middle time" << endl;
00277       testXvt( PRNID, middle );
00278       printf("\nLatest time\n");
00279       fp << endl << "Latest time" << endl;
00280       testXvt( PRNID, latest );
00281    }
00282    catch (gpstk::Exception& e)
00283    {
00284       cout << e << endl;
00285    }
00286    
00287    printf("\nBCEphemerisStore directly from existing FIC handlers.\n");
00288    fp << endl << "BCEphemerisStore directly from existing FIC handlers." << endl;
00289    bc109.dump(1, fp);
00290    printf("BCEphemerisStore from new method.\n");
00291    fp << endl << "BCEphemerisStore from new method." << endl;
00292    minRaw.dump(1, fp);
00293    
00294       // write the file data
00295    if (debugLevel) cout << "Conversion complete." << endl;
00296 }
00297 
00298 void MinSfTest::testXvt( short PRN, gpstk::DayTime dt )
00299 {
00300       short IODC109;
00301       short IODCMin;
00302       Xvt xvt109 = bc109.getPrnXvt( PRN, dt, IODC109 );
00303       Xvt xvtMin = minRaw.getPrnXvt( PRN, dt, IODCMin );
00304       printf("               X(m)             Y(m)            Z(m)      IODC\n");
00305       printf("  109  %15.3lf  %15.3lf %15.3lf  0x%03X\n",
00306          xvt109.x[0],xvt109.x[1],xvt109.x[2],IODC109);
00307       printf("  Min  %15.3lf  %15.3lf %15.3lf  0x%03X\n",
00308          xvtMin.x[0],xvtMin.x[1],xvtMin.x[2],IODCMin);
00309          
00310       
00311       fp << "               X(m)           Y(m)           Z(m)       IODC" << endl;
00312       fp << "  109  ";
00313       fp << setprecision(3) << fixed;
00314       fp << setw(15) << xvt109.x[0];
00315       fp << setw(15) << xvt109.x[1];
00316       fp << setw(15) << xvt109.x[2];
00317       fp << "   0x" << setw(3) << setfill('0') << uppercase << hex << IODC109;
00318       fp << setfill(' ') << endl;
00319       fp << "  Min  ";
00320       fp << setprecision(3) << fixed;
00321       fp << setw(15) << xvtMin.x[0];
00322       fp << setw(15) << xvtMin.x[1];
00323       fp << setw(15) << xvtMin.x[2];
00324       fp << "   0x" << setw(3) << setfill('0') << uppercase << hex << IODCMin << dec;
00325       fp << setfill(' ') << endl;
00326 }
00327 
00328 
00329 

Generated on Wed Feb 8 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1