AntexHeader.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: AntexHeader.cpp 2293 2010-02-12 18:14:16Z btolman $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //  
00026 //  Copyright 2004, The University of Texas at Austin
00027 //
00028 //============================================================================
00029 
00030 //============================================================================
00031 //
00032 //This software developed by Applied Research Laboratories at the University of
00033 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00034 //Department of Defense. The U.S. Government retains all rights to use,
00035 //duplicate, distribute, disclose, or release this software. 
00036 //
00037 //Pursuant to DoD Directive 523024 
00038 //
00039 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00040 //                           release, distribution is unlimited.
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    }  // end AntexHeader::reallyPutRecord
00086       
00087 
00088       // this function writes all valid header records
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    }   // end AntexHeader::WriteHeaderRecords()
00130 
00131       // this function parses a single header record
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    }   // end of AntexHeader::ParseHeaderRecord(string& line)
00171 
00172 
00173       // This function parses the entire header from the given stream
00174    void AntexHeader::reallyGetRecord(FFStream& ffs)
00175       throw(std::exception, FFStreamError, StringException)
00176    {
00177       AntexStream& strm = dynamic_cast<AntexStream&>(ffs);
00178       
00179          // if already read, just return
00180       if (strm.headerRead == true)
00181          return;
00182 
00183          // since we're reading a new header, we need to reinitialize
00184          // all our list structures.  all the other objects should be ok.
00185          // this also applies if we threw an exception the first time we read
00186          // the header and are now re-reading it. some of these could be full
00187          // and we need to empty them.
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       }   // end while(not end of header)
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          // If we get here, we should have reached the end of header line
00223       strm.header = *this;
00224       strm.headerRead = true;
00225             
00226    }  // end of reallyGetRecord()
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 } // namespace gpstk

Generated on Wed Feb 8 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1