Exemplo n.º 1
0
void* HpcOmBenchmarkExtImpl__readCalcTimesFromJson(const char *filename)
{
  void *res = mmc_mk_nil();
  std::string errorMsg = std::string("");
  std::ifstream ifile(filename);
  if (!ifile)
  {
    errorMsg = "File '";
    errorMsg += std::string(filename);
    errorMsg += "' does not exist";
    res = mmc_mk_cons(mmc_mk_scon(errorMsg.c_str()), mmc_mk_nil());
    printf("%s\n",errorMsg.c_str());
    return res;
  }

  std::list<std::list<double> > retLst = ReadJsonBenchFileEquations(filename);

  for (std::list<std::list<double> >::iterator it = retLst.begin();
      it != retLst.end(); it++) {
    int i = 0;
    for (std::list<double>::iterator iter = (*it).begin();
        iter != (*it).end(); iter++) {
      if (i >= 3)
        break;
      res = mmc_mk_cons(mmc_mk_rcon(*iter), res);
      //std::cerr << "value " << *iter << std::endl;
    }
  }
  //std::cerr << "Blaaaa2" << std::endl;
  return res;
}
Exemplo n.º 2
0
extern void* System_getFileModificationTime(const char *fileName)
{
  struct stat attrib;   // create a file attribute structure
  double elapsedTime;    // the time elapsed as double
  int result;            // the result of the function call

  if (stat( fileName, &attrib ) != 0) {
    return mmc_mk_none();
  } else {
    return mmc_mk_some(mmc_mk_rcon(difftime(attrib.st_mtime, 0))); // the file modification time
  }
}
static int lex_number(int ch)
{
    char s[128];
    int i = 0, isreal = 0;

    for(; isdigit(ch); ch = getchar())
  s[i++] = ch;
    if( ch == '.' ) {
  isreal = 1;
  do {
      s[i++] = ch;
      ch = getchar();
  } while( isdigit(ch) );
    }
    if( ch == 'e' || ch == 'E' ) {
  isreal = 1;
  s[i++] = ch;
  ch = getchar();
  if( ch == '-' ) {
      s[i++] = ch;
      ch = getchar();
  } else if( ch == '+' ) {
      s[i++] = ch;
      ch = getchar();
  }
  if( !isdigit(ch) )
      lexerror("Bad exponent: expected digit, got %03o", ch);
  do {
      s[i++] = ch;
      ch = getchar();
  } while( isdigit(ch) );
    }
    s[i] = '\0';
    ungetc(ch, stdin);
    if( isreal ) {
  yylval.voidp = mmc_mk_rcon(atof(s));
  return T_RCON;
    } else {
  yylval.voidp = mmc_mk_icon(atoi(s));
  return T_ICON;
    }
}
Exemplo n.º 4
0
static void* SimulationResultsImpl__readDataset(const char *filename, void *vars, int dimsize, int suggestReadAllVars, SimulationResult_Globals* simresglob, int runningTestsuite)
{
  const char *msg[2] = {"",""};
  void *res,*col;
  char *var;
  double *vals;
  int i;
  if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(filename,simresglob)) {
    return NULL;
  }
  res = mmc_mk_nil();
  switch (simresglob->curFormat) {
  case MATLAB4: {
    ModelicaMatVariable_t *mat_var;
    if (dimsize == 0) {
      dimsize = simresglob->matReader.nrows;
    } else if (simresglob->matReader.nrows != dimsize) {
      fprintf(stderr, "dimsize: %d, rows %d\n", dimsize, simresglob->matReader.nrows);
      c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("readDataset(...): Expected and actual dimension sizes do not match."), NULL, 0);
      return NULL;
    }
    if (suggestReadAllVars) {
      omc_matlab4_read_all_vals(&simresglob->matReader);
    }
    while (MMC_NILHDR != MMC_GETHDR(vars)) {
      var = MMC_STRINGDATA(MMC_CAR(vars));
      vars = MMC_CDR(vars);
      mat_var = omc_matlab4_find_var(&simresglob->matReader,var);
      if (mat_var == NULL) {
        msg[0] = runningTestsuite ? SystemImpl__basename(filename) : filename;
        msg[1] = var;
        c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not read variable %s in file %s."), msg, 2);
        return NULL;
      } else if (mat_var->isParam) {
        col=mmc_mk_nil();
        for (i=0;i<dimsize;i++) col=mmc_mk_cons(mmc_mk_rcon((mat_var->index<0)?-simresglob->matReader.params[abs(mat_var->index)-1]:simresglob->matReader.params[abs(mat_var->index)-1]),col);
        res = mmc_mk_cons(col,res);
      } else {
        vals = omc_matlab4_read_vals(&simresglob->matReader,mat_var->index);
        col=mmc_mk_nil();
        for (i=0;i<dimsize;i++) col=mmc_mk_cons(mmc_mk_rcon(vals[i]),col);
        res = mmc_mk_cons(col,res);
      }
    }
    return res;
  }
  case PLT: {
    return read_ptolemy_dataset(filename,vars,dimsize);
  }
  case CSV: {
    while (MMC_NILHDR != MMC_GETHDR(vars)) {
      var = MMC_STRINGDATA(MMC_CAR(vars));
      vars = MMC_CDR(vars);
      vals = simresglob->csvReader ? read_csv_dataset(simresglob->csvReader,var) : NULL;
      if (vals == NULL) {
        msg[0] = runningTestsuite ? SystemImpl__basename(filename) : filename;
        msg[1] = var;
        c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not read variable %s in file %s."), msg, 2);
        return NULL;
      } else {
        col=mmc_mk_nil();
        for (i=0;i<dimsize;i++) {
          col=mmc_mk_cons(mmc_mk_rcon(vals[i]),col);
        }
        res = mmc_mk_cons(col,res);
      }
    }
    return res;
  }
  default:
    msg[0] = PlotFormatStr[simresglob->curFormat];
    c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("readDataSet() not implemented for plot format: %s\n"), msg, 1);
    return NULL;
  }
}
Exemplo n.º 5
0
modelica_metatype boxptr_realMax(modelica_metatype a,modelica_metatype b)
{
  return mmc_mk_rcon(fmax(mmc_unbox_real(a),mmc_unbox_real(b)));
}