GNSS_OptionFile.cpp

Go to the documentation of this file.
00001 /**
00002 \file    GNSS_OptionFile.cpp
00003 \brief   The option file for EssentialGNSS.
00004 
00005 \author  Glenn D. MacGougan (GDM)
00006 \date    2007-11-28
00007 \since   2006-12-30
00008 
00009 \b "LICENSE INFORMATION" \n
00010 Copyright (c) 2007, refer to 'author' doxygen tags \n
00011 All rights reserved. \n
00012 
00013 Redistribution and use in source and binary forms, with or without
00014 modification, are permitted provided the following conditions are met: \n
00015 
00016 - Redistributions of source code must retain the above copyright
00017   notice, this list of conditions and the following disclaimer. \n
00018 - Redistributions in binary form must reproduce the above copyright
00019   notice, this list of conditions and the following disclaimer in the
00020   documentation and/or other materials provided with the distribution. \n
00021 - The name(s) of the contributor(s) may not be used to endorse or promote 
00022   products derived from this software without specific prior written 
00023   permission. \n
00024 
00025 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00026 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00029 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00031 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00033 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00034 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00035 SUCH DAMAGE.
00036 */
00037 
00038 #include <memory.h>
00039 #include "constants.h"
00040 #include "GNSS_OptionFile.h"
00041 #include "rinex.h"
00042 #include "geodesy.h"
00043 #include "StdStringUtils.h"
00044 
00045 namespace GNSS
00046 {
00047 
00048   GNSS_OptionFile::~GNSS_OptionFile()
00049   {
00050   }
00051 
00052 
00053   GNSS_OptionFile::GNSS_OptionFile()
00054     : m_elevationMask(0.0),
00055     m_cnoMask(0.0),
00056     m_locktimeMask(0.0)
00057   {     
00058     memset( &m_klobuchar, 0, sizeof(m_klobuchar) );
00059   }
00060 
00061 
00062 
00063   bool GNSS_OptionFile::ReadAndInterpretOptions( const std::string OptionFilePath )
00064   {
00065     double d[4];
00066     unsigned n;
00067     bool result;
00068     bool useECEF = false;
00069     BOOL resultBOOL = FALSE;
00070 
00071     if( !ReadOptionFile( OptionFilePath ) )
00072       return false;
00073 
00074     m_OptionFilePath = OptionFilePath;
00075 
00076     if( !GetValue( "OutputFilePath", m_OutputFilePath ) )
00077       return false;
00078 
00079     if( !GetValue( "ProcessingMethod", m_ProcessingMethod ) )
00080       return false; 
00081     if( m_ProcessingMethod != "LSQ" 
00082     && m_ProcessingMethod != "EKF" 
00083     && m_ProcessingMethod != "RTK" 
00084     && m_ProcessingMethod != "RTKDD" )
00085       return false;
00086 
00087     if( m_ProcessingMethod != "LSQ" )
00088     {
00089       if( !GetValue( "alpha_Vn", m_KalmanOptions.alphaVn ) )
00090         return false; 
00091       if( !GetValue( "alpha_Ve", m_KalmanOptions.alphaVe ) )
00092         return false; 
00093       if( !GetValue( "alpha_Vup", m_KalmanOptions.alphaVup ) )
00094         return false; 
00095       if( !GetValue( "alpha_ClkDrift", m_KalmanOptions.alphaClkDrift ) )
00096         return false; 
00097 
00098       if( !GetValue( "sigma_Vn", m_KalmanOptions.sigmaVn ) )
00099         return false; 
00100       if( !GetValue( "sigma_Ve", m_KalmanOptions.sigmaVe ) )
00101         return false; 
00102       if( !GetValue( "sigma_Vup", m_KalmanOptions.sigmaVup ) )
00103         return false; 
00104       if( !GetValue( "sigma_ClkDrift", m_KalmanOptions.sigmaClkDrift ) )
00105         return false; 
00106     }
00107 
00108     if( !GetValue( "StartGPSWeek", m_StartTime.GPSWeek ) )
00109       return false;
00110     if( !GetValue( "StartGPSTimeOfWeek", m_StartTime.GPSTimeOfWeek ) )
00111       return false;
00112 
00113     if( !GetValue( "EndGPSWeek", m_EndTime.GPSWeek ) )
00114       return false;
00115     if( !GetValue( "EndGPSTimeOfWeek", m_EndTime.GPSTimeOfWeek ) )
00116       return false;
00117 
00118     if( !GetValue( "ElevationMask", m_elevationMask ) )
00119       return false;
00120     if( !GetValue( "CNoMask", m_cnoMask ) )
00121       return false;
00122     if( !GetValue( "LockTimeMask", m_locktimeMask ) )
00123       return false;
00124 
00125     if( !GetValue( "ProcessOnlyDGPS", m_processDGPSOnly ) )
00126       return false;
00127 
00128     GetValue( "RINEXNavigationDataPath", m_RINEXNavDataPath );      
00129 
00130     GetValue( "Reference_DataPath", m_Reference.DataPath );
00131 
00132     m_Reference.isValid = false;
00133     if( !m_Reference.DataPath.empty() )
00134     {
00135       if( DoesFileExist( m_Reference.DataPath ) )
00136       { 
00137         m_Reference.isValid = true;
00138 
00139         if( !GetValue( "Reference_DataType", m_Reference.DataTypeStr ) )
00140           return false;
00141 
00142     StdStringUtils::MakeUpper(m_Reference.DataTypeStr);
00143 
00144         if( m_Reference.DataTypeStr.compare("NOVATELOEM4") == 0 )
00145           m_Reference.DataType = GNSS_RXDATA_NOVATELOEM4;
00146         else if( m_Reference.DataTypeStr.compare("RINEX2.1") == 0 )
00147           m_Reference.DataType = GNSS_RXDATA_RINEX21;
00148         else if( m_Reference.DataTypeStr.compare("RINEX2.11") == 0 )
00149           m_Reference.DataType = GNSS_RXDATA_RINEX211;
00150         else
00151           return false;
00152 
00153 
00154         if( !GetValue( "Reference_UseECEF", useECEF ) )
00155           return false;
00156 
00157         if( useECEF )
00158         {
00159           if( !GetValue( "Reference_ECEF_X", m_Reference.x ) )
00160             return false;
00161           if( !GetValue( "Reference_ECEF_Y", m_Reference.y ) )
00162             return false;
00163           if( !GetValue( "Reference_ECEF_Z", m_Reference.z ) )
00164             return false;
00165 
00166           resultBOOL = GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates(
00167             GEODESY_REFERENCE_ELLIPSE_WGS84,
00168             m_Reference.x,
00169             m_Reference.y,
00170             m_Reference.z,
00171             &(m_Reference.latitudeRads),
00172             &(m_Reference.longitudeRads),
00173             &(m_Reference.height)
00174             );
00175           if( resultBOOL == FALSE )
00176             return false;
00177           m_Reference.latitudeDegrees  = m_Reference.latitudeRads  * RAD2DEG;
00178           m_Reference.longitudeDegrees = m_Reference.longitudeRads * RAD2DEG;
00179         }
00180         else
00181         {
00182           GetValueArray( "Reference_Latitude", d, 4, n );
00183           if( n == 1 )
00184           {
00185             m_Reference.latitudeDegrees = d[0];
00186           }
00187           else if( n == 3 )
00188           {
00189             GetDMSValue( "Reference_Latitude", m_Reference.latitudeDegrees );
00190           }
00191           else
00192           {
00193             return false;
00194           }
00195           m_Reference.latitudeRads = m_Reference.latitudeDegrees*DEG2RAD;
00196 
00197           GetValueArray( "Reference_Longitude", d, 4, n );
00198           if( n == 1 )
00199           {
00200             m_Reference.longitudeDegrees = d[0];
00201           }
00202           else if( n == 3 )
00203           {
00204             GetDMSValue( "Reference_Longitude", m_Reference.longitudeDegrees );
00205           }
00206           else
00207           {
00208             return false;
00209           }
00210           m_Reference.longitudeRads = m_Reference.longitudeDegrees*DEG2RAD;
00211 
00212           if( !GetValue( "Reference_Height", m_Reference.height ) )
00213             return false;
00214 
00215           resultBOOL = GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates(
00216             GEODESY_REFERENCE_ELLIPSE_WGS84,
00217             m_Reference.latitudeRads,
00218             m_Reference.longitudeRads,
00219             m_Reference.height,
00220             &m_Reference.x,
00221             &m_Reference.y,
00222             &m_Reference.z 
00223             );
00224           if( resultBOOL == FALSE )
00225             return false;
00226         }
00227 
00228         // The reference is known to sub mm.
00229         m_Reference.uncertaintyLatitudeOneSigma = 1.0e-04;
00230         m_Reference.uncertaintyLongitudeOneSigma = 1.0e-04;
00231         m_Reference.uncertaintyHeightOneSigma = 1.0e-04;
00232 
00233         if( !GetValue( "Reference_EnableTropoCorrection", m_Reference.useTropo ) )
00234           return false;
00235         if( !GetValue( "Reference_EnableIonoCorrection", m_Reference.useIono ) )
00236           return false;
00237         if( !GetValueArray( "Reference_ExcludeSatellites", m_Reference.satsToExclude, 64, n ) )
00238           return false;
00239         m_Reference.nrSatsToExclude = n;
00240       }
00241     }
00242 
00243 
00244 
00245     result = false;
00246     GetValue( "Iono_KlobucharIsValid", result );
00247     if( result )
00248     {
00249       m_klobuchar.isValid = 1;
00250       GetValue( "Iono_KlobucharReferenceWeek", m_klobuchar.week );
00251       GetValue( "Iono_KlobucharReferenceTime", m_klobuchar.tow );
00252 
00253       GetValueArray( "Iono_KlobucharAlphaParameters", d, 4, n );
00254       if( n == 4 )
00255       {
00256         m_klobuchar.alpha0 = d[0];
00257         m_klobuchar.alpha1 = d[1];
00258         m_klobuchar.alpha2 = d[2];
00259         m_klobuchar.alpha3 = d[3];
00260       }
00261       GetValueArray( "Iono_KlobucharBetaParameters", d, 4, n );
00262       if( n == 4 )
00263       {
00264         m_klobuchar.beta0 = d[0];
00265         m_klobuchar.beta1 = d[1];
00266         m_klobuchar.beta2 = d[2];
00267         m_klobuchar.beta3 = d[3];
00268       }
00269     }
00270     else
00271     {
00272       result = false;
00273       GetValue( "Iono_ObtainFromRINEXNavFile", result );
00274       if( result )
00275       {
00276         resultBOOL = RINEX_GetKlobucharIonoParametersFromNavFile(
00277           m_RINEXNavDataPath.c_str(),
00278           &m_klobuchar
00279           );
00280         if( resultBOOL == FALSE )
00281           return false;       
00282       }
00283       else
00284       {
00285         m_klobuchar.isValid = 0;
00286       }
00287     }
00288 
00289     m_Rover.isValid = false;
00290     if( !GetValue( "Rover_DataPath", m_Rover.DataPath ) )
00291       return false;
00292 
00293     if( m_Rover.DataPath.empty() )
00294       return false;
00295     if( !DoesFileExist( m_Rover.DataPath ) )
00296       return false;
00297 
00298     if( !GetValue( "Rover_DataType", m_Rover.DataTypeStr ) )
00299       return false;
00300 
00301   StdStringUtils::MakeUpper(m_Rover.DataTypeStr);
00302 
00303     if( m_Rover.DataTypeStr.compare("NOVATELOEM4") == 0 )
00304       m_Rover.DataType = GNSS_RXDATA_NOVATELOEM4;
00305     else if( m_Rover.DataTypeStr.compare("RINEX2.1") == 0 )
00306       m_Rover.DataType = GNSS_RXDATA_RINEX21;
00307     else if( m_Rover.DataTypeStr.compare("RINEX2.11") == 0 )
00308       m_Rover.DataType = GNSS_RXDATA_RINEX211;
00309     else
00310       return false;
00311 
00312     if( !GetValue( "Rover_UseECEF", useECEF ) )
00313       return false;
00314 
00315     if( useECEF )
00316     {
00317       if( !GetValue( "Rover_ECEF_X", m_Rover.x ) )
00318         return false;
00319       if( !GetValue( "Rover_ECEF_Y", m_Rover.y ) )
00320         return false;
00321       if( !GetValue( "Rover_ECEF_Z", m_Rover.z ) )
00322         return false;
00323 
00324       resultBOOL = GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates(
00325         GEODESY_REFERENCE_ELLIPSE_WGS84,
00326         m_Rover.x,
00327         m_Rover.y,
00328         m_Rover.z,
00329         &(m_Rover.latitudeRads),
00330         &(m_Rover.longitudeRads),
00331         &(m_Rover.height)
00332         );
00333       if( resultBOOL == FALSE )
00334         return false;
00335       m_Rover.latitudeDegrees  = m_Rover.latitudeRads  * RAD2DEG;
00336       m_Rover.longitudeDegrees = m_Rover.longitudeRads * RAD2DEG;
00337     }
00338     else
00339     {
00340       GetValueArray( "Rover_Latitude", d, 4, n );
00341       if( n == 1 )
00342       {
00343         m_Rover.latitudeDegrees = d[0];
00344       }
00345       else if( n == 3 )
00346       {
00347         GetDMSValue( "Rover_Latitude", m_Rover.latitudeDegrees );
00348       }
00349       else
00350       {
00351         return false;
00352       }
00353       m_Rover.latitudeRads = m_Rover.latitudeDegrees*DEG2RAD;
00354 
00355       GetValueArray( "Rover_Longitude", d, 4, n );
00356       if( n == 1 )
00357       {
00358         m_Rover.longitudeDegrees = d[0];
00359       }
00360       else if( n == 3 )
00361       {
00362         GetDMSValue( "Rover_Longitude", m_Rover.longitudeDegrees );
00363       }
00364       else
00365       {
00366         return false;
00367       }
00368       m_Rover.longitudeRads = m_Rover.longitudeDegrees*DEG2RAD;
00369 
00370       if( !GetValue( "Rover_Height", m_Rover.height ) )
00371         return false;
00372 
00373       resultBOOL = GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates(
00374         GEODESY_REFERENCE_ELLIPSE_WGS84,
00375         m_Rover.latitudeRads,
00376         m_Rover.longitudeRads,
00377         m_Rover.height,
00378         &m_Rover.x,
00379         &m_Rover.y,
00380         &m_Rover.z 
00381         );
00382       if( resultBOOL == FALSE )
00383         return false;
00384     }
00385 
00386     if( !GetValue( "Rover_UncertaintyLatitude", m_Rover.uncertaintyLatitudeOneSigma ) )
00387       return false;
00388     if( !GetValue( "Rover_UncertaintyLongitude", m_Rover.uncertaintyLongitudeOneSigma ) )
00389       return false;
00390     if( !GetValue( "Rover_UncertaintyHeight", m_Rover.uncertaintyHeightOneSigma ) )
00391       return false;
00392 
00393     if( !GetValue( "Rover_EnableTropoCorrection", m_Rover.useTropo ) )
00394       return false;
00395     if( !GetValue( "Rover_EnableIonoCorrection", m_Rover.useIono ) )
00396       return false;
00397     if( !GetValueArray( "Rover_ExcludeSatellites", m_Rover.satsToExclude, 64, n ) )
00398       return false;
00399     m_Rover.nrSatsToExclude = n;
00400 
00401     m_Rover.isValid = true;
00402 
00403 
00404     return true;
00405   }
00406 
00407 } // end of namespace GNSS;
00408 
00409