metamodelica_string referenceDebugString(modelica_metatype fnptr)
{
  void *res;
  char **str = backtrace_symbols(&fnptr, 1);
  if (str == 0) {
    return mmc_mk_scon("Unknown symbol");
  }
  res = mmc_mk_scon(*str);
  free(str);
  return res;
}
Example #2
0
static void* makeOMCStyle(const char *var, int omcStyle)
{
  char *res1 = NULL;
  const char *res2 = NULL;
  if (!omcStyle) {
    return mmc_mk_scon(var);
  }
  res1 = openmodelicaStyleVariableName(var);
  res2 = _replace(res1 ? res1 : var, " ", "");
  if (res1 == NULL) {
    free(res1);
  }
  return mmc_mk_scon(res2);
}
void UnitParserExt_str2unit(const char *inStr, void **nums, void **denoms, void **tpnoms, void **tpdenoms, void **tpstrs, double *scaleFactor, double *offset)
{
  string str = string(inStr);
  Unit unit;
  UnitRes res = unitParser->str2unit(str,unit);
  if (!res.Ok()) {
    std::cerr << "error parsing unit " << str << std::endl;
    MMC_THROW();
  }

  /* Build rml objects */
  *nums     = mmc_mk_nil();
  *denoms   = mmc_mk_nil();
  *tpnoms   = mmc_mk_nil();
  *tpdenoms = mmc_mk_nil();
  *tpstrs   = mmc_mk_nil();
  /* baseunits */
  *scaleFactor = unit.scaleFactor.toReal() * pow(10,unit.prefixExpo.toReal());
  *offset = unit.offset.toReal();

  vector<Rational>::reverse_iterator rii;
  for(rii=unit.unitVec.rbegin(); rii!=unit.unitVec.rend(); ++rii) {
    *nums = mmc_mk_cons(mmc_mk_icon(rii->num),*nums);
    *denoms = mmc_mk_cons(mmc_mk_icon(rii->denom),*denoms);
  }
  /* type parameters*/
  map<string,Rational>::reverse_iterator rii2;
  for(rii2=unit.typeParamVec.rbegin(); rii2!=unit.typeParamVec.rend(); ++rii2) {
    *tpnoms = mmc_mk_cons(mmc_mk_icon(rii2->second.num),*tpnoms);
    *tpdenoms = mmc_mk_cons(mmc_mk_icon(rii2->second.denom),*tpdenoms);
    *tpstrs = mmc_mk_cons(mmc_mk_scon((char*)rii2->first.c_str()),*tpstrs);
  }
}
Example #4
0
static void* SimulationResultsImpl__readVarsFilterAliases(const char *filename, SimulationResult_Globals* simresglob)
{
  if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(filename,simresglob)) {
    return mmc_mk_nil();
  }
  switch (simresglob->curFormat) {
  case MATLAB4: {
    void *res = mmc_mk_nil();
    int i;
    int *params = (int*) calloc(simresglob->matReader.nparam+1,sizeof(int));
    int *vars = (int*) calloc(simresglob->matReader.nvar+1,sizeof(int));
    for (i=simresglob->matReader.nall-1; i>=0; i--) {
      if (0 >= simresglob->matReader.allInfo[i].index) continue; /* Negated aliases always have a real variable, so skip it */
      if (simresglob->matReader.allInfo[i].isParam && params[simresglob->matReader.allInfo[i].index]) continue;
      if (!simresglob->matReader.allInfo[i].isParam && vars[simresglob->matReader.allInfo[i].index]) continue;
      if (simresglob->matReader.allInfo[i].isParam) {
        params[simresglob->matReader.allInfo[i].index] = 1;
      } else {
        vars[simresglob->matReader.allInfo[i].index] = 1;
      }
      res = mmc_mk_cons(mmc_mk_scon(simresglob->matReader.allInfo[i].name),res);
    }
    free(params);
    free(vars);
    return res;
  }
  default: return SimulationResultsImpl__readVars(filename, 0, 0, simresglob);
  }
}
Example #5
0
void* System_subDirectories(const char *directory)
{
  void *res;
  WIN32_FIND_DATA FileData;
  BOOL more = TRUE;
  char pattern[1024];
  HANDLE sh;

  sprintf(pattern, "%s\\*.*", directory);

  res = mmc_mk_nil();
  sh = FindFirstFile(pattern, &FileData);
  if (sh != INVALID_HANDLE_VALUE) {
    while(more) {
      if (strcmp(FileData.cFileName,"..") != 0 &&
        strcmp(FileData.cFileName,".") != 0 &&
        (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
      {
          res = mmc_mk_cons(mmc_mk_scon(FileData.cFileName),res);
      }
      more = FindNextFile(sh, &FileData);
    }
    if (sh != INVALID_HANDLE_VALUE) FindClose(sh);
  }
  return res;
}
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;
}
void unpack_string_array(const string_array_t *a, const char **data)
{
  size_t sz = base_array_nr_of_elements(*a);
  long i;
  for (i=0; i<sz; i++) {
    ((void**)a->data)[i] = mmc_mk_scon(data[i]);
  }
}
metamodelica_string nobox_intStringChar(threadData_t *threadData,modelica_integer ix)
{
  char chr[2];
  if (ix < 1 || ix > 255)
    MMC_THROW_INTERNAL();
  chr[0] = (char) ix;
  chr[1] = '\0';
  return mmc_mk_scon(chr);
}
Example #9
0
extern void* System_strtok(const char *str0, const char *delimit)
{
  char *s;
  void *res = mmc_mk_nil();
  char *str = strdup(str0);
  s=strtok(str,delimit);
  if (s == NULL)
  {
    free(str);
    MMC_THROW();
  }
  res = mmc_mk_cons(mmc_mk_scon(s),res);
  while ((s=strtok(NULL,delimit)))
  {
    res = mmc_mk_cons(mmc_mk_scon(s),res);
  }
  free(str);
  return listReverse(res);
}
metamodelica_string intString(modelica_integer i)
{
  /* 64-bit integer: 1+log_10(2**63)+1 = 20 digits max */
  char buffer[22];
  void *res;
  if (i>=0 && i<=9) /* Small integers are used so much it makes sense to cache them */
    return mmc_strings_len1['0'+i];
  sprintf(buffer, "%ld", (long) i);
  res = mmc_mk_scon(buffer);
  MMC_CHECK_STRING(res);
  return res;
}
void* TaskGraphResultsCmp_checkCodeGraph(const char *filename, const char *codeFileName)
{
  void *res = mmc_mk_nil();
  Graph g1;
  Graph g2;
  GraphMLParser parser;
  GraphCodeParser codeParser;
  std::string errorMsg = std::string("");

  if (!GraphMLParser::CheckIfFileExists(filename))
  {
    errorMsg = "File '";
    errorMsg += std::string(filename);
    errorMsg += "' does not exist";
    res = mmc_mk_cons(mmc_mk_scon(errorMsg.c_str()), mmc_mk_nil());
    return res;
  }

  if (!GraphMLParser::CheckIfFileExists(codeFileName))
  {
    errorMsg = "File '";
    errorMsg += std::string(codeFileName);
    errorMsg += "' does not exist";
    res = mmc_mk_cons(mmc_mk_scon(errorMsg.c_str()), mmc_mk_nil());
    return res;
  }

  parser.ParseGraph(&g1, filename, NodeComparator(&NodeComparator::CompareNodeNamesInt), &errorMsg);
  codeParser.ParseGraph(&g2, codeFileName, NodeComparator(&NodeComparator::CompareNodeNamesInt), &errorMsg);

  if (GraphComparator::CompareGraphs(&g1, &g2, NodeComparator(&NodeComparator::CompareNodeIdsInt),EdgeComparator(&EdgeComparator::CompareEdgesByNodeIdsInt), false, false, FULL, &errorMsg))
    res = mmc_mk_cons(mmc_mk_scon("Codegraph correct"), mmc_mk_nil());
  else
    res = mmc_mk_cons(mmc_mk_scon("Codegraph not correct"), mmc_mk_nil());

  if (errorMsg.length() != 0)
    res = mmc_mk_cons(mmc_mk_scon(errorMsg.c_str()), res);

  return res;
}
Example #12
0
void* System_subDirectories(const char *directory)
{
  int i,count;
  void *res;
  struct dirent **files;
  select_from_dir = directory;
  count = scandir(directory, &files, file_select_directories, NULL);
  res = mmc_mk_nil();
  for (i=0; i<count; i++)
  {
    res = mmc_mk_cons(mmc_mk_scon(files[i]->d_name),res);
    free(files[i]);
  }
  return res;
}
metamodelica_string stringListStringChar(metamodelica_string s)
{
  const char *str = MMC_STRINGDATA(s);
  char chr[2] = {'\0', '\0'};
  modelica_metatype res = NULL;
  int i = 0;

  MMC_CHECK_STRING(s);
  res = mmc_mk_nil();
  for (i=MMC_STRLEN(s)-1; i>=0; i--) {
    chr[0] = str[i];
    res = mmc_mk_cons(mmc_mk_scon(chr), res);
  }
  return res;
}
static int lex_kwd_or_ident(char *s)
{
    int low = 0;
    int high = (sizeof kwds) / (sizeof kwds[0]) - 1;

    strlower(s);
    while( low <= high ) {
  int mid = (low + high) / 2;
  int cmp = strcmp(kwds[mid].name, s);
  if( cmp == 0 )
      return kwds[mid].token;
  else if( cmp < 0 )
      low = mid + 1;
  else
      high = mid - 1;
    }
    yylval.voidp = mmc_mk_scon(s);
    return T_IDENT;
}
Example #15
0
int main(int argc, char **argv)
{
  mmc_GC_local_state_type local_GC_state = mmc_GC_save_roots_state("top"); /* push the first mark */
  void *lst = mmc_mk_nil();
  int i = 0;

  for (i=argc-1; i>0; i--)
    lst = mmc_mk_cons(mmc_mk_scon(argv[i]), lst);

  mmc_GC_add_root(&lst, local_GC_state, "commandLineParameters"); /* add to roots */

  MMC_TRY_TOP()

  _Main_main(lst);

  MMC_CATCH_TOP(return rml_execution_failed(local_GC_state));

  return 0;
}
Example #16
0
void* System_moFiles(const char *directory)
{
  void *res;
  WIN32_FIND_DATA FileData;
  BOOL more = TRUE;
  char pattern[1024];
  HANDLE sh;
  sprintf(pattern, "%s\\*.mo", directory);
  res = mmc_mk_nil();
  sh = FindFirstFile(pattern, &FileData);
  if (sh != INVALID_HANDLE_VALUE) {
    while(more) {
      if (strcmp(FileData.cFileName,"package.mo") != 0)
      {
        res = mmc_mk_cons(mmc_mk_scon(FileData.cFileName),res);
      }
      more = FindNextFile(sh, &FileData);
    }
    if (sh != INVALID_HANDLE_VALUE) FindClose(sh);
  }
  return res;
}
Example #17
0
modelica_string _old_realString(modelica_real r)
{
  /* NOTE: The RML runtime uses the same code as this function.
   * If you update one, you must update the other or the testsuite might break
   *
   * 64-bit (1+11+52) double: -d.[15 digits]E-[4 digits] = ~24 digits max.
   * Add safety margin in case some C runtime is trigger happy. */
  char buffer[32];
  char* endptr;
  snprintf(buffer, 32, "%.16g", r);
  /* If it looks like an integer, we need to append .0 so it looks like real */
  endptr = buffer;
  if (*endptr == '-') endptr++;
  while (isdigit(*endptr)) endptr++;
  if (0 == *endptr) {
    *endptr++ = '.';
    *endptr++ = '0';
    *endptr++ = '\0';
  } else if ('E' == *endptr) {
    *endptr = 'e';
  }
  return mmc_mk_scon(buffer);
}
Example #18
0
static const char* path_to_name(void* path, char del)
{
  threadData_t *threadData = (threadData_t *) pthread_getspecific(mmc_thread_data_key);
  char delStr[2] = {del,'\0'};
  return MMC_STRINGDATA(omc_Absyn_pathString2(threadData, path, mmc_mk_scon(delStr)));
}
metamodelica_string referenceDebugString(modelica_metatype fnptr)
{
  return mmc_mk_scon("Unknown symbol");
}
Example #20
0
modelica_string modelica_enumeration_to_modelica_string(modelica_integer nr,const modelica_string e[],modelica_integer minLen, modelica_boolean leftJustified)
{
  return mmc_mk_scon(e[nr-1]);
}
Example #21
0
int SimulationResults_filterSimulationResults(const char *inFile, const char *outFile, void *vars, int numberOfIntervals)
{
  const char *msg[5] = {"","","","",""};
  void *tmp;
  if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(inFile, &simresglob)) {
    return 0;
  }
  vars = mmc_mk_cons(mmc_mk_scon("time"),vars);
  switch (simresglob.curFormat) {
  case MATLAB4: {
    int numToFilter = listLength(vars);
    int i, j;
    int numUnique = 0;
    int numUniqueParam = 1;
    int longestName = 0;
    int longestDesc = 0;
    ModelicaMatVariable_t **mat_var = omc_alloc_interface.malloc(numToFilter*sizeof(ModelicaMatVariable_t*));
    int *indexes = (int*) omc_alloc_interface.malloc(simresglob.matReader.nvar*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
    int *parameter_indexes = (int*) omc_alloc_interface.malloc(simresglob.matReader.nparam*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
    int *indexesToOutput = NULL;
    int *parameter_indexesToOutput = NULL;
    FILE *fout = NULL;
    char *tmp;
    double start_stop[2] = {0};
    double start = omc_matlab4_startTime(&simresglob.matReader);
    double stop = omc_matlab4_stopTime(&simresglob.matReader);
    parameter_indexes[0] = 1; /* time */
    omc_matlab4_read_all_vals(&simresglob.matReader);
    if (endsWith(outFile,".csv")) {
      double **vals = omc_alloc_interface.malloc(sizeof(double*)*numToFilter);
      FILE *fout = NULL;
      for (i=0; i<numToFilter; i++) {
        const char *var = MMC_STRINGDATA(MMC_CAR(vars));
        vars = MMC_CDR(vars);
        mat_var[i] = omc_matlab4_find_var(&simresglob.matReader, var);
        if (mat_var[i] == NULL) {
          msg[0] = SystemImpl__basename(inFile);
          msg[1] = var;
          c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not read variable %s in file %s."), msg, 2);
          return 0;
        }
        if (mat_var[i]->isParam) {
          msg[0] = var;
          c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not filter parameter %s since the output format is CSV (only variables are allowed)."), msg, 1);
          return 0;
        } else {
          vals[i] = omc_matlab4_read_vals(&simresglob.matReader, mat_var[i]->index);
        }
      }
      fout = fopen(outFile, "w");
      fprintf(fout, "time");
      for (i=1; i<numToFilter; i++) {
        fprintf(fout, ",\"%s\"", mat_var[i]->name);
      }
      fprintf(fout, ",nrows=%d\n", simresglob.matReader.nrows);
      for (i=0; i<simresglob.matReader.nrows; i++) {
        fprintf(fout, "%.15g", vals[0][i]);
        for (j=1; j<numToFilter; j++) {
          fprintf(fout, ",%.15g", vals[j][i]);
        }
        fprintf(fout, "\n");
      }
      fclose(fout);
      return 1;
    } /* Not CSV */

    for (i=0; i<numToFilter; i++) {
      const char *var = MMC_STRINGDATA(MMC_CAR(vars));
      vars = MMC_CDR(vars);
      mat_var[i] = omc_matlab4_find_var(&simresglob.matReader,var);
      if (mat_var[i] == NULL) {
        msg[0] = SystemImpl__basename(inFile);
        msg[1] = var;
        c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not read variable %s in file %s."), msg, 2);
        return 0;
      }
      if (mat_var[i]->isParam) {
        /* Store the old index in the array */
        if (0==parameter_indexes[abs(mat_var[i]->index)-1]++) {
          numUniqueParam++;
        }
      } else {
        /* Store the old index in the array */
        if (0==indexes[abs(mat_var[i]->index)-1]++) {
          numUnique++;
        }
      }
      longestName = intMax(longestName, strlen(mat_var[i]->name));
      longestDesc = intMax(longestDesc, strlen(mat_var[i]->descr));
    }
    /* Create the list of variable indexes to output */
    indexesToOutput = omc_alloc_interface.malloc_atomic(numUnique * sizeof(int));
    parameter_indexesToOutput = omc_alloc_interface.malloc_atomic(numUniqueParam * sizeof(int));
    j=0;
    for (i=0; i<simresglob.matReader.nvar; i++) {
      if (indexes[i]) {
        indexesToOutput[j++] = i+1;
      }
      /* indexes becomes the lookup table from old index to new index */
      indexes[i] = j;
    }
    j=0;
    for (i=0; i<simresglob.matReader.nparam; i++) {
      if (parameter_indexes[i]) {
        parameter_indexesToOutput[j++] = i+1;
      }
      /* indexes becomes the lookup table from old index to new index */
      parameter_indexes[i] = j;
    }
    fout = fopen(outFile, "wb");
    if (fout == NULL) {
      return failedToWriteToFile(outFile);
    }
    /* Matrix list: "Aclass" "name" "description" "dataInfo" "data_1" "data_2" */
    if (writeMatVer4AclassNormal(fout)) {
      return failedToWriteToFile(outFile);
    }
    if (writeMatVer4MatrixHeader(fout, "name", numToFilter, longestName, sizeof(int8_t))) {
      return failedToWriteToFile(outFile);
    }

    tmp = omc_alloc_interface.malloc(numToFilter*longestName);
    for (i=0; i<numToFilter; i++) {
      int len = strlen(mat_var[i]->name);
      for (j=0; j<len; j++) {
        tmp[numToFilter*j+i] = mat_var[i]->name[j];
      }
    }
    if (1 != fwrite(tmp, numToFilter*longestName, 1, fout)) {
      return failedToWriteToFile(outFile);
    }
    GC_free(tmp);

    if (writeMatVer4MatrixHeader(fout, "description", numToFilter, longestDesc, sizeof(int8_t))) {
      return failedToWriteToFile(outFile);
    }

    tmp = omc_alloc_interface.malloc(numToFilter*longestDesc);
    for (i=0; i<numToFilter; i++) {
      int len = strlen(mat_var[i]->descr);
      for (j=0; j<len; j++) {
        tmp[numToFilter*j+i] = mat_var[i]->descr[j];
      }
    }
    if (1 != fwrite(tmp, numToFilter*longestDesc, 1, fout)) {
      return failedToWriteToFile(outFile);
    }
    GC_free(tmp);

    if (writeMatVer4MatrixHeader(fout, "dataInfo", numToFilter, 4, sizeof(int32_t))) {
      return failedToWriteToFile(outFile);
    }
    for (i=0; i<numToFilter; i++) {
      int32_t x = mat_var[i]->isParam ? 1 : 2; /* data_1 or data_2 */
      if (1 != fwrite(&x, sizeof(int32_t), 1, fout)) {
        return failedToWriteToFile(outFile);
      }
    }
    for (i=0; i<numToFilter; i++) {
      int32_t x = (mat_var[i]->index < 0 ? -1 : 1) * (mat_var[i]->isParam ? parameter_indexes[abs(mat_var[i]->index)-1] : indexes[abs(mat_var[i]->index)-1]);
      if (1 != fwrite(&x, sizeof(int32_t), 1, fout)) {
        return failedToWriteToFile(outFile);
      }
    }
    for (i=0; i<numToFilter; i++) {
      int32_t x = 0; /* linear interpolation */
      if (1 != fwrite(&x, sizeof(int32_t), 1, fout)) {
        return failedToWriteToFile(outFile);
      }
    }
    for (i=0; i<numToFilter; i++) {
      int32_t x = -1; /* not defined outside the time interval */
      if (1 != fwrite(&x, sizeof(int32_t), 1, fout)) {
        return failedToWriteToFile(outFile);
      }
    }

    if (writeMatVer4MatrixHeader(fout, "data_1", 2, numUniqueParam, sizeof(double))) {
      return failedToWriteToFile(outFile);
    }
    start = omc_matlab4_startTime(&simresglob.matReader);
    stop = omc_matlab4_stopTime(&simresglob.matReader);
    start_stop[0]=start;
    start_stop[1]=stop;

    if (1 != fwrite(start_stop, sizeof(double)*2, 1, fout)) {
      return failedToWriteToFile(outFile);
    }

    for (i=1; i<numUniqueParam; i++) {
      int paramIndex = parameter_indexesToOutput[i];
      double d[2] = {simresglob.matReader.params[abs(paramIndex)-1],0};
      d[1] = d[0];
      if (1!=fwrite(d, sizeof(double)*2, 1, fout)) {
        return failedToWriteToFile(outFile);
      }
    }

    if (numberOfIntervals) {
      double *timevals = omc_matlab4_read_vals(&simresglob.matReader, 1);
      int last_found=0;
      int nevents=0, neventpoints=0;
      for (i=1; i<numberOfIntervals; i++) {
        double t = start + (stop-start)*((double)i)/numberOfIntervals;
        while (timevals[j]<=t) {
          if (timevals[j]==timevals[j+1]) {
            while (timevals[j]==timevals[j+1]) {
              j++;
              neventpoints++;
            }
            nevents++;
          }
          j++;
        }
      }
      msg[4] = inFile;
      GC_asprintf((char**)msg+3, "%d", simresglob.matReader.nrows);
      GC_asprintf((char**)msg+2, "%d", numberOfIntervals);
      GC_asprintf((char**)msg+1, "%d", nevents);
      GC_asprintf((char**)msg+0, "%d", neventpoints);
      c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_notification, gettext("Resampling %s from %s points to %s points, removing %s events stored in %s points.\n"), msg, 5);
    }

    if (writeMatVer4MatrixHeader(fout, "data_2", numberOfIntervals ? numberOfIntervals+1 : simresglob.matReader.nrows, numUnique, sizeof(double))) {
      return failedToWriteToFile(outFile);
    }
    for (i=0; i<numUnique; i++) {
      double *vals = NULL;
      int nrows;
      if (numberOfIntervals) {
        omc_matlab4_read_all_vals(&simresglob.matReader);
        nrows = numberOfIntervals+1;
        vals = omc_alloc_interface.malloc_atomic(sizeof(double)*nrows);
        for (j=0; j<=numberOfIntervals; j++) {
          double t = j==numberOfIntervals ? stop : start + (stop-start)*((double)j)/numberOfIntervals;
          ModelicaMatVariable_t var = {0};
          var.name="";
          var.descr="";
          var.isParam=0;
          var.index=indexesToOutput[i];
          if (omc_matlab4_val(vals+j, &simresglob.matReader, &var, t)) {
            msg[2] = inFile;
            GC_asprintf((char**)msg+1, "%d", indexesToOutput[i]);
            GC_asprintf((char**)msg+0, "%.15g", t);
            c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Resampling %s failed to get variable %s at time %s.\n"), msg, 3);
            return 0;
          }
        }
      } else {
        vals = omc_matlab4_read_vals(&simresglob.matReader, indexesToOutput[i]);
        nrows = simresglob.matReader.nrows;
      }
      if (1!=fwrite(vals, sizeof(double)*nrows, 1, fout)) {
        return failedToWriteToFile(outFile);
      }
      if (numberOfIntervals) {
        GC_free(vals);
      }
    }
    fclose(fout);
    return 1;
  }
  default:
    msg[0] = PlotFormatStr[simresglob.curFormat];
    c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("filterSimulationResults not implemented for plot format: %s\n"), msg, 1);
    return 0;
  }
}
Example #22
0
modelica_string modelica_string_format_to_c_string_format(modelica_string format)
{
  char buf[FMT_BUFSIZE];
  const char *str = MMC_STRINGDATA(format), *tmp = str;
  int cont=1, n=0;
  buf[n++] = '%';
  while (cont) { /* Parse flag characters */
    switch (*tmp) {
    /* Extended flags? ',I */
    case '#':
    case '0':
    case '-':
    case ' ':
    case '+':
      buf[n] = *(tmp++);
      checkBufSize(str, n++);
      break;
    default:
      cont = 0;
    }
  }
  // width: [1-9][0-9]*
  if ((*tmp >= '1') || (*tmp <= '9')) {
    while (*tmp >= '0' && *tmp <= '9') {
      buf[n] = *(tmp++);
      checkBufSize(str, n++);
    }
  }
  // precision: .[0-9]*
  if (*tmp == '.') {
    buf[n] = *(tmp++);
    checkBufSize(str, n++);
    while (*tmp >= '0' && *tmp <= '9') {
      buf[n] = *(tmp++);
      checkBufSize(str, n++);
    }
  }

  switch (*tmp) {
  case 'f':
  case 'e':
  case 'E':
  case 'g':
  case 'G':
    /* double */
  case 'c':
    /* int */
    buf[n] = *(tmp++);
    checkBufSize(str, n++);
    break;
  case 'd':
  case 'i':
    /* int */
  case 'o':
  case 'x':
  case 'X':
  case 'u':
    /* uint */
    buf[n] = 'l'; /* we use long in OpenModelica */
    checkBufSize(str, n++);
    buf[n] = *(tmp++);
    checkBufSize(str, n++);
    break;
  case 'h':
  case 'l':
  case 'L':
  case 'q':
  case 'j':
  case 'z':
  case 't':
    omc_assert(NULL, dummyFILE_INFO, "Length modifiers are not legal in Modelica format strings: %s", str);
    break;
  default:
    omc_assert(NULL, dummyFILE_INFO, "Could not parse format string: invalid conversion specifier: %c in %s", *tmp, str);
  }
  if (*tmp) {
    omc_assert(NULL, dummyFILE_INFO, "Could not parse format string: trailing data after the format directive", *tmp, str);
  }
  buf[n] = '\0';
  return mmc_mk_scon(buf);
}