RinexGloNavHeader.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id"
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 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2011
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "StringUtils.hpp"
00032 #include "DayTime.hpp"
00033 #include "RinexGloNavHeader.hpp"
00034 #include "RinexGloNavStream.hpp"
00035 
00036 #include <iostream>
00037 
00038 using namespace gpstk::StringUtils;
00039 using namespace std;
00040 
00041 namespace gpstk
00042 {
00043    const string RinexGloNavHeader::endOfHeader = "END OF HEADER";
00044    const string RinexGloNavHeader::leapSecondsString = "LEAP SECONDS";
00045    const string RinexGloNavHeader::corrToSystemTime = "CORR TO SYSTEM TIME";
00046    const string RinexGloNavHeader::commentString = "COMMENT";
00047    const string RinexGloNavHeader::runByString = "PGM / RUN BY / DATE";
00048    const string RinexGloNavHeader::versionString = "RINEX VERSION / TYPE";
00049 
00050    void RinexGloNavHeader::reallyPutRecord(FFStream& ffs) const
00051       throw(std::exception, FFStreamError, StringException)
00052    {
00053       RinexGloNavStream& strm = dynamic_cast<RinexGloNavStream&>(ffs);
00054       
00055       strm.header = (*this);
00056       
00057       unsigned long allValid;
00058       if (version == 2.1)        allValid = allValid21;
00059       else
00060       {
00061          FFStreamError err(  "Unknown RINEX GLONASS version: "
00062                            + asString(version,3) );
00063          err.addText("Make sure to set the version correctly.");
00064          GPSTK_THROW(err);
00065       }
00066       
00067       if ((valid & allValid) != allValid)
00068       {
00069          FFStreamError err("Incomplete or invalid header.");
00070          err.addText("Make sure you set all header valid bits for all of the available data.");
00071          GPSTK_THROW(err);
00072       }
00073       
00074       string line;
00075       
00076       if (valid & versionValid)
00077       {
00078          line  = rightJustify(asString(version,2), 9);
00079          line += string(11, ' ');
00080          line += string("G"); //leftJustify(fileType, 20);
00081          line += string(39, ' ');
00082          line += versionString;
00083          strm << line << endl;
00084          strm.lineNumber++;
00085       }
00086       if (valid & runByValid) 
00087       {
00088          line  = leftJustify(fileProgram,20);
00089          line += leftJustify(fileAgency,20);
00090          DayTime dt;
00091          dt.setLocalTime();
00092          string dat = dt.printf("%02d-%0b-%02y %02H:%02M");
00093          line += leftJustify(dat, 20);
00094          line += runByString;
00095          strm << line << endl;
00096          strm.lineNumber++;
00097       }
00098       if (valid & commentValid)
00099       {
00100          vector<string>::const_iterator itr = commentList.begin();
00101          while (itr != commentList.end())
00102          {
00103             line  = leftJustify((*itr), 60);
00104             line += commentString;
00105             strm << line << endl;
00106             strm.lineNumber++;
00107             itr++;
00108          }
00109       }
00110       if (valid & corrToSystemTimeValid)
00111       {
00112          line  = rightJustify(asString(yearRefTime),6);
00113          line += rightJustify(asString(monthRefTime),6);
00114          line += rightJustify(asString(dayRefTime),6);
00115          line += string(3, ' ');
00116          line += doub2for(minusTauC, 19, 2);
00117          line += string(20,' ');
00118          line += corrToSystemTime;
00119          strm << line << endl;
00120          strm.lineNumber++;
00121       }
00122       if (valid & leapSecondsValid)
00123       {
00124          line  = rightJustify(asString(leapSeconds), 6);
00125          line += string(54, ' ');
00126          line += leapSecondsString;
00127          strm << line << endl;
00128          strm.lineNumber++;
00129       }
00130       if (valid & endValid)
00131       {
00132          line  = string(60,' ');
00133          line += endOfHeader;
00134          strm << line << endl;
00135          strm.lineNumber++;
00136       }
00137       
00138    }
00139 
00140    void RinexGloNavHeader::reallyGetRecord(FFStream& ffs)
00141       throw(std::exception, FFStreamError, StringException)
00142    {
00143       RinexGloNavStream& strm = dynamic_cast<RinexGloNavStream&>(ffs);
00144       
00145          // if already read, just return
00146       if (strm.headerRead == true)
00147          return;
00148       
00149       valid = 0;
00150       
00151          // clear out anything that was unsuccessfully read the first
00152       commentList.clear();
00153       
00154       while (! (valid & endValid))
00155       {
00156          string line;
00157          strm.formattedGetLine(line);
00158          StringUtils::stripTrailing(line);
00159 
00160          if (line.length()==0) continue;
00161          else if (line.length()<60 || line.length()>80)
00162          {
00163             FFStreamError e("Invalid line length");
00164             GPSTK_THROW(e);
00165          }
00166          
00167          string thisLabel(line, 60, 20);
00168          
00169          if (thisLabel == versionString)
00170          {
00171             version = asDouble(line.substr(0,20));
00172             fileType = strip(line.substr(20,20));
00173             if ( (fileType[0] != 'G') &&
00174                  (fileType[0] != 'g'))
00175             {
00176                FFStreamError e("This isn't a Rinex GLONASS Nav file");
00177                GPSTK_THROW(e);
00178             }
00179             valid |= versionValid;
00180          }
00181          else if (thisLabel == runByString)
00182          {
00183             fileProgram = strip(line.substr(0,20));
00184             fileAgency = strip(line.substr(20,20));
00185             date = strip(line.substr(40,20));
00186             valid |= runByValid;
00187          }
00188          else if (thisLabel == commentString)
00189          {
00190             commentList.push_back(strip(line.substr(0,60)));
00191             valid |= commentValid;
00192          }
00193          else if (thisLabel == corrToSystemTime)
00194          {
00195             yearRefTime  = asInt(line.substr(0,6));
00196             monthRefTime = asInt(line.substr(6,6));
00197             dayRefTime   = asInt(line.substr(12,6));
00198             minusTauC = gpstk::StringUtils::for2doub(line.substr(21,19));
00199             valid |= corrToSystemTimeValid;
00200          }
00201          else if (thisLabel == leapSecondsString)
00202          {
00203             leapSeconds = asInt(line.substr(0,6));
00204             valid |= leapSecondsValid;
00205          }
00206          else if (thisLabel == endOfHeader)
00207          {
00208             valid |= endValid;
00209          }
00210          else
00211          {
00212             throw(FFStreamError("Unknown header label at line " + 
00213                                 asString<size_t>(strm.lineNumber)));
00214          }
00215       }
00216       
00217       unsigned long allValid;
00218       if      (version == 2.1)      allValid = allValid21;
00219       else
00220       {
00221          FFStreamError e( "Unknown or unsupported RINEX GLONASS sversion "
00222                          + asString(version) );
00223          GPSTK_THROW(e);
00224       }
00225       
00226       if ( (allValid & valid) != allValid)
00227       {
00228          FFStreamError e("Incomplete or invalid header");
00229          GPSTK_THROW(e);               
00230       }            
00231       
00232          // we got here, so something must be right...
00233       strm.header = *this;
00234       strm.headerRead = true;      
00235    }
00236 
00237    void RinexGloNavHeader::dump(ostream& s) const
00238    {
00239       int i;
00240        s << "---------------------------------- REQUIRED ----------------------------------\n";
00241       s << "Rinex Version " << fixed << setw(5) << setprecision(2) << version
00242          << ",  File type " << fileType << ".\n";
00243       s << "Prgm: " << fileProgram << ",  Run: " << date << ",  By: " << fileAgency << endl;
00244 
00245       s << "(This header is ";
00246       if((valid & allValid21) == allValid21) s << "VALID 2.1";
00247       else s << "NOT VALID";
00248       s << " Rinex.)\n";
00249 
00250       if(!(valid & versionValid)) s << " Version is NOT valid\n";
00251       if(!(valid & runByValid)) s << " Run by is NOT valid\n";
00252       if(!(valid & endValid)) s << " End is NOT valid\n";
00253 
00254       s << "---------------------------------- OPTIONAL ----------------------------------\n";
00255       if(valid & corrToSystemTimeValid) s << "Correction to System Time: Year="
00256          << yearRefTime << ", Month=" << monthRefTime << ", Day=" << dayRefTime
00257          << ", -TauC=" << scientific << setprecision(12) << minusTauC << ")\n";
00258       else s << " Correction to System Time is NOT valid\n";
00259       if(valid & leapSecondsValid) s << "Leap seconds: " << leapSeconds << endl;
00260       else s << " Leap seconds is NOT valid\n";
00261       if(commentList.size() > 0) {
00262          s << "Comments (" << commentList.size() << ") :\n";
00263          for(int i=0; i<commentList.size(); i++)
00264             s << commentList[i] << endl;
00265       }
00266       s << "-------------------------------- END OF HEADER -------------------------------\n";
00267    }
00268 
00269 }  // End of namespace gpstk

Generated on Tue May 22 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1