-
Notifications
You must be signed in to change notification settings - Fork 298
/
System.mo
1297 lines (1102 loc) · 45.4 KB
/
System.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package System
" file: System.mo
package: System
description: This file contains runtime system specific function, which are implemented in C.
This module contain a set of system calls, for e.g. compiling and
executing stuff, reading and writing files and so on."
protected
import Autoconf;
public function trim
"removes chars in charsToRemove from begin and end of inString"
input String inString;
input String charsToRemove = " \f\n\r\t\v";
output String outString;
external "C" outString=System_trim(inString,charsToRemove) annotation(Library = "omcruntime");
end trim;
public function trimWhitespace
"removes chars in ' \f\n\r\t\v' from begin and end of inString"
input String inString;
output String outString;
algorithm
outString := trim(inString);
end trimWhitespace;
public function trimChar
input String inString1;
input String inString2;
output String outString;
external "C" outString=System_trimChar(inString1,inString2) annotation(Library = "omcruntime");
end trimChar;
public function strcmp
"This function returns:
0 if inString1 == inString2
1 if inString1 > inString2
-1 if inString1 < inString2
This is different from what C strcmp
returns (negative values if <, positive values if >).
We fix negative values to -1 and positive to +1 so
we can pattern match on them directly in MetaModelica!"
input String inString1;
input String inString2;
output Integer outInteger;
external "C" outInteger=System_strcmp(inString1,inString2) annotation(Library = "omcruntime");
end strcmp;
public function strcmp_offset
"Like strcmp, but also takes offset and lengths of the strings in order to avoid building them through substring"
input String string1;
input Integer offset1;
input Integer length1;
input String string2;
input Integer offset2;
input Integer length2;
output Integer outInteger;
external "C" outInteger=System_strcmp_offset(string1,offset1,length1,string2,offset2,length2) annotation(Library = "omcruntime");
end strcmp_offset;
public function stringFind "locates substring searchStr in str. If succeeds return position (starting from 0), otherwise return -1"
input String str;
input String searchStr;
output Integer outInteger;
external "C" outInteger=System_stringFind(str,searchStr) annotation(Library = "omcruntime");
end stringFind;
public function stringFindString "locates substring searchStr in str. If succeeds return the string, otherwise fail"
input String str;
input String searchStr;
output String outString;
external "C" outString=System_stringFindString(str,searchStr) annotation(Library = "omcruntime");
end stringFindString;
public function regex "Fails and sets Error.mo if the regex does not compile.
The returned result is the same as POSIX regex():
The first value is the complete matched string
The rest are the substrings that you wanted.
For example:
regex(lorem,\" \\([A-Za-z]*\\) \\([A-Za-z]*\\) \",maxMatches=3)
=> {\" ipsum dolor \",\"ipsum\",\"dolor\"}
This means if you have n groups, you want maxMatches=n+1
"
input String str;
input String re;
input Integer maxMatches "The maximum number of matches that will be returned";
input Boolean extended=false "Use POSIX extended or regular syntax";
input Boolean ignoreCase=false;
output Integer numMatches "0 means no match, else returns a number 1..maxMatches (1 if maxMatches<0)";
output list<String> strs "This list has length = maxMatches. Substrings that did not match are filled with the empty string";
external "C" strs=System_regex(str,re,maxMatches,extended,ignoreCase,numMatches) annotation(Library = "omcruntime");
end regex;
public function strncmp
input String inString1;
input String inString2;
input Integer len;
output Integer outInteger;
external "C" outInteger=System_strncmp(inString1,inString2,len) annotation(Library = "omcruntime");
end strncmp;
public function stringReplace
input String str;
input String source;
input String target;
output String res;
external "C" res=System_stringReplace(str,source,target) annotation(Library = "omcruntime");
end stringReplace;
public function makeC89Identifier "Replaces unknown characters with _"
input String str;
output String res;
external "C" res=System_makeC89Identifier(str) annotation(Library = "omcruntime");
end makeC89Identifier;
public function toupper
input String inString;
output String outString;
external "C" outString=System_toupper(inString) annotation(Library = "omcruntime");
end toupper;
public function tolower
input String inString;
output String outString;
external "C" outString=System_tolower(inString) annotation(Library = "omcruntime");
end tolower;
public function strtok
input String string;
input String token;
output list<String> strings;
external "C" strings=System_strtok(string,token) annotation(Library = "omcruntime");
end strtok;
public function strtokIncludingDelimiters
"as strtok but also includes *all* delimiters
split the string at delimiters into a list of strings including *all* delimiters
stringSplitInTokens(*a**b*, *) => {*, a, *, *, b, *}"
input String string;
input String token;
output list<String> strings;
external "C" strings=System_strtokIncludingDelimiters(string,token) annotation(Library = "omcruntime");
end strtokIncludingDelimiters;
public function setCCompiler
input String inString;
external "C" SystemImpl__setCCompiler(inString) annotation(Library = "omcruntime");
end setCCompiler;
public function getCCompiler
output String outString;
external "C" outString=System_getCCompiler() annotation(Library = "omcruntime");
end getCCompiler;
public function setCFlags
input String inString;
external "C" SystemImpl__setCFlags(inString) annotation(Library = "omcruntime");
end setCFlags;
public function getCFlags
output String outString;
external "C" outString=System_getCFlags() annotation(Library = "omcruntime");
end getCFlags;
public function setCXXCompiler
input String inString;
external "C" SystemImpl__setCXXCompiler(inString) annotation(Library = "omcruntime");
end setCXXCompiler;
public function getCXXCompiler
output String outString;
external "C" outString=System_getCXXCompiler() annotation(Library = "omcruntime");
end getCXXCompiler;
public function getOMPCCompiler
output String outString;
external "C" outString=System_getOMPCCompiler() annotation(Library = "omcruntime");
end getOMPCCompiler;
public function setLinker
input String inString;
external "C" SystemImpl__setLinker(inString) annotation(Library = "omcruntime");
end setLinker;
public function getLinker
output String outString;
external "C" outString=System_getLinker() annotation(Library = "omcruntime");
end getLinker;
public function setLDFlags
input String inString;
external "C" SystemImpl__setLDFlags(inString) annotation(Library = "omcruntime");
end setLDFlags;
public function getLDFlags
output String outString;
external "C" outString=System_getLDFlags() annotation(Library = "omcruntime");
end getLDFlags;
public function loadLibrary
input String inLib;
input Boolean inPrintDebug;
output Integer outLibHandle;
external "C" outLibHandle=System_loadLibrary(inLib, inPrintDebug) annotation(Library = "omcruntime");
end loadLibrary;
public function lookupFunction
input Integer inLibHandle;
input String inFunc;
output Integer outFuncHandle;
external "C" outFuncHandle=System_lookupFunction(inLibHandle,inFunc) annotation(Library = "omcruntime");
end lookupFunction;
public function freeFunction
input Integer inFuncHandle;
input Boolean inPrintDebug;
external "C" System_freeFunction(inFuncHandle, inPrintDebug) annotation(Library = "omcruntime");
end freeFunction;
public function freeLibrary
input Integer inLibHandle;
input Boolean inPrintDebug;
external "C" System_freeLibrary(inLibHandle, inPrintDebug) annotation(Library = "omcruntime");
end freeLibrary;
public function writeFile
"This function will write to the file given by first argument the given string"
input String fileNameToWrite "a filename where to write the data";
input String stringToBeWritten "the data";
external "C" System_writeFile(fileNameToWrite,stringToBeWritten) annotation(Library = "omcruntime");
end writeFile;
public function appendFile
input String file;
input String data;
external "C" System_appendFile(file,data) annotation(Library = "omcruntime");
end appendFile;
public function readFile
"Does not fail. Returns strings describing the error instead."
input String inString;
output String outString;
external "C" outString = System_readFile(inString) annotation(Library = "omcruntime");
end readFile;
public function systemCall
input String command;
input String outFile = "" "empty file means no redirection unless it is part of the command";
output Integer outInteger;
external "C" outInteger=SystemImpl__systemCall(command,outFile) annotation(Library = "omcruntime");
end systemCall;
public function popen "Run the command and return the stdout as a string"
input String command;
output String contents;
output Integer status;
external "C" contents=System_popen(OpenModelica.threadData(), command, status) annotation(Library = "omcruntime");
end popen;
public function systemCallParallel
input list<String> inStrings;
input Integer numThreads;
output list<Integer> outIntegers;
external "C" outIntegers=SystemImpl__systemCallParallel(inStrings,numThreads) annotation(Library = "omcruntime");
end systemCallParallel;
public function spawnCall
input String path "The absolute path to the executable";
input String str "The list of arguments with executable";
output Integer outInteger;
external "C" outInteger=SystemImpl__spawnCall(path,str) annotation(Library = "omcruntime");
end spawnCall;
public function plotCallBackDefined
output Boolean outBoolean;
external "C" outBoolean=SystemImpl__plotCallBackDefined(OpenModelica.threadData()) annotation(Library = "omcruntime");
end plotCallBackDefined;
public function plotCallBack
input Boolean externalWindow;
input String filename;
input String title;
input String grid;
input String plotType;
input String logX;
input String logY;
input String xLabel;
input String yLabel;
input String x1;
input String x2;
input String y1;
input String y2;
input String curveWidth;
input String curveStyle;
input String legendPosition;
input String footer;
input String autoScale;
input String variables;
external "C" SystemImpl__plotCallBack(OpenModelica.threadData(), externalWindow, filename, title, grid, plotType, logX, logY, xLabel, yLabel, x1, x2, y1, y2, curveWidth, curveStyle, legendPosition, footer, autoScale, variables) annotation(Library = "omcruntime");
end plotCallBack;
public function cd
input String inString;
output Integer outInteger;
external "C" outInteger=SystemImpl__chdir(inString) annotation(Library = "omcruntime");
end cd;
public function createDirectory
input String inString;
output Boolean outBool;
external "C" outBool=SystemImpl__createDirectory(inString) annotation(Library = "omcruntime");
end createDirectory;
public function createTemporaryDirectory
input String inPrefix;
output String outName;
external "C" outName=SystemImpl__createTemporaryDirectory(inPrefix) annotation(Library = "omcruntime");
end createTemporaryDirectory;
public function pwd
output String outString;
external "C" outString=SystemImpl__pwd() annotation(Library = "omcruntime");
end pwd;
public function readEnv "Reads the environment variable given as string, fails if variable not found"
input String inString;
output String outString;
external "C" outString=System_readEnv(inString) annotation(Library = "omcruntime");
end readEnv;
public function setEnv ""
input String varName;
input String value;
input Boolean overwrite "is always true on Windows, so recommended to always call it using true";
output Integer outInteger;
external "C" outInteger=setenv(varName,value,overwrite) annotation(Library = "omcruntime");
end setEnv;
public function subDirectories
input String inString;
output list<String> outStringLst;
external "C" outStringLst=System_subDirectories(inString) annotation(Library = "omcruntime");
end subDirectories;
public function moFiles
input String inString;
output list<String> outStringLst;
external "C" outStringLst=System_moFiles(inString) annotation(Library = "omcruntime");
end moFiles;
public function mocFiles
input String inString;
output list<String> outStringLst;
external "C" outStringLst=System_mocFiles(inString) annotation(Library = "omcruntime");
end mocFiles;
public function getLoadModelPath
input String className;
input list<String> prios;
input list<String> mps;
input Boolean requireExactVersion = false;
output String dir;
output String name;
output Boolean isDir;
external "C" System_getLoadModelPath(className,prios,mps,requireExactVersion,dir,name,isDir) annotation(Library = "omcruntime");
end getLoadModelPath;
public function time
output Real outReal;
external "C" outReal=SystemImpl__time() annotation(Library = "omcruntime");
end time;
public function regularFileExists
input String inString;
output Boolean outBool;
external "C" outBool = SystemImpl__regularFileExists(inString) annotation(Library = "omcruntime");
end regularFileExists;
public function removeFile "Removes a file, returns 0 if suceeds, implemented using remove() in stdio.h"
input String fileName;
output Integer res;
external "C" res=SystemImpl__removeFile(fileName) annotation(Library = "omcruntime");
end removeFile;
public function directoryExists
input String inString;
output Boolean outBool;
external "C" outBool=SystemImpl__directoryExists(inString) annotation(Library = "omcruntime");
end directoryExists;
public function copyFile
input String source;
input String destination;
output Boolean outBool;
external "C" outBool=SystemImpl__copyFile(source, destination) annotation(Library = "omcruntime");
end copyFile;
public function removeDirectory
input String inString;
output Boolean outBool;
algorithm
outBool := System.removeDirectory_dispatch(inString);
// oh Windows crap: stat fails on very long paths!
if (not outBool) then
if Autoconf.os == "Windows_NT" then
// try rm as that somehow works on long paths
outBool := (0 == System.systemCall("rm -r " + inString));
end if;
end if;
end removeDirectory;
protected function removeDirectory_dispatch
input String inString;
output Boolean outBool;
external "C" outBool=SystemImpl__removeDirectory(inString) annotation(Library = "omcruntime");
end removeDirectory_dispatch;
public function getClassnamesForSimulation
output String outString;
external "C" outString=System_getClassnamesForSimulation() annotation(Library = "omcruntime");
end getClassnamesForSimulation;
public function setClassnamesForSimulation
input String inString;
external "C" System_setClassnamesForSimulation(inString) annotation(Library = "omcruntime");
end setClassnamesForSimulation;
public function getVariableValue
input Real timeStamp;
input list<Real> timeValues;
input list<Real> varValues;
output Real outValue;
external "C" outValue=System_getVariableValue(timeStamp,timeValues,varValues) annotation(Library = "omcruntime");
end getVariableValue;
public function getFileModificationTime
"@author adrpo
this system function returns the modification time of a file as a
SOME(Real) which represents the time elapsed since the
Epoch (00:00:00 UTC, January 1, 1970).
If the file does not exist or if there is an error the returned value
will be NONE.
"
input String fileName;
output Option<Real> outValue;
external "C" outValue=System_getFileModificationTime(fileName) annotation(Library = "omcruntime");
end getFileModificationTime;
public function getCurrentTime
"@author adrpo
this system function returns current time elapsed
since the Epoch (00:00:00 UTC, January 1, 1970)."
output Real outValue;
external "C" outValue=SystemImpl__getCurrentTime() annotation(Library = "omcruntime");
end getCurrentTime;
public function getCurrentDateTime
"@author Frenkel TUD
this system function returns current time elapsed
since the Epoch (00:00:00 UTC, January 1, 1970)."
output Integer sec;
output Integer min;
output Integer hour;
output Integer mday;
output Integer mon;
output Integer year;
external "C" System_getCurrentDateTime(sec,min,hour,mday,mon,year) annotation(Library = "omcruntime");
end getCurrentDateTime;
public function getCurrentTimeStr "
returns current time in format Www Mmm dd hh:mm:ss yyyy
using the asctime() function in time.h (libc)
"
output String timeStr;
external "C" timeStr=System_getCurrentTimeStr() annotation(Library = "omcruntime");
end getCurrentTimeStr;
public function readFileNoNumeric
input String inString;
output String outString;
external "C" outString=SystemImpl__readFileNoNumeric(inString) annotation(Library = "omcruntime");
end readFileNoNumeric;
public function setHasExpandableConnectors
"@author: adrpo
sets the external flag that signals the
presence of expandable connectors in a model"
input Boolean hasExpandable;
external "C" System_setHasExpandableConnectors(hasExpandable) annotation(Library = "omcruntime");
end setHasExpandableConnectors;
public function getHasExpandableConnectors
"@author: adrpo
retrieves the external flag that signals the
presence of expandable connectors in a model"
output Boolean hasExpandable;
external "C" hasExpandable = System_getHasExpandableConnectors() annotation(Library = "omcruntime");
end getHasExpandableConnectors;
public function setHasOverconstrainedConnectors
"@author: adrpo
sets the external flag that signals the
presence of overconstrained connectors in a model"
input Boolean hasOverconstrained;
external "C" System_setHasOverconstrainedConnectors(hasOverconstrained) annotation(Library = "omcruntime");
end setHasOverconstrainedConnectors;
public function getHasOverconstrainedConnectors
"@author: adrpo
retrieves the external flag that signals the
presence of overconstrained connectors in a model"
output Boolean hasOverconstrained;
external "C" hasOverconstrained = System_getHasOverconstrainedConnectors() annotation(Library = "omcruntime");
end getHasOverconstrainedConnectors;
public function setPartialInstantiation
"@author: adrpo
sets the external flag that signals the
presence of expandable connectors in a model"
input Boolean isPartialInstantiation;
external "C" System_setPartialInstantiation(isPartialInstantiation) annotation(Library = "omcruntime");
end setPartialInstantiation;
public function getPartialInstantiation
"@author: adrpo
retrieves the external flag that signals the
presence of expandable connectors in a model"
output Boolean isPartialInstantiation;
external "C" isPartialInstantiation=System_getPartialInstantiation() annotation(Library = "omcruntime");
end getPartialInstantiation;
public function setHasStreamConnectors
"@author: adrpo
sets the external flag that signals the
presence of stream connectors in a model"
input Boolean hasStream;
external "C" System_setHasStreamConnectors(hasStream) annotation(Library = "omcruntime");
end setHasStreamConnectors;
public function getHasStreamConnectors
"@author: adrpo
retrieves the external flag that signals the
presence of stream connectors in a model"
output Boolean hasStream;
external "C" hasStream=System_getHasStreamConnectors() annotation(Library = "omcruntime");
end getHasStreamConnectors;
public function setUsesCardinality
"Sets the external flag that signals the use of the cardinality operator."
input Boolean inUses;
external "C" System_setUsesCardinality(inUses) annotation(Library = "omcruntime");
end setUsesCardinality;
public function getUsesCardinality
"Retrieves the external flag that signals the use of the cardinality operator."
output Boolean outUses;
external "C" outUses=System_getUsesCardinality() annotation(Library = "omcruntime");
end getUsesCardinality;
public function setHasInnerOuterDefinitions
"@author: adrpo
sets the external flag that signals the presence
of inner/outer comoponent definitions in a model"
input Boolean hasInnerOuterDefinitions;
external "C" System_setHasInnerOuterDefinitions(hasInnerOuterDefinitions) annotation(Library = "omcruntime");
end setHasInnerOuterDefinitions;
public function getHasInnerOuterDefinitions
"@author: adrpo
retrieves the external flag that signals the presence
of inner/outer comoponent definitions in a model"
output Boolean hasInnerOuterDefinitions;
external "C" hasInnerOuterDefinitions=System_getHasInnerOuterDefinitions() annotation(Library = "omcruntime");
end getHasInnerOuterDefinitions;
public function tmpTick
"returns a tick that can be reset"
output Integer tickNo;
algorithm
tickNo := tmpTickIndex(index=0);
end tmpTick;
public function tmpTickReset
"resets the tick so it restarts on start"
input Integer start;
external "C" SystemImpl_tmpTickReset(OpenModelica.threadData(),start) annotation(Library = "omcruntime");
end tmpTickReset;
public function tmpTickIndex
"returns a tick that can be reset. TODO: remove me when bootstrapped (default argument index=0)"
input Integer index;
output Integer tickNo;
external "C" tickNo = SystemImpl_tmpTickIndex(OpenModelica.threadData(),index) annotation(Library = "omcruntime");
end tmpTickIndex;
public function tmpTickIndexReserve
"returns a tick that can be reset and reserves N values in it.
TODO: remove me when bootstrapped (default argument index=0)"
input Integer index;
input Integer reserve "current tick + reserve";
output Integer tickNo;
external "C" tickNo = SystemImpl_tmpTickIndexReserve(OpenModelica.threadData(),index,reserve) annotation(Library = "omcruntime");
end tmpTickIndexReserve;
public function tmpTickResetIndex
"resets the tick so it restarts on start. TODO: remove me when bootstrapped (default argument index=0)"
input Integer start;
input Integer index;
external "C" SystemImpl_tmpTickResetIndex(OpenModelica.threadData(),start,index) annotation(Library = "omcruntime");
end tmpTickResetIndex;
public function tmpTickSetIndex
"sets the index, like tmpTickResetIndex, but does not reset the maximum counter"
input Integer start;
input Integer index;
external "C" SystemImpl_tmpTickSetIndex(OpenModelica.threadData(),start,index) annotation(Library = "omcruntime");
end tmpTickSetIndex;
public function tmpTickMaximum
"returns the max tick since the last reset"
input Integer index;
output Integer maxIndex;
external "C" maxIndex=SystemImpl_tmpTickMaximum(OpenModelica.threadData(),index) annotation(Library = "omcruntime");
end tmpTickMaximum;
public function userIsRoot
"Returns true if the current user is root.
Used by main to disable running omc as root as it is very dangerous.
Consider opening a socket and letting anyone run system() commands without authentication. As root."
output Boolean isRoot;
external "C" isRoot=System_userIsRoot() annotation(Library = "omcruntime");
end userIsRoot;
public function getuid
output Integer uid;
external "C" uid=System_getuid() annotation(Library = "omcruntime");
end getuid;
public function realtimeTick
"Tock returns the time since the last tock; undefined if tick was never called.
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
external "C" System_realtimeTick(clockIndex) annotation(Library = "omcruntime");
end realtimeTick;
public function realtimeTock
"Tock returns the time since the last tock, undefined if tick was never called.
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
output Real outTime;
external "C" outTime = System_realtimeTock(clockIndex) annotation(Library = "omcruntime");
end realtimeTock;
public function realtimeClear
"Clears the timer.
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
external "C" System_realtimeClear(clockIndex) annotation(Library = "omcruntime");
end realtimeClear;
public function realtimeNtick
"Returns the number of ticks since last clear.
The clock index is 0-31. The function fails if the number is out of range."
input Integer clockIndex;
output Integer n;
external "C" n = System_realtimeNtick(clockIndex) annotation(Library = "omcruntime");
end realtimeNtick;
function resetTimer
"@autor: adrpo
this function will reset the timer to 0."
external "C" System_resetTimer() annotation(Library = "omcruntime");
end resetTimer;
function startTimer
"@autor: adrpo
this function will start counting the time
that should be aggregated."
external "C" System_startTimer() annotation(Library = "omcruntime");
end startTimer;
function stopTimer
"@autor: adrpo
this function will stop counting the time
that should be aggregated."
external "C" System_stopTimer() annotation(Library = "omcruntime");
end stopTimer;
function getTimerIntervalTime
"@autor: adrpo
this function will return the time that
passed between the last [startTimer,stopTimer] interval.
Notice that if start/stop are called recursively this
function will return the time passed between the
corresponding intervals.
Example:
(start1,
(start2,
(start3, stop3) call getTimerIntervalTime -> (stop3-start3)
stop2) call getTimerIntervalTime -> (stop2-start2)
stop1) call getTimerIntervalTime -> (stop1-start1)"
output Real timerIntervalTime;
external "C" timerIntervalTime=System_getTimerIntervalTime() annotation(Library = "omcruntime");
end getTimerIntervalTime;
function getTimerCummulatedTime
"@autor: adrpo
this function will return the cummulated time
by adding all the interval times [startTimer,stopTimer].
Note that if you have recursive calls to start/stop
this function will not return the *correct* time.
Example:
Recursive:
(start1, (start2, (start3, stop3) stop2) stop1)
getTimerCummulatedTime =
stop3-start3 + stop2-start2 + stop1-start1.
Serial:
(start1, stop1) (start2, stop2) (start3, stop3)
getTimerCummulatedTime =
stop3-start3 + stop2-start2 + stop1-start1."
output Real timerCummulatedTime;
external "C" timerCummulatedTime=System_getTimerCummulatedTime() annotation(Library = "omcruntime");
end getTimerCummulatedTime;
function getTimerElapsedTime
"@autor: adrpo
this function will return the time
passed since the first call to startTimeer
Example:
(start1, (start2, (start3, stop3), stop2) ...
getTimerSinceFirstStartTime = timeNow-start1."
output Real timerElapsedTime;
external "C" timerElapsedTime=System_getTimerElapsedTime() annotation(Library = "omcruntime");
end getTimerElapsedTime;
function getTimerStackIndex
"@autor: adrpo
this function will return number of
times start/stop was called recursively.
You can use this function for pretty printing.
Example:
index 0
(start1, index 1
(start2, index 2
(start3, index 3
stop3), index 2
stop2) index 1
stop1) index 0"
output Integer stackIndex;
external "C" stackIndex=System_getTimerStackIndex() annotation(Library = "omcruntime");
end getTimerStackIndex;
public function getUUIDStr "creates the Globally Unique IDentifier and return it as String"
output String uuidStr;
external "C" uuidStr=System_getUUIDStr() annotation(Library = "omcruntime");
end getUUIDStr;
public function basename
"Returns the name of the file without any leading directory path.
See man 3 basename."
input String filename;
output String base;
// We need to strdup the input, so we can't use basename() directly
external "C" base = System_basename(filename) annotation(Library = "omcruntime");
end basename;
public function dirname
"Returns the name of the file without any leading directory path.
See man 3 dirname."
input String filename;
output String base;
// We need to strdup the input, so we can't use basename() directly
external "C" base = System_dirname(filename) annotation(Library = "omcruntime");
end dirname;
public function escapedString
"Because list() requires escape-sequences to be in the AST, we need to be
able to unescape them in some places of the code."
input String unescapedString;
input Boolean unescapeNewline;
output String escapedString;
external "C" escapedString=System_escapedString(unescapedString,unescapeNewline) annotation(Library = "omcruntime");
end escapedString;
public function unescapedString
"Because list() requires escape-sequences to be in the AST, we need to be
able to unescape them in some places of the code."
input String escapedString;
output String unescapedString;
external "C" unescapedString=System_unescapedString(escapedString) annotation(Library = "omcruntime");
end unescapedString;
public function unescapedStringLength
"Calculates the C string length of the input, if the input was used as a string
literal in C. For example unescapedStringLength('\"')=1, unescapedStringLength('ab')=2."
input String unescapedString;
output Integer length;
external "C" length=SystemImpl__unescapedStringLength(unescapedString) annotation(Library = "omcruntime");
end unescapedStringLength;
public function unquoteIdentifier
"Quoted identifiers, for example 'xyz' need to be translated into canonical form; for example _omcQ_27xyz_27
The prefix is _omcQ, there is no suffix. The escape character is _ (an identifier with _ would be _5F)
This name presents a unique mapping that is also reversible (so the debugger can show the quoted identifier's nam.
The returned name is a valid C89 identifier."
input String str;
output String outStr;
external "C" outStr=System_unquoteIdentifier(str) annotation(Library = "omcruntime");
end unquoteIdentifier;
public function intMaxLit "Returns the maximum integer that can be represent using this version of the compiler"
output Integer outInt;
external "builtin" outInt=intMaxLit();
end intMaxLit;
public function realMaxLit "Returns the maximum integer that can be represent using this version of the compiler"
output Real outReal;
external "builtin" outReal=realMaxLit();
end realMaxLit;
public function uriToClassAndPath "Handles modelica:// and file:// URI's. The result is an absolute path on the local system.
The result depends on the current MODELICAPATH. Sets the error buffer on failure."
input String uri;
output String scheme "file:// or modelica://, in lower-case";
output String classname "empty if file:// is used";
output String pathname;
external "C" System_uriToClassAndPath(uri,scheme,classname,pathname) annotation(Library = "omcruntime");
end uriToClassAndPath;
public function modelicaPlatform "Returns the standardized platform name according to the Modelica specification:
win32 [Microsoft Windows 32 bit]
win64 [Microsoft Windows 64 bit]
i386-pc-linux [Linux Intel 32 bit]
x64_86-linux [Linux Intel 64 bit]
Else, the openModelicaPlatform() is returned
"
output String platform;
external "C" platform=System_modelicaPlatform() annotation(Library = "omcruntime");
end modelicaPlatform;
public function openModelicaPlatform "
Returns uname -sm (with spaces replaced by dashes and only lower-case letters) on Unix platforms
mingw32 or mingw64 is returned for OMDev mingw
"
output String platform;
external "C" platform=System_openModelicaPlatform() annotation(Library = "omcruntime");
end openModelicaPlatform;
public function gccDumpMachine "
Returns gcc -dumpmachine
"
output String machine;
external "C" machine=System_gccDumpMachine() annotation(Library = "omcruntime");
end gccDumpMachine;
public function gccVersion "
Returns gcc --version
"
output String version;
external "C" version=System_gccVersion() annotation(Library = "omcruntime");
end gccVersion;
public function dgesv
"# dgesv from LAPACK
## Purpose
DGESV computes the solution to a real system of linear equations
A * X = B,
where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
The LU decomposition with partial pivoting and row interchanges is
used to factor A as
A = P * L * U,
where P is a permutation matrix, L is unit lower triangular, and U is
upper triangular. The factored form of A is then used to solve the
system of equations A * X = B.
## Return values
### output list<Real> X
On exit, if info = 0, the N-by-NRHS solution matrix X.
### output Integer info
= 0: successful exit
< 0: if INFO = -i, the i-th argument had an illegal value
> 0: if INFO = i, U(i,i) is exactly zero. The factorization
has been completed, but the factor U is exactly
singular, so the solution could not be computed.
"
input list<list<Real>> A;
input list<Real> B;
output list<Real> X;
output Integer info;
external "C" info=SystemImpl__dgesv(A,B,X) annotation(Library = {"omcruntime","Lapack"});
end dgesv;
public function lpsolve55
"lpsolve55"
input list<list<Real>> A;
input list<Real> B;
input list<Integer> intIndices;
output list<Real> X;
output Integer info;
external "C" info=SystemImpl__lpsolve55(A,B,intIndices,X) annotation(Library = {"omcruntime"});
end lpsolve55;
public function reopenStandardStream
input Integer _stream "stdin,stdout,stderr";
input String filename;
output Boolean success;
external "C" success=SystemImpl__reopenStandardStream(_stream,filename) annotation(Library = {"omcruntime"});
end reopenStandardStream;
function iconv "The iconv() function converts one multibyte characters from one character
set to another.
See man (3) iconv for more information.
"
input String string;
input String from;
input String to;
output String result;
external "C" result=SystemImpl__iconv(string,from,to,true /* Print errors */) annotation(Library = {"omcruntime"});
end iconv;
function snprintff "sprintf format string that takes one double as argument"
input String format;
input Integer maxlen;
input Real val;
output String str;
external "C" str=System_snprintff(format,maxlen,val) annotation(Library = {"omcruntime"});
end snprintff;
function sprintff
"sprintf format string that takes one double as argument, but unlike snprintff