testExpression.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: testExpression.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 #include <iostream>
00026 #include <iomanip>
00027 
00028 #include "RinexObsStream.hpp"
00029 #include "Expression.hpp"
00030 
00031 using namespace std;
00032 using namespace gpstk;
00033 
00034 int main(int argc, char* argv[])
00035 {
00036    short test=1;
00037    
00038    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00039    {  
00040       string istr(" 1   + (6 - 2 ) * 3.2");
00041       Expression xpr(istr);
00042       cout << "Input string: \"" << istr << "\"" << endl;
00043       xpr.print(cout);
00044       cout << "=" << xpr.evaluate() << endl;
00045    }
00046 
00047    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00048       try {  
00049          string istr(" 1   + (6 - gamma ) * 3.2");
00050          Expression xpr(istr);
00051          cout << "Input string: \"" << istr << "\"" << endl;
00052          xpr.print(cout);
00053          cout << "=" << xpr.evaluate() << endl;
00054       }
00055       catch (gpstk::Expression::ExpressionException ee)
00056       {
00057          cout << endl << "The expected exception was generated: " << endl;
00058          cout << ee << endl;
00059       }
00060    
00061    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00062    {
00063       string istr(" 1 + 2*(3 + 1)"); 
00064       Expression xpr(istr);
00065       cout << "Input string: \"" << istr << "\"" << endl;
00066       xpr.print(cout);
00067       cout << "=" << xpr.evaluate() << endl;
00068    }
00069 
00070    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00071    {
00072       try {
00073          string istr(" 1 + 2*( beta + 1)"); 
00074          Expression xpr(istr);
00075          cout << "Input string: \"" << istr << "\"" << endl;
00076          xpr.print(cout);
00077          xpr.set("beta",1);
00078          cout << "=" << xpr.evaluate() << endl;
00079       }
00080       catch (...)
00081       {
00082          cout << "An unexpected exception was generated: ";
00083       }
00084    }
00085 
00086    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00087    {
00088       string istr(" 1 + 2*cos(3.141592647)"); 
00089       Expression xpr(istr);
00090       cout << "Input string: \"" << istr << "\"" << endl;
00091       xpr.print(cout);
00092       cout << "=" << xpr.evaluate() << endl;
00093    }
00094 
00095    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00096    {
00097       string istr(" 1E+1 + 4* 2E-2"); 
00098       Expression xpr(istr);
00099       cout << "Input string: \"" << istr << "\"" << endl;
00100       xpr.print(cout);
00101       cout << "=" << xpr.evaluate() << endl;
00102    }
00103 
00104    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00105    {
00106       string istr("C/L1"); 
00107       Expression xpr(istr);
00108       xpr.setGPSConstants();
00109       cout << "Input string: \"" << istr << "\"" << endl;
00110       xpr.print(cout);
00111       cout << "=" << xpr.evaluate() << endl;
00112    }
00113 
00114    cout << endl << "Unit Test #" << setw(2) << test++ << " -----------------------------------" << endl;
00115    {
00116       string istr("1/(1-gamma)*(P1 - P2)"); 
00117       cout << "Input string: \"" << istr << "\"" << endl;
00118       Expression xpr(istr);
00119       xpr.print(cout);
00120       cout << endl;
00121       xpr.setGPSConstants();
00122       
00123       RinexObsStream ros("../examples/bahr1620.04o");
00124       RinexObsData rod;
00125       for (int i=0;i<3;i++)
00126          //while (ros >> rod)
00127       {
00128          ros >> rod;
00129 
00130          RinexObsData::RinexPrnMap::const_iterator it;
00131          for (it = rod.obs.begin(); it!= rod.obs.end(); it++)
00132          {
00133             xpr.setRinexObs(it->second);
00134             cout << rod.time << " " << it->first.prn << " ";
00135             cout << xpr.evaluate() << endl;
00136          } // end step through PRNs in an epoch
00137       } // end step through input obs file epoch by epoch
00138    }
00139    
00140    exit(0);   
00141 }

Generated on Wed May 23 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1