Browse Source

added dymola exported fmus

Casper Thule 3 years ago
parent
commit
17a7adfc6c
100 changed files with 107345 additions and 0 deletions
  1. BIN
      ModelicaModels/Dymola/._Window.fmu
  2. BIN
      ModelicaModels/Dymola/Obstacle.fmu
  3. 12 0
      ModelicaModels/Dymola/Obstacle.mo
  4. BIN
      ModelicaModels/Dymola/Power.fmu
  5. 25 0
      ModelicaModels/Dymola/Power.mo
  6. BIN
      ModelicaModels/Dymola/Window.fmu
  7. 18 0
      ModelicaModels/Dymola/Window.mo
  8. BIN
      ModelicaModels/Dymola/Window/binaries/win32/Window.dll
  9. BIN
      ModelicaModels/Dymola/Window/binaries/win64/Window.dll
  10. 64 0
      ModelicaModels/Dymola/Window/documentation/_main.html
  11. 125 0
      ModelicaModels/Dymola/Window/modelDescription.xml
  12. 61 0
      ModelicaModels/Dymola/Window/sources/Air.h
  13. 68 0
      ModelicaModels/Dymola/Window/sources/FMIversionPrefix.h
  14. 103 0
      ModelicaModels/Dymola/Window/sources/GenerateResultInNonDymosim.h
  15. 497 0
      ModelicaModels/Dymola/Window/sources/GenericRefrigerant.hpp
  16. 61 0
      ModelicaModels/Dymola/Window/sources/HDR81.h
  17. 608 0
      ModelicaModels/Dymola/Window/sources/ModelicaFFT.c
  18. 405 0
      ModelicaModels/Dymola/Window/sources/ModelicaIO.c
  19. 60 0
      ModelicaModels/Dymola/Window/sources/ModelicaIO.h
  20. 1276 0
      ModelicaModels/Dymola/Window/sources/ModelicaInternal.c
  21. 21424 0
      ModelicaModels/Dymola/Window/sources/ModelicaMatIO.c
  22. 389 0
      ModelicaModels/Dymola/Window/sources/ModelicaMatIO.h
  23. 512 0
      ModelicaModels/Dymola/Window/sources/ModelicaRandom.c
  24. 4747 0
      ModelicaModels/Dymola/Window/sources/ModelicaStandardTables.c
  25. 305 0
      ModelicaModels/Dymola/Window/sources/ModelicaStandardTables.h
  26. 471 0
      ModelicaModels/Dymola/Window/sources/ModelicaStrings.c
  27. 141 0
      ModelicaModels/Dymola/Window/sources/ModelicaUtilities.h
  28. 61 0
      ModelicaModels/Dymola/Window/sources/R11.h
  29. BIN
      ModelicaModels/Dymola/Window/sources/R1233zd.dll
  30. 61 0
      ModelicaModels/Dymola/Window/sources/R1233zd.h
  31. 61 0
      ModelicaModels/Dymola/Window/sources/R134a.h
  32. 61 0
      ModelicaModels/Dymola/Window/sources/R22.h
  33. 61 0
      ModelicaModels/Dymola/Window/sources/R290.h
  34. 61 0
      ModelicaModels/Dymola/Window/sources/R32.h
  35. BIN
      ModelicaModels/Dymola/Window/sources/R404A.dll
  36. 61 0
      ModelicaModels/Dymola/Window/sources/R404A.h
  37. 61 0
      ModelicaModels/Dymola/Window/sources/R407C.h
  38. BIN
      ModelicaModels/Dymola/Window/sources/R410A.dll
  39. 61 0
      ModelicaModels/Dymola/Window/sources/R410A.h
  40. 61 0
      ModelicaModels/Dymola/Window/sources/R448A.h
  41. 55 0
      ModelicaModels/Dymola/Window/sources/R717.h
  42. 61 0
      ModelicaModels/Dymola/Window/sources/R744.h
  43. 56 0
      ModelicaModels/Dymola/Window/sources/Refrigerant.h
  44. 278 0
      ModelicaModels/Dymola/Window/sources/adymosim.h
  45. 50 0
      ModelicaModels/Dymola/Window/sources/all.c
  46. 124 0
      ModelicaModels/Dymola/Window/sources/amach.h
  47. 903 0
      ModelicaModels/Dymola/Window/sources/amat.h
  48. 24 0
      ModelicaModels/Dymola/Window/sources/assumption.h
  49. 573 0
      ModelicaModels/Dymola/Window/sources/atraj.h
  50. 73 0
      ModelicaModels/Dymola/Window/sources/bloutil.h
  51. 76 0
      ModelicaModels/Dymola/Window/sources/conf.h
  52. 45 0
      ModelicaModels/Dymola/Window/sources/csvutil.h
  53. 4334 0
      ModelicaModels/Dymola/Window/sources/cvode.c
  54. 59 0
      ModelicaModels/Dymola/Window/sources/cvode/LICENSE
  55. 802 0
      ModelicaModels/Dymola/Window/sources/cvode/cvode.h
  56. 59 0
      ModelicaModels/Dymola/Window/sources/cvode/cvode_dense.h
  57. 290 0
      ModelicaModels/Dymola/Window/sources/cvode/cvode_direct.h
  58. 376 0
      ModelicaModels/Dymola/Window/sources/cvode_dense.c
  59. 495 0
      ModelicaModels/Dymola/Window/sources/cvode_direct.c
  60. 116 0
      ModelicaModels/Dymola/Window/sources/cvode_direct_impl.h
  61. 519 0
      ModelicaModels/Dymola/Window/sources/cvode_impl.h
  62. 1138 0
      ModelicaModels/Dymola/Window/sources/cvode_io.c
  63. 1127 0
      ModelicaModels/Dymola/Window/sources/delay.c
  64. 297 0
      ModelicaModels/Dymola/Window/sources/delay.h
  65. 876 0
      ModelicaModels/Dymola/Window/sources/dlldata.h
  66. 11 0
      ModelicaModels/Dymola/Window/sources/dlldata_impl.h
  67. 191 0
      ModelicaModels/Dymola/Window/sources/dsblock.h
  68. 773 0
      ModelicaModels/Dymola/Window/sources/dsblock1.c
  69. 111 0
      ModelicaModels/Dymola/Window/sources/dsblock2.c
  70. 127 0
      ModelicaModels/Dymola/Window/sources/dsblock3.c
  71. 365 0
      ModelicaModels/Dymola/Window/sources/dsblock4.c
  72. 805 0
      ModelicaModels/Dymola/Window/sources/dsblock5.c
  73. 13 0
      ModelicaModels/Dymola/Window/sources/dsblock6.c
  74. 42 0
      ModelicaModels/Dymola/Window/sources/dsdefs.h
  75. 89 0
      ModelicaModels/Dymola/Window/sources/dse_macros.h
  76. 49409 0
      ModelicaModels/Dymola/Window/sources/dsmodel.c
  77. 40 0
      ModelicaModels/Dymola/Window/sources/dsmodel_fmu.h
  78. 1 0
      ModelicaModels/Dymola/Window/sources/dsmodel_fmuconf.h
  79. 1985 0
      ModelicaModels/Dymola/Window/sources/dsutil.h
  80. 444 0
      ModelicaModels/Dymola/Window/sources/dymf2c.c
  81. 199 0
      ModelicaModels/Dymola/Window/sources/dymosim.h
  82. 2775 0
      ModelicaModels/Dymola/Window/sources/dymtable.c
  83. 201 0
      ModelicaModels/Dymola/Window/sources/dymtable.h
  84. 41 0
      ModelicaModels/Dymola/Window/sources/dymutil.h
  85. 3 0
      ModelicaModels/Dymola/Window/sources/extendedIncludes.h
  86. 391 0
      ModelicaModels/Dymola/Window/sources/f2c.h
  87. 335 0
      ModelicaModels/Dymola/Window/sources/fmi2Functions.c
  88. 93 0
      ModelicaModels/Dymola/Window/sources/fmi2Functions_fwd.h
  89. 180 0
      ModelicaModels/Dymola/Window/sources/fmi2Import.h
  90. 922 0
      ModelicaModels/Dymola/Window/sources/fmiCoSimFunctions_int.c
  91. 1271 0
      ModelicaModels/Dymola/Window/sources/fmiCommonFunctions_int.c
  92. 479 0
      ModelicaModels/Dymola/Window/sources/fmiFunctions.c
  93. 51 0
      ModelicaModels/Dymola/Window/sources/fmiFunctions_.h
  94. 100 0
      ModelicaModels/Dymola/Window/sources/fmiFunctions_1.0_fwd.h
  95. 10 0
      ModelicaModels/Dymola/Window/sources/fmiFunctions_fwd.h
  96. 993 0
      ModelicaModels/Dymola/Window/sources/fmiMEFunctions_int.c
  97. 8 0
      ModelicaModels/Dymola/Window/sources/fmiModelFunctions_.h
  98. 5 0
      ModelicaModels/Dymola/Window/sources/fmiModelIdentifier.h
  99. 94 0
      ModelicaModels/Dymola/Window/sources/fmiPlatformTypes_.h
  100. 0 0
      ModelicaModels/Dymola/Window/sources/gconstructor.h

BIN
ModelicaModels/Dymola/._Window.fmu


BIN
ModelicaModels/Dymola/Obstacle.fmu


+ 12 - 0
ModelicaModels/Dymola/Obstacle.mo

@@ -0,0 +1,12 @@
+model Obstacle
+  parameter Real c = 1e10;
+  parameter Real fixed_x = 0.45;
+  input Real disp;
+  output Real reaction_force;
+  Real compression;
+equation
+  compression = disp - fixed_x;
+  reaction_force = if disp > fixed_x then c * compression else 0;
+  annotation(
+    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
+end Obstacle;

BIN
ModelicaModels/Dymola/Power.fmu


+ 25 - 0
ModelicaModels/Dymola/Power.mo

@@ -0,0 +1,25 @@
+model Power
+  parameter Real J = 0.085;
+  parameter Real b = 5;
+  parameter Real K = 7.45;
+  parameter Real R = 0.15;
+  parameter Real L = 0.036;
+  parameter Real V_abs = 12;
+  Real V;
+  output Real displacement;
+  output Real armature_current;
+  output Real speed;
+  input Real tau;
+  input Real u;
+  input Real d;
+equation
+  V = if u > 0.5 then V_abs 
+      else if d > 0.5 then -V_abs
+      else 0.0;
+  J * der(speed) + b * speed = K * armature_current - tau;
+  L * der(armature_current) + R * armature_current = V - K * speed;
+  der(displacement) = speed;
+annotation(
+  experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002)
+);
+end Power;

BIN
ModelicaModels/Dymola/Window.fmu


+ 18 - 0
ModelicaModels/Dymola/Window.mo

