Beispiel #1
0
      // Method to store conf data in this class' data map
   void ConfDataReader::loadData(void)
      throw(ConfigurationException)
   {

         // By default, section name is "DEFAULT"
      std::string sectionName("DEFAULT");

         // Do this until end-of-file reached or something else happens
      while(1)
      {
         try
         {

            std::string line;
            std::string variable;
            std::string value;

            formattedGetLine(line, true);

               // If line is too long, we throw an exception
            if (line.size()>255)
            {
               ConfigurationException e(
                                    "Line too long in configuration file '" +
                                    filename + "'." );
               GPSTK_THROW(e);
            }
              // Skip the blank line
            if(line.size()<1) continue;
            	
               // Let's find and strip comment lines
            if( (StringUtils::firstWord(line)[0] == '#') ||
                (StringUtils::firstWord(line)[0] == ';')  )
            {
               formattedGetLine(line, true);
            }

               // Let's strip comments at the end of lines
            std::string::size_type idx(line.find('#'));
            if( !(idx == std::string::npos) )
            {
               line = line.substr(0, idx);
            }

            idx = line.find(';');
            if( !(idx == std::string::npos) )
            {
               line = line.substr(0, idx);
            }

               // Remove trailing and leading blanks
            line = StringUtils::strip(line);

               // Skip blank lines
            if (line.size()==0)
            {
               continue;
            }


               // Let's start to get data out of file

               // First, handle section names

               // Test if this line declares a new section. Check for '['
            idx = line.find('[');
            if( !(idx == std::string::npos) )
            {

                  // Now, check if there is a closing ']'
               std::string::size_type idx2(line.find(']'));
               if( !(idx2 == std::string::npos) )
               {
                     // Extract name and remove trailing and leading blanks
                  line = StringUtils::strip( line.substr(idx+1, idx2-idx-1) );

                     // Check if section name is appropriate
                  if( checkName(line) )
                  {

                        // Update 'sectionName': make it uppercase
                     sectionName = StringUtils::upperCase(line);

                  }
                  else
                  {
                        // Throw an exception if section name isn't appropriate
                     ConfigurationException e(
                                          "Section name '" +
                                          line + "' in configuration file '" +
                                          filename +
                                          "' does not comply with rules.");

                     GPSTK_THROW(e);
                  }

                     // If this was a section line, continue with next line
                  continue;

               }
               else
               {
                     // Throw an exception if section line is not closed
                  ConfigurationException e(
                                       "Section line '" +
                                       line +
                                       "' in configuration file '" +
                                       filename +
                                       "' was improperly closed" );

                  GPSTK_THROW(e);
               }

            }

               // Second, handle variables

               // Separate variable name from value. Look for separators
            idx = line.find('=');
            if( idx == std::string::npos )
            {
               idx = line.find(':');
            }


               // If we found a separator, keep processing
            if( !(idx == std::string::npos) )
            {

                  // Read variable and value
               variable = StringUtils::strip( line.substr(0, idx) );
               value = StringUtils::strip( line.substr(idx+1) );

                  // Now separate comments

                  // Work on 'variable'
               std::string varComment;

               idx = variable.find(',');
               if( !(idx == std::string::npos) )
               {
                  varComment = StringUtils::strip(variable.substr(idx+1));
                  variable   = StringUtils::strip(variable.substr(0, idx));
               }

                  // Check if variable name is appropriate
               if( checkName(variable) )
               {
                     // Make 'variable' uppercase
                  variable = StringUtils::upperCase(variable);

               }
               else
               {
                     // Throw an exception if variable name isn't appropriate
                  ConfigurationException e(
                                       "Variable name '" +
                                       variable + "' in configuration file '" +
                                       filename +
                                       "' does not comply with rules.");

                  GPSTK_THROW(e);
               }

                  // Now work on 'value'
               std::string valueComment;

               idx = value.find(',');
               if( !(idx == std::string::npos) )
               {
                  valueComment = StringUtils::strip(value.substr(idx+1));
                  value        = StringUtils::strip(value.substr(0, idx));
               }

                  // Store configuration data
               variableData varData;
               varData.varComment   = varComment;
               varData.value        = value;
               varData.valueComment = valueComment;

               confData[sectionName][variable] = varData;

            }

         }  // End of try block
         catch (ConfigurationException& e)
         {
            GPSTK_THROW(e);
         }
         catch (EndOfFile& e)
         {

               // Initialize itCurrentSection
            itCurrentSection = confData.begin();

            return;

         }
         catch (...)
         {

            return;

         }

      } // End of 'while(1)'

   }  // End of method 'ConfDataReader::loadData()'
