positiontest.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: positiontest.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 2008, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00030 #include <iostream>
00031 #include <iomanip>
00032 #include "Position.hpp"
00033 
00034 using namespace std;
00035 using namespace gpstk;
00036 using namespace gpstk::StringUtils;
00037 
00038 int main()
00039 {
00040    try
00041    {
00042       int i;
00043       Position c,s,d,g;
00044       cout << "Position() " << c << endl;
00045 
00046       // test transformTo
00047       cout << "Test set...() and transformTo\n";
00048       {
00049          c.setECEF(-1575232.0141,-4707872.2332, 3993198.4383);
00050          cout << "Position.set        to Cartesian  " << c << endl;
00051          Position t(c);
00052          t.transformTo(Position::Geodetic);
00053          cout << "Transform Cartesian to Geodetic   " << t;
00054          cout << "  Error : " << range(t,c) << " m" << endl;
00055          t = c;
00056          t.transformTo(Position::Geocentric);
00057          cout << "Transform Cartesian to Geocentric " << t;
00058          cout << "  Error : " << range(t,c) << " m" << endl;
00059          t = c;
00060          t.transformTo(Position::Spherical);
00061          cout << "Transform Cartesian to Spherical  " << t;
00062          cout << "  Error : " << range(t,c) << " m" << endl;
00063       }
00064       {
00065          d.setGeodetic(39.000004186778,251.499999999370,1400.009066903964);
00066          cout << "Position.set         to Geodetic  " << d << endl;
00067          Position t(d);
00068          t.transformTo(Position::Cartesian);
00069          cout << "Transform Geodetic to Cartesian   " << t;
00070          cout << "  Error : " << range(t,d) << " m" << endl;
00071          t = d;
00072          t.transformTo(Position::Geocentric);
00073          cout << "Transform Geodetic to Geocentric  " << t;
00074          cout << "  Error : " << range(t,d) << " m" << endl;
00075          t = d;
00076          t.transformTo(Position::Spherical);
00077          cout << "Transform Geodetic to Spherical   " << t;
00078          cout << "  Error : " << range(t,d) << " m" << endl;
00079       }
00080       {
00081          g.setGeocentric(38.811958506159,251.499999999370,6371110.627671023800);
00082          cout << "Position.set        to Geocentric " << g << endl;
00083          Position t(g);
00084          t.transformTo(Position::Cartesian);
00085          cout << "Transform Geocentric to Cartesian " << t;
00086          cout << "  Error : " << range(t,g) << " m" << endl;
00087          t = g;
00088          t.transformTo(Position::Geodetic);
00089          cout << "Transform Geocentric to Geodetic  " << t;
00090          cout << "  Error : " << range(t,g) << " m" << endl;
00091          t = g;
00092          t.transformTo(Position::Spherical);
00093          cout << "Transform Geocentric to Spherical " << t;
00094          cout << "  Error : " << range(t,g) << " m" << endl;
00095       }
00096       {
00097          s.setSpherical(51.188041493841,251.499999999370,6371110.627671023800);
00098          cout << "Position.set      to Spherical    " << s << endl;
00099          Position t(s);
00100          t.transformTo(Position::Cartesian);
00101          cout << "Transform Spherical to Cartesian  " << t;
00102          cout << "  Error : " << range(t,s) << " m" << endl;
00103          t = s;
00104          t.transformTo(Position::Geocentric);
00105          cout << "Transform Spherical to Geocentric " << t;
00106          cout << "  Error : " << range(t,s) << " m" << endl;
00107          t = s;
00108          t.transformTo(Position::Geodetic);
00109          cout << "Transform Spherical to Geodetic   " << t;
00110          cout << "  Error : " << range(t,s) << " m" << endl;
00111       }
00112 
00113       // test printf
00114       cout << "\nTest printf and the indicated 'get()' functions\n";
00115       cout << c.printf("%13.4x     X() (meters)") << endl;
00116       cout << c.printf("%13.4y     Y() (meters)") << endl;
00117       cout << c.printf("%13.4z     Z() (meters)") << endl;
00118       cout << c.printf("%13.4X     X()/1000 (kilometers)") << endl;
00119       cout << c.printf("%13.4Y     Y()/1000 (kilometers)") << endl;
00120       cout << c.printf("%13.4Z     Z()/1000 (kilometers)") << endl;
00121       cout << c.printf("%15.6A   geodeticLatitude() (degrees North)") << endl;
00122       cout << c.printf("%15.6a   geocentricLatitude() (degrees North)") << endl;
00123       cout << c.printf("%15.6L   longitude() (degrees East)") << endl;
00124       cout << c.printf("%15.6l   longitude() (degrees East)") << endl;
00125       cout << c.printf("%15.6w   longitude() (degrees West)") << endl;
00126       cout << c.printf("%15.6W   longitude() (degrees West)") << endl;
00127       cout << c.printf("%15.6t   theta() (degrees)") << endl;
00128       cout << c.printf("%15.6T   theta() (radians)") << endl;
00129       cout << c.printf("%15.6p   phi() (degrees)") << endl;
00130       cout << c.printf("%15.6P   phi() (radians)") << endl;
00131       cout << c.printf("%13.4r     radius() meters") << endl;
00132       cout << c.printf("%13.4R     radius()/1000 kilometers") << endl;
00133       cout << c.printf("%13.4h     height() meters") << endl;
00134       cout << c.printf("%13.4H     height()/1000 kilometers") << endl;
00135 
00136       // test setToString
00137       cout << "\nTest setToString and equality operators\n";
00138       string fmt[5]={
00139          "",
00140          "%A degN %L degE %h m",
00141          "%a degN %L degE %r m",
00142          "%x m %y m %z m",
00143          "%t deg %p deg %r M"};
00144       for(i=1; i<5; i++) {
00145          string str;
00146          Position t(c),tt;
00147          t.transformTo(static_cast<Position::CoordinateSystem>(i));
00148          {
00149             ostringstream o;
00150             o << t;
00151             str = o.str();
00152          }
00153          tt.setToString(str,fmt[i]);
00154          cout << "System: " << t.getSystemName() << endl;
00155          cout << "Original    " << t << endl;
00156          cout << "string      " << str << endl;
00157          cout << "setToString " << tt
00158             << " Error " << range(tt,t) << " m" << endl;
00159          cout << " equality: " << (t==tt ? "==" : "not ==");
00160          cout << " but " << (t!=tt ? "!=" : "not !=") << endl;
00161          cout << endl;
00162       }
00163 
00164       // test elevation and azimuth
00165       cout << "Elevation and azimth" << fixed << endl;
00166       c.setECEF(-1575232.0141,-4707872.2332, 3993198.4383);
00167       s.setECEF(3*6371110.62767,0,0);
00168       cout << setw(6) << setprecision(2) << c.elevation(s)
00169          << " " << setw(6) << setprecision(2) << c.azimuth(s) << endl;
00170       // compare with functions from Triple::
00171       cout << setw(6) << setprecision(2) << c.elvAngle(s)
00172          << " " << setw(6) << setprecision(2) << c.azAngle(s) << endl;
00173       cout << endl;
00174 
00175       // test IPP
00176       cout << "The IPP at " << g << " (90,0,350000) is\n"
00177            << "           " << g.getIonosphericPiercePoint(90,0,350000)
00178            << " " << g.getSystemName() << endl << endl;
00179 
00180       // test ALL transforms with pole
00181       // X -> D -> C -> S -> X -> C -> D -> X -> S -> D -> S -> C -> X
00182       cout << "Try to break it at the pole\n";
00183       c.setECEF(0,0,6371110.6277);
00184       //c.setECEF(0,0,0.0001);         // this will break it
00185       cout << "Set to the pole in cartesian : " << c << endl;
00186       c.transformTo(Position::Geodetic);
00187       cout << "The pole in geodetic   " << c << endl;
00188       c.transformTo(Position::Geocentric);
00189       cout << "The pole in geocentric " << c << endl;
00190       c.transformTo(Position::Spherical);
00191       cout << "The pole in spherical  " << c << endl;
00192       c.transformTo(Position::Cartesian);
00193       cout << "The pole in cartesian  " << c << endl;
00194       c.transformTo(Position::Geocentric);
00195       cout << "The pole in geocentric " << c << endl;
00196       c.transformTo(Position::Geodetic);
00197       cout << "The pole in geodetic   " << c << endl;
00198       c.transformTo(Position::Cartesian);
00199       cout << "The pole in cartesian  " << c << endl;
00200       c.transformTo(Position::Spherical);
00201       cout << "The pole in spherical  " << c << endl;
00202       c.transformTo(Position::Geodetic);
00203       cout << "The pole in geodetic   " << c << endl;
00204       c.transformTo(Position::Spherical);
00205       cout << "The pole in spherical  " << c << endl;
00206       c.transformTo(Position::Geocentric);
00207       cout << "The pole in geocentric " << c << endl;
00208       c.transformTo(Position::Cartesian);
00209       cout << "The pole in cartesian  " << c << endl;
00210 
00211       // test ALL transforms with origin
00212       // X -> D -> C -> S -> X -> C -> D -> X -> S -> D -> S -> C -> X
00213       cout << endl << "Try to break it at the origin\n";
00214       c.setECEF(0,0,0);
00215       cout << "Set to the origin in cartesian : " << c << endl;
00216       c.transformTo(Position::Geodetic);
00217       cout << "The origin in geodetic   " << c << endl;
00218       c.transformTo(Position::Geocentric);
00219       cout << "The origin in geocentric " << c << endl;
00220       c.transformTo(Position::Spherical);
00221       cout << "The origin in spherical  " << c << endl;
00222       c.transformTo(Position::Cartesian);
00223       cout << "The origin in cartesian  " << c << endl;
00224       c.transformTo(Position::Geocentric);
00225       cout << "The origin in geocentric " << c << endl;
00226       c.transformTo(Position::Geodetic);
00227       cout << "The origin in geodetic   " << c << endl;
00228       c.transformTo(Position::Cartesian);
00229       cout << "The origin in cartesian  " << c << endl;
00230       c.transformTo(Position::Spherical);
00231       cout << "The origin in spherical  " << c << endl;
00232       c.transformTo(Position::Geodetic);
00233       cout << "The origin in geodetic   " << c << endl;
00234       c.transformTo(Position::Spherical);
00235       cout << "The origin in spherical  " << c << endl;
00236       c.transformTo(Position::Geocentric);
00237       cout << "The origin in geocentric " << c << endl;
00238       c.transformTo(Position::Cartesian);
00239       cout << "The origin in cartesian  " << c << endl;
00240 
00241       cout << "Tests complete." << endl;
00242       return 0;
00243    }
00244    catch(gpstk::Exception& e)
00245    {
00246       cout << e << endl;
00247    }
00248    catch(...)
00249    {
00250       cout << "Some other exception thrown..." << endl;
00251    }
00252 
00253    cout << "Exiting with exceptions." << endl;
00254    return -1;
00255 }

Generated on Thu Feb 9 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1