YumaData.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: YumaData.cpp 2741 2011-06-22 16:37:02Z nwu $"
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 
00030 #include "StringUtils.hpp"
00031 #include "icd_200_constants.hpp"
00032 
00033 #include "YumaData.hpp"
00034 #include "YumaStream.hpp"
00035 
00036 
00037 using namespace gpstk::StringUtils;
00038 using namespace std;
00039 
00040 namespace gpstk
00041 {
00042    short YumaData::nearFullWeek = 0;
00043 
00044    const std::string YumaData::sID   = "ID:";
00045    const std::string YumaData::sHlth = "Health:";
00046    const std::string YumaData::sEcc  = "Eccentricity:";
00047    const std::string YumaData::sTOA  = "Time of Applicability(s):";
00048    const std::string YumaData::sOrbI = "Orbital Inclination(rad):";
00049    const std::string YumaData::sRRA  = "Rate of Right Ascen(r/s):";
00050    const std::string YumaData::sSqrA = "SQRT(A)  (m 1/2):";
00051    const std::string YumaData::sRtAs = "Right Ascen at Week(rad):";
00052    const std::string YumaData::sArgP = "Argument of Perigee(rad):";
00053    const std::string YumaData::sMnAn = "Mean Anom(rad):";
00054    const std::string YumaData::sAf0  = "Af0(s):";
00055    const std::string YumaData::sAf1  = "Af1(s/s):";
00056    const std::string YumaData::sweek = "week:";
00057 
00058    void YumaData::reallyPutRecord(FFStream& ffs) const
00059       throw(std::exception, FFStreamError,
00060                gpstk::StringUtils::StringException)
00061    {
00062       YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
00063 
00064       const int width=27;
00065       strm << "******** Week" << setw(5) << (week % 1024)
00066            << " almanac for PRN-" << PRN
00067            << " ********" << endl
00068            << left
00069            << setw(width) << sID   << PRN << endl
00070            << setw(width) << sHlth << hex << SV_health << endl
00071            << setw(width) << sEcc  << ecc << endl
00072            << setw(width) << sTOA  << Toa << endl
00073            << setw(width) << sOrbI << (i_offset + 54.0 * (gpstk::PI / 180.0)) << endl
00074            << setw(width) << sRRA  << OMEGAdot << endl
00075            << setw(width) << sSqrA << Ahalf << endl
00076            << setw(width) << sRtAs << OMEGA0 << endl
00077            << setw(width) << sArgP << w << endl
00078            << setw(width) << sMnAn << M0 << endl
00079            << setw(width) << sAf0  << AF0 << endl
00080            << setw(width) << sAf1  << AF1 << endl
00081            << setw(width) << sweek << week << endl;
00082    }   // end YumaData::reallyPutRecord
00083 
00084 
00085    string YumaData::lineParser(const string& line, const string& s)
00086       const throw(FFStreamError)
00087    {
00088       int i = line.find_first_of(":");
00089 
00090       // Gotta have a colon or the format is wrong
00091       if (i == string::npos)
00092          GPSTK_THROW(FFStreamError("Format error in YumaData"));
00093 
00094       // Only compare the first five characters since some files differ after that
00095       int w = std::min(5, std::min(i, (int)s.size()));
00096       if (line.substr(0,w) != s.substr(0,w))
00097          GPSTK_THROW(FFStreamError("Format error in YumaData"));
00098 
00099       return stripLeading(line.substr(i+1), " ");
00100    }
00101 
00102 
00103    void YumaData::reallyGetRecord(FFStream& ffs)
00104       throw(std::exception, FFStreamError,
00105                gpstk::StringUtils::StringException)
00106    {
00107       YumaStream& strm = dynamic_cast<YumaStream&>(ffs);
00108 
00109       string line;
00110 
00111       // We don't need first line as we will get all the information from the others
00112       strm.formattedGetLine(line, true);
00113 
00114       //Second Line - PRN
00115       strm.formattedGetLine(line, true);
00116       PRN = asInt(lineParser(line, sID));
00117 
00118       //Third Line - Satellite Health
00119       strm.formattedGetLine(line, true);
00120       SV_health = asInt(lineParser(line, sHlth));
00121 
00122       //Fourth Line - Eccentricity
00123       strm.formattedGetLine(line, true);
00124       ecc = asDouble(lineParser(line, sEcc));
00125 
00126       //Fifth Line - Time of Applicability
00127       strm.formattedGetLine(line, true);
00128       Toa = (long) asDouble(lineParser(line, sTOA));
00129 
00130       //Sixth Line - Orbital Inclination
00131       strm.formattedGetLine(line, true);
00132       double i_total = asDouble(lineParser(line, sOrbI));
00133       i_offset = i_total - 54.0 * (gpstk::PI / 180.0);
00134 
00135       //Seventh Line - Rate of Right Ascen
00136       strm.formattedGetLine(line, true);
00137       OMEGAdot = asDouble(lineParser(line, sRRA));
00138 
00139       //Eigth Line - SqrtA
00140       strm.formattedGetLine(line, true);
00141       Ahalf = asDouble(lineParser(line, sSqrA));
00142 
00143       //Ninth Line - Right Ascen at Week
00144       strm.formattedGetLine(line, true);
00145       OMEGA0 = asDouble(lineParser(line, sRtAs));
00146 
00147       //Tenth Line - Argument of Perigee
00148       strm.formattedGetLine(line, true);
00149       w = asDouble(lineParser(line, sArgP));
00150 
00151       //Eleventh Line - Mean Anomaly
00152       strm.formattedGetLine(line, true);
00153       M0 = asDouble(lineParser(line, sMnAn));
00154 
00155       //Twelfth Line - Af0
00156       strm.formattedGetLine(line, true);
00157       AF0 = asDouble(lineParser(line, sAf0));
00158 
00159       //Thirteenth Line - Af1
00160       strm.formattedGetLine(line, true);
00161       AF1 = asDouble(lineParser(line, sAf1));
00162 
00163       //Fourteenth Line - week
00164       // Its unclear whether this is a full week or week % 1024
00165       strm.formattedGetLine(line, true);
00166       week = asInt(lineParser(line, sweek));
00167 
00168       if (nearFullWeek > 0)
00169       {
00170             // In case a full week is provided.
00171          week %= 1024;
00172          week += (nearFullWeek / 1024) * 1024;
00173          short diff = nearFullWeek - week;
00174          if (diff > 512)
00175             week += 512;
00176          else if(diff < -512)
00177             week -= 512;
00178       }
00179 
00180       xmit_time = 0;
00181       strm.formattedGetLine(line,true);
00182 
00183    } // end of reallyGetRecord()
00184 
00185    void YumaData::dump(ostream& s) const
00186    {
00187       cout << "PRN = " << PRN << endl;
00188       cout << "week = " << week << endl;
00189       cout << "SV_health = " << SV_health << endl;
00190       cout << "ecc = " << ecc << endl;
00191       cout << "Toa = " << Toa << endl;
00192       cout << "i_offset = " << i_offset << endl;
00193       cout << "OMEGAdot = " << OMEGAdot << endl;
00194       cout << "Ahalf = " << Ahalf << endl;
00195       cout << "OMEGA0 = " << OMEGA0 << endl;
00196       cout << "w = " << w << endl;
00197       cout << "M0 = " << M0 << endl;
00198       cout << "AF0 = " << AF0 << endl;
00199       cout << "AF1 = " << AF1 << endl;
00200       cout << "xmit_time = " << xmit_time << endl;
00201 
00202    } // end of dump()
00203 
00204    YumaData::operator AlmOrbit() const
00205    {
00206       AlmOrbit ao(PRN, ecc,i_offset, OMEGAdot, Ahalf, OMEGA0,
00207                    w, M0, AF0, AF1, Toa, xmit_time, week, SV_health);
00208 
00209       return ao;
00210 
00211    } // end of AlmOrbit()
00212 } // namespace

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