00001 #pragma ident "$Id: SP3Header.cpp 793 2007-09-28 16:17:04Z ckiesch $"
00002
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
00040
00041
00042
00043
00044 #include "StringUtils.hpp"
00045 #include "SP3Stream.hpp"
00046 #include "SP3Header.hpp"
00047
00048 namespace gpstk
00049 {
00050 using namespace StringUtils;
00051 using namespace std;
00052
00053 void SP3Header::reallyPutRecord(FFStream& ffs) const
00054 throw(exception, FFStreamError, StringException)
00055 {
00056 SP3Stream& strm = dynamic_cast<SP3Stream&>(ffs);
00057 int i,j,k;
00058 string line;
00059 SatID SVid;
00060
00061 if(version != 'a' && version != 'c') {
00062 Exception e(string("SP3 version must be 'a' or 'c' : ") + version);
00063 GPSTK_THROW(e);
00064 }
00065 if(pvFlag != 'P' && pvFlag != 'V') {
00066 Exception e(string("SP3 pv flag must be 'P' or 'V' : ") + pvFlag);
00067 GPSTK_THROW(e);
00068 }
00069
00070
00071 line = "#";
00072 line += version;
00073 line += pvFlag;
00074 line += time.printf("%4Y %2m %2d %2H %2M");
00075 line += " " + rightJustify(time.printf("%f"),11);
00076 line += " " + rightJustify(asString(numberOfEpochs),7);
00077 line += " " + rightJustify(dataUsed,5);
00078 line += " " + rightJustify(coordSystem,5);
00079 line += " " + rightJustify(orbitType,3);
00080 line += " " + rightJustify(agency,4);
00081 strm << line << endl;
00082
00083
00084 line = "##";
00085 line += rightJustify(time.printf("%F"),5);
00086 line += rightJustify(time.printf("%g"),16);
00087 line += " " + rightJustify(asString(epochInterval,8),14);
00088 line += " " + time.printf("%5.0Q");
00089 line += " " + rightJustify(asString(time.DOYsecond()/86400.,13),15);
00090 strm << line << endl;
00091
00092
00093
00094 std::map<SatID, short>::const_iterator it;
00095 for(i=3; i<=12; i++) {
00096 if(i==3) line = "+ " + rightJustify(asString(satList.size()),2) + " ";
00097 else if(i < 8) line = "+ ";
00098 else line = "++ ";
00099 k = 0;
00100 if(i == 3 || i == 8)
00101 it = satList.begin();
00102 while(k < 17) {
00103 if(it != satList.end()) {
00104 if(i < 8) {
00105 if(version == 'c') {
00106
00107 SVid = it->first;
00108 j = -1;
00109 }
00110 else j = it->first.id;
00111 }
00112 else
00113 j = it->second;
00114 it++;
00115 }
00116 else j=0;
00117
00118 if(j == -1)
00119 try {
00120 line += rightJustify(SP3SatID(SVid).toString(),3);
00121 }
00122 catch (Exception& e)
00123 {
00124 FFStreamError ffse(e);
00125 GPSTK_THROW(ffse);
00126 }
00127 else
00128 line += rightJustify(asString(j),3);
00129 k++;
00130 }
00131 strm << line << endl;
00132 }
00133
00134
00135 string ft(" cc");
00136 if (version == 'c')
00137 {
00138 ft[1] = system.systemChar(); ft[2] = ' '; }
00139 strm << "%c" << ft << " cc"
00140 << " " << (version == 'c' ? timeSystemString() : "ccc")
00141 << " ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc" << endl;
00142
00143 strm << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc" << endl;
00144
00145 strm << "%f "
00146 << (version == 'c' ? rightJustify(asString(basePV,7),10) : " 0.0000000")
00147 << " "
00148 << (version == 'c' ? rightJustify(asString(baseClk,9),12) : " 0.000000000")
00149 << " 0.00000000000 0.000000000000000" << endl;
00150
00151 strm << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000" << endl;
00152 strm << "%i 0 0 0 0 0 0 0 0 0" << endl;
00153 strm << "%i 0 0 0 0 0 0 0 0 0" << endl;
00154
00155
00156
00157 for(j=0,i=19; i<=22; i++) {
00158 line = "/* ";
00159 if(j < comments.size()) line += leftJustify(comments[j++],57);
00160 else line += string(57,'C');
00161 strm << line << endl;
00162 }
00163 }
00164
00165 void SP3Header::dump(ostream& s) const
00166 {
00167 s << "SP3 Header: version '" << version << "' containing ";
00168 if(pvFlag=='P') s << "positions.";
00169 if(pvFlag=='V') s << "positions and velocities.";
00170 s << endl;
00171 s << " Time tag in header is " << time << endl;
00172 s << " Timespacing is " << epochInterval
00173 << " sec, and the number of epochs is " << numberOfEpochs << endl;
00174 s << " Data used as input : " << dataUsed << endl;
00175 s << " Coordinate system : " << coordSystem << endl;
00176 s << " Orbit estimate type : " << orbitType << endl;
00177 s << " Agency : " << agency << endl;
00178 if(version == 'c') {
00179 s << " File type: '" << system.systemChar() << "' which is "
00180 << system.systemString() << endl;
00181 s << " Time System: " << timeSystemString() << endl;
00182 s << " Base for Pos/Vel =" << fixed << setw(10) << setprecision(7)
00183 << basePV << endl;
00184 s << " Base for Clk/Rate =" << setw(12) << setprecision(9)
00185 << baseClk << endl;
00186 }
00187
00188 s << " List of satellite PRN/acc (" << satList.size() << " total) :\n";
00189 int i=0;
00190 std::map<SatID,short>::const_iterator it=satList.begin();
00191 while(it != satList.end()) {
00192 s << " " << it->first << "/" << it->second;
00193 if(!(++i % 8)) s << endl;
00194 it++;
00195 }
00196 if(++i % 8) s << endl;
00197
00198 s << " Comments:\n";
00199 for(size_t j=0; j<comments.size(); j++) s << " " << comments[j] << endl;
00200
00201 s << "End of SP3 header" << endl;
00202
00203 }
00204
00205 void SP3Header::reallyGetRecord(FFStream& ffs)
00206 throw(exception, FFStreamError, StringException)
00207 {
00208 SP3Stream& strm = dynamic_cast<SP3Stream&>(ffs);
00209
00210 string line;
00211 strm.formattedGetLine(line);
00212
00213 if (line[0]=='#' && line[1]!='#')
00214 {
00215 version=line[1];
00216 pvFlag=line[2];
00217 int year = asInt(line.substr(3,4));
00218 int month = asInt(line.substr(8,2));
00219 int dom = asInt(line.substr(11,2));
00220 int hour = asInt(line.substr(14,2));
00221 int minute = asInt(line.substr(17,2));
00222 double second = asInt(line.substr(20,10));
00223 try {
00224 time = DayTime(year, month, dom, hour, minute, second);
00225 }
00226 catch (DayTime::DayTimeException& e) {
00227 FFStreamError fe("Invalid time:" + string(1, line[0]));
00228 GPSTK_THROW(fe);
00229 }
00230 numberOfEpochs = asInt(line.substr(32,7));
00231 dataUsed = line.substr(40,5);
00232 coordSystem = line.substr(46,5);
00233 orbitType = line.substr(52,3);
00234 agency = line.substr(56,4);
00235 }
00236 else
00237 {
00238 FFStreamError e("Unknown label " + string(1, line[0]));
00239 GPSTK_THROW(e);
00240 }
00241
00242 strm.formattedGetLine(line);
00243 if (line[0]=='#' && line[1]=='#')
00244 {
00245 epochInterval = asDouble(line.substr(24,14));
00246 }
00247 else
00248 {
00249 FFStreamError e("Unknown label " + string(1, line[0]));
00250 GPSTK_THROW(e);
00251 }
00252
00253 int i, index;
00254 int numSVs(0), readSVs(0);
00255
00256
00257
00258 vector<SatID> svsAsWritten;
00259 SatID sat;
00260
00261
00262 for(i = 3; i <= 7; i++)
00263 {
00264 strm.formattedGetLine(line);
00265 if (line[0]=='+')
00266 {
00267
00268 if (i == 3)
00269 {
00270 numSVs = asInt(line.substr(4,2));
00271 svsAsWritten.resize(numSVs);
00272 }
00273 for(index = 9; index < 60; index += 3)
00274 {
00275 if (readSVs < numSVs)
00276 {
00277 try {
00278 sat = SP3SatID(line.substr(index,3));
00279 }
00280 catch (Exception& e) {
00281 FFStreamError ffse(e);
00282 GPSTK_THROW(ffse);
00283 }
00284 svsAsWritten[readSVs] = sat;
00285 satList[sat] = 0;
00286 readSVs++;
00287 }
00288 }
00289 }
00290 else
00291 {
00292 FFStreamError e("Unknown label " + string(1, line[0]));
00293 GPSTK_THROW(e);
00294 }
00295 }
00296
00297 readSVs = 0;
00298
00299
00300 for(i = 8; i <= 12; i++)
00301 {
00302 strm.formattedGetLine(line);
00303 if ((line[0]=='+') && (line[1]=='+'))
00304 {
00305 for(index = 9; index < 60; index += 3)
00306 {
00307 if (readSVs < numSVs)
00308 {
00309 satList[svsAsWritten[readSVs]] = asInt(line.substr(index,3));
00310 readSVs++;
00311 }
00312 }
00313 }
00314 else
00315 {
00316 FFStreamError e("Unknown label " + string(1, line[0]));
00317 GPSTK_THROW(e);
00318 }
00319 }
00320
00321
00322 for(i = 13; i <= 18; i++)
00323 strm.formattedGetLine(line);
00324
00325
00326 for(i = 19; i <= 22; i++)
00327 {
00328 strm.formattedGetLine(line);
00329
00330 line.erase(0, 3);
00331
00332 comments.push_back(line);
00333 }
00334 }
00335
00336 }