Changeset 2f79bb55 in OpenModelica


Ignore:
Timestamp:
2010-11-26T18:32:05+01:00 (13 years ago)
Author:
Martin Sjölund <martin.sjolund@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
2bdc23d5
Parents:
0adb6189
Message:
  • Added support for SimulationResult (79/119 mosfiles succeed)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7207 f25d12d1-65f4-0310-ae8a-bbce733d8d8e

Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • Compiler/SimulationResults.mo

    rdb22d3e7 r2f79bb55  
    4040
    4141public import Values;
     42protected import ValuesUtil;
    4243
    4344public function readPtolemyplotVariables
     
    4950end readPtolemyplotVariables;
    5051
    51 public function readPtolemyplotDataset
     52protected function readPtolemyplotDatasetWork
    5253  input String inString;
    5354  input list<String> inStringLst;
     
    5657
    5758  external "C" outValue=SimulationResults_readPtolemyplotDataset(inString,inStringLst,inInteger) annotation(Library = "omcruntime");
     59end readPtolemyplotDatasetWork;
     60
     61public function readPtolemyplotDataset
     62  input String inString;
     63  input list<String> inStringLst;
     64  input Integer inInteger;
     65  output Values.Value outValue;
     66algorithm
     67  outValue := ValuesUtil.reverseMatrix(readPtolemyplotDatasetWork(inString,inStringLst,inInteger));
    5868end readPtolemyplotDataset;
    5969
  • Compiler/runtime/Makefile.common

    r3de1383b r2f79bb55  
    2121  SimulationResults_rml.c IOStreamExt_rml.c rtclock.c Database.c Socket_rml.c
    2222
    23 CPPSRC  = unitparser.cpp UnitParserExt_rml.cpp ptolemyio.cpp \
     23CPPSRC  = unitparser.cpp UnitParserExt_rml.cpp ptolemyio_rml.cpp \
    2424  BackendDAEEXT_rml.cpp ErrorMessage.cpp Error_rml.cpp OptManager_rml.cpp \
    2525  systemimplmisc.cpp Dynload_rml.cpp $(CORBASRC)
     
    3030  IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o rtclock.o \
    3131  UnitParserExt_omc.o unitparser.o BackendDAEEXT_omc.o Socket_omc.o \
    32   Dynload_omc.o OptManager_omc.o SimulationResults_omc.o $(OMCCORBASRC)
     32  Dynload_omc.o OptManager_omc.o SimulationResults_omc.o ptolemyio_omc.o $(OMCCORBASRC)
    3333
    3434all: runtime.a install
     
    7373Socket_rml.o : socketimpl.c
    7474Socket_omc.o : socketimpl.c
     75ptolemyio_rml.o : ptolemyio.cpp
     76ptolemyio_omc.o : ptolemyio.cpp
    7577
    7678clean:
  • Compiler/runtime/SimulationResults_omc.cpp

    r130fe761 r2f79bb55  
    3232#include <stdlib.h>
    3333
     34#include "meta_modelica.h"
     35#include "OpenModelicaBootstrappingHeader.h"
     36
    3437extern "C" {
     38
     39void* read_ptolemy_dataset(const char*filename, int size,const char**vars,int);
     40void* read_ptolemy_variables(const char* filename, const char* visvars);
     41int read_ptolemy_dataset_size(const char*filename);
    3542
    3643void* SimulationResults_readPtolemyplotVariables(const char *filename, const char *visvars)
    3744{
    38   fprintf(stderr, "SimulationResults_readPtolemyplotVariables NYI\n");
    39   exit(1);
     45  void* res = read_ptolemy_variables(filename, visvars);
     46  if (res == NULL) MMC_THROW();
     47  return res;
    4048}
    4149
    42 void* SimulationResults_readPtolemyplotDataset(const char *filename, void *vars, int i)
     50extern void* _ValuesUtil_reverseMatrix(void*);
     51void* SimulationResults_readPtolemyplotDataset(const char *filename, void *lst, int datasize)
    4352{
    44   fprintf(stderr, "SimulationResults_readPtolemyplotDataset NYI\n");
    45   exit(1);
     53  int i, size = listLength(lst);
     54  void *p,*res;
     55  const char** vars = (const char**) malloc(sizeof(const char*)*size);
     56  for (i=0, p=lst; i<size; i++) {
     57    vars[i] = MMC_STRINGDATA(MMC_CAR(p));
     58    p = MMC_CDR(p);
     59  }
     60  res = read_ptolemy_dataset(filename,size,vars,datasize);
     61  if (res == NULL) MMC_THROW();
     62  return res;
    4663}
    4764
    4865void* SimulationResults_readPtolemyplotDatasetSize(const char *filename)
    4966{
    50   fprintf(stderr, "SimulationResults_readPtolemyplotDatasetSize NYI\n");
    51   exit(1);
     67  return Values__INTEGER(mmc_mk_icon(read_ptolemy_dataset_size(filename)));
    5268}
    5369
  • Compiler/runtime/SimulationResults_rml.c

    rdb22d3e7 r2f79bb55  
    6565  rml_sint_t datasize = RML_UNTAGFIXNUM(rmlA2);
    6666  void* p;
     67  /* Dark magic, be aware */
    6768  rmlA0 = lst;
    6869  rml_prim_once(RML__list_5flength);
     
    7980  }
    8081
    81   rml_prim_once(ValuesUtil__reverseMatrix);
    82 
    83   RML_TAILCALLK(rmlSC);
     82  RML_TAILCALLQ(ValuesUtil__reverseMatrix,1);
    8483}
    8584RML_END_LABEL
     
    9089  char* filename = RML_STRINGDATA(rmlA0);
    9190  void* p;
    92 
    9391  size = read_ptolemy_dataset_size(filename);
    94 
    9592  rmlA0 = (void*)Values__INTEGER(mk_icon(size));
    96   if (rmlA0 == NULL) {
    97     RML_TAILCALLK(rmlFC);
    98   }
    9993  RML_TAILCALLK(rmlSC);
    10094}
  • Compiler/runtime/System_omc.cpp

    r13108204 r2f79bb55  
    2929 */
    3030
     31#include "meta_modelica.h"
     32#include "rml_compatibility.h"
    3133#include "systemimpl.c"
    3234
     
    243245extern double System_getVariableValue(double _timeStamp, void* _timeValues, void* _varValues)
    244246{
    245   fprintf(stderr, "System_getVariableValue NYI\n");
    246   exit(1);
     247  double res;
     248  if (SystemImpl__getVariableValue(_timeStamp,_timeValues,_varValues,&res))
     249    MMC_THROW();
     250  return res;
    247251}
    248252
    249253extern const char* System_getVariableNames(const char* _modelname)
    250254{
    251   fprintf(stderr, "System_getVariableNames NYI\n");
    252   exit(1);
     255  char* res = SystemImpl__getVariableNames(_modelname);
     256  if(res==NULL) MMC_THROW();
     257  return res; /* it's malloc'ed already */
    253258}
    254259
  • Compiler/runtime/System_rml.c

    r13108204 r2f79bb55  
    4242#endif
    4343
     44#include "rml.h"
    4445#include "systemimpl.c"
    45 
    46 #include "rml.h"
    4746
    4847/* use this one to output messages depending on flags! */
     
    505504{
    506505  char* model = RML_STRINGDATA(rmlA0);
    507   int size = getVariableListSize(model);
    508   char* lst = 0;
    509 
    510   if(!size)
    511     RML_TAILCALLK(rmlFC);
    512 
    513   lst = (char*)malloc(sizeof(char)*size +1);
    514 
    515   getVariableList(model, lst);
    516   rmlA0 = (void*)mk_scon(lst);
     506  char* res = SystemImpl__getVariableNames(model);
     507  if (res == NULL)
     508    RML_TAILCALLK(rmlFC);
     509  rmlA0 = (void*)mk_scon(res);
     510  free(res);
    517511  RML_TAILCALLK(rmlSC);
    518512}
     
    589583  void *timeValues   = rmlA1;
    590584  void *varValues   = rmlA2;
    591 
    592   // values to find the correct range
    593   double preValue   = 0.0;
    594   double preTime   = 0.0;
    595   double nowValue   = 0.0;
    596   double nowTime   = 0.0;
    597 
    598   // linjear interpolation data
    599   double timedif       = 0.0;
    600   double valuedif      = 0.0;
    601   double valueSlope      = 0.0;
    602   double timeDifTimeStamp  = 0.0;
    603 
    604   // break loop and return value
    605   int valueFound = 0;
    606   double returnValue = 0.0;
    607 
    608 for(; RML_GETHDR(timeValues) == RML_CONSHDR && valueFound == 0; timeValues = RML_CDR(timeValues), varValues = RML_CDR(varValues)) {
    609 
    610 
    611     nowValue   = rml_prim_get_real(RML_CAR(varValues));
    612     nowTime   =  rml_prim_get_real(RML_CAR(timeValues));
    613 
    614 
    615   if(timeStamp == nowTime){
    616       valueFound   = 1;
    617       returnValue = nowValue;
    618 
    619     } else if (timeStamp >= preTime && timeStamp <= nowTime) { // need to do interpolation
    620       valueFound       = 1;
    621       timedif       = nowTime - preTime;
    622       valuedif      = nowValue - preValue;
    623       valueSlope       = valuedif / timedif;
    624       timeDifTimeStamp   = timeStamp - preTime;
    625       returnValue     = preValue + (valueSlope*timeDifTimeStamp);
    626       /*
    627       printf("\t ### Interpolation ###");
    628       printf("nowTime: %f", nowTime);
    629       printf("\n");
    630       printf("preTime: %f", preTime);
    631       printf("\n");
    632       printf("nowValue: %f", nowValue);
    633       printf("\n");
    634       printf("preValue: %f", preValue);
    635       printf("\n");
    636 
    637     printf("timedif: %f", timedif);
    638       printf("\n");
    639       printf("valuedif: %f", valuedif);
    640       printf("\n");
    641       printf("valueSlope: %f", valueSlope);
    642       printf("\n");
    643       printf("timeDifTimeStamp: %f", timeDifTimeStamp);
    644       printf("\n");
    645       printf("returnValue: %f", returnValue);
    646       printf("\n");
    647     */
    648   } else {
    649     preValue   = nowValue;
    650       preTime   = nowTime;
    651 
    652   }
    653 
    654   }
    655   if(valueFound == 0){
    656     // value could not be found in the dataset, what do we do?
    657       printf("\n WARNING: timestamp(%f) outside simulation timeline \n",timeStamp);
    658     RML_TAILCALLK(rmlFC);
    659   } else {
    660 
    661       rmlA0 = (void*)mk_rcon(returnValue);
    662       RML_TAILCALLK(rmlSC);
    663   }
     585  double res;
     586  if (SystemImpl__getVariableValue(timeStamp,timeValues,varValues,&res))
     587    RML_TAILCALLK(rmlFC);
     588  rmlA0 = mk_rcon(res);
     589  RML_TAILCALLK(rmlSC);
    664590}
    665591RML_END_LABEL
  • Compiler/runtime/ptolemyio.cpp

    rf575064 r2f79bb55  
    4545#include <string.h>
    4646#include <stdlib.h>
    47 #include "rml.h" 
    48 #include "Values.h"
    4947#include <stdio.h>
    5048#include <string.h>
     
    5654/* Given a file name and an array of variables, return the RML datastructure
    5755   in Values for Real[size(vars,1],:] i.e. a matrix of variable values, one column for each variable. */
    58 void * read_ptolemy_dataset(char*filename, int size,char**vars,int datasize)
     56void * read_ptolemy_dataset(const char*filename, int size,const char**vars,int datasize)
    5957{
    6058  char buf[255];
     
    149147
    150148/* Given a file name, returns the size of that simulation result in that file*/
    151 int read_ptolemy_dataset_size(char*filename)
     149int read_ptolemy_dataset_size(const char*filename)
    152150{
    153151  char buf[255];
     
    174172}
    175173
    176 void * read_ptolemy_variables(char* filename, char* visvars)
     174void * read_ptolemy_variables(const char* filename, const char* visvars)
    177175{
    178176  char buf[255];
  • Compiler/runtime/systemimpl.c

    r13108204 r2f79bb55  
    110110static const char *select_from_dir = NULL;
    111111
     112// SendData crap
     113int getVariableListSize(const char* model);
     114unsigned char getVariableList(const char* model, char* lst);
     115
    112116/*
    113117 * Common implementations
     
    747751}
    748752
    749 int SystemImpl__freeFunction(int funcIndex)
     753static int SystemImpl__freeFunction(int funcIndex)
    750754{
    751755  modelica_ptr_t func = NULL, lib = NULL;
     
    778782}
    779783
    780 int SystemImpl__freeLibrary(int libIndex)
     784static int SystemImpl__freeLibrary(int libIndex)
    781785{
    782786  modelica_ptr_t lib = NULL;
     
    797801}
    798802
    799 void free_library(modelica_ptr_t lib)
     803static void free_library(modelica_ptr_t lib)
    800804{
    801805  if (check_debug_flag("dynload")) { fprintf(stderr, "LIB UNLOAD handle[%lu].\n", (unsigned long) lib->data.lib); fflush(stderr); }
     
    808812}
    809813
    810 void free_function(modelica_ptr_t func)
     814static void free_function(modelica_ptr_t func)
    811815{
    812816  /* noop */
     
    816820}
    817821
     822static int SystemImpl__getVariableValue(double timeStamp, void* timeValues, void *varValues, double *returnValue)
     823{
     824  // values to find the correct range
     825  double preValue   = 0.0;
     826  double preTime   = 0.0;
     827  double nowValue   = 0.0;
     828  double nowTime   = 0.0;
     829
     830  // linjear interpolation data
     831  double timedif       = 0.0;
     832  double valuedif      = 0.0;
     833  double valueSlope      = 0.0;
     834  double timeDifTimeStamp  = 0.0;
     835
     836  // break loop and return value
     837  int valueFound = 0;
     838
     839  for(; RML_GETHDR(timeValues) == RML_CONSHDR && valueFound == 0; timeValues = RML_CDR(timeValues), varValues = RML_CDR(varValues)) {
     840    nowValue   = rml_prim_get_real(RML_CAR(varValues));
     841    nowTime   =  rml_prim_get_real(RML_CAR(timeValues));
     842
     843    if(timeStamp == nowTime){
     844      valueFound   = 1;
     845      *returnValue = nowValue;
     846    } else if (timeStamp >= preTime && timeStamp <= nowTime) { // need to do interpolation
     847      valueFound       = 1;
     848      timedif          = nowTime - preTime;
     849      valuedif         = nowValue - preValue;
     850      valueSlope       = valuedif / timedif;
     851      timeDifTimeStamp = timeStamp - preTime;
     852      *returnValue     = preValue + (valueSlope*timeDifTimeStamp);
     853    } else {
     854      preValue  = nowValue;
     855      preTime   = nowTime;
     856    }
     857  }
     858
     859  if(valueFound == 0){
     860    // value could not be found in the dataset, what do we do?
     861    printf("\n WARNING: timestamp(%f) outside simulation timeline \n", timeStamp);
     862    return 1;
     863  }
     864  return 0;
     865}
     866
     867static char* SystemImpl__getVariableNames(const char* model)
     868{
     869  int size = getVariableListSize(model);
     870  char *res;
     871  if(!size) return NULL;
     872  res = (char*)malloc(sizeof(char)*size +1);
     873  getVariableList(model, res);
     874  return res;
     875}
     876
     877
    818878#ifdef __cplusplus
    819879}
  • c_runtime/rml_compatibility.h

    r13108204 r2f79bb55  
    6969#define RML_FETCH MMC_FETCH
    7070#define RML_OFFSET MMC_OFFSET
     71#define RML_CONSHDR MMC_CONSHDR
    7172
    7273/* For external functions, since I was stupid and put the
Note: See TracChangeset for help on using the changeset viewer.