daytimetest.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: daytimetest.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 //
00026 // test the daytime implementation
00027 //
00028 
00029 #include <iostream>
00030 
00031 #include "StringUtils.hpp"
00032 #include "DayTime.hpp"
00033 #include "GPSZcount.hpp"
00034 
00035 using namespace std;
00036 using namespace gpstk::StringUtils;
00037 
00039 void dtft(ostream& s, const gpstk::DayTime& t, const string& fmt)
00040 {
00041    string fs = fmt;
00042    string p = t.printf(fmt.c_str());
00043 
00044    s << leftJustify(fs, 30) << " " 
00045      << p << endl;
00046 }
00047 
00049 int main()
00050 {
00051    using gpstk::DayTime;
00052    
00053    try
00054    {
00055       cout << "BOT:" << DayTime(gpstk::DayTime::BEGINNING_OF_TIME) << endl;
00056       cout << "EOT:" << DayTime(gpstk::DayTime::END_OF_TIME) << endl;
00057      
00058       DayTime dt;
00059       dt.setSystemTime();
00060       cout << "Check that the output matches the current UTC time." << endl
00061            << "string                         printf()" << endl;
00062 
00063       dtft(cout, dt, "mjd:  %Q (%.0Q)");
00064       dtft(cout, dt, "mjd:  %5.3Q");
00065       dtft(cout, dt, "mdy:  %02m/%02d/%04Y");
00066       dtft(cout, dt, "hms:  %02H:%02M:%02S");
00067       dtft(cout, dt, "hms:  %02H:%02M:%06.3f");
00068       dtft(cout, dt, "cal:  %A, %B %d, %Y");
00069       dtft(cout, dt, "week: %F(%G)");
00070       dtft(cout, dt, "sow:  %g");
00071       dtft(cout, dt, "sow:  %06.3g");
00072       dtft(cout, dt, "doy:  %j:%s");
00073       dtft(cout, dt, "dow:  %w");
00074       dtft(cout, dt, "z:    %Z (%z)");
00075       dtft(cout, dt, "unix: %U.%06u");
00076 
00077       cout << endl
00078            << "The following functions use DayTime::setToString()" << endl;
00079 
00080       string format = "%02m/%02d/%04Y %02H:%02M:%02S";
00081       string st = dt.printf(format);
00082 
00083       DayTime q;
00084       q.setToString(st, format);
00085       dtft(cout, q, format);
00086 
00087       cout << "Tests complete." << endl;
00088       return 0;
00089    }
00090    catch(gpstk::Exception& e)
00091    {
00092       cout << e << endl;
00093    }
00094    catch(...)
00095    {
00096       cout << "Some other exception thrown..." << endl;
00097    }
00098 
00099    cout << "Exiting with exceptions." << endl;
00100    return -1;
00101 }

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