Changeset 2f79bb55 in OpenModelica
- Timestamp:
- 2010-11-26T18:32:05+01:00 (13 years ago)
- 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
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Compiler/SimulationResults.mo
rdb22d3e7 r2f79bb55 40 40 41 41 public import Values; 42 protected import ValuesUtil; 42 43 43 44 public function readPtolemyplotVariables … … 49 50 end readPtolemyplotVariables; 50 51 51 p ublic function readPtolemyplotDataset52 protected function readPtolemyplotDatasetWork 52 53 input String inString; 53 54 input list<String> inStringLst; … … 56 57 57 58 external "C" outValue=SimulationResults_readPtolemyplotDataset(inString,inStringLst,inInteger) annotation(Library = "omcruntime"); 59 end readPtolemyplotDatasetWork; 60 61 public function readPtolemyplotDataset 62 input String inString; 63 input list<String> inStringLst; 64 input Integer inInteger; 65 output Values.Value outValue; 66 algorithm 67 outValue := ValuesUtil.reverseMatrix(readPtolemyplotDatasetWork(inString,inStringLst,inInteger)); 58 68 end readPtolemyplotDataset; 59 69 -
Compiler/runtime/Makefile.common
r3de1383b r2f79bb55 21 21 SimulationResults_rml.c IOStreamExt_rml.c rtclock.c Database.c Socket_rml.c 22 22 23 CPPSRC = unitparser.cpp UnitParserExt_rml.cpp ptolemyio .cpp \23 CPPSRC = unitparser.cpp UnitParserExt_rml.cpp ptolemyio_rml.cpp \ 24 24 BackendDAEEXT_rml.cpp ErrorMessage.cpp Error_rml.cpp OptManager_rml.cpp \ 25 25 systemimplmisc.cpp Dynload_rml.cpp $(CORBASRC) … … 30 30 IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o rtclock.o \ 31 31 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) 33 33 34 34 all: runtime.a install … … 73 73 Socket_rml.o : socketimpl.c 74 74 Socket_omc.o : socketimpl.c 75 ptolemyio_rml.o : ptolemyio.cpp 76 ptolemyio_omc.o : ptolemyio.cpp 75 77 76 78 clean: -
Compiler/runtime/SimulationResults_omc.cpp
r130fe761 r2f79bb55 32 32 #include <stdlib.h> 33 33 34 #include "meta_modelica.h" 35 #include "OpenModelicaBootstrappingHeader.h" 36 34 37 extern "C" { 38 39 void* read_ptolemy_dataset(const char*filename, int size,const char**vars,int); 40 void* read_ptolemy_variables(const char* filename, const char* visvars); 41 int read_ptolemy_dataset_size(const char*filename); 35 42 36 43 void* SimulationResults_readPtolemyplotVariables(const char *filename, const char *visvars) 37 44 { 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; 40 48 } 41 49 42 void* SimulationResults_readPtolemyplotDataset(const char *filename, void *vars, int i) 50 extern void* _ValuesUtil_reverseMatrix(void*); 51 void* SimulationResults_readPtolemyplotDataset(const char *filename, void *lst, int datasize) 43 52 { 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; 46 63 } 47 64 48 65 void* SimulationResults_readPtolemyplotDatasetSize(const char *filename) 49 66 { 50 fprintf(stderr, "SimulationResults_readPtolemyplotDatasetSize NYI\n"); 51 exit(1); 67 return Values__INTEGER(mmc_mk_icon(read_ptolemy_dataset_size(filename))); 52 68 } 53 69 -
Compiler/runtime/SimulationResults_rml.c
rdb22d3e7 r2f79bb55 65 65 rml_sint_t datasize = RML_UNTAGFIXNUM(rmlA2); 66 66 void* p; 67 /* Dark magic, be aware */ 67 68 rmlA0 = lst; 68 69 rml_prim_once(RML__list_5flength); … … 79 80 } 80 81 81 rml_prim_once(ValuesUtil__reverseMatrix); 82 83 RML_TAILCALLK(rmlSC); 82 RML_TAILCALLQ(ValuesUtil__reverseMatrix,1); 84 83 } 85 84 RML_END_LABEL … … 90 89 char* filename = RML_STRINGDATA(rmlA0); 91 90 void* p; 92 93 91 size = read_ptolemy_dataset_size(filename); 94 95 92 rmlA0 = (void*)Values__INTEGER(mk_icon(size)); 96 if (rmlA0 == NULL) {97 RML_TAILCALLK(rmlFC);98 }99 93 RML_TAILCALLK(rmlSC); 100 94 } -
Compiler/runtime/System_omc.cpp
r13108204 r2f79bb55 29 29 */ 30 30 31 #include "meta_modelica.h" 32 #include "rml_compatibility.h" 31 33 #include "systemimpl.c" 32 34 … … 243 245 extern double System_getVariableValue(double _timeStamp, void* _timeValues, void* _varValues) 244 246 { 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; 247 251 } 248 252 249 253 extern const char* System_getVariableNames(const char* _modelname) 250 254 { 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 */ 253 258 } 254 259 -
Compiler/runtime/System_rml.c
r13108204 r2f79bb55 42 42 #endif 43 43 44 #include "rml.h" 44 45 #include "systemimpl.c" 45 46 #include "rml.h"47 46 48 47 /* use this one to output messages depending on flags! */ … … 505 504 { 506 505 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); 517 511 RML_TAILCALLK(rmlSC); 518 512 } … … 589 583 void *timeValues = rmlA1; 590 584 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); 664 590 } 665 591 RML_END_LABEL -
Compiler/runtime/ptolemyio.cpp
rf575064 r2f79bb55 45 45 #include <string.h> 46 46 #include <stdlib.h> 47 #include "rml.h"48 #include "Values.h"49 47 #include <stdio.h> 50 48 #include <string.h> … … 56 54 /* Given a file name and an array of variables, return the RML datastructure 57 55 in Values for Real[size(vars,1],:] i.e. a matrix of variable values, one column for each variable. */ 58 void * read_ptolemy_dataset(c har*filename, int size,char**vars,int datasize)56 void * read_ptolemy_dataset(const char*filename, int size,const char**vars,int datasize) 59 57 { 60 58 char buf[255]; … … 149 147 150 148 /* Given a file name, returns the size of that simulation result in that file*/ 151 int read_ptolemy_dataset_size(c har*filename)149 int read_ptolemy_dataset_size(const char*filename) 152 150 { 153 151 char buf[255]; … … 174 172 } 175 173 176 void * read_ptolemy_variables(c har* filename,char* visvars)174 void * read_ptolemy_variables(const char* filename, const char* visvars) 177 175 { 178 176 char buf[255]; -
Compiler/runtime/systemimpl.c
r13108204 r2f79bb55 110 110 static const char *select_from_dir = NULL; 111 111 112 // SendData crap 113 int getVariableListSize(const char* model); 114 unsigned char getVariableList(const char* model, char* lst); 115 112 116 /* 113 117 * Common implementations … … 747 751 } 748 752 749 int SystemImpl__freeFunction(int funcIndex)753 static int SystemImpl__freeFunction(int funcIndex) 750 754 { 751 755 modelica_ptr_t func = NULL, lib = NULL; … … 778 782 } 779 783 780 int SystemImpl__freeLibrary(int libIndex)784 static int SystemImpl__freeLibrary(int libIndex) 781 785 { 782 786 modelica_ptr_t lib = NULL; … … 797 801 } 798 802 799 void free_library(modelica_ptr_t lib)803 static void free_library(modelica_ptr_t lib) 800 804 { 801 805 if (check_debug_flag("dynload")) { fprintf(stderr, "LIB UNLOAD handle[%lu].\n", (unsigned long) lib->data.lib); fflush(stderr); } … … 808 812 } 809 813 810 void free_function(modelica_ptr_t func)814 static void free_function(modelica_ptr_t func) 811 815 { 812 816 /* noop */ … … 816 820 } 817 821 822 static 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 867 static 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 818 878 #ifdef __cplusplus 819 879 } -
c_runtime/rml_compatibility.h
r13108204 r2f79bb55 69 69 #define RML_FETCH MMC_FETCH 70 70 #define RML_OFFSET MMC_OFFSET 71 #define RML_CONSHDR MMC_CONSHDR 71 72 72 73 /* For external functions, since I was stupid and put the
Note: See TracChangeset
for help on using the changeset viewer.