00001 #pragma ident "$Id: MSCData.cpp 2453 2010-08-13 17:22:09Z 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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00045 #include <math.h>
00046 #include "MSCData.hpp"
00047 #include "MSCStream.hpp"
00048
00049 using namespace gpstk::StringUtils;
00050 using namespace std;
00051
00052 namespace gpstk
00053 {
00054
00055 static const unsigned long SEC_YEAR =
00056 static_cast<unsigned long>(365.25 * gpstk::DayTime::SEC_DAY);
00057
00058 void MSCData::reallyPutRecord(gpstk::FFStream & ffs) const
00059 throw(std::exception, gpstk::FFStreamError, StringException)
00060 {
00061 MSCStream& strm = dynamic_cast<MSCStream&>(ffs);
00062
00063 string line;
00064
00065 if ( time == DayTime::BEGINNING_OF_TIME )
00066 {
00067 line += string(7, ' ');
00068 }
00069 else
00070 {
00071 line += rightJustify(asString<short>(time.DOYyear()), 4);
00072 line += rightJustify(asString<short>(time.DOYday()), 3 , '0');
00073 }
00074 line += rightJustify(asString<long>(station), 5);
00075 line += leftJustify(mnemonic, 7);
00076 if ( refepoch == DayTime::BEGINNING_OF_TIME )
00077 {
00078 line += string(14, ' ');
00079 }
00080 else
00081 {
00082 line += rightJustify(asString<short>(refepoch.DOYyear()), 4);
00083 line += " ";
00084 line += rightJustify(asString<short>(refepoch.DOYday()), 3, '0');
00085 line += " ";
00086 line += rightJustify(asString<long>(refepoch.DOYsecond()), 5, '0');
00087 }
00088 if ( effepoch == DayTime::BEGINNING_OF_TIME )
00089 {
00090 line += string(14, ' ');
00091 }
00092 else
00093 {
00094 line += rightJustify(asString<short>(effepoch.DOYyear()), 4);
00095 line += " ";
00096 line += rightJustify(asString<short>(effepoch.DOYday()), 3, '0');
00097 line += " ";
00098 line += rightJustify(asString<long>(effepoch.DOYsecond()), 5, '0');
00099 }
00100 line += rightJustify(asString(coordinates[0], 3), 12);
00101 line += rightJustify(asString(coordinates[1], 3), 12);
00102 line += rightJustify(asString(coordinates[2], 3), 12);
00103 line += rightJustify(asString(velocities[0], 4), 7);
00104 line += rightJustify(asString(velocities[1], 4), 7);
00105 line += rightJustify(asString(velocities[2], 4), 7);
00106
00107 ffs << line << endl;
00108 strm.lineNumber++;
00109 }
00110
00111 void MSCData::reallyGetRecord(gpstk::FFStream& ffs)
00112 throw(std::exception, gpstk::FFStreamError,
00113 gpstk::StringUtils::StringException)
00114 {
00115 MSCStream& strm = dynamic_cast<MSCStream&>(ffs);
00116
00117 string currentLine;
00118
00119 strm.formattedGetLine(currentLine, true);
00120 int len = currentLine.length();
00121
00122 if(len == 90)
00123 {
00124 short year = asInt(currentLine.substr(0, 4));
00125 short day = asInt(currentLine.substr(4, 3));
00126 time.setYDoySod(year, day, 0.0);
00127
00128 station = asInt(currentLine.substr(7, 5));
00129 mnemonic = currentLine.substr(12, 7);
00130
00131 double epoch, intg, frac, sod;
00132 short doy;
00133
00134 epoch = asDouble(currentLine.substr(19, 7));
00135 frac = modf(epoch, &intg);
00136 doy = (short)(frac * SEC_YEAR / gpstk::DayTime::SEC_DAY);
00137 sod = (frac * SEC_YEAR) - (doy * gpstk::DayTime::SEC_DAY);
00138 refepoch = gpstk::DayTime((short)intg, doy+1, sod);
00139
00140 epoch = asDouble(currentLine.substr(26, 7));
00141 frac = modf(epoch, &intg);
00142 doy = (short)(frac * SEC_YEAR / gpstk::DayTime::SEC_DAY);
00143 sod = (frac * SEC_YEAR) - (doy * gpstk::DayTime::SEC_DAY);
00144 effepoch = gpstk::DayTime((short)intg, doy+1, sod);
00145
00146 coordinates[0] = asDouble(currentLine.substr(33, 12));
00147 coordinates[1] = asDouble(currentLine.substr(45, 12));
00148 coordinates[2] = asDouble(currentLine.substr(57, 12));
00149
00150 velocities[0] = asDouble(currentLine.substr(69, 7));
00151 velocities[1] = asDouble(currentLine.substr(76, 7));
00152 velocities[2] = asDouble(currentLine.substr(83, 7));
00153 }
00154 else if(len == 104)
00155 {
00156 if ( ( currentLine.substr(0, 4) == string(' ', 4) ) ||
00157 ( currentLine.substr(4, 3) == string(' ', 3) ) ||
00158 ( asInt(currentLine.substr(0, 4)) == 0 ) ||
00159 ( asInt(currentLine.substr(4, 3)) == 0 ) )
00160 {
00161 time = DayTime::BEGINNING_OF_TIME;
00162 }
00163 else
00164 {
00165 time = DayTime( (short)asInt(currentLine.substr(0, 4)),
00166 (short)asInt(currentLine.substr(4, 3)),
00167 (double)0.0 );
00168 }
00169
00170 station = asInt(currentLine.substr(7, 5));
00171 mnemonic = currentLine.substr(12, 7);
00172
00173 if ( ( currentLine.substr(19, 4) == string(' ', 4) ) ||
00174 ( currentLine.substr(24, 3) == string(' ', 3) ) ||
00175 ( asInt(currentLine.substr(19, 4)) == 0 ) ||
00176 ( asInt(currentLine.substr(24, 3)) == 0 ) )
00177 {
00178 refepoch = DayTime::BEGINNING_OF_TIME;
00179 }
00180 else
00181 {
00182 refepoch = DayTime( (short)asInt(currentLine.substr(19, 4)),
00183 (short)asInt(currentLine.substr(24, 3)),
00184 asDouble(currentLine.substr(28,5)) );
00185 }
00186 if ( ( currentLine.substr(33, 4) == string(' ', 4) ) ||
00187 ( currentLine.substr(38, 3) == string(' ', 3) ) ||
00188 ( asInt(currentLine.substr(33, 4)) == 0 ) ||
00189 ( asInt(currentLine.substr(38, 3)) == 0 ) )
00190 {
00191 effepoch = DayTime::BEGINNING_OF_TIME;
00192 }
00193 else
00194 {
00195 effepoch = DayTime( (short)asInt(currentLine.substr(33, 4)),
00196 (short)asInt(currentLine.substr(38, 3)),
00197 asDouble(currentLine.substr(42,5)) );
00198 }
00199
00200 coordinates[0] = asDouble(currentLine.substr(47, 12));
00201 coordinates[1] = asDouble(currentLine.substr(59, 12));
00202 coordinates[2] = asDouble(currentLine.substr(71, 12));
00203
00204 velocities[0] = asDouble(currentLine.substr(83, 7));
00205 velocities[1] = asDouble(currentLine.substr(90, 7));
00206 velocities[2] = asDouble(currentLine.substr(97, 7));
00207 }
00208 else
00209 {
00210 }
00211 }
00212
00213 Xvt MSCData::getXvt(const DayTime& t)
00214 const throw(InvalidRequest)
00215 {
00216 try
00217 {
00218
00219
00220
00221
00222 double dt = (t - refepoch) / SEC_YEAR;
00223 Xvt xvt;
00224 xvt.x = coordinates;
00225 xvt.v = velocities;
00226 xvt.dtime = 0.0;
00227 xvt.ddtime = 0.0;
00228 const Triple& drift = velocities;
00229
00230
00231 xvt.x[0] += drift[0] * dt;
00232 xvt.x[1] += drift[1] * dt;
00233 xvt.x[2] += drift[2] * dt;
00234 return( xvt );
00235 }
00236 catch(InvalidRequest& ir)
00237 {
00238 GPSTK_RETHROW(ir);
00239 }
00240 }
00241
00242
00243 }