00001 #pragma ident "$Id: AntexHeader.cpp 2293 2010-02-12 18:14:16Z btolman $"
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 "AntexHeader.hpp"
00046 #include "AntexStream.hpp"
00047
00048 using namespace std;
00049 using namespace gpstk::StringUtils;
00050
00051 namespace gpstk
00052 {
00053 const string AntexHeader::versionString = "ANTEX VERSION / SYST";
00054 const string AntexHeader::pcvTypeString = "PCV TYPE / REFANT";
00055 const string AntexHeader::headerCommentString = "COMMENT";
00056 const string AntexHeader::endOfHeaderString = "END OF HEADER";
00057
00058 void AntexHeader::reallyPutRecord(FFStream& ffs) const
00059 throw(std::exception, FFStreamError, StringException)
00060 {
00061 AntexStream& strm = dynamic_cast<AntexStream&>(ffs);
00062
00063 strm.header = *this;
00064
00065 unsigned long allValid;
00066 if (version == 1.3) allValid = allValid13;
00067 else {
00068 FFStreamError err("Unknown Antex version: " + asString(version,2));
00069 err.addText("Make sure to set the version correctly.");
00070 GPSTK_THROW(err);
00071 }
00072
00073 if ((valid & allValid) != allValid) {
00074 FFStreamError err("Incomplete or invalid header.");
00075 err.addText("Set all header valid bits for all of the available data.");
00076 GPSTK_THROW(err);
00077 }
00078
00079 try {
00080 WriteHeaderRecords(strm);
00081 }
00082 catch(FFStreamError& e) { GPSTK_RETHROW(e); }
00083 catch(StringException& e) { GPSTK_RETHROW(e); }
00084
00085 }
00086
00087
00088
00089 void AntexHeader::WriteHeaderRecords(FFStream& ffs) const
00090 throw(FFStreamError, StringException)
00091 {
00092 AntexStream& strm = dynamic_cast<AntexStream&>(ffs);
00093 string line;
00094
00095 if(valid & versionValid|systemValid) {
00096 line = rightJustify(asString(version,1), 8);
00097 line += string(12,' ');
00098 line += system;
00099 line = leftJustify(line, 60);
00100 line += versionString;
00101 strm << leftJustify(line,80) << endl;
00102 strm.lineNumber++;
00103 }
00104 if(valid & pcvTypeValid) {
00105 line = pcvType;
00106 line += string(19,' ');
00107 line += leftJustify(refAntType, 20);
00108 line += leftJustify(refAntSerNum, 20);
00109 line += pcvTypeString;
00110 strm << leftJustify(line,80) << endl;
00111 strm.lineNumber++;
00112 }
00113 if(valid & commentValid) {
00114 vector<string>::const_iterator itr = commentList.begin();
00115 while(itr != commentList.end()) {
00116 line = leftJustify((*itr), 60);
00117 line += headerCommentString;
00118 strm << leftJustify(line,80) << endl;
00119 strm.lineNumber++;
00120 itr++;
00121 }
00122 }
00123 if(valid & endValid) {
00124 line = string(60, ' ');
00125 line += endOfHeaderString;
00126 strm << leftJustify(line,80) << endl;
00127 strm.lineNumber++;
00128 }
00129 }
00130
00131
00132 void AntexHeader::ParseHeaderRecord(string& line)
00133 throw(FFStreamError)
00134 {
00135 string label(line, 60, 20);
00136
00137 if(label == versionString) {
00138 version = asDouble(line.substr(0,8));
00139 system = line[20];
00140 if(system != ' ' && system != 'G' &&
00141 system != 'R' && system != 'E' && system != 'M')
00142 {
00143 FFStreamError e("Satellite system is invalid: " + system);
00144 GPSTK_THROW(e);
00145 }
00146 valid |= versionValid;
00147 valid |= systemValid;
00148 }
00149 else if(label == pcvTypeString) {
00150 pcvType = line[0];
00151 if(pcvType != 'A' && pcvType != 'R') {
00152 FFStreamError e("PCV type is invalid: " + pcvType);
00153 GPSTK_THROW(e);
00154 }
00155 refAntType = line.substr(20,20);
00156 refAntSerNum = line.substr(40,20);
00157 valid |= pcvTypeValid;
00158 }
00159 else if(label == headerCommentString) {
00160 commentList.push_back(stripTrailing(line.substr(0,60)));
00161 valid |= commentValid;
00162 }
00163 else if(label == endOfHeaderString) {
00164 valid |= endValid;
00165 }
00166 else {
00167 FFStreamError e("Unidentified label: " + label);
00168 GPSTK_THROW(e);
00169 }
00170 }
00171
00172
00173
00174 void AntexHeader::reallyGetRecord(FFStream& ffs)
00175 throw(std::exception, FFStreamError, StringException)
00176 {
00177 AntexStream& strm = dynamic_cast<AntexStream&>(ffs);
00178
00179
00180 if (strm.headerRead == true)
00181 return;
00182
00183
00184
00185
00186
00187
00188 commentList.clear();
00189 version = 1.3;
00190 valid = 0;
00191
00192 string line;
00193 while(!(valid & endValid)) {
00194 strm.formattedGetLine(line);
00195 stripTrailing(line);
00196
00197 if (line.length()==0)
00198 continue;
00199 else if(line.length()<60 || line.length()>80) {
00200 FFStreamError e("Invalid line length");
00201 GPSTK_THROW(e);
00202 }
00203
00204 try { ParseHeaderRecord(line); }
00205 catch(FFStreamError& e) { GPSTK_RETHROW(e); }
00206
00207 }
00208
00209 unsigned long allValid;
00210 if (version == 1.3)
00211 allValid = allValid13;
00212 else {
00213 FFStreamError e("Unknown or unsupported Antex version " + asString(version));
00214 GPSTK_THROW(e);
00215 }
00216
00217 if((allValid & valid) != allValid) {
00218 FFStreamError e("Incomplete or invalid header");
00219 GPSTK_THROW(e);
00220 }
00221
00222
00223 strm.header = *this;
00224 strm.headerRead = true;
00225
00226 }
00227
00228 void AntexHeader::dump(ostream& s) const
00229 {
00230 s << "Dump of AntexHeader, version " << fixed << setprecision(1)
00231 << version << " system " << system << endl;
00232 s << "These are " << (pcvType == 'A' ? "absolute" : "relative")
00233 << " phase center offsets.\n";
00234 s << "Reference antenna: type " << refAntType
00235 << ", serial no. " << refAntSerNum << endl;
00236
00237 for(int i=0; i<commentList.size(); i++) {
00238 if(i==0) s << "Comments:\n";
00239 s << "Comment " << setw(2) << i+1 << ": " << commentList[i] << endl;
00240 }
00241 s << "End of AntexHeader dump" << endl;
00242 }
00243
00244 }