示例#1
0
//------------------------------------------------------------------------------
Integer FileInterface::Open(const std::string& name)
{
   #ifdef DEBUG_READER_CREATION
      MessageInterface::ShowMessage("FileInterface::Open() called\n"
            "   theReader = <%p>\n", theReader);
   #endif

   Integer retval = -1;

   if (theReader)
   {
      if (theStream.is_open())
         throw InterfaceException("The FileInterface \"" + instanceName +
            "\" attempted to open the file \"" + filename +
            "\", but the file is already open.");

      theStream.open(filename.c_str());
      theReader->SetStream(&theStream, filename);

      retval = 0;
   }
   else
      throw InterfaceException("Cannot open the file interface");

   return retval;
}
示例#2
0
//------------------------------------------------------------------------------
void TcopsVHFAscii::ManageStartData()
{
   // Task 9 files have the isDumpFile flag set false
   if (!isDumpFile)
   {
      // Fill in the starting vector, assumed to be first 7 lines of the file
      Real value;
      Integer errorCode;
      if (dataBuffer.size() >= 7)
      {
         for (Integer i = 0; i < 7; ++i)
         if (GmatStringUtil::IsValidReal(dataBuffer[i], value, errorCode))
            startVector[i] = value;
         else
         {
            throw InterfaceException("The Task 9 TVHF \"" + filename +
                  "\" initial vector contains invalid data in the element \"" +
                  dataBuffer[i] + "\"");
         }
      }
      else
         throw InterfaceException("The Task 9 TVHF \"" + filename +
               "\" does not contain an initial vector");

      #ifdef DEBUG_FILEREAD
         MessageInterface::ShowMessage("Code 9 file detected with initial "
               "data:\n");
         for (Integer i = 0; i < 7; ++i)
            MessageInterface::ShowMessage("   %16lf\n", startVector[i]);
      #endif
   }
}
示例#3
0
//------------------------------------------------------------------------------
std::string DataInterface::GetStringParameter(const Integer id,
      const Integer index) const
{
   if (id == SELECTED_FIELD_NAMES)
   {
      if (theReader)
      {
         StringArray selections = theReader->GetSelectedFieldNames();
         if ((index >= 0) && (index < (Integer)selections.size()))
            return selections[index];
         throw InterfaceException("The selection index is out of bounds in the "
               "DataReader \"" + instanceName + "\"");
      }
      throw InterfaceException("The DataReader has not been set in the "
            "DataInterface \"" + instanceName + "\"");
   }

   if (id == SUPPORTED_FIELD_NAMES)
   {
      if (theReader)
      {
         StringArray selections = theReader->GetSupportedFieldNames();
         if ((index >= 0) && (index < (Integer)selections.size()))
            return selections[index];
         throw InterfaceException("The supported field index is out of bounds "
               "in the DataReader \"" + instanceName + "\"");
      }
      throw InterfaceException("The DataReader has not been set in the "
            "DataInterface \"" + instanceName + "\"");
   }

   return Interface::GetStringParameter(id, index);
}
示例#4
0
//------------------------------------------------------------------------------
bool FileInterface::Initialize()
{
   bool retval = false;

   #ifdef DEBUG_READER_CREATION
      MessageInterface::ShowMessage("Initializing the %s file interface\n",
            instanceName.c_str());
   #endif

   if (filename == "")
      throw InterfaceException("The FileInterface \"" + instanceName +
            "\" does not identify the file that it needs to read.  Please set "
            "the \"Filename\" field on the object.");

   // Verify that the file exists
   std::string sep = GmatFileUtil::GetPathSeparator();
   std::replace(filename.begin(), filename.end(), '/', sep[0]);
   std::replace(filename.begin(), filename.end(), '\\', sep[0]);

   if (GmatFileUtil::DoesFileExist(filename))
   {
      if (readerFormat == "")
         throw InterfaceException("The FileInterface \"" + instanceName +
               "\" does not identify the file format that it needs to read.  "
               "Please set the \"Format\" field on the object.");

      ReaderFactory rf;

      if (theReader != NULL)
         delete theReader;
      theReader = (DataReader*)rf.CreateObject(readerFormat, "");
      if (theReader != NULL)
      {
         #ifdef DEBUG_READER_CREATION
            MessageInterface::ShowMessage("A %s reader was created\n",
                  readerFormat.c_str());
         #endif
         retval = true;
      }
      else
         throw InterfaceException("The FileInterface \"" + instanceName +
               "\" was unable to create a \"" + readerFormat + 
               "\" reader for the data.");
   }
   else
      throw InterfaceException("The FileInterface \"" + instanceName +
            "\" is set to read the file \"" + filename +
            "\", but the file does not exist.");

   return retval;
}
示例#5
0
//------------------------------------------------------------------------------
const StringArray& DataInterface::GetSupportedFieldNames() const
{
   if (theReader)
      return theReader->GetSupportedFieldNames();
   throw InterfaceException("The DataReader has not been set in the "
         "DataInterface \"" + instanceName + "\"");
}
示例#6
0
//------------------------------------------------------------------------------
bool DataInterface::SetStringParameter(const Integer id,
      const std::string& value, const Integer index)
{
   if (id == SELECTED_FIELD_NAMES)
   {
      if (theReader)
         return theReader->SetStringParameter("SelectedFieldNames", value,
               index);
      throw InterfaceException("The DataReader has not been set in the "
            "DataInterface \"" + instanceName + "\"");
   }

   if (id == SUPPORTED_FIELD_NAMES)
   {
      if (theReader)
         return theReader->SetStringParameter("SupportedFieldNames", value,
               index);
      throw InterfaceException("The DataReader has not been set in the "
            "DataInterface \"" + instanceName + "\"");
   }

   return Interface::SetStringParameter(id, value, index);
}
示例#7
0
//------------------------------------------------------------------------------
const StringArray& DataInterface::GetStringArrayParameter(
      const Integer id) const
{
   if (id == SELECTED_FIELD_NAMES)
   {
      if (theReader)
         return theReader->GetSelectedFieldNames();
      throw InterfaceException("The DataReader has not been set in the "
            "DataInterface \"" + instanceName + "\"");
   }

   if (id == SUPPORTED_FIELD_NAMES)
   {
      return GetSupportedFieldNames();
   }

   return Interface::GetStringArrayParameter(id);
}
示例#8
0
//------------------------------------------------------------------------------
Integer Interface::Close(const wxString &name)
{
   throw InterfaceException(wxT("Close() not defined for ") + typeName +
                            wxT(" named \"") + instanceName + wxT("\"\n"));
}
示例#9
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
   }
示例#10
0
//------------------------------------------------------------------------------
std::string DataInterface::GetStringValue(const std::string& forField)
{
   if (!theReader)
      throw InterfaceException("The data reader has not been set");
   return theReader->GetStringValue(forField);
}
示例#11
0
//------------------------------------------------------------------------------
Rvector6 DataInterface::GetReal6Vector(const std::string& forField)
{
   if (!theReader)
      throw InterfaceException("The data reader has not been set");
   return theReader->GetReal6Vector(forField);
}
示例#12
0
//------------------------------------------------------------------------------
Integer Interface::Close(const std::string &name)
{
   throw InterfaceException("Close() not defined for " + typeName +
                            " named \"" + instanceName + "\"\n");
}