Beispiel #2
0
      // Method to store load ocean tide harmonics data in this class'
      // data map
   void BLQDataReader::loadData(void)
      throw( FFStreamError, gpstk::StringUtils::StringException )
   {

         // Counter of valid data lines
      int row(0);

         // We will store here the station name
      std::string nameString("");

         // Declare structure to store tide harmonics data
      BLQDataReader::tideData data;

         // Do this until end-of-file reached or something else happens
      while(1)
      {

         try
         {

            if(row>6)
            {
                  // If row>6, all station harmonics are already read,
                  // so let's store tide data in data map
               setData(nameString, data);

                  // Clear harmonics data
               data.harmonics.resize(6,11,0.0);

                  // Reset counter to get data from an additional station
               row = 0;
            }

            std::string line;

            formattedGetLine(line, true);

               // If line is too long, we throw an exception
            if (line.size()>255)
            {
               FFStreamError e("Line too long");
               GPSTK_THROW(e);
            }

               // Let's find and strip comments, wherever they are
            if( StringUtils::firstWord(line)[0] == '$' )
            {
               formattedGetLine(line, true);
            }

            std::string::size_type idx = line.find('$');
            if( !(idx == std::string::npos) )
            {
               line = line.substr(0, idx);
            }

               // Remove trailing and leading blanks
            line = StringUtils::strip(line);

               // Skip blank lines
            if (line.size()==0)
            {
               continue;
            }

               // Let's start to get data out of file
               // If this is the first valid line, it contains station name
            if (row==0)
            {

               nameString =
                  StringUtils::upperCase(StringUtils::stripFirstWord(line));

               ++row;

               continue;

            }
            else
            {

                  // 2nd to 7th valid lines contains tide harmonics
               if ( (row>0) && (row<=6) )
               {
                  for(int col=0; col<11; col++)
                  {
                     std::string value(StringUtils::stripFirstWord(line));
                     data.harmonics((row-1),col) = StringUtils::asDouble(value);
                  }
                  ++row;
                  continue;
               }
            }

         }  // End of try block
         catch (EndOfFile& e)
         {

               // We should close this data stream before returning
            (*this).close();

            return;
         }
         catch (...)
         {

               // We should close this data stream before returning
            (*this).close();

            return;

         }

      }  // End of 'while(1)...'

   }  // End of method 'BLQDataReader::loadData()'
Beispiel #3
0
      // Method to store load ocean tide harmonics data in this class'
      // data map
   void DCBDataReader::loadData()
      throw( FFStreamError, gpstk::StringUtils::StringException )
   {

      try
      {
         allDCB.satDCB.clear();
         allDCB.gpsDCB.clear();
         allDCB.glonassDCB.clear();

            // a buffer
         string line;
         
            // read first line 
         formattedGetLine(line, true);
                  
            // Let's skip 6 lines
         for(int i=0; i<6; i++) formattedGetLine(line, true);
         
         
            // Now, let's read data
         while(1)
         {
            formattedGetLine(line, true);

            if(line.length() < 46) continue;
            
            string sysFlag = line.substr(0,1);
            
            int satPRN = StringUtils::asInt(line.substr(1,2));
            
            string station = StringUtils::strip(line.substr(6,4));
            
            const double dcbVal = StringUtils::asDouble(line.substr(26,9));
            //const double dcbRms = StringUtils::asDouble(line.substr(38,9));
             
            if(station.length() < 4)       // this is satellite DCB data
            {

               SatID sat;
               if(sysFlag == "G")
               {
                  sat = SatID(satPRN,SatID::systemGPS);
               }
               else if(sysFlag == "R")
               {
                  sat = SatID(satPRN,SatID::systemGlonass);
               }
               else
               {
                  // Unexpected and we do nothing here
                  

               }
               
               allDCB.satDCB[sat] = dcbVal;
               
            }
            else                           // this is receiver DCB data
            {
               if(sysFlag == "G")
               {
                  allDCB.gpsDCB[station] = dcbVal;
               }
               else if(sysFlag == "R")
               {
                  allDCB.glonassDCB[station] = dcbVal;
               }
               else
               {
                  // Unexpected and we do nothing here

               }
            }

         }  // End of 'while(1)'

      }  // End of try block
      catch (EndOfFile& e)
      {
       
            // We should close this data stream before returning
         (*this).close();

         return;
      }
      catch (...)
      {

         // We should close this data stream before returning
         (*this).close();

         return;

      }


   }  // End of 'DCBDataReader::loadData()'
