RinexMetData.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: RinexMetData.cpp 438 2007-03-21 17:22:21Z btolman $"
00002 
00003 
00004 
00005 //============================================================================
00006 //
00007 //  This file is part of GPSTk, the GPS Toolkit.
00008 //
00009 //  The GPSTk is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU Lesser General Public License as published
00011 //  by the Free Software Foundation; either version 2.1 of the License, or
00012 //  any later version.
00013 //
00014 //  The GPSTk is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with GPSTk; if not, write to the Free Software Foundation,
00021 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //  
00023 //  Copyright 2004, The University of Texas at Austin
00024 //
00025 //============================================================================
00026 
00027 //============================================================================
00028 //
00029 //This software developed by Applied Research Laboratories at the University of
00030 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00031 //Department of Defense. The U.S. Government retains all rights to use,
00032 //duplicate, distribute, disclose, or release this software. 
00033 //
00034 //Pursuant to DoD Directive 523024 
00035 //
00036 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00037 //                           release, distribution is unlimited.
00038 //
00039 //=============================================================================
00040 
00041 
00042 
00043 
00044 
00045 
00051 #include "StringUtils.hpp"
00052 #include "DayTime.hpp"
00053 #include "RinexMetHeader.hpp"
00054 #include "RinexMetData.hpp"
00055 #include "RinexMetStream.hpp"
00056 
00057 using namespace gpstk::StringUtils;
00058 using namespace std;
00059 
00060 namespace gpstk
00061 {
00062    const int RinexMetData::maxObsPerLine = 8;
00063    const int RinexMetData::maxObsPerContinuationLine = 10;
00064 
00065    void RinexMetData::reallyPutRecord(FFStream& ffs) const
00066       throw(std::exception, FFStreamError, 
00067             gpstk::StringUtils::StringException)
00068    {
00069       const int maxObsPerOutputLine = 8;
00070       const int maxObsPerOutputContLine = 10;
00071 
00072       RinexMetStream& strm = dynamic_cast<RinexMetStream&>(ffs);
00073       string line;
00074       
00075          // write the first line
00076       line += " ";
00077       line += rightJustify(asString<short>(time.year()),2,'0');
00078       line += " ";
00079       line += rightJustify(asString<short>(time.month()),2);
00080       line += " ";
00081       line += rightJustify(asString<short>(time.day()),2);
00082       line += " ";
00083       line += rightJustify(asString<short>(time.hour()),2);
00084       line += " ";
00085       line += rightJustify(asString<short>(time.minute()),2);
00086       line += " ";
00087       line += rightJustify(asString<short>(short(time.second())),2);
00088       
00089       for (int i = 0; 
00090            (i < strm.header.obsTypeList.size()) &&
00091               (i < maxObsPerOutputLine);
00092            i++)
00093       {
00094          RinexMetHeader::RinexMetType thistype = strm.header.obsTypeList[i];
00095          RinexMetMap::const_iterator itr = data.find(thistype);
00096          if (itr == data.end())
00097          {
00098             FFStreamError err("Couldn't find data for " + 
00099                               RinexMetHeader::convertObsType(strm.header.obsTypeList[i]));
00100             GPSTK_THROW(err);
00101          }
00102          line += rightJustify(asString((*itr).second,1),7);
00103       }
00104       
00105          // do we need continuation lines?
00106       if (strm.header.obsTypeList.size() > maxObsPerOutputLine)
00107       {
00108          for (int i = maxObsPerOutputLine;
00109               i < strm.header.obsTypeList.size();
00110               i++)
00111          {
00112             
00113             if (((i - maxObsPerOutputLine) % maxObsPerOutputContLine) == 0)
00114             {
00115                ffs << line << endl;
00116                strm.lineNumber++;
00117                line.clear();
00118                line += string(4,' ');
00119             }
00120             RinexMetHeader::RinexMetType thistype = strm.header.obsTypeList[i];
00121             RinexMetMap::const_iterator itr = data.find(thistype);
00122             if (itr == data.end())
00123             {
00124                FFStreamError err("Couldn't find data for " + 
00125                   RinexMetHeader::convertObsType(strm.header.obsTypeList[i]));
00126                GPSTK_THROW(err);
00127             }
00128             line += rightJustify(asString((*itr).second,1),7);
00129          }
00130       }
00131       
00132       ffs << line << endl;
00133       strm.lineNumber++;
00134    }
00135 
00136    void RinexMetData::reallyGetRecord(FFStream& ffs) 
00137       throw(std::exception, FFStreamError, 
00138             gpstk::StringUtils::StringException)
00139    {
00140       RinexMetStream& strm = dynamic_cast<RinexMetStream&>(ffs);
00141       
00142       if(!strm.headerRead)
00143          strm >> strm.header;
00144       
00145       RinexMetHeader& hdr = strm.header;
00146       
00147       string line;
00148       data.clear();
00149       
00150          // this is to see whether or not we expect an EOF
00151          // when we read this next line
00152       if (hdr.obsTypeList.size() > maxObsPerLine)
00153          strm.formattedGetLine(line); 
00154       else
00155          strm.formattedGetLine(line, true); 
00156 
00157       processFirstLine(line, hdr);
00158       
00159       time = parseTime(line);
00160       
00161       while (data.size() < hdr.obsTypeList.size())
00162       {
00163          if (hdr.obsTypeList.size() - data.size() < maxObsPerContinuationLine)
00164             strm.formattedGetLine(line, true); 
00165          else
00166             strm.formattedGetLine(line);
00167          processContinuationLine(line, hdr);
00168       }
00169       
00170       if (data.size() != hdr.obsTypeList.size())
00171       {
00172          FFStreamError e("Incorrect number of records");
00173          GPSTK_THROW(e);
00174       }
00175    } 
00176 
00177    void RinexMetData::processFirstLine(const string& line,
00178                                        const RinexMetHeader& hdr)
00179       throw(FFStreamError)
00180    {
00181       try
00182       {
00183           for (int i = 0; 
00184               (i < maxObsPerLine) && (i < hdr.obsTypeList.size());
00185               i++)
00186          {
00187             int currPos = i * 7 + 18;
00188             data[hdr.obsTypeList[i]] = asDouble(line.substr(currPos,7));
00189          }
00190       }
00191       catch (std::exception &e)
00192       {
00193          FFStreamError err("std::exception: " + string(e.what()));
00194          GPSTK_THROW(err);
00195       }
00196    }
00197 
00198    void RinexMetData::processContinuationLine(const string& line,
00199                                               const RinexMetHeader& hdr)
00200       throw(FFStreamError)
00201    {
00202       try
00203       {
00204          int currentElements = data.size();
00205          for (int i = currentElements; 
00206               (i < (maxObsPerContinuationLine + currentElements)) && 
00207                  (i < hdr.obsTypeList.size());
00208               i++)
00209          {
00210             int currPos = ((i - maxObsPerLine) % maxObsPerContinuationLine) * 7 
00211                + 4;
00212             data[hdr.obsTypeList[i]] = asDouble(line.substr(currPos,7));
00213          }
00214       }
00215       catch (std::exception &e)
00216       {
00217          FFStreamError err("std::exception: " + string(e.what()));
00218          GPSTK_THROW(err);
00219       }
00220    }
00221 
00222    DayTime RinexMetData::parseTime(const string& line) const
00223       throw(FFStreamError)
00224    {
00225       try
00226       {
00227             // according to the RINEX spec, any 2 digit year 80 or greater
00228             // is a year in the 1900s (1980-1999), under 80 is 2000s
00229          const int YearRollover = 80;
00230          
00231             // check if the spaces are in the right place - an easy way to check
00232             // if there's corruption in the file
00233          if ( (line[0] != ' ') ||
00234               (line[3] != ' ') ||
00235               (line[6] != ' ') ||
00236               (line[9] != ' ') ||
00237               (line[12] != ' ') ||
00238               (line[15] != ' '))
00239          {
00240             FFStreamError e("Invalid time format");
00241             GPSTK_THROW(e);
00242          }
00243          
00244          int year, month, day, hour, min;
00245          double sec;
00246          
00247          year  = asInt(   line.substr(1,  2 ));
00248          month = asInt(   line.substr(3,  3 ));
00249          day   = asInt(   line.substr(6,  3 ));
00250          hour  = asInt(   line.substr(9,  3 ));
00251          min   = asInt(   line.substr(12, 3 ));
00252          sec   = asInt(   line.substr(15, 3 ));
00253          
00254          if (year < YearRollover)
00255          {
00256             year += 100;
00257          }
00258          year += 1900;
00259          
00260          DayTime rv(year, month, day, hour, min, sec);
00261          return rv;
00262       }
00263       catch (std::exception &e)
00264       {
00265          FFStreamError err("std::exception: " + string(e.what()));
00266          GPSTK_THROW(err);
00267       }
00268    }
00269 
00270    void RinexMetData::dump(ostream& s) const
00271    {
00272       s << time << endl;
00273 
00274       RinexMetMap::const_iterator itr;
00275       for(itr = data.begin(); itr != data.end(); itr++)
00276       {
00277          s << RinexMetHeader::convertObsType((*itr).first) 
00278            << " " << (*itr).second << endl;
00279       }
00280    }
00281 
00282 
00283 
00284 }  // end of namespace

Generated on Thu Feb 9 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1