SP3Data.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: SP3Data.cpp 1073 2008-01-24 20:16:04Z pben $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 //============================================================================
00026 //
00027 //This software developed by Applied Research Laboratories at the University of
00028 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00029 //Department of Defense. The U.S. Government retains all rights to use,
00030 //duplicate, distribute, disclose, or release this software. 
00031 //
00032 //Pursuant to DoD Directive 523024 
00033 //
00034 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00035 //                           release, distribution is unlimited.
00036 //
00037 //=============================================================================
00038 
00039 
00045 #include "SP3Stream.hpp"
00046 #include "SP3Header.hpp"
00047 #include "SP3Data.hpp"
00048 #include "StringUtils.hpp"
00049 #include "DayTime.hpp"
00050 
00051 using namespace gpstk::StringUtils;
00052 using namespace std;
00053 
00054 namespace gpstk
00055 {
00056    void SP3Data::reallyPutRecord(FFStream& ffs) const 
00057       throw(std::exception, FFStreamError, StringException)
00058    {
00059       SP3Stream& strm = dynamic_cast<SP3Stream&>(ffs);
00060       
00061       string line;
00062       if(flag == '*') {// output Epoch Header Record
00063          line = "* ";
00064          line += time.printf(" %4Y %2m %2d %2H %2M");
00065          line += " " + rightJustify(time.printf("%.8f"),11);
00066       }
00067       else {           // output Position and Clock OR Velocity and Clock Rate Record
00068          line = flag;
00069          if(version == 'c')
00070             line += SP3SatID(sat).toString();
00071          else
00072             line += rightJustify(asString(sat.id),3);
00073          line += rightJustify(asString(x[0],6),14);
00074          line += rightJustify(asString(x[1],6),14);
00075          line += rightJustify(asString(x[2],6),14);
00076          line += rightJustify(asString(clk,6),14);
00077          if(version == 'c') {
00078             line += rightJustify(asString(sig[0]),3);
00079             line += rightJustify(asString(sig[1]),3);
00080             line += rightJustify(asString(sig[2]),3);
00081             line += rightJustify(asString(sig[3]),4);
00082             if(flag == 'P') {
00083                line += string(" ");
00084                line += (clockEventFlag ? string("E") : string(" "));
00085                line += (clockPredFlag ? string("P") : string(" "));
00086                line += string("  ");
00087                line += (orbitManeuverFlag ? string("M") : string(" "));
00088                line += (orbitPredFlag ? string("P") : string(" "));
00089             }
00090             //else {
00091             //   line += string("       ");
00092             //}
00093          }
00094 
00095          // if version is 'c' and correlation flag is set,
00096          // output P|V Correlation Record
00097          if(version == 'c' && correlationFlag) {
00098             // first output the P|V record
00099             strm << line << endl;
00100 
00101             // now output the correlation record
00102             if(flag == 'P') line = "EP ";
00103             else line = "EV ";
00104             line += rightJustify(asString(sdev[0]),5);
00105             line += rightJustify(asString(sdev[1]),5);
00106             line += rightJustify(asString(sdev[2]),5);
00107             line += rightJustify(asString(sdev[3]),8);
00108             for(int i=0; i<6; i++)
00109                line += rightJustify(asString(correlation[i]),9);
00110          }
00111       }
00112 
00113       // write the line
00114       strm << line << endl;
00115    }
00116 
00117    void SP3Data::dump(ostream& s) const 
00118    {
00119       s << flag << " " << sat
00120          << " " << time.printf("%Y/%02m/%02d %2H:%02M:%06.3f = %F/%10.3g");
00121       if(flag != '*') {
00122          s << fixed << setprecision(6)
00123            << " X=" << setw(14) << x[0]
00124            << " Y=" << setw(14) << x[1]
00125            << " Z=" << setw(14) << x[2]
00126            << " C=" << setw(14) << clk;
00127 
00128          if(version == 'c') {
00129             s << " sX=" << setw(2) << sig[0]
00130               << " sY=" << setw(2) << sig[1]
00131               << " sZ=" << setw(2) << sig[2]
00132               << " sC=" << setw(3) << sig[3];
00133             if(flag == 'P')
00134               s << " " << (clockEventFlag ? "clockEvent" : "-")
00135                 << " " << (clockPredFlag ? "clockPrediction" : "-")
00136                 << " " << (orbitManeuverFlag ? "orbitManeuver" : "-")
00137                 << " " << (orbitPredFlag ? "orbitPrediction" : "-");
00138             if(correlationFlag)
00139                s << endl
00140                  << 'E' << flag
00141                  << " cXX=" << setw(4) << sdev[0]
00142                  << " cYY=" << setw(4) << sdev[1]
00143                  << " cZZ=" << setw(4) << sdev[2]
00144                  << " cCC=" << setw(7) << sdev[3]
00145                  << " cXY=" << setw(8) << correlation[0]
00146                  << " cXZ=" << setw(8) << correlation[1]
00147                  << " cXC=" << setw(8) << correlation[2]
00148                  << " cYZ=" << setw(8) << correlation[3]
00149                  << " cYC=" << setw(8) << correlation[4]
00150                  << " cZC=" << setw(8) << correlation[5];
00151          }
00152       }
00153       s << endl;
00154    };
00155 
00156    void SP3Data::reallyGetRecord(FFStream& ffs)
00157       throw(std::exception, FFStreamError, StringException)
00158    {
00159       SP3Stream& strm = dynamic_cast<SP3Stream&>(ffs);
00160 
00161       correlationFlag = false;
00162       int status = 0;                                          // initial status = 0
00163       while(1) {
00164          // set the time in the record
00165          time = strm.currentEpoch;
00166 
00167          // ---------------------------------------------------------
00168          // process the buffer containing the last line read
00169          if(strm.buffer.size() < 3) {
00170             // nothing in buffer - do nothing here, get another line
00171             ;
00172          }
00173 
00174          else if(strm.buffer.substr(0,3) == string("EOF")) {      // 'EOF' record
00175             // if a data record has been processed during this call, then
00176             // return and let the next call process this EOF.
00177             //if(status == 1) throw - found EOF right after an epoch record
00178             if(status > 1) break;
00179 
00180             // this next read had better fail - if it does, an exception will
00181             // be thrown, and the FFStreamError created next won't get thrown
00182             strm.formattedGetLine(strm.buffer, true);
00183          
00184             FFStreamError err("EOF text found but file didn't end");
00185             GPSTK_THROW(err);
00186          }
00187 
00188          else if(strm.buffer[0] == '*') {                         // Epoch record
00189             // if another record has been process during this call, quit now
00190             if(status > 0) break;
00191             status = 1;                                           // epoch status = 1
00192 
00193             // throw if the line is short
00194             if(strm.buffer.size() <= 30) {
00195                FFStreamError err("Invalid line length "+asString(strm.buffer.size()));
00196                GPSTK_THROW(err);                  
00197             }
00198 
00199             // parse the epoch line
00200             int year = asInt(strm.buffer.substr(3,4));
00201             int month = asInt(strm.buffer.substr(8,2));
00202             int dom = asInt(strm.buffer.substr(11,2));
00203             int hour = asInt(strm.buffer.substr(14,2));
00204             int minute = asInt(strm.buffer.substr(17,2));
00205             double second = asInt(strm.buffer.substr(20,10));
00206             DayTime t;
00207             try {
00208                t = DayTime(year, month, dom, hour, minute, second);
00209             } catch (DayTime::DayTimeException& e) {
00210                FFStreamError fe("Invalid time in:" + strm.buffer);
00211                GPSTK_THROW(fe);
00212             }               
00213             time = strm.currentEpoch = t;
00214          }
00215 
00216          else if(strm.buffer[0] == 'P' || strm.buffer[0] == 'V') {// P|V record
00217             // if nothing, or epoch record, was processed during this call,
00218             // process this P|V, otherwise (P|V or EP|V were processed), quit now
00219             if(status > 1) break;
00220             status = 2;                                           // P|V status = 2
00221 
00222             flag = strm.buffer[0];     // P or V
00223 
00224             // 6/20/07 IGS SP3c files sometimes have short lines, apparently implying
00225             // zero sigma and no flags...add the following to be tolerant of this.
00226             if (version == 'a' && (strm.buffer.substr(1,1)=="G" ||
00227                                    strm.buffer.substr(1,1)=="R" ||
00228                                    strm.buffer.substr(1,1)=="L" ||
00229                                    strm.buffer.substr(1,1)=="E"))
00230             {
00231                version='c';   
00232             }
00233             
00234                                    
00235             if (version == 'c' && strm.buffer.size() < 73 && strm.buffer.size() > 59)
00236                leftJustify(strm.buffer,73);
00237 
00238             // throw if the line is short
00239             if ((version == 'a' && strm.buffer.size() < 60) ||
00240                (version == 'c' && strm.buffer.size() < 73) ) {
00241                FFStreamError err("Invalid line length "+asString(strm.buffer.size()));
00242                GPSTK_THROW(err);
00243             }
00244 
00245             // parse the line
00246             if(version == 'a')
00247                sat = SatID(asInt(strm.buffer.substr(1, 3)), SP3SatID::systemGPS);
00248             else
00249                sat = SP3SatID(strm.buffer.substr(1,3));
00250 
00251             x[0] = asDouble(strm.buffer.substr(4,14));
00252             x[1] = asDouble(strm.buffer.substr(18,14));
00253             x[2] = asDouble(strm.buffer.substr(32,14));
00254             clk = asDouble(strm.buffer.substr(46,14));
00255 
00256             if(version == 'c') {
00257                // get sigmas from P|V record
00258                sig[0] = asInt(strm.buffer.substr(61,2));
00259                sig[1] = asInt(strm.buffer.substr(64,2));
00260                sig[2] = asInt(strm.buffer.substr(67,2));
00261                sig[3] = asInt(strm.buffer.substr(70,3));
00262 
00263                // get flags
00264                if(flag == 'P') {
00265                   clockEventFlag = clockPredFlag
00266                      = orbitManeuverFlag = orbitPredFlag = false;
00267                   if(strm.buffer.size() >= 75 && strm.buffer[74] == 'E')
00268                      clockEventFlag = true;
00269                   if(strm.buffer.size() >= 76 && strm.buffer[75] == 'P')
00270                      clockPredFlag = true;
00271                   if(strm.buffer.size() >= 79 && strm.buffer[78] == 'M')
00272                      orbitManeuverFlag = true;
00273                   if(strm.buffer.size() >= 80 && strm.buffer[79] == 'P')
00274                      orbitPredFlag = true;
00275                }
00276             }
00277 
00278          }
00279          else if(strm.buffer[0] == 'E' &&                      // EP|EV record
00280                (strm.buffer[1] == 'P' || strm.buffer[1] == 'V')) {
00281 
00282             // always process an EP|V immediately, since it must follow P|V
00283             status = 3;                                        // EP|V status = 3
00284 
00285             // throw if correlation record did not follow corresponding P|V record
00286             if(strm.buffer[1] != flag) {
00287                Exception e("SP3c correlation record mismatched with previous P|V");
00288                GPSTK_THROW(e);
00289             }
00290 
00291             // throw if line is short
00292             if(strm.buffer.size()<80) {
00293                FFStreamError err("Invalid SP3c correlation line length "
00294                   + asString(strm.buffer.size()));
00295                GPSTK_THROW(err);
00296             }
00297 
00298             sdev[0] = abs(asInt(strm.buffer.substr(4,4)));
00299             sdev[1] = abs(asInt(strm.buffer.substr(9,4)));
00300             sdev[2] = abs(asInt(strm.buffer.substr(14,4)));
00301             sdev[3] = abs(asInt(strm.buffer.substr(19,7)));
00302             correlation[0] = asInt(strm.buffer.substr(27,8));
00303             correlation[1] = asInt(strm.buffer.substr(36,8));
00304             correlation[2] = asInt(strm.buffer.substr(45,8));
00305             correlation[3] = asInt(strm.buffer.substr(54,8));
00306             correlation[4] = asInt(strm.buffer.substr(63,8));
00307             correlation[5] = asInt(strm.buffer.substr(72,8));
00308 
00309             // tell the caller that correlation data is now present
00310             correlationFlag = true;
00311          }
00312 
00313          else {                              // Unknown record
00314             FFStreamError err("Unknown line label " + strm.buffer.substr(0,2));
00315             GPSTK_THROW(err);
00316          }
00317 
00318          // ---------------------------------------------------------
00319          // read next line into the buffer
00320          strm.formattedGetLine(strm.buffer);
00321 
00322          // ---------------------------------------------------------
00323          // quit if EP|EV was processed
00324          if(status == 3) break;
00325          // go back if buffer was empty    (0)
00326          // go back if epoch was processed (1)
00327          // go back if P|V was processed   (2)
00328       }
00329 
00330    }   // end reallyGetRecord()
00331 
00332 } // namespace

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