@@ -0,0 +1,18 @@
+model Window
+  parameter Real r = 0.11;
+  parameter Real b = 10;
+  input Real speed;
+  input Real displacement;
+  input Real reaction_force;
+  output Real reaction_torque;
+  output Real height;
+  Real v;
+  output Real friction;
+equation
+  reaction_torque = reaction_force * r + friction;
+  height = r * displacement;
+  v = r * speed;
+  friction = b * v;
+  annotation(
+    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
+end Window;

BIN
ModelicaModels/Dymola/Window/binaries/win32/Window.dll


BIN
ModelicaModels/Dymola/Window/binaries/win64/Window.dll


+ 64 - 0
ModelicaModels/Dymola/Window/documentation/_main.html

@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+<body>
+
+This documentation is limited to a description of the source code distribution.
+
+<h1>Source code distribution</h1>
+
+<p>Source code is provided in directory "sources". Except for a c file containing the C main function, the files listed below needs to be compiled as separate compilation units. The remaining c files distributed are included from those in one way or another. Some header files from Sundials are located in sub directories, e.g. "cvode" to match the original Sundials code structure. This is necessary since some #include statements rely on this structure.
+
+<p>
+The files below are sufficent to create a DLL or shared object file. For a complete executable, also a main program is needed of course.
+</p>
+
+<p>
+cvode.c <br/>
+cvode_dense.c <br/>
+cvode_direct.c <br/>
+cvode_io.c <br/>
+dsmodel.c <br/>
+fmiCommonFunctions_int.c <br/>
+fmiCoSimFunctions_int.c <br/>
+fmiFunctions.c <br/>
+fmiMEFunctions_int.c <br/>
+integration.c <br/>
+jac.c <br/>
+nvector_serial.c <br/>
+sundials_dense.c <br/>
+sundials_direct.c <br/>
+sundials_math.c <br/>
+sundials_nvector.c <br/>
+util.c
+</p>
+
+<p>
+If you set the MODEL_IDENTIFIER (FMI 1) or FMI2_FUNCTION_PREFIX (FMI 2) explicitly in your source code, e.g.:
+
+<pre>
+#define FMI2_FUNCTION_PREFIX MyModel_
+#include "fmiFunctions.h"
+</pre>
+
+you must also update fmiModelIdentifier.h accordingly.
+</p>
+
+<p>
+If your target platform does not have a file system you have to define NO_FILE in conf.h:
+<pre>
+#define NO_FILE
+</pre>
+</p>
+
+
+<h2>Handling multiple FMUs</h2>
+In order to be able to combine several source code FMUs, the internal functions and symbols need to be static. This in turn requires that
+the whole source code is compiled in a single compilation unit. To facilitate this, an extra source code file
+
+<pre>all.c</pre>
+
+is provided, that includes all other C files. The only disadvantage of compiling this instead, is that any modification in the source code
+requires re-compilation of everything.
+
+</body>
+</html>

+ 125 - 0
ModelicaModels/Dymola/Window/modelDescription.xml

@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fmiModelDescription
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  fmiVersion="2.0"
+  modelName="Window"
+  guid="{d7056926-5e42-4677-8ad1-6e3af7153257}"
+  generationTool="Dymola Version 2017 FD01 (64-bit), 2016-10-11"
+  generationDateAndTime="2017-11-10T15:23:44Z"
+  variableNamingConvention="structured"
+  numberOfEventIndicators="0">
+  <ModelExchange
+    modelIdentifier="Window"
+    canGetAndSetFMUstate="true"
+    providesDirectionalDerivative="true">
+    <SourceFiles>
+      <File
+        name="all.c"/>
+    </SourceFiles>
+  </ModelExchange>
+  <CoSimulation
+    modelIdentifier="Window"
+    canHandleVariableCommunicationStepSize="true"
+    canInterpolateInputs="true"
+    maxOutputDerivativeOrder="1"
+    canGetAndSetFMUstate="true"
+    providesDirectionalDerivative="true">
+    <SourceFiles>
+      <File
+        name="all.c"/>
+    </SourceFiles>
+  </CoSimulation>
+  <DefaultExperiment startTime="0.0"
+    stopTime="1.0"
+    tolerance="1E-006"/>
+  <ModelVariables>
+    <!-- Index for next variable = 1 -->
+    <ScalarVariable
+      name="r"
+      valueReference="16777216"
+      causality="parameter"
+      variability="tunable">
+      <Real start="0.11"/>
+    </ScalarVariable>
+    <!-- Index for next variable = 2 -->
+    <ScalarVariable
+      name="b"
+      valueReference="16777217"
+      causality="parameter"
+      variability="tunable">
+      <Real start="10"/>
+    </ScalarVariable>
+    <!-- Index for next variable = 3 -->
+    <ScalarVariable
+      name="speed"
+      valueReference="352321536"
+      causality="input">
+      <Real start="0.0"/>
+    </ScalarVariable>
+    <!-- Index for next variable = 4 -->
+    <ScalarVariable
+      name="displacement"
+      valueReference="352321537"
+      causality="input">
+      <Real start="0.0"/>
+    </ScalarVariable>
+    <!-- Index for next variable = 5 -->
+    <ScalarVariable
+      name="reaction_force"
+      valueReference="352321538"
+      causality="input">
+      <Real start="0.0"/>
+    </ScalarVariable>
+    <!-- Index for next variable = 6 -->
+    <ScalarVariable
+      name="reaction_torque"
+      valueReference="335544320"
+      causality="output">
+      <Real/>
+    </ScalarVariable>
+    <!-- Index for next variable = 7 -->
+    <ScalarVariable
+      name="height"
+      valueReference="335544321"
+      causality="output">
+      <Real/>
+    </ScalarVariable>
+    <!-- Index for next variable = 8 -->
+    <ScalarVariable
+      name="v"
+      valueReference="369098752">
+      <Real/>
+    </ScalarVariable>
+    <!-- Index for next variable = 9 -->
+    <ScalarVariable
+      name="friction"
+      valueReference="335544322"
+      causality="output">
+      <Real/>
+    </ScalarVariable>
+  </ModelVariables>
+  <ModelStructure>
+    <Outputs>
+      <Unknown index="6"
+        dependencies="3 5"
+        dependenciesKind="fixed fixed"/>
+      <Unknown index="7"
+        dependencies="4"
+        dependenciesKind="fixed"/>
+      <Unknown index="9"
+        dependencies="3"
+        dependenciesKind="fixed"/>
+    </Outputs>
+    <InitialUnknowns>
+      <Unknown index="6"
+        dependencies="1 2 3 5"
+        dependenciesKind="dependent dependent dependent dependent"/>
+      <Unknown index="7"
+        dependencies="1 4"
+        dependenciesKind="dependent dependent"/>
+      <Unknown index="9"
+        dependencies="1 2 3"
+        dependenciesKind="dependent dependent dependent"/>
+    </InitialUnknowns>
+  </ModelStructure>
+</fmiModelDescription>

+ 61 - 0
ModelicaModels/Dymola/Window/sources/Air.h

@@ -0,0 +1,61 @@
+	/*==========================================================================*/ 
+	/*  Description: Refrigerant property subroutines from IPM 5.0
+	/*  Author: Weijiang Zhang (weijiang.zhang@carrier.utc.com)
+	/*  Copyright reserved by Carrier M&A KCG, 2007
+	/*  Date: 2007.7.12 
+	/*==========================================================================*/
+	#include "math.h"
+	// extern  all function list
+	extern   double FT_PX_Air(const double dP,const double dX);
+	extern   double FTs_PX_Air(const double dP,const double dX);
+	extern   double FSH_PX_Air(const double dP,const double dX);
+	extern   double FH_PX_Air(const double dP,const double dX);
+	extern   double FRho_PX_Air(const double dP,const double dX);
+	extern   double FS_PX_Air(const double dP,const double dX);
+	extern   double FCp_PX_Air(const double dP,const double dX);
+	extern   double FLambda_PX_Air(const double dP,const double dX);
+	extern   double FMu_PX_Air(const double dP,const double dX);
+	extern   double FCpCv_PX_Air(const double dP,const double dX);
+	extern   double FIsotropic_PX_Air(const double dP,const double dX);
+	extern   double FA_PX_Air(const double dP,const double dX);
+	extern   double FTg_P_Air(const double dP);
+	extern   double FX_PH_Air(const double dP,const double dH);
+	extern   double FT_PH_Air(const double dP,const double dH);
+	extern   double FTs_PH_Air(const double dP,const double dH);
+	extern   double FSH_PH_Air(const double dP,const double dH);
+	extern   double FRho_PH_Air(const double dP,const double dH);
+	extern   double FS_PH_Air(const double dP,const double dH);
+	extern   double FCp_PH_Air(const double dP,const double dH);
+	extern   double FLambda_PH_Air(const double dP,const double dH);
+	extern   double FMu_PH_Air(const double dP,const double dH);
+	extern   double FCpCv_PH_Air(const double dP,const double dH);
+	extern   double FIsotropic_PH_Air(const double dP,const double dH);
+	extern   double FA_PH_Air(const double dP,const double dH);
+	extern   double FDRhoDP_PH_Air(const double dP,const double dH);
+	extern   double FDRhoDH_PH_Air(const double dP,const double dH);
+	extern   double FHls_PX_Air(const double dP,const double dX);
+	extern   double FHvs_PX_Air(const double dP,const double dX);
+	extern   double FRhols_PX_Air(const double dP,const double dX);
+	extern   double FRhovs_PX_Air(const double dP,const double dX);
+	extern   double FSls_PX_Air(const double dP,const double dX);
+	extern   double FSvs_PX_Air(const double dP,const double dX);
+	extern   double FCpls_PX_Air(const double dP,const double dX);
+	extern   double FCpvs_PX_Air(const double dP,const double dX);
+	extern   double FMuls_PX_Air(const double dP,const double dX);
+	extern   double FMuvs_PX_Air(const double dP,const double dX);
+	extern   double FLambdals_PX_Air(const double dP,const double dX);
+	extern   double FLambdavs_PX_Air(const double dP,const double dX);
+	extern   double FSurfTens_PX_Air(const double dP,const double dX);
+	extern   double FPs_TX_Air(const double dT,const double dX); 
+	extern   double FH_PT_Air(const double dP,const double dT);
+	extern   double FH_PS_Air(const double dP,const double dS);
+	extern   double FPc_Air();
+	// supporting functions
+	extern   char* ShowLibInfo_Air();
+	extern   char* ShowSourceDataInfo_Air();
+	extern   double FPercentPseudo_Air();
+
+	//double FGenIndex_PH(const int CI, const double P,const double H);
+
+	extern   double FDDPH_PX_Air(const double dP,const double dX);
+	extern   double FDDHP_PX_Air(const double dP,const double dX);

+ 68 - 0
ModelicaModels/Dymola/Window/sources/FMIversionPrefix.h

@@ -0,0 +1,68 @@
+/*Header for applying correct version prefix to FMI types and Functions*/
+#ifndef FMI_VERSION_PREFIX
+#define FMI_VERSION_PREFIX
+#ifdef FMI_2
+#include "fmi2TypesPlatform.h"
+#include "fmi2FunctionTypes.h"
+#define FMIprefix fmi2
+#else
+#ifdef FMU_SOURCE_CODE_EXPORT
+#include "fmiFunctions_.h"
+#else
+#include "fmiPlatformTypes_.h"
+#include "fmiFunctions_1.0.h"
+#endif /* FMU_SOURCE_CODE_EXPORT */
+#define FMIprefix fmi
+#endif/*FMI_2*/
+
+#define VersionPaste(a,b)     a ## b
+#define VersionPasteB(a,b)    VersionPaste(a,b)
+#define VersionFullName(name) VersionPasteB(FMIprefix, name)
+
+/*-------------- fmi2TypesPlatform Conversion------------------*/
+#define FMIComponent			VersionFullName(Component)               
+#define FMICompoenetEnvironment VersionFullName(ComponentEnvironment) 
+#define FMIFMUstate				VersionFullName(FMUstate)      
+#define FMIValueReference		VersionFullName(ValueReference)
+#define FMIReal					VersionFullName(Real)
+#define FMIInteger				VersionFullName(Integer)
+#define FMIBoolean				VersionFullName(Boolean)
+#define FMIChar					VersionFullName(Char)
+#define FMIString				VersionFullName(String)
+#define FMIByte					VersionFullName(Byte)
+#define FMITrue					VersionFullName(True)	
+#define FMIFalse				VersionFullName(False)
+
+/*fmiFunctions/fmi2FunctionTypes*/
+/*--------------------Enumeraiton Status----------------------*/
+#define FMIOK					VersionFullName(OK)
+#define FMIWarning				VersionFullName(Warning)
+#define FMIDiscard				VersionFullName(Discard)
+#define FMIError				VersionFullName(Error)
+#define FMIFatal				VersionFullName(Fatal)
+#define FMIPending				VersionFullName(Pending)
+#define FMIStatus				VersionFullName(Status)
+
+/*-------------------Enumeration Type--------------------------*/
+#define FMIModelExchange        VersionFullName(ModelExchange)
+#define FMICoSimulation			VersionFullName(CoSimulation)
+#define FMIType					VersionFullName(Type)
+
+/*-------------------Enumeraion StausKind----------------------*/
+#define FMIDoStepStatus			VersionFullName(DoStpeStatus)
+#define FMIPendingStatus		VersionFullName(PendingStatus)
+#define FMILastSuccessfulTime   VersionFullName(LastSuccessfulTime)
+#define FMITerminated			VersionFullName(Terminated)
+#define FMIStatusKind			VersionFullName(StatusKind)
+
+/*-------------------Struct CallBackFunctions-------------------*/
+#define FMICallbackLogger			VersionFullName(CallBackLogger)
+#define FMICallbackAllocateMemory	VersionFullName(CallbackAllocateMemory)
+#define FMICallbackFreeMemory		VersionFullName(CallbackFreeMemory)
+#define FMIStepFinished				VersionFullName(StepFinished)
+#define FMICallbackFunctions		VersionFullName(CallbackFunctions)
+
+/*-------------------Struct EventInfo---------------------------*/
+#define FMIEventInfo			VersionFullName(EventInfo)
+
+#endif /*FMI_VERSION_PREFIX*/

+ 103 - 0
ModelicaModels/Dymola/Window/sources/GenerateResultInNonDymosim.h

@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2003 Dynasim AB.
+ * All rights reserved.
+ *
+ */
+
+
+#ifndef GenerateResultInNonDymosim_HEADER
+#define GenerateResultInNonDymosim_HEADER
+
+
+/* #define GenerateResultInNonDymosim_DT 0.01 
+To limit result file size.
+*/
+
+/* Calling sequence:
+   // DeclarePhase0();
+   SetDeclarePhase(0,...); //Reset.
+
+   declare_(...); // Normal call of declare. Not needed
+
+   // DeclarePhase1(...);
+   SetDeclarePhase(1,...); //Init
+   declare_(...);
+   SetDeclarePhase(2,...);
+
+   // DeclarePhase3(...);
+   SetDeclarePhase(3,...); //Open file
+   declare_(...);
+   SetDeclarePhase(4,...);
+   SetDeclarePhase(5,...); //Store constants
+   declare_(...)
+   SetDeclarePhase(6,...); 
+
+   for(...) {
+      
+	  // DeclarePhase7(...);
+	  SetDeclarePhase(7,...); // Store non-constants
+	  declare_(...)
+	  SetDeclarePhase(8,...); 
+  }
+
+  // DeclarePhase9();
+  SetDeclarePhase(9,...);
+
+  The arguments to SetDeclarePhase should be the same except the first one. 
+
+  The routine use local variables during each call of declare from even to odd.
+  But no non-local storage remains between the groups.
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <dsblock.h>
+#include "atraj.h"
+
+struct DeclarePhaseTemp {
+	int declarePhase_;
+	int countConst_,countAlias_,countNonConst_;
+	int *(offsets_[7]);
+	int **baseoffsets_;
+	float* resultPart_;
+	const double* (pointers_[7]);
+	char const** trajNames_;
+	char const** trajDesc_;
+	int* trajInfo_;
+	int infoCount_;
+	char* isPublicW_;
+	char* isPublicX_;
+	char* isPublicXD_;
+	char* isPublicP_;
+};
+struct DeclarePhase {
+	struct Atrajectory traj;
+	AmatData nameData,descData,infoData,data1,data2;
+	int totalInfoCount;
+	int* (baseoffsets[7]);
+    const char* filePath;
+	AmatPutFile file;
+	int openedFile;
+	int createdTraj;
+	double lastTime;
+	int counter;
+	struct DeclarePhaseTemp temp;
+};
+void DeclarePhase0(void**cuser);
+void DeclarePhase1(struct DeclarePhase*phase);
+void DeclarePhase3(struct DeclarePhase*phase,double startTime,double stopTime,
+				   const double*parameters,const double*states,
+				   const double*derivatives,
+				   const double*outputs,
+				   const double*inputs,
+				   const double*auxiliary);
+void DeclarePhase7(struct DeclarePhase*phase,double time,double tEnd,
+				   const double*parameters,const double*states,
+				   const double*derivatives,
+				   const double*outputs,
+				   const double*inputs,
+				   const double*auxiliary);
+void DeclarePhase9(struct DeclarePhase*phase);
+#endif

+ 497 - 0
ModelicaModels/Dymola/Window/sources/GenericRefrigerant.hpp

@@ -0,0 +1,497 @@
+/*!
+    \file
+    
+    \attention <b> Subject to the EAR </b>
+    
+    \attention
+    <b> ECCN: EAR99. </b> This information is subject to the export control laws of the
+    United States, specifically including the Export Administration Regulations (EAR), 15 C.F.R. Part 730
+    et seq.  Transfer, retransfer or disclosure of this data by any means to a non-US person (individual
+    or company), whether in the U.S. or abroad, without any required export license or other approval from
+    the U.S. Govt. is prohibited.
+    
+    \attention
+    <b> UTC Proprietary. </b> This material contains proprietary information of United Technologies Corporation.
+    Any copying, distribution, or dissemination of the contents of this material is strictly prohibited and may be
+    unlawful without the express written permission of UTC. If you have obtained this material in error, please
+    notify the UTRC IP Counsel at (860) 610-7339 immediately.
+*/
+#ifndef GENERIC_REFRIGERANT_HPP
+#define GENERIC_REFRIGERANT_HPP
+
+//#include <sstream>
+//return multiple properties
+//#include "RefrigerantInterface.hpp"
+//#include "RefrigerantEnum.h"
+enum RefrigerantID
+{
+	  R1233zd,
+      R410A,
+      R134a,
+      R1234ze,
+      R22,
+      R290,
+      R744,
+      R452A,
+      R718,
+      R404A,
+    NUM_REFRIGERANTS
+};
+
+// convert variable var to string
+//template <typename T>
+//std::string lexical_cast(T var)
+//{
+//    std::ostringstream os;
+//    os << var;
+//    return os.str();
+//}
+/*
+// enumeration of all refrigerant IDs
+enum RefrigerantID
+{
+    R1233zd,
+    R410A,
+    R134a,
+    R1234ze,
+    R22,
+    R290,
+    R404A,
+    R407C,
+    R744,
+	R452A,
+	R718,
+    NUM_REFRIGERANTS
+};//please add refrigerant in the end and do not insert in the middle
+
+static const std::string refName[] = {"R1233zd",
+                                      "R410A",
+                                      "R134a",
+                                      "R1234ze",
+                                      "R22",
+                                      "R290",
+                                      "R404A",
+                                      "R407C",
+                                      "R744",
+									  "R452A",
+									  "R718"
+                                     };
+
+
+*/
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct GenRefPropertiesPipev2
+    {
+        double T;
+        double Ts;
+        double rho;  
+        double Cp;
+        double mu;
+        double lambda;
+    };
+
+struct GenRefPropertiesPipeph
+    {
+        double T;
+        double Ts;
+        double rho;  
+        double Cp;
+        double mu;
+        double lambda;
+		double ddph;
+		double ddhp;
+    };
+
+struct GenRefPropertiesPipepx
+    {
+        double T;
+        double Ts;
+        double rho;  
+		double h;
+		double Cp;
+        double mu;
+        double lambda;
+        double dhpx;
+        double dhxp;
+		double dvpx;
+        double dvxp;
+}; 
+
+
+    struct SatRefPropertiesPipe
+    {
+        double rhosl;     //liquid specific volume
+        double rhosv;
+        double hsl;
+        double hsv;
+        double Cpsl;
+        double Cpsv;
+        double musl;
+        double musv;
+        double lambdasl;
+        double lambdasv;
+        double sigma;
+    };
+
+ struct GenRefProperties
+    {
+        double T;
+        double Ts;
+        double v;      
+        double h;
+        double s;
+        double Cp;
+        double mu;
+        double lambda;
+        double CpCv;
+        double n_is;    //isentropic exponent
+        double c;       //sonic velocity
+        double dTglide; //temperature gliding
+    };
+
+    struct SatRefProperties
+    {
+        double vsl;     //liquid specific volume
+        double vsv;
+        double hsl;
+        double hsv;
+        double ssl;
+        double ssv;
+        double Cpsl;
+        double Cpsv;
+        double musl;
+        double musv;
+        double lambdasl;
+        double lambdasv;
+        double sigma;
+		double csl;
+		double csv;
+    };
+	 struct GenRefPropertiesAll
+    {
+		double p;
+		double x;
+        double T;
+        double Ts;
+        double v;      
+        double h;
+        double s;
+        double Cp;
+        double mu;
+        double lambda;
+        double CpCv;
+        double n_is;    //isentropic exponent
+        double c;       //sonic velocity
+        double dTglide; //temperature gliding
+    };
+	struct pxProperties
+    {
+		double p;
+		double x;
+    };
+
+
+
+void computeGenValuesPipePH_px(int ID, const double p, const double x,struct GenRefPropertiesPipeph* GenPropPipe,int errorFlag);
+void computeGenValuesPipePX_px(int ID, const double p, const double x,struct GenRefPropertiesPipepx* GenPropPipe,int errorFlag);
+void computeGenValuesPipev2_px(int ID, const double p, const double x,struct GenRefPropertiesPipev2* GenPropPipe,int errorFlag);
+void computeSatValuesPipe_px(int ID, const double p, const double x, struct SatRefPropertiesPipe* SatPropPipe,int errorFlag);
+
+void computeGenValues_px(int ID, const double p, const double x, struct GenRefProperties* GenProp,int errorFlag);
+void computeGenValues2_px(int ID, const double p, const double x, struct GenRefProperties* GenProp, int errorFlag);
+void computeSatValues_px(int ID, const double p, const double x, struct SatRefProperties* SatProp,int errorFlag);
+void computeGenDxValues_px(int ID, const double p, const double x, struct GenRefProperties* GenDxProp,int errorFlag);
+void computeSatDxValues_px(int ID, const double p, const double x, struct SatRefProperties* SatDxProp,int errorFlag);
+void computeGenDpValues_px(int ID, const double p, const double x, struct GenRefProperties* GenDpProp,int errorFlag);
+void computeSatDpValues_px(int ID, const double p, const double x, struct SatRefProperties* SatDpProp,int errorFlag);
+void computeGenThermalValues_px(int ID, double p, double x, struct GenThermalPro* GenThermal, int errorFlag);  //added 12-15
+void computeGenTransportValues_px(int ID, double p, double x, struct GenTransportPro* GenTransport, int errorFlag);  //added 12-15
+void computeSatThermalValues_px(int ID, double p, double x, struct SatThermalPro* SatThermal, int errorFlag);  //added 12-15
+void computeSatTransportValues_px(int ID, double p, double x, struct SatTransportPro* SatTransport, int errorFlag); //added 12-15
+void computeConcentration_px(int ID, double p, double x, struct Concentration * concentration);  //added 12-15
+///////////////////////////
+void computeGenValues_ph(int ID, const double p, const double h, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_ph(int ID, const double p, const double h, struct SatRefProperties* SatProp,int errorFlag);
+double x_pT       (int ID, const double p, const double T);
+void computeGenValues_pT(int ID, const double p, const double T, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_pT(int ID, const double p, const double T, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_TTs       (int ID,const double T, const double Ts, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_TTs(int ID, const double T, const double Ts, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_TTs(int ID, const double T, const double Ts, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_Th       (int ID,const double T, const double h, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_Th(int ID, const double T, const double h, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_Th(int ID, const double T, const double h, struct SatRefProperties* SatProp,int errorFlag);
+
+void computeGenValues_Tx(int ID, const double T, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_Tx(int ID, const double T, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+double p_Tsx       (int ID, const double Ts, const double x);
+void computeGenValues_Tsx(int ID, const double Ts, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_Tsx(int ID, const double Ts, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+double p_hx       (int ID, const double h, const double x);
+void computeGenValues_hx(int ID, const double h, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_hx(int ID, const double h, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+
+double p_vx       (int ID, const double v, const double x);
+void computeGenValues_vx(int ID, const double v, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_vx(int ID, const double v, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+double p_dTshx      (int ID, const double dTsh, const double x);
+void computeGenValues_dTshx(int ID, const double dTsh, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_dTshx(int ID, const double dTsh, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+double p_sx      (int ID, const double s, const double x);
+void computeGenValues_sx(int ID, const double s, const double x, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_sx(int ID, const double s, const double x, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_TdTsh       (int ID,const double T, const double dTsh, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_TdTsh(int ID, const double T, const double dTsh, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_TdTsh(int ID, const double T, const double dTsh, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_Ts       (int ID,const double T, const double s, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_Ts(int ID, const double T, const double s, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_Ts(int ID, const double T, const double s, struct SatRefProperties* SatProp,int errorFlag);
+
+
+
+void px_hs       (int ID,const double h, const double s, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_hs(int ID, const double h, const double s, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_hs(int ID, const double h, const double s, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_hdTsh       (int ID,const double h, const double dTsh, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_hdTsh(int ID, const double h, const double dTsh, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_hdTsh(int ID, const double h, const double dTsh, struct SatRefProperties* SatProp,int errorFlag);
+
+void px_sdTsh       (int ID,const double s, const double dTsh, struct pxProperties* pxProp,int errorFlag);
+void computeGenValues_sdTsh(int ID, const double s, const double dTsh, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_sdTsh(int ID, const double s, const double dTsh, struct SatRefProperties* SatProp,int errorFlag);
+
+/* input T & v     */
+void px_Tv(int ID, double T, double v, struct pxProperties* pxProp, int errorFlag);
+void computeGenValues_Tv(int ID, const double T, const double v, struct GenRefPropertiesAll* GenProp,int errorFlag);
+void computeSatValues_Tv(int ID, const double T, const double v, struct SatRefProperties* SatProp,int errorFlag);
+
+/*  input p & v   */
+double x_pv (int ID, const double p, const double v, int errorFlag);
+void computeGenValues_pv(int ID, const double p, const double v, struct GenRefPropertiesAll* GenProp, int errorFlag);  //added 1-7-2016
+void computeSatValues_pv(int ID, const double p, const double v, struct SatRefProperties* SatProp, int errorFlag);  //added 1-7-2016
+
+/*  input p & dTsh   */
+double x_pdTsh (int ID, const double p, const double dTsh, int errorFlag);
+void computeGenValues_pdTsh(int ID, const double p, const double dTsh, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_pdTsh(int ID, const double p, const double dTsh, struct SatRefProperties* SatProp, int errorFlag);
+
+/*  input p & s   */
+double x_ps (int ID, double p, double s, int errorFlag);
+void computeGenValues_ps(int ID, double p, double s,  struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_ps(int ID, double p, double s,  struct SatRefProperties* SatProp, int errorFlag);
+
+
+/* intput Ts & h */
+void px_Tsh(int ID, const double Ts, const double h, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_Tsh(int ID,  const double Ts, const double h, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_Tsh(int ID, const double Ts, const double h, struct SatRefProperties* SatProp, int errorFlag);
+
+/* intput Ts & v */
+void px_Tsv(int ID, const double Ts, const double v, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_Tsv(int ID,  const double Ts, const double v, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_Tsv(int ID, const double Ts, const double v, struct SatRefProperties* SatProp, int errorFlag);
+
+/* intput Ts & dTsh */
+void computeGenValues_TsdTsh(int ID,  const double Ts, const double dTsh, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_TsdTsh(int ID, const double Ts, const double dTsh, struct SatRefProperties* SatProp, int errorFlag);
+
+/*        input Ts and s               */
+void px_Tss(int ID, double Ts, double s, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_Tss(int ID,  double Ts, double s, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_Tss(int ID, double Ts, double s, struct SatRefProperties* SatProp, int errorFlag);
+
+/*        input v and dTsh               */
+void px_vdTsh(int ID, double v, double dTsh, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_vdTsh(int ID,  double v, double dTsh, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_vdTsh(int ID, double v, double dTsh, struct SatRefProperties* SatProp, int errorFlag);
+
+/*        input v and s               */
+void px_vs(int ID, double v, double s, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_vs(int ID,  double v, double s, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_vs(int ID, double v, double s, struct SatRefProperties* SatProp, int errorFlag);
+
+/*        input h and v               */
+void px_hv(int ID, double h, double v, struct pxProperties *pxProp, int errorFlag);
+void computeGenValues_hv(int ID,  double h, double v, struct GenRefPropertiesAll* GenProp, int errorFlag);
+void computeSatValues_hv(int ID, double h, double v, struct SatRefProperties* SatProp, int errorFlag);
+
+
+double T_px        (int ID, const double p, const double x);
+double Ts_px       (int ID, const double p, const double x);
+double dTsh_px     (int ID, const double p, const double x);
+double h_px        (int ID, const double p, const double x);
+double rho_px      (int ID, const double p, const double x);
+double v_px      (int ID, const double p, const double x);
+double s_px        (int ID, const double p, const double x);
+double Cp_px       (int ID, const double p, const double x);
+
+
+
+
+double dTdx_px         (int ID, const double p, const double x);
+double dTdp_px         (int ID, const double p, const double x);
+double dTsdx_px         (int ID, const double p, const double x);
+double dTsdp_px         (int ID, const double p, const double x);
+double dCpdx_px        (int ID, const double p, const double x);
+double dCpdp_px        (int ID, const double p, const double x);
+double drhodx2_px      (int ID, const double p, const double x);
+double drhodp2_px      (int ID, const double p, const double x);
+double dhdx_px        (int ID, const double p, const double x);
+double dhdp_px        (int ID, const double p, const double x);
+double dsdx_px        (int ID, const double p, const double x);
+double dsdp_px        (int ID, const double p, const double x);
+double dmudx_px        (int ID, const double p, const double x);
+double dmudp_px        (int ID, const double p, const double x);
+double dlambdadx_px    (int ID, const double p, const double x);
+double dlambdadp_px      (int ID, const double p, const double x);
+double dCpCvdx_px        (int ID, const double p, const double x);
+double dCpCvdp_px        (int ID, const double p, const double x);
+double dn_isdx_px        (int ID, const double p, const double x);
+double dn_isdp_px        (int ID, const double p, const double x);
+double dcdx_px        (int ID, const double p, const double x);
+double dcdp_px        (int ID, const double p, const double x);
+double ddTglidedx_px        (int ID, const double p, const double x);
+double ddTglidedp_px        (int ID, const double p, const double x);
+
+double dsigmadx_px        (int ID, const double p, const double x);
+double dsigmadp_px        (int ID, const double p, const double x);
+double drhosldx_px        (int ID, const double p, const double x);
+double drhosldp_px        (int ID, const double p, const double x);
+double drhosvdx_px        (int ID, const double p, const double x);
+double drhosvdp_px        (int ID, const double p, const double x);
+double dhsldx_px        (int ID, const double p, const double x);
+double dhsldp_px        (int ID, const double p, const double x);
+double dhsvdx_px        (int ID, const double p, const double x);
+double dhsvdp_px        (int ID, const double p, const double x);
+double dssldx_px        (int ID, const double p, const double x);
+double dssldp_px        (int ID, const double p, const double x);
+double dssvdx_px        (int ID, const double p, const double x);
+double dssvdp_px        (int ID, const double p, const double x);
+double dCpsldx_px        (int ID, const double p, const double x);
+double dCpsldp_px        (int ID, const double p, const double x);
+double dCpsvdx_px        (int ID, const double p, const double x);
+double dCpsvdp_px        (int ID, const double p, const double x);
+double dmusldx_px        (int ID, const double p, const double x);
+double dmusldp_px        (int ID, const double p, const double x);
+double dmusvdx_px        (int ID, const double p, const double x);
+double dmusvdp_px        (int ID, const double p, const double x);
+double dlambdasldx_px        (int ID, const double p, const double x);
+double dlambdasldp_px        (int ID, const double p, const double x);
+double dlambdasvdx_px        (int ID, const double p, const double x);
+double dlambdasvdp_px        (int ID, const double p, const double x);
+double dcsldx_px     (int ID, const double p, const double x);
+double dcsldp_px     (int ID, const double p, const double x);
+double dcsvdp_px    (int ID, const double p, const double x);
+double dcsvdx_px    (int ID, const double p, const double x);
+
+
+
+double lambda_px   (int ID, const double p, const double x);
+double mu_px       (int ID, const double p, const double x);
+double nu_px       (int ID, const double p, const double x);
+double Pr_px       (int ID, const double p, const double x);
+double CpCv_px     (int ID, const double p, const double x);
+double n_is_px     (int ID, const double p, const double x);
+double c_px        (int ID, const double p, const double x);
+double dTglide_p   (int ID, const double p);
+
+double x_ph        (int ID, const double p, const double h);
+double T_ph        (int ID, const double p, const double h);
+double Ts_ph       (int ID, const double p, const double h);
+double dTsh_ph     (int ID, const double p, const double h);
+double rho_ph      (int ID, const double p, const double h);
+double s_ph        (int ID, const double p, const double h);
+double Cp_ph       (int ID, const double p, const double h);
+double lambda_ph   (int ID, const double p, const double h);
+double mu_ph       (int ID, const double p, const double h);
+double nu_ph       (int ID, const double p, const double h);
+double Pr_ph       (int ID, const double p, const double h);
+double CpCv_ph     (int ID, const double p, const double h);
+double n_is_ph     (int ID, const double p, const double h);
+double c_ph        (int ID, const double p, const double h);
+double drhodp_ph   (int ID, const double p, const double h);
+double drhodh_ph   (int ID, const double p, const double h);
+
+double hsl_px      (int ID, const double p, const double x);
+double hsv_px      (int ID, const double p, const double x);
+double rhosl_px    (int ID, const double p, const double x);
+double rhosv_px    (int ID, const double p, const double x);
+double ssl_px      (int ID, const double p, const double x);
+double ssv_px      (int ID, const double p, const double x);
+double Cpsl_px     (int ID, const double p, const double x);
+double Cpsv_px     (int ID, const double p, const double x);
+double musl_px     (int ID, const double p, const double x);
+double musv_px     (int ID, const double p, const double x);
+double lambdasl_px (int ID, const double p, const double x);
+double lambdasv_px (int ID, const double p, const double x);
+double csl_px         (int ID, const double p, const double x);
+double csv_px        (int ID, const double p, const double x);
+double sigma_px    (int ID, const double p, const double x);
+
+double p_Tx       (int ID, const double T, const double x);
+double h_pT        (int ID, const double p, const double T);
+double h_ps        (int ID, const double p, const double s);
+double pc          (int ID);
+double pcPseudo    (int ID);
+double pchlPseudo  (int ID);
+double pchvPseudo  (int ID);
+double Tc          (int ID);
+double xilMax  (int ID);
+double MolarMass (int ID);
+
+//Input files
+double qbegin (int ID);
+double qend (int ID);
+double pbegin (int ID);
+double pend (int ID);
+double qinc (int ID);
+double deltap (int ID);
+double Tlow (int ID);
+double Thigh (int ID);
+double Tbeg (int ID);
+double Tend (int ID);
+double Tinc (int ID);
+
+
+// supporting functions
+char* getName          (int ID);
+const char* getVersion (int ID);
+double FPercentPseudo  (int ID);
+void getRefComposition( int ID, const char* refCon[]); //added 12-15
+int getRefComNum(int ID);
+
+double vx_px (int ID, const double p, const double x);
+double vp_px (int ID, const double p, const double x);
+double hp_px (int ID, const double p, const double x);
+double hx_px (int ID, const double p, const double x);
+
+
+//
+//double F_to_K(const double& T);
+
+/// \todo SK: Are these functions not used, why is ID not passed as a parameter?
+double drhodp_px(int ID, const double p, const double x);
+double drhodh_px(int ID, const double p, const double x);
+
+#ifdef __cplusplus
+} // extern C
+#endif
+
+#endif // GENERIC_REFRIGERANT_HPP
+

+ 61 - 0
ModelicaModels/Dymola/Window/sources/HDR81.h

@@ -0,0 +1,61 @@
+	/*==========================================================================*/ 
+	/*  Description: Refrigerant property subroutines from IPM 5.0
+	/*  Author: Weijiang Zhang (weijiang.zhang@carrier.utc.com)
+	/*  Copyright reserved by Carrier M&A KCG, 2007
+	/*  Date: 2007.7.12 
+	/*==========================================================================*/
+	#include "math.h"
+	// extern "C" all function list
+	extern  double FT_PX_HDR81(const double dP,const double dX);
+	extern  double FTs_PX_HDR81(const double dP,const double dX);
+	extern  double FSH_PX_HDR81(const double dP,const double dX);
+	extern  double FH_PX_HDR81(const double dP,const double dX);
+	extern  double FRho_PX_HDR81(const double dP,const double dX);
+	extern  double FS_PX_HDR81(const double dP,const double dX);
+	extern  double FCp_PX_HDR81(const double dP,const double dX);
+	extern  double FLambda_PX_HDR81(const double dP,const double dX);
+	extern  double FMu_PX_HDR81(const double dP,const double dX);
+	extern  double FCpCv_PX_HDR81(const double dP,const double dX);
+	extern  double FIsotropic_PX_HDR81(const double dP,const double dX);
+	extern  double FA_PX_HDR81(const double dP,const double dX);
+	extern  double FTg_P_HDR81(const double dP);
+	extern  double FX_PH_HDR81(const double dP,const double dH);
+	extern  double FT_PH_HDR81(const double dP,const double dH);
+	extern  double FTs_PH_HDR81(const double dP,const double dH);
+	extern  double FSH_PH_HDR81(const double dP,const double dH);
+	extern  double FRho_PH_HDR81(const double dP,const double dH);
+	extern  double FS_PH_HDR81(const double dP,const double dH);
+	extern  double FCp_PH_HDR81(const double dP,const double dH);
+	extern  double FLambda_PH_HDR81(const double dP,const double dH);
+	extern  double FMu_PH_HDR81(const double dP,const double dH);
+	extern  double FCpCv_PH_HDR81(const double dP,const double dH);
+	extern  double FIsotropic_PH_HDR81(const double dP,const double dH);
+	extern  double FA_PH_HDR81(const double dP,const double dH);
+	extern  double FDRhoDP_PH_HDR81(const double dP,const double dH);
+	extern  double FDRhoDH_PH_HDR81(const double dP,const double dH);
+	extern  double FHls_PX_HDR81(const double dP,const double dX);
+	extern  double FHvs_PX_HDR81(const double dP,const double dX);
+	extern  double FRhols_PX_HDR81(const double dP,const double dX);
+	extern  double FRhovs_PX_HDR81(const double dP,const double dX);
+	extern  double FSls_PX_HDR81(const double dP,const double dX);
+	extern  double FSvs_PX_HDR81(const double dP,const double dX);
+	extern  double FCpls_PX_HDR81(const double dP,const double dX);
+	extern  double FCpvs_PX_HDR81(const double dP,const double dX);
+	extern  double FMuls_PX_HDR81(const double dP,const double dX);
+	extern  double FMuvs_PX_HDR81(const double dP,const double dX);
+	extern  double FLambdals_PX_HDR81(const double dP,const double dX);
+	extern  double FLambdavs_PX_HDR81(const double dP,const double dX);
+	extern  double FSurfTens_PX_HDR81(const double dP,const double dX);
+	extern  double FPs_TX_HDR81(const double dT,const double dX); 
+	extern  double FH_PT_HDR81(const double dP,const double dT);
+	extern  double FH_PS_HDR81(const double dP,const double dS);
+	extern  double FPc_HDR81();
+	// supporting functions
+	extern  char* ShowLibInfo_HDR81();
+	extern  char* ShowSourceDataInfo_HDR81();
+	extern  double FPercentPseudo_HDR81();
+
+	//double FGenIndex_PH(const int CI, const double P,const double H);
+
+	extern  double FDDPH_PX_HDR81(const double dP,const double dX);
+	extern  double FDDHP_PX_HDR81(const double dP,const double dX);

+ 608 - 0
ModelicaModels/Dymola/Window/sources/ModelicaFFT.c

@@ -0,0 +1,608 @@
+/* ModelicaFFT.c - FFT functions
+
+   Copyright (C) 2003-2010, Mark Borgerding
+   Copyright (C) 2015-2016, Modelica Association and DLR
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   3. Neither the author nor the names of any contributors may be used to
+      endorse or promote products derived from this software without specific
+      prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Adapted to the needs of the Modelica Standard Library library:
+
+   The functions in this file are non-portable. The following #define's are used
+   to define the system calls of the operating system
+
+   __GNUC__       : GNU C compiler
+   MODELICA_EXPORT: Prefix used for function calls. If not defined, blank is used
+                    Useful definitions:
+                    - "static" that is all functions become static
+                      (useful if file is included with other C-sources for an
+                       embedded system)
+                    - "__declspec(dllexport)" if included in a DLL and the
+                      functions shall be visible outside of the DLL
+
+   Release Notes:
+      Dec. 02, 2015: by Martin Otter, DLR
+                     Combined the C- and Header files of Kiss-FFT as needed for MSL
+                     Adapted the memory allocation scheme so that for exponents of 2,3,5
+                     memory has to be provided from the calling function
+                     (for if length of vector is not a multiple of 2,3,5, the function
+                     allocates additional memory, whenever it is called, and frees it before
+                     the function is left)
+*/
+
+#ifndef MRKISS_FTR_H
+#define MRKISS_FTR_H
+
+#include <math.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !defined(MODELICA_EXPORT)
+#   define MODELICA_EXPORT DYMOLA_STATIC
+#endif
+
+#define MRKISS_FFT_TMP_ALLOC malloc
+#define MRKISS_FFT_TMP_FREE free
+
+#define mrkiss_fft_scalar double
+#define MAXFACTORS 32
+/* e.g. an fft of length 128 has 4 factors
+ as far as kissfft is concerned
+ 4*4*4*2
+*/
+
+typedef struct {
+    mrkiss_fft_scalar r;
+    mrkiss_fft_scalar i;
+} mrkiss_fft_cpx;
+
+struct mrkiss_fft_state {
+    int nfft;
+    int inverse;
+    int factors[2*MAXFACTORS];
+    mrkiss_fft_cpx *twiddles;     /* twiddles[nfft] */
+};
+typedef struct mrkiss_fft_state* mrkiss_fft_cfg;
+
+struct mrkiss_fftr_state {
+    mrkiss_fft_cfg substate;
+    mrkiss_fft_cpx * tmpbuf;
+    mrkiss_fft_cpx * super_twiddles;
+};
+typedef struct mrkiss_fftr_state* mrkiss_fftr_cfg;
+
+/*
+ * Non-null pointers need to be passed to external functions.
+ *
+ * The following macros handle nonnull attributes for GNU C and Microsoft SAL.
+ */
+#if defined(__GNUC__)
+#define MODELICA_NONNULLATTR __attribute__((nonnull))
+#else
+#define MODELICA_NONNULLATTR
+#endif
+#if !defined(__ATTR_SAL)
+#define _In_
+#define _Out_
+#endif
+
+MODELICA_EXPORT int ModelicaFFT_kiss_fftr(_In_ double u[], size_t nu, _In_ double work[], size_t nwork,
+    _Out_ double *amplitudes, _Out_ double *phases) MODELICA_NONNULLATTR;
+
+/* include from _kiss_fft_guts.h ------------------------------------------ */
+
+/*
+  Explanation of macros dealing with complex math:
+
+   C_MUL(m,a,b)         : m = a*b
+   C_FIXDIV( c , div )  : if a fixed point impl., c /= div. noop otherwise
+   C_SUB( res, a,b)     : res = a - b
+   C_SUBFROM( res , a)  : res -= a
+   C_ADDTO( res , a)    : res += a
+ * */
+
+#define S_MUL(a,b) ( (a)*(b) )
+#define C_MUL(m,a,b) \
+    do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
+        (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
+#define C_FIXDIV(c,div) /* NOOP */
+#define C_MULBYSCALAR( c, s ) \
+    do{ (c).r *= (s);\
+        (c).i *= (s); }while(0)
+
+#ifndef CHECK_OVERFLOW_OP
+#  define CHECK_OVERFLOW_OP(a,op,b) /* noop */
+#endif
+
+#define  C_ADD( res, a,b)\
+    do { \
+        CHECK_OVERFLOW_OP((a).r,+,(b).r)\
+        CHECK_OVERFLOW_OP((a).i,+,(b).i)\
+        (res).r=(a).r+(b).r;  (res).i=(a).i+(b).i; \
+    }while(0)
+#define  C_SUB( res, a,b)\
+    do { \
+        CHECK_OVERFLOW_OP((a).r,-,(b).r)\
+        CHECK_OVERFLOW_OP((a).i,-,(b).i)\
+        (res).r=(a).r-(b).r;  (res).i=(a).i-(b).i; \
+    }while(0)
+#define C_ADDTO( res , a)\
+    do { \
+        CHECK_OVERFLOW_OP((res).r,+,(a).r)\
+        CHECK_OVERFLOW_OP((res).i,+,(a).i)\
+        (res).r += (a).r;  (res).i += (a).i;\
+    }while(0)
+
+#define C_SUBFROM( res , a)\
+    do {\
+        CHECK_OVERFLOW_OP((res).r,-,(a).r)\
+        CHECK_OVERFLOW_OP((res).i,-,(a).i)\
+        (res).r -= (a).r;  (res).i -= (a).i; \
+    }while(0)
+
+#define MRKISS_FFT_COS(phase) (mrkiss_fft_scalar) cos(phase)
+#define MRKISS_FFT_SIN(phase) (mrkiss_fft_scalar) sin(phase)
+#define HALF_OF(x) ((x)*.5)
+
+#define  kf_cexp(x,phase) \
+    do{ \
+        (x)->r = MRKISS_FFT_COS(phase);\
+        (x)->i = MRKISS_FFT_SIN(phase);\
+    }while(0)
+
+/* end of include from _kiss_fft_guts.h ------------------------------------------ */
+
+/* include of kiss_fft.c -------------------------------------------------------- */
+
+static void kf_bfly2(
+    mrkiss_fft_cpx * Fout,
+    const size_t fstride,
+    const mrkiss_fft_cfg st,
+    int m
+) {
+    mrkiss_fft_cpx * Fout2;
+    mrkiss_fft_cpx * tw1 = st->twiddles;
+    mrkiss_fft_cpx t;
+    Fout2 = Fout + m;
+    do {
+        C_FIXDIV(*Fout,2);
+        C_FIXDIV(*Fout2,2);
+
+        C_MUL (t,  *Fout2 , *tw1);
+        tw1 += fstride;
+        C_SUB( *Fout2 ,  *Fout , t );
+        C_ADDTO( *Fout ,  t );
+        ++Fout2;
+        ++Fout;
+    } while (--m);
+}
+
+static void kf_bfly4(
+    mrkiss_fft_cpx * Fout,
+    const size_t fstride,
+    const mrkiss_fft_cfg st,
+    const size_t m
+) {
+    mrkiss_fft_cpx *tw1,*tw2,*tw3;
+    mrkiss_fft_cpx scratch[6];
+    size_t k=m;
+    const size_t m2=2*m;
+    const size_t m3=3*m;
+
+    tw3 = tw2 = tw1 = st->twiddles;
+
+    do {
+        C_FIXDIV(*Fout,4);
+        C_FIXDIV(Fout[m],4);
+        C_FIXDIV(Fout[m2],4);
+        C_FIXDIV(Fout[m3],4);
+
+        C_MUL(scratch[0],Fout[m] , *tw1 );
+        C_MUL(scratch[1],Fout[m2] , *tw2 );
+        C_MUL(scratch[2],Fout[m3] , *tw3 );
+
+        C_SUB( scratch[5] , *Fout, scratch[1] );
+        C_ADDTO(*Fout, scratch[1]);
+        C_ADD( scratch[3] , scratch[0] , scratch[2] );
+        C_SUB( scratch[4] , scratch[0] , scratch[2] );
+        C_SUB( Fout[m2], *Fout, scratch[3] );
+        tw1 += fstride;
+        tw2 += fstride*2;
+        tw3 += fstride*3;
+        C_ADDTO( *Fout , scratch[3] );
+
+        if(st->inverse) {
+            Fout[m].r = scratch[5].r - scratch[4].i;
+            Fout[m].i = scratch[5].i + scratch[4].r;
+            Fout[m3].r = scratch[5].r + scratch[4].i;
+            Fout[m3].i = scratch[5].i - scratch[4].r;
+        } else {
+            Fout[m].r = scratch[5].r + scratch[4].i;
+            Fout[m].i = scratch[5].i - scratch[4].r;
+            Fout[m3].r = scratch[5].r - scratch[4].i;
+            Fout[m3].i = scratch[5].i + scratch[4].r;
+        }
+        ++Fout;
+    } while(--k);
+}
+
+static void kf_bfly3(
+    mrkiss_fft_cpx * Fout,
+    const size_t fstride,
+    const mrkiss_fft_cfg st,
+    size_t m
+) {
+    size_t k=m;
+    const size_t m2 = 2*m;
+    mrkiss_fft_cpx *tw1,*tw2;
+    mrkiss_fft_cpx scratch[5];
+    mrkiss_fft_cpx epi3;
+    epi3 = st->twiddles[fstride*m];
+
+    tw1=tw2=st->twiddles;
+
+    do {
+        C_FIXDIV(*Fout,3);
+        C_FIXDIV(Fout[m],3);
+        C_FIXDIV(Fout[m2],3);
+
+        C_MUL(scratch[1],Fout[m] , *tw1);
+        C_MUL(scratch[2],Fout[m2] , *tw2);
+
+        C_ADD(scratch[3],scratch[1],scratch[2]);
+        C_SUB(scratch[0],scratch[1],scratch[2]);
+        tw1 += fstride;
+        tw2 += fstride*2;
+
+        Fout[m].r = Fout->r - HALF_OF(scratch[3].r);
+        Fout[m].i = Fout->i - HALF_OF(scratch[3].i);
+
+        C_MULBYSCALAR( scratch[0] , epi3.i );
+
+        C_ADDTO(*Fout,scratch[3]);
+
+        Fout[m2].r = Fout[m].r + scratch[0].i;
+        Fout[m2].i = Fout[m].i - scratch[0].r;
+
+        Fout[m].r -= scratch[0].i;
+        Fout[m].i += scratch[0].r;
+
+        ++Fout;
+    } while(--k);
+}
+
+static void kf_bfly5(
+    mrkiss_fft_cpx * Fout,
+    const size_t fstride,
+    const mrkiss_fft_cfg st,
+    int m
+) {
+    mrkiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
+    int u;
+    mrkiss_fft_cpx scratch[13];
+    mrkiss_fft_cpx * twiddles = st->twiddles;
+    mrkiss_fft_cpx *tw;
+    mrkiss_fft_cpx ya,yb;
+    ya = twiddles[fstride*m];
+    yb = twiddles[fstride*2*m];
+
+    Fout0=Fout;
+    Fout1=Fout0+m;
+    Fout2=Fout0+2*m;
+    Fout3=Fout0+3*m;
+    Fout4=Fout0+4*m;
+
+    tw=st->twiddles;
+    for ( u=0; u<m; ++u ) {
+        C_FIXDIV( *Fout0,5);
+        C_FIXDIV( *Fout1,5);
+        C_FIXDIV( *Fout2,5);
+        C_FIXDIV( *Fout3,5);
+        C_FIXDIV( *Fout4,5);
+        scratch[0] = *Fout0;
+
+        C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
+        C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
+        C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
+        C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
+
+        C_ADD( scratch[7],scratch[1],scratch[4]);
+        C_SUB( scratch[10],scratch[1],scratch[4]);
+        C_ADD( scratch[8],scratch[2],scratch[3]);
+        C_SUB( scratch[9],scratch[2],scratch[3]);
+
+        Fout0->r += scratch[7].r + scratch[8].r;
+        Fout0->i += scratch[7].i + scratch[8].i;
+
+        scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r);
+        scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r);
+
+        scratch[6].r =  S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i);
+        scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i);
+
+        C_SUB(*Fout1,scratch[5],scratch[6]);
+        C_ADD(*Fout4,scratch[5],scratch[6]);
+
+        scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r);
+        scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r);
+        scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i);
+        scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i);
+
+        C_ADD(*Fout2,scratch[11],scratch[12]);
+        C_SUB(*Fout3,scratch[11],scratch[12]);
+
+        ++Fout0;
+        ++Fout1;
+        ++Fout2;
+        ++Fout3;
+        ++Fout4;
+    }
+}
+
+/* perform the butterfly for one stage of a mixed radix FFT */
+static void kf_bfly_generic(
+    mrkiss_fft_cpx * Fout,
+    const size_t fstride,
+    const mrkiss_fft_cfg st,
+    int m,
+    int p
+) {
+    int u,k,q1,q;
+    mrkiss_fft_cpx * twiddles = st->twiddles;
+    mrkiss_fft_cpx t;
+    int Norig = st->nfft;
+
+    mrkiss_fft_cpx * scratch = (mrkiss_fft_cpx*)MRKISS_FFT_TMP_ALLOC(sizeof(mrkiss_fft_cpx)*p);
+
+    for ( u=0; u<m; ++u ) {
+        k=u;
+        for ( q1=0 ; q1<p ; ++q1 ) {
+            scratch[q1] = Fout[ k  ];
+            C_FIXDIV(scratch[q1],p);
+            k += m;
+        }
+
+        k=u;
+        for ( q1=0 ; q1<p ; ++q1 ) {
+            int twidx=0;
+            Fout[ k ] = scratch[0];
+            for (q=1; q<p; ++q ) {
+                twidx += fstride * k;
+                if (twidx>=Norig) twidx-=Norig;
+                C_MUL(t,scratch[q] , twiddles[twidx] );
+                C_ADDTO( Fout[ k ] ,t);
+            }
+            k += m;
+        }
+    }
+    MRKISS_FFT_TMP_FREE(scratch);
+}
+
+static void kf_work(
+    mrkiss_fft_cpx * Fout,
+    const mrkiss_fft_cpx * f,
+    const size_t fstride,
+    int in_stride,
+    int * factors,
+    const mrkiss_fft_cfg st
+) {
+    mrkiss_fft_cpx * Fout_beg=Fout;
+    const int p=*factors++; /* the radix  */
+    const int m=*factors++; /* stage's fft length/p */
+    const mrkiss_fft_cpx * Fout_end = Fout + p*m;
+
+    if (m==1) {
+        do {
+            *Fout = *f;
+            f += fstride*in_stride;
+        } while(++Fout != Fout_end );
+    } else {
+        do {
+            /* recursive call:
+               DFT of size m*p performed by doing
+               p instances of smaller DFTs of size m,
+               each one takes a decimated version of the input */
+            kf_work( Fout , f, fstride*p, in_stride, factors,st);
+            f += fstride*in_stride;
+        } while( (Fout += m) != Fout_end );
+    }
+
+    Fout=Fout_beg;
+
+    /* recombine the p smaller DFTs */
+    switch (p) {
+        case 2:
+            kf_bfly2(Fout,fstride,st,m);
+            break;
+        case 3:
+            kf_bfly3(Fout,fstride,st,m);
+            break;
+        case 4:
+            kf_bfly4(Fout,fstride,st,m);
+            break;
+        case 5:
+            kf_bfly5(Fout,fstride,st,m);
+            break;
+        default:
+            kf_bfly_generic(Fout,fstride,st,m,p);
+            break;
+    }
+}
+
+/*  facbuf is populated by p1,m1,p2,m2, ...
+    where
+    p[i] * m[i] = m[i-1]
+    m0 = n                  */
+static void kf_factor(int n,int * facbuf) {
+    int p=4;
+    double floor_sqrt;
+    floor_sqrt = floor( sqrt((double)n) );
+
+    /* factor out powers of 4, powers of 2, then any remaining primes */
+    do {
+        while (n % p) {
+            switch (p) {
+                case 4:
+                    p = 2;
+                    break;
+                case 2:
+                    p = 3;
+                    break;
+                default:
+                    p += 2;
+                    break;
+            }
+            if (p > floor_sqrt)
+                p = n;          /* no more factors, skip to end */
+        }
+        n /= p;
+        *facbuf++ = p;
+        *facbuf++ = n;
+    } while (n > 1);
+}
+
+static void mrkiss_fft_stride(mrkiss_fft_cfg st,const mrkiss_fft_cpx *fin,mrkiss_fft_cpx *fout,int in_stride) {
+    if (fin == fout) {
+        /* NOTE: this is not really an in-place FFT algorithm. */
+        /* It just performs an out-of-place FFT into a temp buffer */
+        mrkiss_fft_cpx * tmpbuf = (mrkiss_fft_cpx*)MRKISS_FFT_TMP_ALLOC( sizeof(mrkiss_fft_cpx)*st->nfft);
+        kf_work(tmpbuf,fin,1,in_stride, st->factors,st);
+        memcpy(fout,tmpbuf,sizeof(mrkiss_fft_cpx)*st->nfft);
+        MRKISS_FFT_TMP_FREE(tmpbuf);
+    } else {
+        kf_work( fout, fin, 1,in_stride, st->factors,st );
+    }
+}
+
+static void mrkiss_fft(mrkiss_fft_cfg cfg,const mrkiss_fft_cpx *fin,mrkiss_fft_cpx *fout) {
+    mrkiss_fft_stride(cfg,fin,fout,1);
+}
+
+/* end of include from kiss_fft.c --------------------------------------------------*/
+
+static void mrkiss_fft_alloc(int nfft, mrkiss_fft_cfg cfg) {
+    int i;
+    cfg->nfft    = nfft;
+    cfg->inverse = 0;
+
+    for (i=0; i<nfft; ++i) {
+        const double pi=3.141592653589793238462643383279502884197169399375105820974944;
+        double phase = -2*pi*i / nfft;
+        kf_cexp(cfg->twiddles+i, phase);
+    }
+    kf_factor(nfft, cfg->factors);
+}
+
+static void mrkiss_fftr(mrkiss_fftr_cfg st, const mrkiss_fft_scalar *timedata, mrkiss_fft_cpx *freqdata) {
+    /* input buffer timedata is stored row-wise */
+    int k,ncfft;
+    mrkiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc;
+
+    ncfft = st->substate->nfft;
+
+    /*perform the parallel fft of two real signals packed in real,imag*/
+    mrkiss_fft( st->substate , (const mrkiss_fft_cpx*)timedata, st->tmpbuf );
+
+    tdc.r = st->tmpbuf[0].r;
+    tdc.i = st->tmpbuf[0].i;
+    C_FIXDIV(tdc,2);
+    CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i);
+    CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i);
+    freqdata[0].r = tdc.r + tdc.i;
+    freqdata[ncfft].r = tdc.r - tdc.i;
+    freqdata[ncfft].i = freqdata[0].i = 0;
+
+    for ( k=1; k <= ncfft/2 ; ++k ) {
+        fpk    = st->tmpbuf[k];
+        fpnk.r =   st->tmpbuf[ncfft-k].r;
+        fpnk.i = - st->tmpbuf[ncfft-k].i;
+        C_FIXDIV(fpk,2);
+        C_FIXDIV(fpnk,2);
+
+        C_ADD( f1k, fpk , fpnk );
+        C_SUB( f2k, fpk , fpnk );
+        C_MUL( tw , f2k , st->super_twiddles[k-1]);
+
+        freqdata[k].r = HALF_OF(f1k.r + tw.r);
+        freqdata[k].i = HALF_OF(f1k.i + tw.i);
+        freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r);
+        freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i);
+    }
+}
+
+MODELICA_EXPORT int ModelicaFFT_kiss_fftr(double u[], size_t nu, double work[], size_t nwork,
+        double *amplitudes, double *phases) {
+
+    /* Compute real FFT with mrkiss_fftr
+       -> u[nu]        : Real data at sample points; nu must be even
+       -> work[nwork]  : Work array; nwork >= 3*nu + 2*nf (nf = nu/2+1)
+       <- amplitude[nf]: Amplitudes; nf = nu/2+1
+       <- phases   [nf]: phases
+       <- return       : info = 0: computation o.k.
+                              = 1: nu is not even
+                              = 2: nwork is wrong
+                              = 3: another error
+
+    */
+    int i;
+    int nu2 = nu / 2;
+    int nf  = nu2+1;
+
+    struct mrkiss_fft_state  fft_obj;
+    struct mrkiss_fftr_state fftr_obj;
+    mrkiss_fft_cpx *freqdata;
+
+    /* Check dimensions */
+    if ( nu % 2 != 0 ) return 1;
+    if ( nwork < 3*nu + 2*(nu/2+1) ) return 2;
+
+    /* Set values of struct fft_obj */
+    fft_obj.twiddles = (mrkiss_fft_cpx *) &work[0];    /* length nu (2*nu2) */
+    mrkiss_fft_alloc(nu2, &fft_obj);
+
+    /* Set values of struct fftr_obj */
+    fftr_obj.substate       = &fft_obj;
+    fftr_obj.tmpbuf         = (mrkiss_fft_cpx *) &work[nu];     /* length: nu */
+    fftr_obj.super_twiddles = (mrkiss_fft_cpx *) &work[nu+nu];  /* length: nu  */
+    for (i = 0; i < nu2/2; ++i) {
+        double phase =
+            -3.14159265358979323846264338327 * ((double) (i+1) / nu2 + .5);
+        kf_cexp (fftr_obj.super_twiddles+i,phase);
+    }
+
+    /* Compute FFT */
+    freqdata = (mrkiss_fft_cpx *) &work[nu+nu+nu];  /* length: 2*nf */
+    mrkiss_fftr(&fftr_obj, u, freqdata);
+    for (i=0; i<nf; i++) {
+        amplitudes[i] = sqrt (freqdata[i].r*freqdata[i].r + freqdata[i].i*freqdata[i].i) / nf;
+        phases[i]     = atan2(freqdata[i].i, freqdata[i].r);
+    }
+    return 0;
+}
+
+#endif

+ 405 - 0
ModelicaModels/Dymola/Window/sources/ModelicaIO.c

@@ -0,0 +1,405 @@
+/* ModelicaIO.c - Array I/O functions
+
+   Copyright (C) 2016, Modelica Association
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* The functions in this file are non-portable. The following #define's are used
+   to define the system calls of the operating system
+
+   __GNUC__       : GNU C compiler
+   NO_FILE_SYSTEM : A file system is not present (e.g. on dSPACE or xPC).
+   MODELICA_EXPORT: Prefix used for function calls. If not defined, blank is used
+                    Useful definitions:
+                    - "static" that is all functions become static
+                      (useful if file is included with other C-sources for an
+                       embedded system)
+                    - "__declspec(dllexport)" if included in a DLL and the
+                      functions shall be visible outside of the DLL
+
+   Release Notes:
+      Mar. 03, 2016: by Thomas Beutlich, ITI GmbH and Martin Otter, DLR
+                     Implemented a first version (ticket #1856)
+*/
+
+#if !defined(MODELICA_EXPORT)
+  #define MODELICA_EXPORT DYMOLA_STATIC
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "ModelicaUtilities.h"
+
+#ifdef NO_FILE_SYSTEM
+static void ModelicaNotExistError(const char* name) {
+  /* Print error message if a function is not implemented */
+    ModelicaFormatError("C-Function \"%s\" is called "
+        "but is not implemented for the actual environment "
+        "(e.g., because there is no file system available on the machine "
+        "as for dSPACE or xPC systems)\n", name);
+}
+
+MODELICA_EXPORT void ModelicaIO_readMatrixSizes(const char* fileName,
+    const char* varName, int* dim) {
+    ModelicaNotExistError("ModelicaIO_readMatrixSizes"); }
+MODELICA_EXPORT void ModelicaIO_readRealMatrix(const char* fileName,
+    const char* varName, double* a, size_t m, size_t n, int verbose) {
+    ModelicaNotExistError("ModelicaIO_readRealMatrix"); }
+MODELICA_EXPORT int ModelicaIO_writeRealMatrix(const char* fileName,
+    const char* varName, double* a, size_t m, size_t n, int append, const char* version) {
+    ModelicaNotExistError("ModelicaIO_writeRealMatrix"); return 0; }
+#else
+
+#include <stdio.h>
+#include "ModelicaIO.h"
+#include "ModelicaMatIO.h"
+
+static void ModelicaIO_transpose(double* table, size_t nRow, size_t nCol) {
+  /* Reference:
+
+     Cycle-based in-place array transposition
+     (http://en.wikipedia.org/wiki/In-place_matrix_transposition#Non-square_matrices:_Following_the_cycles)
+  */
+
+    size_t i;
+    for (i = 1; i < nRow*nCol - 1; i++) {
+        size_t x = nRow*(i % nCol) + i/nCol; /* predecessor of i in the cycle */
+        /* Continue if cycle is of length one or predecessor already was visited */
+        if (x <= i) {
+            continue;
+        }
+        /* Continue if cycle already was visited */
+        while (x > i) {
+            x = nRow*(x % nCol) + x/nCol;
+        }
+        if (x < i) {
+            continue;
+        }
+        {
+            double tmp = table[i];
+            size_t s = i; /* start index in the cycle */
+            x = nRow*(i % nCol) + i/nCol; /* predecessor of i in the cycle */
+            while (x != i) {
+                table[s] = table[x];
+                s = x;
+                x = nRow*(x % nCol) + x/nCol;
+            }
+            table[s] = tmp;
+        }
+    }
+}
+
+MODELICA_EXPORT void ModelicaIO_readMatrixSizes(const char* fileName,
+    const char* varName, int* dim) {
+    mat_t* mat;
+    matvar_t* matvar;
+    matvar_t* matvarRoot;
+    char* varNameCopy;
+    char* token;
+
+    varNameCopy = (char*)malloc((strlen(varName) + 1)*sizeof(char));
+    if (varNameCopy != NULL) {
+        strcpy(varNameCopy, varName);
+    }
+    else {
+        dim[0] = 0;
+        dim[1] = 0;
+        ModelicaError("Memory allocation error\n");
+        return;
+    }
+
+    mat = Mat_Open(fileName, (int)MAT_ACC_RDONLY);
+    if (mat == NULL) {
+        dim[0] = 0;
+        dim[1] = 0;
+        free(varNameCopy);
+        ModelicaFormatError("Not possible to open file \"%s\": "
+            "No such file or directory\n", fileName);
+        return;
+    }
+
+    token = strtok(varNameCopy, ".");
+    matvarRoot = Mat_VarReadInfo(mat, token == NULL ? varName : token);
+    if (matvarRoot == NULL) {
+        dim[0] = 0;
+        dim[1] = 0;
+        free(varNameCopy);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Variable \"%s\" not found on file \"%s\".\n",
+            token == NULL ? varName : token, fileName);
+        return;
+    }
+
+    matvar = matvarRoot;
+    token = strtok(NULL, ".");
+    /* Get field while matvar is of struct class and of 1x1 size */
+    while (token != NULL && matvar != NULL &&
+        matvar->class_type == MAT_C_STRUCT && matvar->rank == 2 &&
+        matvar->dims[0] == 1 && matvar->dims[1] == 1) {
+        matvar = Mat_VarGetStructField(matvar, (void*)token, MAT_BY_NAME, 0);
+        token = strtok(NULL, ".");
+    }
+    free(varNameCopy);
+
+    if (matvar == NULL) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Matrix \"%s\" not found on file \"%s\".\n", varName, fileName);
+        return;
+    }
+
+    /* Check if matvar is a matrix */
+    if (matvar->rank != 2) {
+        dim[0] = 0;
+        dim[1] = 0;
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Array \"%s\" has not the required rank 2.\n", varName);
+        return;
+    }
+
+    dim[0] = (int)matvar->dims[0];
+    dim[1] = (int)matvar->dims[1];
+
+    Mat_VarFree(matvarRoot);
+    (void)Mat_Close(mat);
+}
+
+MODELICA_EXPORT void ModelicaIO_readRealMatrix(const char* fileName,
+    const char* varName, double* a, size_t m, size_t n, int verbose) {
+    mat_t* mat;
+    matvar_t* matvar;
+    matvar_t* matvarRoot;
+    size_t nRow, nCol;
+    int tableReadError = 0;
+    char* varNameCopy;
+    char* token;
+
+    if (verbose == 1) {
+        /* Print info message, that matrix / file is loading */
+        ModelicaFormatMessage("... loading \"%s\" from \"%s\"\n",
+            varName, fileName);
+    }
+
+    varNameCopy = (char*)malloc((strlen(varName) + 1)*sizeof(char));
+    if (varNameCopy != NULL) {
+        strcpy(varNameCopy, varName);
+    }
+    else {
+        ModelicaError("Memory allocation error\n");
+        return;
+    }
+
+    mat = Mat_Open(fileName, (int)MAT_ACC_RDONLY);
+    if (mat == NULL) {
+        free(varNameCopy);
+        ModelicaFormatError("Not possible to open file \"%s\": "
+            "No such file or directory\n", fileName);
+        return;
+    }
+
+    token = strtok(varNameCopy, ".");
+    matvarRoot = Mat_VarReadInfo(mat, token == NULL ? varName : token);
+    if (matvarRoot == NULL) {
+        free(varNameCopy);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Variable \"%s\" not found on file \"%s\".\n",
+            token == NULL ? varName : token, fileName);
+        return;
+    }
+
+    matvar = matvarRoot;
+    token = strtok(NULL, ".");
+    /* Get field while matvar is of struct class and of 1x1 size */
+    while (token != NULL && matvar != NULL &&
+        matvar->class_type == MAT_C_STRUCT && matvar->rank == 2 &&
+        matvar->dims[0] == 1 && matvar->dims[1] == 1) {
+        matvar = Mat_VarGetStructField(matvar, (void*)token, MAT_BY_NAME, 0);
+        token = strtok(NULL, ".");
+    }
+    free(varNameCopy);
+
+    if (matvar == NULL) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Matrix \"%s\" not found on file \"%s\".\n", varName, fileName);
+        return;
+    }
+
+    /* Check if matvar is a matrix */
+    if (matvar->rank != 2) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Array \"%s\" has not the required rank 2.\n", varName);
+        return;
+    }
+
+    /* Check if matvar is of double precision class (and thus non-sparse) */
+    if (matvar->class_type != MAT_C_DOUBLE) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError("2D array \"%s\" has not the required "
+            "double precision class.\n", varName);
+        return;
+    }
+
+    /* Check if matvar is purely real-valued */
+    if (matvar->isComplex) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError("2D array \"%s\" must not be complex.\n",
+            varName);
+        return;
+    }
+
+    nRow = matvar->dims[0];
+    nCol = matvar->dims[1];
+
+    /* Check if number of rows matches */
+    if (m != nRow) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Cannot read %lu rows of array \"%s(%lu,%lu)\" "
+            "from file \"%s\"\n", (unsigned long)m, varName,
+            (unsigned long)nRow, (unsigned long)nCol, fileName);
+        return;
+    }
+
+    /* Check if number of columns matches */
+    if (n != nCol) {
+        Mat_VarFree(matvarRoot);
+        (void)Mat_Close(mat);
+        ModelicaFormatError(
+            "Cannot read %lu columns of array \"%s(%lu,%lu)\" "
+            "from file \"%s\"\n", (unsigned long)n, varName,
+            (unsigned long)nRow, (unsigned long)nCol, fileName);
+        return;
+    }
+
+    {
+        int start[2] = {0, 0};
+        int stride[2] = {1, 1};
+        int edge[2];
+        edge[0] = (int)nRow;
+        edge[1] = (int)nCol;
+        tableReadError = Mat_VarReadData(mat, matvar, a, start, stride, edge);
+    }
+
+    Mat_VarFree(matvarRoot);
+    (void)Mat_Close(mat);
+
+    if (tableReadError == 0) {
+        /* Array is stored column-wise -> need to transpose */
+        ModelicaIO_transpose(a, nRow, nCol);
+    }
+    else {
+        ModelicaFormatError(
+            "Error when reading numeric data of matrix \"%s(%lu,%lu)\" "
+            "from file \"%s\"\n", varName, (unsigned long)nRow,
+            (unsigned long)nCol, fileName);
+        return;
+    }
+}
+
+MODELICA_EXPORT int ModelicaIO_writeRealMatrix(const char* fileName,
+    const char* varName, double* a, size_t m, size_t n, int append, const char* version) {
+    int status;
+    mat_t* mat;
+    matvar_t* matvar;
+    size_t dims[2];
+    double* aT;
+    enum mat_ft matv;
+    enum matio_compression matc;
+
+    if ((0 != strcmp(version, "4")) && (0 != strcmp(version, "6")) && (0 != strcmp(version, "7")) && (0 != strcmp(version, "7.3"))) {
+        ModelicaFormatError("Invalid version %s for file \"%s\"\n", version, fileName);
+        return 0;
+    }
+    if (0 == strcmp(version, "4")) {
+        matv = MAT_FT_MAT4;
+        matc = MAT_COMPRESSION_NONE;
+    }
+    else if (0 == strcmp(version, "7.3")) {
+        matv = MAT_FT_MAT73;
+        matc = MAT_COMPRESSION_ZLIB;
+    }
+    else if (0 == strcmp(version, "7")) {
+        matv = MAT_FT_MAT5;
+        matc = MAT_COMPRESSION_ZLIB;
+    }
+    else {
+        matv = MAT_FT_MAT5;
+        matc = MAT_COMPRESSION_NONE;
+    }
+
+    if ( append == 0 ) {
+        mat = Mat_CreateVer(fileName, NULL, matv);
+        if (mat == NULL) {
+            ModelicaFormatError("Not possible to newly create file \"%s\"\n(maybe version 7.3 not supported)\n", fileName);
+            return 0;
+        }
+    } else {
+        mat = Mat_Open(fileName, (int)MAT_ACC_RDWR | matv);
+        if (mat == NULL) {
+            ModelicaFormatError("Not possible to open file \"%s\"\n", fileName);
+            return 0;
+        }
+    }
+
+    /* MAT file array is stored column-wise -> need to transpose */
+    aT = (double*)malloc(m*n*sizeof(double));
+    if (aT == NULL) {
+        (void)Mat_Close(mat);
+        ModelicaError("Memory allocation error\n");
+        return 0;
+    }
+    memcpy(aT, a, m*n*sizeof(double));
+    ModelicaIO_transpose(aT, n, m);
+
+    if (append != 0) {
+        (void)Mat_VarDelete(mat, varName);
+    }
+
+    dims[0] = m;
+    dims[1] = n;
+    matvar = Mat_VarCreate(varName, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, aT, MAT_F_DONT_COPY_DATA);
+    status = Mat_VarWrite(mat, matvar, matc);
+    Mat_VarFree(matvar);
+    (void)Mat_Close(mat);
+    free(aT);
+    if (status != 0) {
+        ModelicaFormatError("Cannot write variable \"%s\" to \"%s\"\n", varName, fileName);
+        return 0;
+    }
+    return 1;
+}
+
+#endif

+ 60 - 0
ModelicaModels/Dymola/Window/sources/ModelicaIO.h

@@ -0,0 +1,60 @@
+/* ModelicaIO.h - Array I/O functions header
+
+   Copyright (C) 2016, Modelica Association
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Definition of interface to external functions for array I/O
+   in the Modelica Standard Library:
+
+      Modelica.Utilities.Streams.readMatrixSize
+      Modelica.Utilities.Streams.readRealMatrix
+      Modelica.Utilities.Streams.writeRealMatrix
+
+   Release Notes:
+      Mar. 03, 2016: by Thomas Beutlich, ITI GmbH and Martin Otter, DLR
+                     Implemented a first version (ticket #1856)
+*/
+
+#if !defined(MODELICAIO_H)
+#define MODELICAIO_H
+
+#include <stdlib.h>
+
+#if defined(__GNUC__)
+#define MODELICA_NONNULLATTR __attribute__((nonnull))
+#else
+#define MODELICA_NONNULLATTR
+#endif
+#if !defined(__ATTR_SAL)
+#define _In_
+#define _In_z_
+#define _Out_
+#endif
+
+void ModelicaIO_readMatrixSizes(_In_z_ const char* fileName, _In_z_ const char* arrayName, _Out_ int* dim) MODELICA_NONNULLATTR;
+void ModelicaIO_readRealMatrix(_In_z_ const char* fileName, _In_z_ const char* arrayName, _Out_ double* a, size_t m, size_t n, int verbose) MODELICA_NONNULLATTR;
+int  ModelicaIO_writeRealMatrix(_In_z_ const char* fileName, _In_z_ const char* arrayName, _In_ double* a, size_t m, size_t n, int append, _In_z_ const char* version) MODELICA_NONNULLATTR;
+
+#endif

File diff suppressed because it is too large
+ 1276 - 0
ModelicaModels/Dymola/Window/sources/ModelicaInternal.c


File diff suppressed because it is too large
+ 21424 - 0
ModelicaModels/Dymola/Window/sources/ModelicaMatIO.c


+ 389 - 0
ModelicaModels/Dymola/Window/sources/ModelicaMatIO.h

@@ -0,0 +1,389 @@
+/* ModelicaMatIO.h - MAT file I/O functions header
+
+   Copyright (C) 2013-2016, Christopher C. Hulbert, Modelica Association, and ITI GmbH
+   Copyright (C) 2005-2013, Christopher C. Hulbert
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+   This file was created by concatenation of the following header files of the
+   MAT file I/O library from <http://sourceforge.net/projects/matio/>:
+
+   matio.h
+   matio_pubconf.h
+*/
+
+#ifndef MODELICAMATIO_H
+#define MODELICAMATIO_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifndef MATIO_PUBCONF_H
+#define MATIO_PUBCONF_H 1
+
+/* Matio major version number */
+#define MATIO_MAJOR_VERSION 1
+
+/* Matio minor version number */
+#define MATIO_MINOR_VERSION 5
+
+/* Matio release level number */
+#define MATIO_RELEASE_LEVEL 6
+
+/* Matio version number */
+#define MATIO_VERSION 156
+
+/* Matio version string */
+#define MATIO_VERSION_STR "1.5.6"
+
+/* Default file format */
+#define MAT_FT_DEFAULT MAT_FT_MAT5
+
+/* Have MAT int64 / uint64 */
+#if defined(_WIN32)
+#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+#define HAVE_MATIO_INT64_T 1
+#define HAVE_MATIO_UINT64_T 1
+#else
+#undef HAVE_MATIO_INT64_T
+#undef HAVE_MATIO_UINT64_T
+#endif
+#else
+#define HAVE_MATIO_INT64_T 1
+#define HAVE_MATIO_UINT64_T 1
+#endif
+
+/* Have the <stdint.h> header file */
+#if defined(_WIN32)
+#if defined(_MSC_VER) && _MSC_VER >= 1600
+#define HAVE_MATIO_STDINT_H 1
+#elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+#define HAVE_MATIO_STDINT_H 1
+#else
+#undef HAVE_MATIO_STDINT_H
+#endif
+#elif defined(__GNUC__) && !defined(__VXWORKS__)
+#define HAVE_MATIO_STDINT_H 1
+#else
+#undef HAVE_MATIO_STDINT_H
+#endif
+
+/* Include integer type header */
+#if defined(HAVE_MATIO_STDINT_H)
+#include <stdint.h>
+typedef int16_t mat_int16_t;
+typedef int32_t mat_int32_t;
+typedef int64_t mat_int64_t;
+typedef int8_t mat_int8_t;
+typedef uint16_t mat_uint16_t;
+typedef uint32_t mat_uint32_t;
+typedef uint64_t mat_uint64_t;
+typedef uint8_t mat_uint8_t;
+#else
+#define mat_int16_t short
+#define mat_int32_t int
+#if defined(HAVE_MATIO_INT64_T)
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define mat_int64_t __int64
+#else
+#define mat_int64_t long long
+#endif
+#endif
+#define mat_int8_t signed char
+#define mat_uint16_t unsigned short
+#define mat_uint32_t unsigned
+#if defined(HAVE_MATIO_UINT64_T)
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define mat_uint64_t unsigned __int64
+#else
+#define mat_uint64_t unsigned long long
+#endif
+#endif
+#define mat_uint8_t unsigned char
+#endif
+
+#endif /* MATIO_PUBCONF_H */
+
+#include <stdarg.h>
+
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+/** @defgroup MAT Matlab MAT File I/O Library */
+/** @defgroup mat_util MAT File I/O Utility Functions */
+/** @if mat_devman @defgroup mat_internal Internal Functions @endif */
+
+/** @brief MAT file access types
+ *
+ * @ingroup MAT
+ * MAT file access types
+ */
+enum mat_acc {
+    MAT_ACC_RDONLY = 0,  /**< @brief Read only file access                */
+    MAT_ACC_RDWR   = 1   /**< @brief Read/Write file access               */
+};
+
+/** @brief MAT file versions
+ *
+ * @ingroup MAT
+ * MAT file versions
+ */
+enum mat_ft {
+    MAT_FT_MAT73  = 0x0200,   /**< @brief Matlab version 7.3 file             */
+    MAT_FT_MAT5   = 0x0100,   /**< @brief Matlab version 5 file               */
+    MAT_FT_MAT4   = 0x0010,   /**< @brief Matlab version 4 file               */
+    MAT_FT_UNDEFINED =   0    /**< @brief Undefined version                   */
+};
+
+/** @brief Matlab data types
+ *
+ * @ingroup MAT
+ * Matlab data types
+ */
+enum matio_types {
+    MAT_T_UNKNOWN    =  0,    /**< @brief UNKNOWN data type                    */
+    MAT_T_INT8       =  1,    /**< @brief 8-bit signed integer data type      */
+    MAT_T_UINT8      =  2,    /**< @brief 8-bit unsigned integer data type    */
+    MAT_T_INT16      =  3,    /**< @brief 16-bit signed integer data type     */
+    MAT_T_UINT16     =  4,    /**< @brief 16-bit unsigned integer data type   */
+    MAT_T_INT32      =  5,    /**< @brief 32-bit signed integer data type     */
+    MAT_T_UINT32     =  6,    /**< @brief 32-bit unsigned integer data type   */
+    MAT_T_SINGLE     =  7,    /**< @brief IEEE 754 single precision data type */
+    MAT_T_DOUBLE     =  9,    /**< @brief IEEE 754 double precision data type */
+    MAT_T_INT64      = 12,    /**< @brief 64-bit signed integer data type     */
+    MAT_T_UINT64     = 13,    /**< @brief 64-bit unsigned integer data type   */
+    MAT_T_MATRIX     = 14,    /**< @brief matrix data type                    */
+    MAT_T_COMPRESSED = 15,    /**< @brief compressed data type                */
+    MAT_T_UTF8       = 16,    /**< @brief 8-bit unicode text data type        */
+    MAT_T_UTF16      = 17,    /**< @brief 16-bit unicode text data type       */
+    MAT_T_UTF32      = 18,    /**< @brief 32-bit unicode text data type       */
+
+    MAT_T_STRING     = 20,    /**< @brief String data type                    */
+    MAT_T_CELL       = 21,    /**< @brief Cell array data type                */
+    MAT_T_STRUCT     = 22,    /**< @brief Structure data type                 */
+    MAT_T_ARRAY      = 23,    /**< @brief Array data type                     */
+    MAT_T_FUNCTION   = 24     /**< @brief Function data type                  */
+};
+
+/** @brief Matlab variable classes
+ *
+ * @ingroup MAT
+ * Matlab variable classes
+ */
+enum matio_classes {
+    MAT_C_EMPTY    =  0, /**< @brief Empty array                           */
+    MAT_C_CELL     =  1, /**< @brief Matlab cell array class               */
+    MAT_C_STRUCT   =  2, /**< @brief Matlab structure class                */
+    MAT_C_OBJECT   =  3, /**< @brief Matlab object class                   */
+    MAT_C_CHAR     =  4, /**< @brief Matlab character array class          */
+    MAT_C_SPARSE   =  5, /**< @brief Matlab sparse array class             */
+    MAT_C_DOUBLE   =  6, /**< @brief Matlab double-precision class         */
+    MAT_C_SINGLE   =  7, /**< @brief Matlab single-precision class         */
+    MAT_C_INT8     =  8, /**< @brief Matlab signed 8-bit integer class     */
+    MAT_C_UINT8    =  9, /**< @brief Matlab unsigned 8-bit integer class   */
+    MAT_C_INT16    = 10, /**< @brief Matlab signed 16-bit integer class    */
+    MAT_C_UINT16   = 11, /**< @brief Matlab unsigned 16-bit integer class  */
+    MAT_C_INT32    = 12, /**< @brief Matlab signed 32-bit integer class    */
+    MAT_C_UINT32   = 13, /**< @brief Matlab unsigned 32-bit integer class  */
+    MAT_C_INT64    = 14, /**< @brief Matlab signed 64-bit integer class    */
+    MAT_C_UINT64   = 15, /**< @brief Matlab unsigned 64-bit integer class  */
+    MAT_C_FUNCTION = 16  /**< @brief Matlab function class                 */
+};
+
+/** @brief Matlab array flags
+ *
+ * @ingroup MAT
+ * Matlab array flags
+ */
+enum matio_flags {
+    MAT_F_COMPLEX        = 0x0800, /**< @brief Complex bit flag */
+    MAT_F_GLOBAL         = 0x0400, /**< @brief Global bit flag */
+    MAT_F_LOGICAL        = 0x0200, /**< @brief Logical bit flag */
+    MAT_F_DONT_COPY_DATA = 0x0001  /**< Don't copy data, use keep the pointer */
+};
+
+/** @brief MAT file compression options
+ *
+ * This option is only used on version 5 MAT files
+ * @ingroup MAT
+ */
+enum matio_compression {
+    MAT_COMPRESSION_NONE = 0,   /**< @brief No compression */
+    MAT_COMPRESSION_ZLIB = 1    /**< @brief zlib compression */
+};
+
+/** @brief matio lookup type
+ *
+ * @ingroup MAT
+ * matio lookup type
+ */
+enum {
+    MAT_BY_NAME  = 1, /**< Lookup by name */
+    MAT_BY_INDEX = 2  /**< Lookup by index */
+};
+
+/** @brief Complex data type using split storage
+ *
+ * Complex data type using split real/imaginary pointers
+ * @ingroup MAT
+ */
+typedef struct mat_complex_split_t {
+    void *Re; /**< Pointer to the real part */
+    void *Im; /**< Pointer to the imaginary part */
+} mat_complex_split_t;
+
+struct _mat_t;
+/** @brief Matlab MAT File information
+ * Contains information about a Matlab MAT file
+ * @ingroup MAT
+ */
+typedef struct _mat_t mat_t;
+
+/* Incomplete definition for private library data */
+struct matvar_internal;
+
+/** @brief Matlab variable information
+ *
+ * Contains information about a Matlab variable
+ * @ingroup MAT
+ */
+typedef struct matvar_t {
+    size_t nbytes;                    /**< Number of bytes for the MAT variable */
+    int    rank;                      /**< Rank (Number of dimensions) of the data */
+    enum matio_types   data_type;     /**< Data type(MAT_T_*) */
+    int   data_size;                  /**< Bytes / element for the data */
+    enum matio_classes class_type;    /**< Class type in Matlab(MAT_C_DOUBLE, etc) */
+    int   isComplex;                  /**< non-zero if the data is complex, 0 if real */
+    int   isGlobal;                   /**< non-zero if the variable is global */
+    int   isLogical;                  /**< non-zero if the variable is logical */
+    size_t *dims;                     /**< Array of lengths for each dimension */
+    char *name;                       /**< Name of the variable */
+    void *data;                       /**< Pointer to the data */
+    int   mem_conserve;               /**< 1 if Memory was conserved with data */
+    enum matio_compression  compression; /**< Variable compression type */
+    struct matvar_internal *internal;    /**< matio internal data */
+} matvar_t;
+
+/** @brief sparse data information
+ *
+ * Contains information and data for a sparse matrix
+ * @ingroup MAT
+ */
+typedef struct mat_sparse_t {
+    int nzmax;               /**< Maximum number of non-zero elements */
+    int *ir;                 /**< Array of size nzmax where ir[k] is the row of
+                               *  data[k].  0 <= k <= nzmax
+                               */
+    int nir;                 /**< number of elements in ir */
+    int *jc;                 /**< Array size N+1 (N is number of columns) with
+                               *  jc[k] being the index into ir/data of the
+                               *  first non-zero element for row k.
+                               */
+    int   njc;               /**< Number of elements in jc */
+    int   ndata;             /**< Number of complex/real data values */
+    void *data;              /**< Array of data elements */
+} mat_sparse_t;
+
+/* Library function */
+EXTERN void Mat_GetLibraryVersion(int *major,int *minor,int *release);
+
+/*     io.c         */
+EXTERN char  *strdup_vprintf(const char *format, va_list ap);
+EXTERN char  *strdup_printf(const char *format, ...);
+EXTERN void   Mat_Critical( const char *format, ... );
+EXTERN void   Mat_Warning( const char *format, ... );
+EXTERN size_t Mat_SizeOf(enum matio_types data_type);
+EXTERN size_t Mat_SizeOfClass(int class_type);
+
+/*   MAT File functions   */
+#define            Mat_Create(a,b) Mat_CreateVer(a,b,MAT_FT_DEFAULT)
+EXTERN mat_t      *Mat_CreateVer(const char *matname,const char *hdr_str,
+                       enum mat_ft mat_file_ver);
+EXTERN int         Mat_Close(mat_t *mat);
+EXTERN mat_t      *Mat_Open(const char *matname,int mode);
+EXTERN const char *Mat_GetFilename(mat_t *matfp);
+EXTERN enum mat_ft Mat_GetVersion(mat_t *matfp);
+EXTERN int         Mat_Rewind(mat_t *mat);
+
+/* MAT variable functions */
+EXTERN matvar_t  *Mat_VarCalloc(void);
+EXTERN matvar_t  *Mat_VarCreate(const char *name,enum matio_classes class_type,
+                      enum matio_types data_type,int rank,size_t *dims,
+                      void *data,int opt);
+EXTERN matvar_t  *Mat_VarCreateStruct(const char *name,int rank,size_t *dims,
+                      const char **fields,unsigned nfields);
+EXTERN int        Mat_VarDelete(mat_t *mat, const char *name);
+EXTERN matvar_t  *Mat_VarDuplicate(const matvar_t *in, int opt);
+EXTERN void       Mat_VarFree(matvar_t *matvar);
+EXTERN matvar_t  *Mat_VarGetCell(matvar_t *matvar,int index);
+EXTERN matvar_t **Mat_VarGetCells(matvar_t *matvar,int *start,int *stride,
+                      int *edge);
+EXTERN matvar_t **Mat_VarGetCellsLinear(matvar_t *matvar,int start,int stride,
+                      int edge);
+EXTERN size_t     Mat_VarGetSize(matvar_t *matvar);
+EXTERN unsigned   Mat_VarGetNumberOfFields(matvar_t *matvar);
+EXTERN int        Mat_VarAddStructField(matvar_t *matvar,const char *fieldname);
+EXTERN char * const *Mat_VarGetStructFieldnames(const matvar_t *matvar);
+EXTERN matvar_t  *Mat_VarGetStructFieldByIndex(matvar_t *matvar,
+                      size_t field_index,size_t index);
+EXTERN matvar_t  *Mat_VarGetStructFieldByName(matvar_t *matvar,
+                      const char *field_name,size_t index);
+EXTERN matvar_t  *Mat_VarGetStructField(matvar_t *matvar,void *name_or_index,
+                      int opt,int index);
+EXTERN matvar_t  *Mat_VarGetStructs(matvar_t *matvar,int *start,int *stride,
+                      int *edge,int copy_fields);
+EXTERN matvar_t  *Mat_VarGetStructsLinear(matvar_t *matvar,int start,int stride,
+                      int edge,int copy_fields);
+EXTERN void       Mat_VarPrint( matvar_t *matvar, int printdata );
+EXTERN matvar_t  *Mat_VarRead(mat_t *mat, const char *name );
+EXTERN int        Mat_VarReadData(mat_t *mat,matvar_t *matvar,void *data,
+                      int *start,int *stride,int *edge);
+EXTERN int        Mat_VarReadDataAll(mat_t *mat,matvar_t *matvar);
+EXTERN int        Mat_VarReadDataLinear(mat_t *mat,matvar_t *matvar,void *data,
+                      int start,int stride,int edge);
+EXTERN matvar_t  *Mat_VarReadInfo( mat_t *mat, const char *name );
+EXTERN matvar_t  *Mat_VarReadNext( mat_t *mat );
+EXTERN matvar_t  *Mat_VarReadNextInfo( mat_t *mat );
+EXTERN matvar_t  *Mat_VarSetCell(matvar_t *matvar,int index,matvar_t *cell);
+EXTERN matvar_t  *Mat_VarSetStructFieldByIndex(matvar_t *matvar,
+                      size_t field_index,size_t index,matvar_t *field);
+EXTERN matvar_t  *Mat_VarSetStructFieldByName(matvar_t *matvar,
+                      const char *field_name,size_t index,matvar_t *field);
+EXTERN int        Mat_VarWrite(mat_t *mat,matvar_t *matvar,
+                      enum matio_compression compress );
+EXTERN int        Mat_VarWriteInfo(mat_t *mat,matvar_t *matvar);
+EXTERN int        Mat_VarWriteData(mat_t *mat,matvar_t *matvar,void *data,
+                      int *start,int *stride,int *edge);
+
+/* Other functions */
+EXTERN int       Mat_CalcSingleSubscript(int rank,int *dims,int *subs);
+EXTERN int       Mat_CalcSingleSubscript2(int rank,size_t *dims,size_t *subs,size_t *index);
+EXTERN int      *Mat_CalcSubscripts(int rank,int *dims,int index);
+EXTERN size_t   *Mat_CalcSubscripts2(int rank,size_t *dims,size_t index);
+
+#endif /* MODELICAMATIO_H */

+ 512 - 0
ModelicaModels/Dymola/Window/sources/ModelicaRandom.c

@@ -0,0 +1,512 @@
+/* ModelicaRandom.c - External functions for Modelica.Math.Random library
+
+   Copyright (C) 2015-2016, Modelica Association and DLR
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* The functions in this file are non-portable. The following #define's are used
+   to define the system calls of the operating system
+
+   _MSC_VER       : Microsoft Visual C++
+   MODELICA_EXPORT: Prefix used for function calls. If not defined, blank is used
+                    Useful definitions:
+                    - "static" that is all functions become static
+                      (useful if file is included with other C-sources for an
+                       embedded system)
+                    - "__declspec(dllexport)" if included in a DLL and the
+                      functions shall be visible outside of the DLL
+
+   Release Notes:
+      Oct. 27, 2015: by Thomas Beutlich, ITI GmbH
+                     Added nonnull attribute/annotations (ticket #1436)
+
+      Feb. 17, 2015: by Andreas Kloeckner and Martin Otter, DLR-SR
+                     Implemented a first version
+*/
+
+#if !defined(MODELICA_EXPORT)
+#   define MODELICA_EXPORT DYMOLA_STATIC
+#endif
+
+/* Have RANDOM int64 / uint64 */
+#if defined (_WIN32)
+#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+#define HAVE_RANDOM_INT64_T 1
+#define HAVE_RANDOM_UINT64_T 1
+#else
+#undef HAVE_RANDOM_INT64_T
+#undef HAVE_RANDOM_UINT64_T
+#endif
+#else
+#define HAVE_RANDOM_INT64_T 1
+#define HAVE_RANDOM_UINT64_T 1
+#endif
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#if defined(_WIN32)
+#if defined(_MSC_VER) && _MSC_VER >= 1600
+#define HAVE_RANDOM_STDINT_H 1
+#elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+#define HAVE_RANDOM_STDINT_H 1
+#else
+#undef HAVE_RANDOM_STDINT_H
+#endif
+#elif defined(__GNUC__) && !defined(__VXWORKS__)
+#define HAVE_RANDOM_STDINT_H 1
+#else
+#undef HAVE_RANDOM_STDINT_H
+#endif
+
+/* Include integer type header */
+#if defined(HAVE_RANDOM_STDINT_H)
+#include <stdint.h>
+#else
+#define int32_t  int
+#define uint32_t unsigned int
+#if defined(HAVE_RANDOM_INT64_T)
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define int64_t __int64
+#else
+#define int64_t long long
+#endif
+#endif
+#if defined(HAVE_RANDOM_UINT64_T)
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define uint64_t unsigned __int64
+#else
+#define uint64_t unsigned long long
+#endif
+#endif
+#endif
+
+#include <stdlib.h>
+#include <limits.h>
+#include <math.h>
+#include <string.h>
+#include "ModelicaUtilities.h"
+#include "gconstructor.h"
+
+/* The standard way to detect posix is to check _POSIX_VERSION,
+ * which is defined in <unistd.h>
+ */
+#if defined(__unix__) || defined(__linux__) || defined(__APPLE_CC__)
+#if !defined(NO_FILE_SYSTEM) && !defined(LABCAR)
+  #include <unistd.h>
+#endif
+#endif
+#if !defined(_POSIX_) && defined(_POSIX_VERSION)
+  #define _POSIX_ 1
+#endif
+
+/* On Posix systems define a mutex using the single static variable "m" */
+#if defined(_POSIX_) && !defined(NO_FILE_SYSTEM) && !defined(LABCAR) 
+#include <pthread.h>
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+#define MUTEX_LOCK() pthread_mutex_lock(&m)
+#define MUTEX_UNLOCK() pthread_mutex_unlock(&m)
+
+/* On Windows systems define a critical section using the single static variable "cs" */
+#elif defined(_WIN32) && defined(G_HAS_CONSTRUCTORS)
+#if !defined(WIN32_LEAN_AND_MEAN)
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <Windows.h>
+static CRITICAL_SECTION cs;
+#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
+#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(ModelicaRandom_initializeCS)
+#endif
+G_DEFINE_CONSTRUCTOR(ModelicaRandom_initializeCS)
+static void ModelicaRandom_initializeCS(void) {
+    InitializeCriticalSection(&cs);
+}
+#ifdef G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
+#pragma G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(ModelicaRandom_deleteCS)
+#endif
+G_DEFINE_DESTRUCTOR(ModelicaRandom_deleteCS)
+static void ModelicaRandom_deleteCS(void) {
+    DeleteCriticalSection(&cs);
+}
+#define MUTEX_LOCK() EnterCriticalSection(&cs)
+#define MUTEX_UNLOCK() LeaveCriticalSection(&cs)
+
+/* On other systems do not use a mutex at all */
+#else
+#define MUTEX_LOCK()
+#define MUTEX_UNLOCK()
+#endif
+
+/*
+ * Non-null pointers need to be passed to external functions.
+ *
+ * The following macros handle nonnull attributes for GNU C and Microsoft SAL.
+ */
+#if defined(__GNUC__)
+#define MODELICA_NONNULLATTR __attribute__((nonnull))
+#else
+#define MODELICA_NONNULLATTR
+#endif
+#if !defined(__ATTR_SAL)
+#define _In_
+#define _Out_
+#endif
+
+MODELICA_EXPORT void ModelicaRandom_xorshift64star(_In_ int state_in[],
+    _Out_ int state_out[], _Out_ double* y) MODELICA_NONNULLATTR;
+MODELICA_EXPORT void ModelicaRandom_xorshift128plus(_In_ int state_in[],
+    _Out_ int state_out[], _Out_ double* y) MODELICA_NONNULLATTR;
+MODELICA_EXPORT void ModelicaRandom_xorshift1024star(_In_ int state_in[],
+    _Out_ int state_out[], _Out_ double* y) MODELICA_NONNULLATTR;
+MODELICA_EXPORT void ModelicaRandom_setInternalState_xorshift1024star(
+    _In_ int* state, size_t nState, int id) MODELICA_NONNULLATTR;
+MODELICA_EXPORT void ModelicaRandom_convertRealToIntegers(double d,
+    _Out_ int i[]) MODELICA_NONNULLATTR;
+MODELICA_EXPORT void ModelicaInternal_getTime(_Out_ int* ms, _Out_ int* sec,
+    _Out_ int* min, _Out_ int* hour, _Out_ int* mday, _Out_ int* mon,
+    _Out_ int* year) MODELICA_NONNULLATTR;
+MODELICA_EXPORT int ModelicaInternal_getpid(void);
+
+/* XORSHIFT ALGORITHMS */
+
+/* For details see http://xorshift.di.unimi.it/
+
+   Written in 2014 by Sebastiano Vigna (vigna@acm.org)
+
+   To the extent possible under law, the author has dedicated all copyright
+   and related and neighboring rights to this software to the public domain
+   worldwide. This software is distributed without any warranty.
+
+   See <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+   Adapted by Martin Otter and Andreas Kloeckner for use with Modelica:
+   - Inputs and outputs must be int's, that is int32_t.
+   - Inputs are casted accordingly.
+   - Outputs are casted accordingly.
+   - The additional double between 0 and 1 is output.
+*/
+
+/* transform 64-bit unsigned integer to double such that zero cannot appear, by
+   first transforming to a 64-bit signed integer, then to a double in the range 0 .. 1.
+   (using the algorithm given here: http://www.doornik.com/research/randomdouble.pdf) */
+#define ModelicaRandom_INVM64 5.42101086242752217004e-20 /* = 2^(-64) */
+#define ModelicaRandom_RAND(INT64) ( (int64_t)(INT64) * ModelicaRandom_INVM64 + 0.5 )
+
+MODELICA_EXPORT void ModelicaRandom_xorshift64star(int state_in[], int state_out[], double* y) {
+    /*  xorshift64* random number generator.
+        For details see http://xorshift.di.unimi.it/
+
+        Written in 2014 by Sebastiano Vigna (vigna@acm.org)
+
+        To the extent possible under law, the author has dedicated all copyright
+        and related and neighboring rights to this software to the public domain
+        worldwide. This software is distributed without any warranty.
+
+        See <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+        Adapted by Martin Otter and Andreas Kloeckner (DLR)
+        for the Modelica external function interface.
+    */
+
+    /*  This is a good generator if you're short on memory, but otherwise we
+        rather suggest to use a xorshift128+ (for maximum speed) or
+        xorshift1024* (for speed and very long period) generator. */
+
+    /* Convert inputs */
+    union s_tag {
+        int32_t  s32[2];
+        uint64_t s64;
+    } s;
+    size_t i;
+    uint64_t x;
+    for (i=0; i<sizeof(s)/sizeof(uint32_t); i++) {
+        s.s32[i] = state_in[i];
+    }
+    x = s.s64;
+
+    /* The actual algorithm */
+    x ^= x >> 12; /* a */
+    x ^= x << 25; /* b */
+    x ^= x >> 27; /* c */
+#if defined(_MSC_VER)
+    x  = x * 2685821657736338717i64;
+#else
+    x  = x * 2685821657736338717LL;
+#endif
+    /* Convert outputs */
+    s.s64 = x;
+    for (i=0; i<sizeof(s)/sizeof(uint32_t); i++) {