00001 #pragma ident "$Id: GPSWeekSecond.cpp 2091 2009-08-21 14:24:47Z afarris $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "GPSWeekSecond.hpp"
00028 #include "TimeConstants.hpp"
00029
00030 namespace gpstk
00031 {
00032 GPSWeekSecond&
00033 GPSWeekSecond::operator=( const GPSWeekSecond& right )
00034 throw()
00035 {
00036 GPSWeek::operator=(right);
00037 sow = right.sow;
00038 return *this;
00039 }
00040
00041 CommonTime GPSWeekSecond::convertToCommonTime() const
00042 throw(InvalidRequest)
00043 {
00044 try
00045 {
00046
00047 int dow = static_cast<int>( sow / SEC_PER_DAY );
00048 int jday = GPS_EPOCH_JDAY + ( 7 * week ) + dow;
00049 double sod( sow - SEC_PER_DAY * dow );
00050 return CommonTime( jday,
00051 static_cast<long>( sod ),
00052 sod - static_cast<long>( sod ) );
00053 }
00054 catch (InvalidParameter& ip)
00055 {
00056 InvalidRequest ir(ip);
00057 GPSTK_THROW(ir);
00058 }
00059 }
00060
00061 void GPSWeekSecond::convertFromCommonTime( const CommonTime& ct )
00062 throw(InvalidRequest)
00063 {
00065 static const CommonTime MIN_CT = GPSWeekSecond();
00066
00067 if (ct < MIN_CT)
00068 {
00069 InvalidRequest ir("Unable to convert CommonTime to GPSWeekSecond.");
00070 GPSTK_THROW(ir);
00071 }
00072
00073 long day, sod;
00074 double fsod;
00075 ct.get( day, sod, fsod );
00076
00077
00078 day -= GPS_EPOCH_JDAY;
00079
00080 week = static_cast<int>( day / 7 );
00081
00082 day %= 7;
00083
00084 sow = static_cast<double>( day * SEC_PER_DAY + sod ) + fsod;
00085 }
00086
00087 std::string GPSWeekSecond::printf( const std::string& fmt ) const
00088 throw( gpstk::StringUtils::StringException )
00089 {
00090 try
00091 {
00092 using gpstk::StringUtils::formattedPrint;
00093
00094 std::string rv = GPSWeek::printf( fmt );
00095
00096 rv = formattedPrint( rv, getFormatPrefixInt() + "w",
00097 "wu", getDayOfWeek() );
00098 rv = formattedPrint( rv, getFormatPrefixFloat() + "g",
00099 "gf", sow);
00100 return rv;
00101 }
00102 catch( gpstk::StringUtils::StringException& exc )
00103 {
00104 GPSTK_RETHROW( exc );
00105 }
00106 }
00107
00108 std::string GPSWeekSecond::printError( const std::string& fmt ) const
00109 throw( gpstk::StringUtils::StringException )
00110 {
00111 try
00112 {
00113 using gpstk::StringUtils::formattedPrint;
00114
00115 std::string rv = GPSWeek::printError( fmt );
00116
00117 rv = formattedPrint( rv, getFormatPrefixInt() + "w",
00118 "ws", getError().c_str() );
00119 rv = formattedPrint( rv, getFormatPrefixFloat() + "g",
00120 "gs", getError().c_str() );
00121 return rv;
00122 }
00123 catch( gpstk::StringUtils::StringException& exc )
00124 {
00125 GPSTK_RETHROW( exc );
00126 }
00127 }
00128
00129 bool GPSWeekSecond::setFromInfo( const IdToValue& info )
00130 throw()
00131 {
00132 using namespace gpstk::StringUtils;
00133
00134 GPSWeek::setFromInfo( info );
00135
00136 for( IdToValue::const_iterator i = info.begin(); i != info.end(); i++ )
00137 {
00138
00139 switch ( i->first )
00140 {
00141 case 'w':
00142 sow = static_cast<double>( asInt( i->second ) ) * SEC_PER_DAY;
00143 break;
00144 case 'g':
00145 sow = asDouble( i->second );
00146 break;
00147 default:
00148
00149 break;
00150 };
00151
00152 }
00153
00154 return true;
00155 }
00156
00157 bool GPSWeekSecond::isValid() const
00158 throw()
00159 {
00160 return ( GPSWeek::isValid() &&
00161 sow < FULLWEEK );
00162 }
00163
00164 void GPSWeekSecond::reset()
00165 throw()
00166 {
00167 GPSWeek::reset();
00168 sow = 0.0;
00169 }
00170
00171 bool
00172 GPSWeekSecond::operator==( const GPSWeekSecond& right ) const
00173 throw()
00174 {
00175 return ( GPSWeek::operator==(right) &&
00176 sow == right.sow );
00177 }
00178
00179 bool
00180 GPSWeekSecond::operator!=( const GPSWeekSecond& right ) const
00181 throw()
00182 {
00183 return (! operator==( right ) );
00184 }
00185
00186 bool
00187 GPSWeekSecond::operator<( const GPSWeekSecond& right ) const
00188 throw()
00189 {
00190 if( GPSWeek::operator<(right) )
00191 {
00192 return true;
00193 }
00194 if( GPSWeek::operator>(right) )
00195 {
00196 return false;
00197 }
00198 if( sow < right.sow )
00199 {
00200 return true;
00201 }
00202 return false;
00203 }
00204
00205 bool
00206 GPSWeekSecond::operator>( const GPSWeekSecond& right ) const
00207 throw()
00208 {
00209 return (! operator<=( right ) );
00210 }
00211
00212 bool
00213 GPSWeekSecond::operator<=( const GPSWeekSecond& right ) const
00214 throw()
00215 {
00216 return ( operator<( right ) || operator==( right ) );
00217 }
00218
00219 bool
00220 GPSWeekSecond::operator>=( const GPSWeekSecond& right ) const
00221 throw()
00222 {
00223 return (! operator<( right ) );
00224 }
00225
00226 }