OMCompiler/Compiler/FrontEnd/UnitParserExt.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package UnitParserExt | ||
| 37 | |||
| 38 | 1108 | public function initSIUnits "initialize the UnitParser with the SI units" | |
| 39 | external "C" UnitParserExtImpl__initSIUnits() annotation(Library = "omcruntime"); | ||
| 40 | end initSIUnits; | ||
| 41 | |||
| 42 | 554 | public function unit2str"Translate a unit to a string" | |
| 43 | input list<Integer> noms "nominators"; | ||
| 44 | input list<Integer> denoms"denominators"; | ||
| 45 | input list<Integer> tpnoms ; | ||
| 46 | input list<Integer> tpdenoms; | ||
| 47 | input list<String> tpstrs; | ||
| 48 | input Real scaleFactor; | ||
| 49 | input Real offset; | ||
| 50 | output String res; | ||
| 51 | external "C" res=UnitParserExt_unit2str(noms,denoms,tpnoms,tpdenoms,tpstrs,scaleFactor,offset) annotation(Library = "omcruntime"); | ||
| 52 | end unit2str; | ||
| 53 | |||
| 54 | ✗ | public function str2unit "Translate a unit string to a unit" | |
| 55 | input String res; | ||
| 56 | output list<Integer> noms; | ||
| 57 | output list<Integer> denoms; | ||
| 58 | output list<Integer> tpnoms; | ||
| 59 | output list<Integer> tpdenoms; | ||
| 60 | output list<String> tpstrs; | ||
| 61 | output Real scaleFactor; | ||
| 62 | output Real offset; | ||
| 63 | external "C" UnitParserExt_str2unit(res,noms,denoms,tpnoms,tpdenoms,tpstrs,scaleFactor,offset) annotation(Library = "omcruntime"); | ||
| 64 | end str2unit; | ||
| 65 | |||
| 66 | 1260 | public function allUnitSymbols | |
| 67 | output list<String> unitSymbols; | ||
| 68 | external "C" unitSymbols = UnitParserExtImpl__allUnitSymbols() annotation(Library = "omcruntime"); | ||
| 69 | end allUnitSymbols; | ||
| 70 | |||
| 71 | 3 | public function addBase "adds a base unit without weight" | |
| 72 | input String name; | ||
| 73 | external "C" UnitParserExtImpl__addBase(name) annotation(Library = "omcruntime"); | ||
| 74 | end addBase; | ||
| 75 | |||
| 76 | ✗ | public function registerWeight "registers a weight to be multiplied with the weigth factor of a derived unit" | |
| 77 | input String name; | ||
| 78 | input Real weight; | ||
| 79 | external "C" UnitParserExtImpl__registerWeight(name,weight) annotation(Library = "omcruntime"); | ||
| 80 | end registerWeight; | ||
| 81 | |||
| 82 | |||
| 83 | ✗ | public function addDerived "adds a derived unit without weight" | |
| 84 | input String name; | ||
| 85 | input String exp; | ||
| 86 | external "C" UnitParserExtImpl__addDerived(name,exp) annotation(Library = "omcruntime"); | ||
| 87 | end addDerived; | ||
| 88 | |||
| 89 | ✗ | public function addDerivedWeight "adds a derived unit with weight" | |
| 90 | input String name; | ||
| 91 | input String exp; | ||
| 92 | input Real weight; | ||
| 93 | external "C" UnitParserExtImpl__addDerivedWeight(name,exp,weight) annotation(Library = "omcruntime"); | ||
| 94 | end addDerivedWeight; | ||
| 95 | |||
| 96 | ✗ | public function checkpoint "copies all unitparser information to allow changing unit weights locally for a component" | |
| 97 | external "C" UnitParserExtImpl__checkpoint() annotation(Library = "omcruntime"); | ||
| 98 | end checkpoint; | ||
| 99 | |||
| 100 | ✗ | public function rollback "rollback the copy made in checkPoint call" | |
| 101 | external "C" UnitParserExtImpl__rollback() annotation(Library = "omcruntime"); | ||
| 102 | end rollback; | ||
| 103 | |||
| 104 | ✗ | public function clear "clears the unitparser from stored units" | |
| 105 | external "C" UnitParserExtImpl__clear() annotation(Library = "omcruntime"); | ||
| 106 | end clear; | ||
| 107 | |||
| 108 | ✗ | public function commit "commits all units, must be run before doing unit checking and after last unit has been added | |
| 109 | with addBase or addDerived." | ||
| 110 | external "C" UnitParserExtImpl__commit() annotation(Library = "omcruntime"); | ||
| 111 | end commit; | ||
| 112 | |||
| 113 | annotation(__OpenModelica_Interface="script_util"); | ||
| 114 | end UnitParserExt; | ||
| 115 |