00001 #pragma ident "$Id: GPSWeekZcount.cpp 1225 2008-05-06 17:53:22Z vorce $"
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 "GPSWeekZcount.hpp"
00028 #include "TimeConstants.hpp"
00029 #include "TimeConverters.hpp"
00030
00031 namespace gpstk
00032 {
00033 GPSWeekZcount& GPSWeekZcount::operator=( const GPSWeekZcount& right )
00034 throw()
00035 {
00036 GPSWeek::operator=(right);
00037 zcount = right.zcount;
00038 return *this;
00039 }
00040
00041 CommonTime GPSWeekZcount::convertToCommonTime() const
00042 throw(InvalidRequest)
00043 {
00044 try
00045 {
00046 int dow = zcount / ZCOUNT_PER_DAY;
00047 int jday = GPS_EPOCH_JDAY + ( 7 * week ) + dow;
00048 double sod = static_cast<double>( zcount % ZCOUNT_PER_DAY ) * 1.5;
00049 return CommonTime( jday,
00050 static_cast<long>( sod ),
00051 sod - static_cast<long>( sod ) );
00052 }
00053 catch (InvalidParameter& ip)
00054 {
00055 InvalidRequest ir(ip);
00056 GPSTK_THROW(ir);
00057 }
00058 }
00059
00060 void GPSWeekZcount::convertFromCommonTime( const CommonTime& ct )
00061 throw(InvalidRequest)
00062 {
00064 static const CommonTime MIN_CT = GPSWeekZcount();
00065
00066 if (ct < MIN_CT)
00067 {
00068 InvalidRequest ir("Unable to convert CommonTime to GPSWeekZcount.");
00069 GPSTK_THROW(ir);
00070 }
00071
00072 long day, sod;
00073 double fsod;
00074 ct.get( day, sod, fsod );
00075
00076
00077 day -= GPS_EPOCH_JDAY;
00078
00079 week = static_cast<int>( day / 7 );
00080
00081 day %= 7;
00082
00083 zcount = static_cast<long>( day * ZCOUNT_PER_DAY )
00084 + static_cast<long>( static_cast<double>( sod + fsod ) / 1.5 );
00085 }
00086
00087 std::string GPSWeekZcount::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, getFormatPrefixInt() + "z",
00099 "zu", zcount );
00100 rv = formattedPrint( rv, getFormatPrefixInt() + "Z",
00101 "Zu", zcount );
00102 rv = formattedPrint( rv, getFormatPrefixInt() + "c",
00103 "cu", getZcount29() );
00104 rv = formattedPrint( rv, getFormatPrefixInt() + "C",
00105 "Cu", getZcount32() );
00106 return rv;
00107 }
00108 catch( gpstk::StringUtils::StringException& exc )
00109 {
00110 GPSTK_RETHROW( exc );
00111 }
00112 }
00113
00114 std::string GPSWeekZcount::printError( const std::string& fmt ) const
00115 throw( gpstk::StringUtils::StringException )
00116 {
00117 try
00118 {
00119 using gpstk::StringUtils::formattedPrint;
00120
00121 std::string rv = GPSWeek::printError( fmt );
00122
00123 rv = formattedPrint( rv, getFormatPrefixInt() + "w",
00124 "ws", getError().c_str() );
00125 rv = formattedPrint( rv, getFormatPrefixInt() + "z",
00126 "zs", getError().c_str() );
00127 rv = formattedPrint( rv, getFormatPrefixInt() + "Z",
00128 "Zs", getError().c_str() );
00129 rv = formattedPrint( rv, getFormatPrefixInt() + "c",
00130 "cs", getError().c_str() );
00131 rv = formattedPrint( rv, getFormatPrefixInt() + "C",
00132 "Cs", getError().c_str() );
00133 return rv;
00134 }
00135 catch( gpstk::StringUtils::StringException& exc )
00136 {
00137 GPSTK_RETHROW( exc );
00138 }
00139 }
00140
00141 bool GPSWeekZcount::setFromInfo( const IdToValue& info )
00142 throw()
00143 {
00144 using namespace gpstk::StringUtils;
00145
00146 for( IdToValue::const_iterator i = info.begin(); i != info.end(); i++ )
00147 {
00148
00149 switch( i->first )
00150 {
00151 case 'w':
00152 zcount = asInt( i->second) * ZCOUNT_PER_DAY;
00153 break;
00154
00155 case 'z':
00156 case 'Z':
00157 zcount = asInt( i->second );
00158 break;
00159
00160 case 'c':
00161 setZcount29( asInt( i->second ) );
00162 break;
00163
00164 case 'C':
00165 setZcount32( asInt( i->second ) );
00166 break;
00167
00168 default:
00169
00170 break;
00171 };
00172 }
00173
00174 return true;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 GPSWeekZcount& GPSWeekZcount::setZcount29(unsigned int z)
00192 throw()
00193 {
00194 setWeek10( (z >> 19) & bits10 );
00195 zcount = z & bits19;
00196 return *this;
00197 }
00198
00199 GPSWeekZcount& GPSWeekZcount::setZcount32(unsigned int z)
00200 throw()
00201 {
00202 week = z >> 19;
00203 zcount = z & bits19;
00204 return *this;
00205 }
00206
00207
00208 }