Пример #1
0
//------------------------------------------------------------------------------
void TcopsVHFAscii::ParseTime(std::string& theField)
{
   // Only process if the field is in the string map
   if (stringData.find(theField) != stringData.end())
   {
      std::stringstream theData;
      theData << stringData[theField];

      #ifdef DEBUG_FILEREAD
         MessageInterface::ShowMessage("      Raw data: \"%s\" stream data: "
               "\"%s\"\n", stringData[theField].c_str(), theData.str().c_str());
      #endif

      Integer year, month, day, hour, minute;
      Real second;

      theData >> year >> month >> day >> hour >> minute >> second;

      if (year < 50)
         year += 2000;
      else if (year < 100)
         year += 1900;

      // Validate the ranges
      std::stringstream errstream;
      if (year < 1950)
         errstream << "   The specified year, " << year << ", is not valid.\n";
      if ((month < 1) || (month > 12))
         errstream << "   The specified month, " << month 
                   << ", is not valid; it must be between 1 and 12.\n";
      if ((day < 1) || (day > 31))
         errstream <<    "   The specified day of month, " << day << ", is not valid.\n";
      else
      {
         if (month == 2)
         {
            if (day > 29)
               errstream << "   The specified day of month, " << day << ", is not "
                  "valid for month " << month << ".\n";
            else if (day == 29)
            {
               if (year % 4 != 0)
                  errstream << "   The specified day of month, " << day 
                            << ", is not valid for month " << month 
                            << "in the year " << year << ".\n";
            }
         }
         if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
            if (day > 30)
               errstream << "   The specified day of month, " << day 
                         << ", is not valid for month " << month << ".\n";
      }

      if ((hour < 0) || (hour > 24))
         errstream << "   The specified hour of day, " << hour 
                     << ", is not valid[ it must be between 0 and 24.\n";
      else
         if (((minute > 0) || (second > 0.0)) && (hour == 24))
            errstream << "   The specified hour of day, " << hour 
                        << ", is not valid with non-zero minutes "
                           "or seconds.\n";

      if ((minute < 0) || (minute > 60))
         errstream << "   The specified number of minutes, " << minute 
                     << ", is not valid; it must be between 0 and 60.\n";
      else
         if ((minute == 60) && (second > 0.0))
            errstream << "   The specified number of minutes, " << minute 
                        << ", is not valid with non-zero seconds.\n";

      if ((second < 0.0) || (second > 60.5))
         errstream << "   The specified number of seconds, " << second 
                   << ", is not valid; it must be between 0 and 60.5\n";

      if (errstream.str().length() > 0)
         throw InterfaceException("Error parsing the epoch data from the data file " + filename +
         ":\n" + errstream.str());

      utcEpoch = ModifiedJulianDate(year,month,day,hour,minute,second);
      realData[theField] = utcEpoch;
      dataLoaded[theField] = true;

      #ifdef DEBUG_FILEREAD
         MessageInterface::ShowMessage("   %s is at [%d %d %d %d %d %lf] = "
               "%17.12lf\n", theField.c_str(), year, month, day, hour,
               minute, second, utcEpoch);
      #endif
   }
Пример #2
0
//------------------------------------------------------------------------------
bool SolarFluxReader::LoadObsData()
{
   Integer hour = 0, minute = 0;
   Real sec = 0.0;

   std::stringstream buffer;

   inObs.seekg(begObs, std::ios_base::beg);
   std::string theLine;
   GmatFileUtil::GetLine(&inObs, theLine);

   Integer year, month, day, value;

   while (!inObs.eof() && (theLine.find(end_ObsTag) == std::string::npos))
   {
      buffer.str("");
      buffer << theLine;

      #ifdef DEBUG_INITIALIZATION
         MessageInterface::ShowMessage("%s\n", buffer.str());
      #endif

      if (theLine.length() > 8)
      {
         FluxData fD;

         buffer.str("");
         buffer << theLine;
         buffer >> year >> month >> day;

         // Set ref epoch to midnight for the date on the current line
         Real mjd = ModifiedJulianDate(year, month, day, hour, minute, sec);
         fD.epoch = mjd;

         // Just drop the next 2 entries;
         buffer >> value;
         buffer >> value;

         // The CSSI file conains Kp * 10, then rounded to an int. Undo that here.
         for (Integer m = 0; m < 8; ++m)
         {
            buffer >> value;
            fD.kp[m] = value / 10.0;
         }
         // Drop the sum column
         buffer >> value;
         for (Integer m = 0; m < 8; ++m)
            buffer >> fD.ap[m];

         buffer >> value;
         fD.apAvg = value;

         // Set for the second part of the string
         buffer.str("");
         buffer << theLine.substr(92);

         buffer >> fD.adjF107;
         buffer >> value;
         buffer >> fD.adjCtrF107a;
         buffer >> fD.obsF107;      // Intentional throw away (Adj Lst value)
         buffer >> fD.obsF107;
         buffer >> fD.obsCtrF107a;

         fD.index = -1;
         for (Integer l = 0; l<9; l++)
            fD.F107a[l] = -1;
         for (Integer l =0; l<3; l++)
            fD.apSchatten[l] = -1;

         fD.isObsData = true;
         obsFluxData.push_back(fD);
      }
      GmatFileUtil::GetLine(&inObs, theLine);

   }