00001 #pragma ident "$Id: YumaData.cpp 2741 2011-06-22 16:37:02Z nwu $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include "StringUtils.hpp"
00031 #include "icd_200_constants.hpp"
00032
00033 #include "YumaData.hpp"
00034 #include "YumaStream.hpp"
00035
00036
00037 using namespace gpstk::StringUtils;
00038 using namespace std;
00039
00040 namespace gpstk
00041 {
00042 short YumaData::nearFullWeek = 0;
00043
00044 const std::string YumaData::sID = "ID:";
00045 const std::string YumaData::sHlth = "Health:";
00046 const std::string YumaData::sEcc = "Eccentricity:";
00047 const std::string YumaData::sTOA = "Time of Applicability(s):";
00048 const std::string YumaData::sOrbI = "Orbital Inclination(rad):";
00049 const std::string YumaData::sRRA = "Rate of Right Ascen(r/s):";
00050 const std::string YumaData::sSqrA = "SQRT(A) (m 1/2):";
00051 const std::string YumaData::sRtAs = "Right Ascen at Week(rad):";
00052 const std::string YumaData::sArgP = "Argument of Perigee(rad):";
00053 const std::string YumaData::sMnAn = "Mean Anom(rad):";
00054 const std::string YumaData::sAf0 = "Af0(s):";
00055 const std::string YumaData::sAf1 = "Af1(s/s):";
00056 const std::string YumaData::sweek = "week:";
00057
00058 void YumaData::reallyPutRecord(FFStream& ffs) const
00059 throw(std::exception, FFStreamError,
00060 gpstk::StringUtils::StringException)
00061 {
00062 YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
00063
00064 const int width=27;
00065 strm << "******** Week" << setw(5) << (week % 1024)
00066 << " almanac for PRN-" << PRN
00067 << " ********" << endl
00068 << left
00069 << setw(width) << sID << PRN << endl
00070 << setw(width) << sHlth << hex << SV_health << endl
00071 << setw(width) << sEcc << ecc << endl
00072 << setw(width) << sTOA << Toa << endl
00073 << setw(width) << sOrbI << (i_offset + 54.0 * (gpstk::PI / 180.0)) << endl
00074 << setw(width) << sRRA << OMEGAdot << endl
00075 << setw(width) << sSqrA << Ahalf << endl
00076 << setw(width) << sRtAs << OMEGA0 << endl
00077 << setw(width) << sArgP << w << endl
00078 << setw(width) << sMnAn << M0 << endl
00079 << setw(width) << sAf0 << AF0 << endl
00080 << setw(width) << sAf1 << AF1 << endl
00081 << setw(width) << sweek << week << endl;
00082 }
00083
00084
00085 string YumaData::lineParser(const string& line, const string& s)
00086 const throw(FFStreamError)
00087 {
00088 int i = line.find_first_of(":");
00089
00090
00091 if (i == string::npos)
00092 GPSTK_THROW(FFStreamError("Format error in YumaData"));
00093
00094
00095 int w = std::min(5, std::min(i, (int)s.size()));
00096 if (line.substr(0,w) != s.substr(0,w))
00097 GPSTK_THROW(FFStreamError("Format error in YumaData"));
00098
00099 return stripLeading(line.substr(i+1), " ");
00100 }
00101
00102
00103 void YumaData::reallyGetRecord(FFStream& ffs)
00104 throw(std::exception, FFStreamError,
00105 gpstk::StringUtils::StringException)
00106 {
00107 YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
00108
00109 string line;
00110
00111
00112 strm.formattedGetLine(line, true);
00113
00114
00115 strm.formattedGetLine(line, true);
00116 PRN = asInt(lineParser(line, sID));
00117
00118
00119 strm.formattedGetLine(line, true);
00120 SV_health = asInt(lineParser(line, sHlth));
00121
00122
00123 strm.formattedGetLine(line, true);
00124 ecc = asDouble(lineParser(line, sEcc));
00125
00126
00127 strm.formattedGetLine(line, true);
00128 Toa = (long) asDouble(lineParser(line, sTOA));
00129
00130
00131 strm.formattedGetLine(line, true);
00132 double i_total = asDouble(lineParser(line, sOrbI));
00133 i_offset = i_total - 54.0 * (gpstk::PI / 180.0);
00134
00135
00136 strm.formattedGetLine(line, true);
00137 OMEGAdot = asDouble(lineParser(line, sRRA));
00138
00139
00140 strm.formattedGetLine(line, true);
00141 Ahalf = asDouble(lineParser(line, sSqrA));
00142
00143
00144 strm.formattedGetLine(line, true);
00145 OMEGA0 = asDouble(lineParser(line, sRtAs));
00146
00147
00148 strm.formattedGetLine(line, true);
00149 w = asDouble(lineParser(line, sArgP));
00150
00151
00152 strm.formattedGetLine(line, true);
00153 M0 = asDouble(lineParser(line, sMnAn));
00154
00155
00156 strm.formattedGetLine(line, true);
00157 AF0 = asDouble(lineParser(line, sAf0));
00158
00159
00160 strm.formattedGetLine(line, true);
00161 AF1 = asDouble(lineParser(line, sAf1));
00162
00163
00164
00165 strm.formattedGetLine(line, true);
00166 week = asInt(lineParser(line, sweek));
00167
00168 if (nearFullWeek > 0)
00169 {
00170
00171 week %= 1024;
00172 week += (nearFullWeek / 1024) * 1024;
00173 short diff = nearFullWeek - week;
00174 if (diff > 512)
00175 week += 512;
00176 else if(diff < -512)
00177 week -= 512;
00178 }
00179
00180 xmit_time = 0;
00181 strm.formattedGetLine(line,true);
00182
00183 }
00184
00185 void YumaData::dump(ostream& s) const
00186 {
00187 cout << "PRN = " << PRN << endl;
00188 cout << "week = " << week << endl;
00189 cout << "SV_health = " << SV_health << endl;
00190 cout << "ecc = " << ecc << endl;
00191 cout << "Toa = " << Toa << endl;
00192 cout << "i_offset = " << i_offset << endl;
00193 cout << "OMEGAdot = " << OMEGAdot << endl;
00194 cout << "Ahalf = " << Ahalf << endl;
00195 cout << "OMEGA0 = " << OMEGA0 << endl;
00196 cout << "w = " << w << endl;
00197 cout << "M0 = " << M0 << endl;
00198 cout << "AF0 = " << AF0 << endl;
00199 cout << "AF1 = " << AF1 << endl;
00200 cout << "xmit_time = " << xmit_time << endl;
00201
00202 }
00203
00204 YumaData::operator AlmOrbit() const
00205 {
00206 AlmOrbit ao(PRN, ecc,i_offset, OMEGAdot, Ahalf, OMEGA0,
00207 w, M0, AF0, AF1, Toa, xmit_time, week, SV_health);
00208
00209 return ao;
00210
00211 }
00212 }