55 using namespace StringUtils;
64 if(
debug) std::cout <<
"SP3 Header Line 1 " << line << std::endl;
66 if (line[0]==
'#' && line[1]!=
'#')
69 if(line[1] ==
'a')
version = SP3a;
70 else if(line[1] ==
'b')
version = SP3b;
71 else if(line[1] ==
'c')
version = SP3c;
72 else if(line[1] ==
'd')
version = SP3d;
74 FFStreamError e(
"Unknown version of SP3: " + line.substr(0,3));
79 if(line[2] ==
'V') containsVelocity =
true;
80 else containsVelocity =
false;
85 int dom =
asInt(line.substr(11,2));
93 FFStreamError fe(
"Invalid time:" +
string(1, line[0]));
96 numberOfEpochs =
asInt(line.substr(32,7));
97 dataUsed = line.substr(40,5);
98 coordSystem = line.substr(46,5);
99 orbitType = line.substr(52,3);
100 agency = line.substr(56,4);
104 FFStreamError e(
"Unknown label in line 1: " + line.substr(0,2));
109 if(
debug) std::cout <<
"SP3 Header Line 2 " << line << std::endl;
110 if (line[0]==
'#' && line[1]==
'#')
112 epochInterval =
asDouble(line.substr(24,14));
116 FFStreamError e(
"Unknown label in line 2: " + line.substr(0,2));
121 int numSVs(0), readSVs(0);
125 vector<SP3SatID> svsAsWritten;
138 if(
debug) std::cout <<
"SP3 Header Line " << lineCount <<
" " << line << std::endl;
139 if (line[0]==
'+' && line[1]==
'+')
150 if (svLineCount == 1)
153 svsAsWritten.resize(
numSVs);
155 for(index = 9; index < 60; index += 3)
160 sat =
SP3SatID(line.substr(index,3));
163 FFStreamError ffse(e);
166 svsAsWritten[readSVs] = sat;
178 FFStreamError e(
"Unknown 1st char: "
180 +
string(1, line[0]));
189 for (i = 0; i < svLineCount; i++)
201 if(
debug) std::cout <<
"SP3 Header Line " << lineCount <<
" " << line << std::endl;
202 if ((line[0]==
'+') && (line[1]==
'+'))
204 for(index = 9; index < 60; index += 3)
208 satList[svsAsWritten[readSVs]] =
asInt(line.substr(index,3));
215 FFStreamError e(
"Unknown label in line " +
asString(i) +
": "
223 if(
debug) std::cout <<
"SP3 Header Line %c1 " << line << std::endl;
225 if(line[0]==
'%' && line[1]==
'c')
228 system.fromString(line.substr(3,2));
236 FFStreamError e(
"Unknown label in line %c1: " + line.substr(0,2));
247 time.setTimeSystem(timeSystem);
251 if(
debug) std::cout <<
"SP3 Header Line %c2 " << line << std::endl;
255 if(
debug) std::cout <<
"SP3 Header Line %f1 " << line << std::endl;
257 if (line[0]==
'%' && line[1]==
'f')
259 basePV =
asDouble(line.substr(3,10));
260 baseClk =
asDouble(line.substr(14,12));
264 FFStreamError e(
"Unknown label in line %f1: " + line.substr(0,2));
271 if(
debug) std::cout <<
"SP3 Header Line %f2 " << line << std::endl;
274 for(i = 0; i <= 1; i++) {
277 if(
debug) std::cout <<
"SP3 Header Line %i " << line << std::endl;
287 if(line[0]==
'/' && line[1]==
'*')
289 if(
debug) std::cout <<
"SP3 Header Line " << i <<
" " << line << std::endl;
293 comments.push_back(line);
316 bool isVerA = (
version == SP3a);
317 bool isVerB = (
version == SP3b);
318 bool isVerC = (
version == SP3c);
319 bool isVerD = (
version == SP3d);
324 line += versionChar();
325 line += (containsVelocity ?
"V" :
"P");
326 line += civTime.
printf(
"%4Y %2m %2d %2H %2M");
333 strm << line << endl;
342 line +=
" " + (
static_cast<MJD>(
time)).printf(
"%5.0Q");
344 strm << line << endl;
349 std::map<SP3SatID, short>::const_iterator it;
352 int totalLines = satList.size()/17;
353 if (satList.size()%17 != 0) totalLines++;
354 int numberOfLines = 2*totalLines;
355 if (numberOfLines < 10){
358 int linesInSec = numberOfLines/2;
359 for(i=1;i<=numberOfLines;i++){
361 else if ( i < linesInSec+1) line =
"+ ";
364 if(i==1 || i==linesInSec+1)
366 it = satList.begin();
370 if (it != satList.end())
372 if (i < linesInSec+1)
394 FFStreamError ffse(e);
404 strm << line << endl;
410 for(i=3; i<=12; i++) {
412 else if(i < 8) line =
"+ ";
416 it = satList.begin();
418 if(it != satList.end()) {
425 else j = it->first.
id;
439 FFStreamError ffse(e);
446 strm << line << endl;
455 ft[0] = system.systemChar();
462 FFStreamError ffse(
"Time system must be GPS or UTC");
472 FFStreamError ffse(
"Time system must be GPS, GLO, GAL, TAI, UTC, or QZS");
476 strm <<
"%c " << ft <<
" cc"
477 <<
" " << (isVerA ?
"ccc" : timeSystemString())
478 <<
" ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc" << endl;
482 strm <<
"%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc" << endl;
489 <<
" 0.00000000000 0.000000000000000" << endl;
493 strm <<
"%f 0.0000000 0.000000000 0.00000000000 0.000000000000000" << endl;
495 strm <<
"%i 0 0 0 0 0 0 0 0 0" << endl;
497 strm <<
"%i 0 0 0 0 0 0 0 0 0" << endl;
504 int linesOfComments = 4;
505 if ((
int)comments.size() > linesOfComments){
506 linesOfComments = (int)comments.size();
511 if(j < (
int)comments.size()) line +=
leftJustify(comments[j],77);
512 else line += string(77,
'C');
515 if(j < (
int)comments.size()) line +=
leftJustify(comments[j],57);
516 else line += string(57,
'C');
519 if(j==linesOfComments){
522 strm << line << endl;
536 s <<
"SP3 Header: version " << versionString() <<
" containing ";
537 if(containsVelocity) s <<
"positions and velocities.";
538 else s <<
"positions only.";
541 s <<
" Time tag : " << ct.
printf(
"%4Y/%02m/%02d %2H:%02M:%02S") << endl;
542 s <<
" Timespacing is " << epochInterval
543 <<
" sec, and the number of epochs is " << numberOfEpochs << endl;
544 s <<
" Data used as input : " << dataUsed << endl;
545 s <<
" Coordinate system : " << coordSystem << endl;
546 s <<
" Orbit estimate type : " << orbitType << endl;
547 s <<
" Agency : " <<
agency << endl;
549 s <<
" File type: '" << system.systemChar() <<
"' which is "
550 << system.systemString() << endl;
551 s <<
" Time System: " << timeSystemString() << endl;
552 s <<
" Base for Pos/Vel =" << fixed << setw(10) << setprecision(7)
554 s <<
" Base for Clk/Rate =" << setw(12) << setprecision(9)
558 s <<
" List of satellite PRN/accuracy (" << satList.size() <<
" total) :\n";
560 std::map<SP3SatID,short>::const_iterator it=satList.begin();
561 while(it != satList.end()) {
562 s <<
" " << it->first <<
"/" << it->second;
563 if(!(++i % 8)) s << endl;
569 for(
size_t j=0; j<comments.size(); j++) s <<
" " << comments[j] << endl;
571 s <<
"End of SP3 header" << endl;