コード例 #1
0
// output time and all variables in CSV format
// if separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
// otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used
// as decimal dot in floating-point numbers.
void outputRow(double value, double time, FILE* file, char separator, bool header) {
    fmiReal r = value;
    char buffer[32];

    // print first column
    if (header) {
        fprintf(file, "time");
    }
    else {
        if (separator==',') {
            fprintf(file, "%.16g", time);
        }
        else {
            // separator is e.g. ';' or '\t'
            doubleToCommaString(buffer, time);
            fprintf(file, "%s", buffer);
        }
    }

    // print result column
    if (header) {
        // output names only
        if (separator == ',') {
            // treat array element, e.g. print a[1, 2] as a[1.2]
            const char* s = "output";
            fprintf(file, "%c", separator);
            while (*s) {
                if (*s != ' ') {
                    fprintf(file, "%c", *s == ',' ? '.' : *s);
                }
                s++;
            }
        }
        else {
            fprintf(file, "%c%s", separator, "output");
        }
    }
    else {
            // output values
            if (separator == ',') {
                fprintf(file, ",%.16g", r);
            }
            else {
                // separator is e.g. ';' or '\t'
                doubleToCommaString(buffer, r);
                fprintf(file, "%c%s", separator, buffer);
            }
    }
    // terminate this row
    fprintf(file, "\n");
}
コード例 #2
0
ファイル: main.c プロジェクト: rajdye/modelica-projects
///////////////////////////////////////////////////////////////////////////////
/// Output time and all non-alias variables in CSV format.
/// If separator is ',', columns are separated by ',' and '.' is used for floating-point numbers.
/// Otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used for 
/// floating-point numbers.
///
///\param fmu FMU.
///\param c FMI component.
///\param time Time when data is outputed.
///\param separator Separator in file.
///\param header Indicator of row head.
///////////////////////////////////////////////////////////////////////////////
static void outputRow(FMU *fmu, fmiComponent c, double time, FILE* file, char separator, boolean header, double x, double y) {
  int k;
  fmiReal r;
  fmiInteger i;
  fmiBoolean b;
  fmiString s;
  fmiValueReference vr;				
  ScalarVariable** vars = fmu->modelDescription->modelVariables;
  char buffer[32];
  
  // Print first column
  if (header) 
    fprintf(file, "time"); 
  else {
    if (separator==',') 
      fprintf(file, "%.4f", time);				
    else {
      // Separator is e.g. ';' or '\t'
      doubleToCommaString(buffer, time);
      fprintf(file, "%s", buffer);       
    }
  }
    
  // Print all other columns
  for (k=0; vars[k]; k++) {
    ScalarVariable* sv = vars[k];
    if (getAlias(sv)!=enu_noAlias) continue;
    if (header) {
      // Output names only
      fprintf(file, "%c%s", separator, getName(sv));
    }
    else {
      // Output values
      vr = getValueReference(sv);
      switch (sv->typeSpec->type){
        case elm_Real:
          fmu->getReal(c, &vr, 1, &r);
          if (separator==',') 
            fprintf(file, ",%.4f", r);				
        else {
          // Separator is e.g. ';' or '\t'
          doubleToCommaString(buffer, r);
          fprintf(file, "%c%s", separator, buffer);       
          }
          break;
        case elm_Integer:
          fmu->getInteger(c, &vr, 1, &i);
          fprintf(file, "%c%d", separator, i);
          break;
        case elm_Boolean:
          fmu->getBoolean(c, &vr, 1, &b);
          fprintf(file, "%c%d", separator, b);
          break;
        case elm_String:
		  printDebug("get string in outputrow");
          //fmu->getString(c, &vr, 1, &s);
          //fprintf(file, "%c%s", separator, s);
          break;
      }
    }
  } // for
    
  // Terminate this row
  fprintf(file, "\n"); 
}