LinearClockModel.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: LinearClockModel.cpp 229 2006-10-13 17:13:41Z ocibu $"
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 
00047 #include <math.h>
00048 #include "Stats.hpp"
00049 
00050 #include "LinearClockModel.hpp"
00051 
00052 namespace gpstk
00053 {
00054    using namespace std;
00055 
00056    void LinearClockModel::reset() throw()
00057    {
00058       startTime == gpstk::DayTime::END_OF_TIME;
00059       endTime == gpstk::DayTime::BEGINNING_OF_TIME;
00060       clockObs.clear();
00061       prnStatus.clear();
00062       clockModel.Reset();
00063       tossCount=0;
00064    }
00065 
00066    void LinearClockModel::addEpoch(const ORDEpoch& oe)
00067       throw(gpstk::InvalidValue)
00068    {
00069       ORDEpoch::ORDMap::const_iterator itr;
00070       const gpstk::DayTime t=oe.time;
00071       
00072       // Start off by getting an estimate of this epoch's clock
00073       // note that this also sets the prn status map
00074       gpstk::Stats<double> stat = simpleOrdClock(oe);
00075       SvStatusMap& statusMap = prnStatus[t];
00076       statusMap = status;
00077 
00078       double mean;
00079       if (clockModel.N()==0)
00080       {
00081          double clkc = stat.Average();
00082          startTime = endTime = baseTime = t;
00083          tossCount = 0;
00084       }
00085 
00086       const double deltaT = t-baseTime;
00087 
00088       if (t<startTime)
00089          startTime=t;
00090       if (t>endTime)
00091          endTime=t;
00092 
00093       if (clockModel.N()>24)
00094          mean = clockModel.Slope()*deltaT + clockModel.Intercept();
00095       else
00096          mean = stat.Average();
00097 
00098       if (std::abs(stat.Average() - mean) > 20)
00099       {
00100          cout << t
00101               << " slope=" << setw(12) << clockModel.Slope()
00102               << ", intercept=" << setw(8) << clockModel.Intercept()
00103               << ", est=" << setw(8) << clockModel.Slope()*deltaT + clockModel.Intercept()
00104               << ", N=" << setw(6) << clockModel.N()
00105               << ", stdev=" << setw(6) << clockModel.StdDevY()
00106               << endl;
00107          tossCount++;
00108          if (tossCount>5)
00109          {
00110             reset();
00111             cout << "Reseting model" << endl;
00112          }
00113       }
00114       else
00115       {
00116          tossCount=0;
00117          for (itr = oe.ords.begin(); itr != oe.ords.end(); itr++)
00118             if (statusMap[itr->second.getSvID()] == USED)
00119             {
00120                const double ord = itr->second.getORD();
00121                clockModel.Add(deltaT, ord);
00122                std::pair<const double,double> o(deltaT, ord);
00123                clockObs.insert(o);
00124             }
00125       }
00126 
00127       std::multimap<double,double>::iterator i1,i2;
00128       i1 = clockObs.begin();
00129       while (i1!=clockObs.end())
00130       {
00131          i2=i1;
00132          i1++;
00133          double dt = i2->first;
00134          double ord = i2->second;
00135          if ((deltaT - dt)>1800)
00136          {
00137             clockObs.erase(i2);
00138             clockModel.Subtract(dt, ord);
00139          }
00140          else
00141             break;
00142       }
00143    }
00144 
00145    void LinearClockModel::dump(std::ostream& s, short detail) const throw()
00146    {
00147       s << "base: " << baseTime
00148         << ", start: " << startTime
00149         << ", end: " << endTime
00150         << endl
00151         << "Clock: est(end)=" << getOffset(endTime)
00152         << ", n=" << clockModel.N()
00153         << ", b=" << clockModel.Intercept()
00154         << ", m=" << clockModel.Slope()
00155         << ", sigma=" << clockModel.StdDevY()
00156         << ", r=" << clockModel.Correlation()
00157         << endl;
00158 
00159       if (detail>0)
00160       {
00161          s << "min elev: " << elvmask
00162            << ", max sigma: " << sigmam
00163            << endl;
00164 
00165          map<DayTime,SvStatusMap>::const_iterator e = prnStatus.find(endTime);
00166          const SvStatusMap& statusMap = e->second;
00167          SvStatusMap::const_iterator i;
00168          for ( i=statusMap.begin(); i!= statusMap.end(); i++)
00169             s << i->first << "/" << i->second << " ";
00170          s << endl;
00171       }
00172    }
00173 }

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