Exemplo n.º 1
0
void executeHistory(icmProcessorP processor, char *cmd)
{
    int id;
    command_history_t *his;
    
    if(cmd == 0 || *cmd == '\0') {
        showHistory();        
    } else if(!strcmp(cmd, "!")) {
        if( his = lastHistory() ) {
            executeCommand(processor, his->cmd);
        } else {
            printf("ERROR: no previous command found\n");
        }                    
    } else {
        if(!getNumberFromString(cmd, & id)) {
            if( his = findHistory(id) ) {
                executeCommand(processor, his->cmd);
            } else {
                printf("ERROR: could not find history '%d'\n", id);
            }            
        } else {
            printf("ERROR: Bad number: '%s'\n", cmd);                                        
        }                
    }
}
Exemplo n.º 2
0
 static int de_atoi(std::ostream &log, std::string s, int line = -1) {
   double val = getNumberFromString(s);
   int ival = (int) val;
   double val2 = (double) ival;
   if (fabs(val - val2) >= 0.00001 * (val + val2)) {
     string sss = "de_atoi: Conversion of int failed: " + s;
     throw CK_SyntaxError(log, sss, line);
   }
   return ival;
 }
Exemplo n.º 3
0
/* BAD PART. NEEDS REFACTORING */
void Configurator::handleConfigurationFileLine(std::string line, int type) {
	std::string configurationExpressions[] = {CONFIGURATIONEXPRESSIONS};
	int numberOfExpressions = sizeof(configurationExpressions) / sizeof(std::string);
	double value = -1;
	for(int i = 0; i < numberOfExpressions; i++) {
		std::string toFind(configurationExpressions[i]);
		std::size_t found = line.find(toFind);
		if (found != std::string::npos) {
			value = getNumberFromString(line);
			defineVariable(i, value, type);
		}
	}
}
Exemplo n.º 4
0
  /**
   *
   * Read one species definition in a NASA9 string.
   *
   */
  void CKParser::readNASA9ThermoRecord(Species& sp) {
    string s;
    string numstr;
    double cf;
    // Set to the NASA9 polynomial format
    sp.thermoFormatType = 1;

    // look for line 1, but if a keyword is found first or the end of
    // the file is reached, return "<END>" as the species name
    string comment;

    // Name of the species
    string nameid;
    vector<string> toks;
    int nToks = 0;

    // Loop forward until we get to the next nonempty line.
    do {
      getCKLine(s, comment);
      if (isKeyword(s) || match(s, "<EOF>")) {
	sp.name = "<END>";
	putCKLine(s, comment);
	return;
      }

      // The first 18 spaces are devoted to the name of the species
      string nameid = s.substr(0,18);
      getTokens(nameid, static_cast<int>(nameid.size()), toks);
      nToks = toks.size();
    }  while (nToks == 0);

    //------------- line 1 ---------------------------
    //  Everything after the first 18 spaces is a comment.
    int nt = s.size();
    sp.m_commentsRef = s.substr(18, nt-18);

    // Parse the species name
    sp.name = toks[0];
    sp.id = "";
    if (nToks > 1) {
      throw CK_SyntaxError(*m_log,
			   "Illegal number of tokens for string name", m_line);
    }
    checkSpeciesName(sp.name);


    //------------- line 2 ---------------------------

    getCKLine(s, comment);
    if (s.size() < 79) {
      throw CK_SyntaxError(*m_log,
			   "Size of second line is too small", m_line);
    }
    // Read the number of temperature regions.
    string sN = s.substr(0,2);
    sp.nTempRegions = de_atoi(*m_log, sN);

    string refDataCode = s.substr(3,6);

    // elemental composition (first 5 elements)
    for (int i = 0; i < 5; i++) {
      string elementSym = "";
      int iloc = 10 + 8*i;
      if (s[iloc] != ' ') {
	if (s[iloc+1] != ' ') {
	  elementSym = s.substr(iloc,2);
	} else { 
	  elementSym = s.substr(iloc,1);
	}
      } else if (s[iloc+1] != ' ') {
	elementSym = s.substr(iloc+1,1);
      }
      double atoms = de_atof(s.substr(iloc+2,6));
      addElement(elementSym, atoms, sp, *m_log);
    }
    
  
    // single-character phase descriptor
    sp.phase = s.substr(50,2);

    // Molecular weight in gm per gmol
    string molecWeight = s.substr(52, 13);

    // Heat of formation at 298.15 K in J / gmol
    string Hf298_Jgmol = s.substr(65, 15);

    vector_fp *coeffs_ptr;
    for (int i = 0; i < sp.nTempRegions; i++) {

      coeffs_ptr = new vector_fp(9);
      vector_fp &coeffs = *coeffs_ptr;

      //------------- line 3 ---------------------------
      getCKLine(s, comment);
      if (s.size() < 79) {
	throw CK_SyntaxError(*m_log,
			     "Size of third line is too small", m_line);
      }

      string sTlow = s.substr(0, 11);
      double tLow = de_atof(sTlow);

      string sTHigh = s.substr(11, 11);
      double tHigh = de_atof(sTHigh);

      string sNCoeff = s.substr(22, 1);
      int nCoeff = de_atoi(*m_log, sNCoeff);
      if (nCoeff != 7) {
	throw CK_SyntaxError(*m_log, "ncoeff ne 7", m_line);
      }

      string sTCoeff1 = s.substr(24, 5);
      double TCoeff1 = de_atof(sTCoeff1);
      if (TCoeff1 != -2.0) {
	throw CK_SyntaxError(*m_log, "TCoeff1 ne -2.0", m_line);
      }

      string sTCoeff2 = s.substr(29, 5);
      double TCoeff2 = de_atof(sTCoeff2);
      if (TCoeff2 != -1.0) {
	throw CK_SyntaxError(*m_log, "TCoeff2 ne -1.0", m_line);
      }

      string sTCoeff3 = s.substr(34, 5);
      double TCoeff3 = de_atof(sTCoeff3);
      if (TCoeff3 != 0.0) {
	throw CK_SyntaxError(*m_log, "TCoeff3 ne 0.0", m_line);
      }

      string sTCoeff4 = s.substr(39, 5);
      double TCoeff4 = de_atof(sTCoeff4);
      if (TCoeff4 != 1.0) {
	throw CK_SyntaxError(*m_log, "TCoeff4 ne 1.0", m_line);
      }

      string sTCoeff5 = s.substr(44, 5);
      double TCoeff5 = de_atof(sTCoeff5);
      if (TCoeff5 != 2.0) {
	throw CK_SyntaxError(*m_log, "TCoeff5 ne 2.0", m_line);
      }

      string sTCoeff6 = s.substr(49, 5);
      double TCoeff6 = de_atof(sTCoeff6);
      if (TCoeff6 != 3.0) {
	throw CK_SyntaxError(*m_log, "TCoeff6 ne 3.0", m_line);
      }

      string sTCoeff7 = s.substr(54, 5);
      double TCoeff7 = de_atof(sTCoeff7);
      if (TCoeff7 != 4.0) {
	throw CK_SyntaxError(*m_log, "TCoeff7 ne 4.0", m_line);
      }

      string sHf298mHF0 = s.substr(65, 15);
      
      //------------- line 4 ---------------------------
      getCKLine(s, comment);
      if (s.size() < 79) {
	throw CK_SyntaxError(*m_log,
			     "Size of third line is too small", m_line);
      }

      numstr = s.substr(0, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[0] = cf;

      numstr = s.substr(16, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[1] = cf;

      numstr = s.substr(32, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[2] = cf;

      numstr = s.substr(48, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[3] = cf;

      numstr = s.substr(64, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[4] = cf;

      //------------- line 5 ---------------------------
      getCKLine(s, comment);
      if (s.size() < 79) {
	throw CK_SyntaxError(*m_log,
			     "Size of fourth line is too small", m_line);
      }

      numstr = s.substr(0, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[5] = cf;

      numstr = s.substr(16, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[6] = cf;

      numstr = s.substr(48, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[7] = cf;

      numstr = s.substr(64, 16);
      cf = getNumberFromString(numstr);
      if (cf == UNDEF) illegalNumber(*m_log, numstr, m_line);
      coeffs[8] = cf;

      // Store the coefficients.
      sp.minTemps.push_back(tLow);
      sp.maxTemps.push_back(tHigh);

      sp.region_coeffs.push_back(coeffs_ptr);

    }

    sp.valid = 1;
  }