Beispiel #4
0
      // Method to store satellite data in this class' data map
   void SatDataReader::loadData(void)
      throw(FFStreamError, gpstk::StringUtils::StringException)
   {

         // Do this until end-of-file reached or something else happens
      while(1)
      {
         try
         {
            std::string line;

            formattedGetLine(line, true);

               // If line is too long, we throw an exception
            if (line.size()>255)
            {
               FFStreamError e("Line too long");
               GPSTK_THROW(e);
            }

               // Let's find and strip comments, wherever they are
            if( StringUtils::firstWord(line)[0] == '#' )
            {
               formattedGetLine(line, true);
            }

            std::string::size_type idx = line.find('#');
            if( !(idx == std::string::npos) )
            {
               line = line.substr(0, idx);
            }

               // We erase the header (first line)
            if( StringUtils::firstWord(line) == "Launch" )
            {
               formattedGetLine(line, true);
            }

               // Remove trailing and leading blanks
            line = StringUtils::strip(line);

               // Skip blank lines
            if (line.size()==0)
            {
               continue;
            }

               // Let's start to get data out of file
               // Launch date
            string ldate(StringUtils::stripFirstWord(line));
               // Deactivation date
            string ddate(StringUtils::stripFirstWord(line));
               // GPS number
            string gnumber(StringUtils::stripFirstWord(line));
               // PRN number
            string prn(StringUtils::stripFirstWord(line));
               // Block tipe
            string block(StringUtils::upperCase(
               StringUtils::stripFirstWord(line)));

               // Get satellite id. If it doesn't fit GPS or Glonass, it is
               // marked as unknown
            SatID sat(StringUtils::asInt(prn),SatID::systemUnknown);
               // Let's identify satellite system
            if(block[0] == 'I')
            {
               sat.system = SatID::systemGPS;
            }
            else
            { 
               if (block.substr(0, 3) == "GLO")
               {
                  sat.system = SatID::systemGlonass;
               }
            }

               // Declare the structure to store data
            SatDataReader::svData data;

            data.block = block;
            data.gpsNumber = StringUtils::asInt(gnumber);

               // Get launch date in a proper format
            if(ldate[0] != '0')
            {
                ldate = StringUtils::translate(ldate, "-", " ");
                scanTime(data.launchDate, ldate, "%Y %m %d");
            }

               // Get deactivation date in a proper format
            if(ddate[0] != '0')
            {
                ddate = StringUtils::translate(ddate, "-", " ");
                scanTime(data.deactivationDate, ddate, "%Y %m %d");
            }

            // It's not a good way!!! 
            data.launchDate.setTimeSystem(TimeSystem::Any);
            data.deactivationDate.setTimeSystem(TimeSystem::Any);

               // Insert data in data map
            setData(sat, data);

         }  // End of try block
         catch (EndOfFile& e)
         {
               // Close this data stream
            (*this).close();

            return;
         }
         catch (...)
         {
               // Close this data stream
            (*this).close();

            return;
         }

      } // End of while(1)

   }  // End of method 'SatDataReader::loadData()'