PhaseCodeAlignment.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: PhaseCodeAlignment.cpp 1915 2009-05-25 11:49:54Z architest $"
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 ). 2008, 2009
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "PhaseCodeAlignment.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037       // Index initially assigned to this class
00038    int PhaseCodeAlignment::classIndex = 4400000;
00039 
00040 
00041       // Returns an index identifying this object.
00042    int PhaseCodeAlignment::getIndex() const
00043    { return index; }
00044 
00045 
00046       // Returns a string identifying this object.
00047    std::string PhaseCodeAlignment::getClassName() const
00048    { return "PhaseCodeAlignment"; }
00049 
00050 
00051       /* Common constructor
00052        *
00053        * @param phase            Phase TypeID.
00054        * @param code             Code TypeID.
00055        * @param wavelength       Phase wavelength, in meters.
00056        * @param useArc           Whether satellite arcs will be used or not.
00057        */
00058    PhaseCodeAlignment::PhaseCodeAlignment( const TypeID& phase,
00059                                            const TypeID& code,
00060                                            const double wavelength,
00061                                            bool useArc )
00062       : phaseType(phase), codeType(code), useSatArcs(useArc),
00063         watchCSFlag(TypeID::CSL1)
00064    {
00065 
00066          // Set the wavelength
00067       setPhaseWavelength(wavelength);
00068 
00069       setIndex();
00070 
00071    }  // End of 'PhaseCodeAlignment::PhaseCodeAlignment()'
00072 
00073 
00074 
00075       /* Method to set the phase wavelength to be used.
00076        *
00077        * @param wavelength       Phase wavelength, in meters.
00078        */
00079    PhaseCodeAlignment& PhaseCodeAlignment::setPhaseWavelength(double wavelength)
00080    {
00081 
00082          // Check that wavelength is bigger than zero
00083       if (wavelength > 0.0)
00084       {
00085          phaseWavelength = wavelength;
00086       }
00087       else
00088       {
00089          phaseWavelength = 0.1069533781421467;   // Be default, LC wavelength
00090       }
00091 
00092       return (*this);
00093 
00094    }  // End of 'PhaseCodeAlignment::setPhaseWavelength()'
00095 
00096 
00097 
00098       /* Returns a satTypeValueMap object, adding the new data generated
00099        *  when calling this object.
00100        *
00101        * @param epoch     Time of observations.
00102        * @param gData     Data object holding the data.
00103        */
00104    satTypeValueMap& PhaseCodeAlignment::Process( const DayTime& epoch,
00105                                            satTypeValueMap& gData )
00106       throw(ProcessingException)
00107    {
00108 
00109       try
00110       {
00111 
00112          SatIDSet satRejectedSet;
00113 
00114             // Loop through all the satellites
00115          for( satTypeValueMap::iterator it = gData.begin();
00116               it != gData.end();
00117               ++it )
00118          {
00119 
00120                // Check if satellite currently has entries
00121             std::map<SatID, alignData>::const_iterator itDat(
00122                                                 svData.find( (*it).first ) );
00123             if( itDat == svData.end() )
00124             {
00125 
00126                   // If it doesn't have an entry, insert one
00127                alignData aData;
00128 
00129                svData[ (*it).first ] = aData;
00130 
00131             }
00132 
00133 
00134                // Place to store if there was a cycle slip. False by default
00135             bool csflag(false);
00136 
00137 
00138                // Check if we want to use satellite arcs of cycle slip flags
00139             if(useSatArcs)
00140             {
00141 
00142                double arcN(0.0);
00143 
00144                try
00145                {
00146 
00147                      // Try to extract the satellite arc value
00148                   arcN = (*it).second(TypeID::satArc);
00149 
00150                }
00151                catch(...)
00152                {
00153 
00154                      // If satellite arc is missing, then schedule this
00155                      // satellite for removal
00156                   satRejectedSet.insert( (*it).first );
00157 
00158                   continue;
00159 
00160                }
00161 
00162 
00163                   // Check if satellite arc has changed
00164                if( svData[(*it).first].arcNumber != arcN )
00165                {
00166 
00167                      // Set flag
00168                   csflag = true;
00169 
00170                      // Update satellite arc information
00171                   svData[(*it).first].arcNumber = arcN;
00172                }
00173 
00174             }  // End of first part of 'if(useSatArcs)'
00175             else
00176             {
00177 
00178                double flag(0.0);
00179 
00180                try
00181                {
00182 
00183                      // Try to extract the CS flag value
00184                   flag = (*it).second(watchCSFlag);
00185 
00186                }
00187                catch(...)
00188                {
00189 
00190                      // If flag is missing, then schedule this satellite
00191                      // for removal
00192                   satRejectedSet.insert( (*it).first );
00193 
00194                   continue;
00195 
00196                }
00197 
00198                   // Check if there was a cycle slip
00199                if( flag > 0.0)
00200                {
00201                      // Set flag
00202                   csflag = true;
00203                }
00204 
00205             }  // End of second part of 'if(useSatArcs)...'
00206 
00207 
00208                // If there was an arc change or cycle slip, let's
00209                // compute the new offset
00210             if(csflag)
00211             {
00212 
00213                   // Compute difference between code and phase measurements
00214                double diff( (*it).second(codeType) - (*it).second(phaseType) );
00215 
00216                   // Convert 'diff' to cycles
00217                diff = diff/phaseWavelength;
00218 
00219                   // Convert 'diff' to an INTEGER number of cycles
00220                diff = std::floor(diff);
00221 
00222                   // The new offset is the INTEGER number of cycles, in meters
00223                svData[(*it).first].offset = diff * phaseWavelength;
00224 
00225             }
00226 
00227                // Let's align the phase measurement using the
00228                // corresponding offset
00229             (*it).second[phaseType] = (*it).second[phaseType]
00230                                       + svData[(*it).first].offset;
00231 
00232          }
00233 
00234             // Remove satellites with missing data
00235          gData.removeSatID(satRejectedSet);
00236 
00237          return gData;
00238 
00239       }
00240       catch(Exception& u)
00241       {
00242             // Throw an exception if something unexpected happens
00243          ProcessingException e( getClassName() + ":"
00244                                 + StringUtils::asString( getIndex() ) + ":"
00245                                 + u.what() );
00246 
00247          GPSTK_THROW(e);
00248 
00249       }
00250 
00251    }  // End of 'PhaseCodeAlignment::Process()'
00252 
00253 
00254 
00255       /* Returns a gnnsSatTypeValue object, adding the new data generated
00256        *  when calling this object.
00257        *
00258        * @param gData    Data object holding the data.
00259        */
00260    gnssSatTypeValue& PhaseCodeAlignment::Process(gnssSatTypeValue& gData)
00261       throw(ProcessingException)
00262    {
00263 
00264       try
00265       {
00266 
00267          Process(gData.header.epoch, gData.body);
00268 
00269          return gData;
00270 
00271       }
00272       catch(Exception& u)
00273       {
00274             // Throw an exception if something unexpected happens
00275          ProcessingException e( getClassName() + ":"
00276                                 + StringUtils::asString( getIndex() ) + ":"
00277                                 + u.what() );
00278 
00279          GPSTK_THROW(e);
00280 
00281       }
00282 
00283    }  // End of 'PhaseCodeAlignment::Process()'
00284 
00285 
00286 
00287       /* Returns a gnnsRinex object, adding the new data generated when
00288        *  calling this object.
00289        *
00290        * @param gData    Data object holding the data.
00291        */
00292    gnssRinex& PhaseCodeAlignment::Process(gnssRinex& gData)
00293       throw(ProcessingException)
00294    {
00295 
00296       try
00297       {
00298 
00299          Process(gData.header.epoch, gData.body);
00300 
00301          return gData;
00302 
00303       }
00304       catch(Exception& u)
00305       {
00306             // Throw an exception if something unexpected happens
00307          ProcessingException e( getClassName() + ":"
00308                                 + StringUtils::asString( getIndex() ) + ":"
00309                                 + u.what() );
00310 
00311          GPSTK_THROW(e);
00312 
00313       }
00314 
00315    }  // End of 'PhaseCodeAlignment::Process()'
00316 
00317 
00318 
00319 } // End of namespace gpstk

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