API reference
OMRuntimeExternalC — Module
Julia bindings to the external C functions of the Modelica Standard Library (tables, strings, I/O, files, random numbers, FFT) and the tool side of ModelicaUtilities.h. They call libModelicaExternalC, built from the C sources of the Standard Library (see libraryPath).
Loading the library
OMRuntimeExternalC.libModelicaExternalC — Constant
libModelicaExternalC::StringThe name ccall uses for the library, as the JLL packages do: the library is loaded by its full path in __init__, and the system finds the loaded one under this name (its install name on macOS, its SONAME on Linux, its module name on Windows).
OMRuntimeExternalC.libraryFileName — Constant
libraryFileName::StringThe file name of the library on this platform.
OMRuntimeExternalC.artifactDirectory — Method
artifactDirectory()::Union{Nothing, String}The directory of the library in the installed artifact "ModelicaExternalC", if Artifacts.toml has an entry for this platform and the artifact is installed.
OMRuntimeExternalC.libraryDirectory — Function
libraryDirectory(environment = ENV)::Union{Nothing, String}The directory with libModelicaExternalC, in the order of the list at the top of this file: the directory of the environment variable OMRUNTIMEEXTERNALC_LIBRARY_DIR, the build directory deps/usr/lib (bin on Windows), the artifact. nothing when none of them has the library file.
OMRuntimeExternalC.libraryPath — Method
libraryPath()::Union{Nothing, String}The full path of the loaded libModelicaExternalC, nothing if the library was not found or did not load. Its functions are the Modelica external C functions of the Standard Library (dlsym finds them in it) and the safe_* functions of the shim.
OMRuntimeExternalC.loadLibrary — Method
loadLibrary()::Union{Nothing, String}Load libModelicaExternalC with RTLD_GLOBAL, so that compiled external C code of a model, which calls ModelicaError and the other functions of ModelicaUtilities.h, finds them in the process. Returns the path, nothing (with a warning) if there is no library or it does not load.
Functions
Not every function of the library has a Julia interface: src/api.jl has the ones that have.
OMRuntimeExternalC.ModelicaError — Method
ModelicaError(msg)Throw the Modelica error msg as a Julia error ("Modelica runtime error: ..."). The method for a Cstring is the error handler of libModelicaExternalC (installErrorHandler): C code that calls ModelicaError or ModelicaFormatError ends up here.
OMRuntimeExternalC.ModelicaFFT_kiss_fftr — Method
ModelicaFFT_kiss_fftr(u, nu, work, nwork, amplitudes, phases) -> infoModelica.Math.FastFourierTransform's real FFT (MSL's ModelicaFFT.c): the amplitudes |Xk| / nf and phases arg(Xk) of the frequencies k = 0..nu/2 of the real signal u, X_k = sum(u[n+1] * exp(-2impik*n/nu) for n in 0:nu-1), nf = nu/2 + 1. A direct sum over a table of the nu roots of unity (no FFT library; nu is at most a few thousand in the MSL examples); work is only checked for its size. info: 0 o.k., 1 nu not even, 2 work too small.
OMRuntimeExternalC.ModelicaIO_readMatrixSizes — Method
ModelicaIO_readMatrixSizes(fileName, matrixName) -> Vector{Int64}Read the dimensions [nrow, ncol] of a matrix stored in a MATLAB MAT file.
OMRuntimeExternalC.ModelicaIO_readRealMatrix — Function
ModelicaIO_readRealMatrix(fileName, matrixName, nrow, ncol, verbose) -> Matrix{Float64}Read a real matrix of size nrow x ncol from a MATLAB MAT file.
OMRuntimeExternalC.ModelicaIO_writeRealMatrix — Function
ModelicaIO_writeRealMatrix(fileName, matrixName, matrix; append, version)Write a real matrix to a MATLAB MAT file.
OMRuntimeExternalC.ModelicaInternal_countLines — Method
ModelicaInternal_countLines(fileName) -> Int64Count the number of lines in a file.
OMRuntimeExternalC.ModelicaInternal_fullPathName — Method
ModelicaInternal_fullPathName(fileName) -> StringReturn the full (absolute) path name of a file.
OMRuntimeExternalC.ModelicaInternal_print — Method
ModelicaInternal_print(string, fileName)Print a string to a file (append mode) or to stdout if fileName is empty.
OMRuntimeExternalC.ModelicaInternal_readLine — Method
ModelicaInternal_readLine(fileName, lineNumber) -> (String, Bool)Read a specific line from a file. Returns (line_content, endOfFile).
OMRuntimeExternalC.ModelicaInternal_removeFile — Method
ModelicaInternal_removeFile(file)Remove a file from the filesystem. ccall goes directly to libModelicaExternalC because the shim has no safeModelicaInternalremoveFile wrapper. The C function calls ModelicaFormatError on failure (e.g. file does not exist), which ends the process when no safe_* call is running.
OMRuntimeExternalC.ModelicaInternal_stat — Method
ModelicaInternal_stat(name) -> Int64Return Modelica FileType: 1=NoFile, 2=RegularFile, 3=Directory, 4=SpecialFile.
OMRuntimeExternalC.ModelicaRandom_automaticGlobalSeed — Function
ModelicaRandom_automaticGlobalSeed(dummy) -> IntGenerate an automatic integer seed (typically derived from current time and pid). The dummy argument exists only to constrain Modelica call ordering.
OMRuntimeExternalC.ModelicaRandom_convertRealToIntegers — Method
ModelicaRandom_convertRealToIntegers(d, i)Reinterpret a Float64 as two Int32 words, written into i (Vector{Cint} of length 2).
OMRuntimeExternalC.ModelicaRandom_impureRandom_xorshift1024star — Method
ModelicaRandom_impureRandom_xorshift1024star(id) -> Float64Draw a uniform [0, 1) sample from the impure xorshift1024* generator previously seeded via ModelicaRandomsetInternalStatexorshift1024star.
OMRuntimeExternalC.ModelicaRandom_setInternalState_xorshift1024star — Method
ModelicaRandom_setInternalState_xorshift1024star(state, nState, id)Initialize the internal (impure) state used by ModelicaRandomimpureRandomxorshift1024star. state is a Vector{Cint} of length nState; id is the generator id (Int).
OMRuntimeExternalC.ModelicaRandom_xorshift1024star — Method
ModelicaRandom_xorshift1024star(state_in, state_out, y)xorshift1024* RNG. statein / stateout are Vector{Cint} of length 33; y is a Ref{Cdouble} that receives a uniform sample in [0, 1).
OMRuntimeExternalC.ModelicaRandom_xorshift128plus — Method
ModelicaRandom_xorshift128plus(state_in, state_out, y)xorshift128+ RNG. statein / stateout are Vector{Cint} of length 4; y is a Ref{Cdouble} that receives a uniform sample in [0, 1).
OMRuntimeExternalC.ModelicaRandom_xorshift64star — Method
ModelicaRandom_xorshift64star(state_in, state_out, y)xorshift64* RNG. statein / stateout are Vector{Cint} of length 2; y is a Ref{Cdouble} that receives a uniform sample in [0, 1).
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_close — Method
Desctructor: void ModelicaStandardTablesCombiTable1Dclose(void* _tableID)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_getDer2Value — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable1DgetDer2Value(void* tableID, int icol, double u, double deru, double der2_u);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_getDer2Value — Method
ModelicaStandardTablesCombiTable1DgetDer2Value( tableID::ExternalCombiTable1D, icol::Int64, u::Float64, deru::Float64, der2u::Float64, )
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_getDerValue — Method
Externally defined as: MODELICAEXPORT double ModelicaStandardTablesCombiTable1DgetDerValue(void* tableID, int icol, double u, double deru);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_getDerValue — Method
ModelicaStandardTablesCombiTable1DgetDerValue( tableID::ExternalCombiTable1D, icol::Int64, u::Float64, der_u::Float64, )
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_getValue — Method
double ModelicaStandardTablesCombiTable1DgetValue(void* _tableID, int iCol, double u)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_init2 — Method
MODELICAEXPORT void* ModelicaStandardTablesCombiTable1Dinit2( _Inz_ const char* fileName, Inz_ const char* tableName, In double* table, sizet nRow, sizet nColumn, In int* columns, sizet nCols, int smoothness, int extrapolation, int verbose) MODELICANONNULLATTR;
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_maximumAbscissa — Method
ModelicaStandardTablesCombiTable1DmaximumAbscissa(tableID::ExternalCombiTable1D)::Float64
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_maximumAbscissa — Method
double ModelicaStandardTablesCombiTable1DmaximumAbscissa(void* _tableID)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_minimumAbscissa — Method
ModelicaStandardTablesCombiTable1DminimumAbscissa(tableID::ExternalCombiTable1D)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_minimumAbscissa — Method
double ModelicaStandardTablesCombiTable1DminimumAbscissa(void* _tableID)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_read — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable1D_read(void* tableID, int force, int verbose);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable1D_read — Method
ModelicaStandardTablesCombiTable1Dread(tableID::ExternalCombiTable1D, force::Int64, verbose::Int64)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_close — Method
void ModelicaStandardTablesCombiTable2Dclose(void* tableID)
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_getDer2Value — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable2DgetDer2Value(void* tableID, double u1, double u2, double deru1, double deru2, double der2u1, double der2_u2);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_getDerValue — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable2DgetDerValue(void* tableID, double u1, double u2, double deru1, double der_u2);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_getValue — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable2D_getValue(void* tableID, double u1, double u2);
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_init2 — Method
MODELICAEXPORT void* ModelicaStandardTablesCombiTable2Dinit2( _Inz_ const char* fileName, Inz_ const char* tableName, In double* table, sizet nRow, sizet nColumn, int smoothness, int extrapolation, int verbose) MODELICA_NONNULLATTR;
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_maximumAbscissa — Method
MODELICAEXPORT void ModelicaStandardTablesCombiTable2D_maximumAbscissa(void* tableID, double* uMax); Writes two doubles to uMax: uMax[0] = max of u1 axis, uMax[1] = max of u2 axis.
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_minimumAbscissa — Method
MODELICAEXPORT void ModelicaStandardTablesCombiTable2D_minimumAbscissa(void* tableID, double* uMin); Writes two doubles to uMin: uMin[0] = min of u1 axis, uMin[1] = min of u2 axis.
OMRuntimeExternalC.ModelicaStandardTables_CombiTable2D_read — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTable2D_read(void* tableID, int force, int verbose);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_close — Method
void ModelicaStandardTablesCombiTimeTableclose(void* tableID)
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_getDer2Value — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTablegetDer2Value(void* tableID, int icol, double t, double nextTimeEvent, double preNextTimeEvent, double dert, double der2_t);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_getDerValue — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTablegetDerValue(void* tableID, int icol, double t, double nextTimeEvent, double preNextTimeEvent, double dert);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_getValue — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTable_getValue(void* tableID, int icol, double t, double nextTimeEvent, double preNextTimeEvent);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_init2 — Method
MODELICAEXPORT void* ModelicaStandardTablesCombiTimeTableinit2( _Inz_ const char* fileName, Inz_ const char* tableName, In double* table, sizet nRow, sizet nColumn, double startTime, In int* columns, sizet nCols, int smoothness, int extrapolation, double shiftTime, int timeEvents, int verbose) MODELICANONNULLATTR;
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_maximumTime — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTable_maximumTime(void* tableID);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_minimumTime — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTable_minimumTime(void* tableID);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_nextTimeEvent — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTable_nextTimeEvent(void* tableID, double t);
OMRuntimeExternalC.ModelicaStandardTables_CombiTimeTable_read — Method
MODELICAEXPORT double ModelicaStandardTablesCombiTimeTable_read(void* tableID, int force, int verbose);
OMRuntimeExternalC.ModelicaStreams_closeFile — Method
ModelicaStreams_closeFile(fileName)Close a file that was opened for reading via ModelicaInternal_readLine.
OMRuntimeExternalC.ModelicaStrings_compare — Method
MODELICAEXPORT int ModelicaStringscompare(Inz_ const char* string1, Inz_ const char* string2, int caseSensitive);
OMRuntimeExternalC.ModelicaStrings_compare — Method
ModelicaStrings_compare(string1::String, string2::String, caseSensitive::Int64) Compares two strings. Returns 1 if string1 < string2, 2 if equal, 3 if string1 > string2.
OMRuntimeExternalC.ModelicaStrings_hashString — Method
MODELICAEXPORT int ModelicaStringshashString(Inz_ const char* str);
OMRuntimeExternalC.ModelicaStrings_hashString — Method
ModelicaStrings_hashString(string::String) Returns a hash value for the given string.
OMRuntimeExternalC.ModelicaStrings_length — Method
ModelicaStringslength(Inz const char* string)
OMRuntimeExternalC.ModelicaStrings_length — Method
ModelicaStrings_length(string::String)
OMRuntimeExternalC.ModelicaStrings_scanIdentifier — Method
MODELICAEXPORT void ModelicaStringsscanIdentifier(Inz_ const char* string, int startIndex, int* nextIndex, const char** identifier);
OMRuntimeExternalC.ModelicaStrings_scanIdentifier — Method
ModelicaStrings_scanIdentifier(string::String, startIndex::Int64) Scans for an identifier starting at startIndex. Returns (nextIndex, identifier).
OMRuntimeExternalC.ModelicaStrings_scanInteger — Method
MODELICAEXPORT void ModelicaStringsscanInteger(Inz_ const char* string, int startIndex, int unsignedNumber, int* nextIndex, int* integerNumber);
OMRuntimeExternalC.ModelicaStrings_scanInteger — Method
ModelicaStrings_scanInteger(string::String, startIndex::Int64, unsignedNumber::Int64) Scans for an integer starting at startIndex. If unsignedNumber != 0, only unsigned integers are recognized. Returns (nextIndex, integerNumber).
OMRuntimeExternalC.ModelicaStrings_scanReal — Method
MODELICAEXPORT void ModelicaStringsscanReal(Inz_ const char* string, int startIndex, int unsignedNumber, int* nextIndex, double* number);
OMRuntimeExternalC.ModelicaStrings_scanReal — Method
ModelicaStrings_scanReal(string::String, startIndex::Int64, unsignedNumber::Int64) Scans for a real number starting at startIndex. If unsignedNumber != 0, only unsigned numbers are recognized. Returns (nextIndex, number).
OMRuntimeExternalC.ModelicaStrings_scanString — Method
MODELICAEXPORT void ModelicaStringsscanString(Inz_ const char* string, int startIndex, int* nextIndex, const char** result);
OMRuntimeExternalC.ModelicaStrings_scanString — Method
ModelicaStrings_scanString(string::String, startIndex::Int64) Scans for a quoted string starting at startIndex. Returns (nextIndex, result).
OMRuntimeExternalC.ModelicaStrings_skipWhiteSpace — Method
int ModelicaStringsskipWhiteSpace(Inz const char* string, int i) Returns index of the string after whitespace have been skipped.
OMRuntimeExternalC.ModelicaStrings_skipWhiteSpace — Method
ModelicaStrings_skipWhiteSpace(string::String, startIndex::Int64)
OMRuntimeExternalC.ModelicaStrings_substring — Method
MODELICAEXPORT const char* ModelicaStringssubstring(Inz_ const char* string, int startIndex, int endIndex);
OMRuntimeExternalC.ModelicaStrings_substring — Method
ModelicaStrings_substring(string::String, startIndex::Int64, endIndex::Int64) Returns the substring from startIndex to endIndex (1-based, inclusive).
OMRuntimeExternalC.Modelica_Math_Random_Utilities_impureRandom — Method
Modelica_Math_Random_Utilities_impureRandom(id) -> Float64Modelica.Math.Random.Utilities.impureRandom: draw the next impure sample.
OMRuntimeExternalC.Modelica_Math_Random_Utilities_impureRandomInteger — Function
Modelica_Math_Random_Utilities_impureRandomInteger(id, imin, imax) -> IntModelica.Math.Random.Utilities.impureRandomInteger: map an impure sample to the integer range [imin, imax].
OMRuntimeExternalC.Modelica_Math_Random_Utilities_initializeImpureRandom — Method
Modelica_Math_Random_Utilities_initializeImpureRandom(seed) -> IntModelica.Math.Random.Utilities.initializeImpureRandom: seed the impure xorshift1024* generator's hidden C state from seed and return the id (the constant localSeed) to be passed to impureRandom.
OMRuntimeExternalC.get_modelica_error — Method
get_modelica_error()::StringRetrieve the error message from the last failed safe_* call.
OMRuntimeExternalC.installErrorHandler — Method
installErrorHandler()::NothingSet ModelicaError(::Cstring) as the error handler of the loaded libModelicaExternalC (modelica_set_error_handler of the shim): an error that C code reports with ModelicaError or ModelicaFormatError while no safe_* function is running is thrown as a Julia error from the ccall that was running, instead of ending the process. The C frames between are left without cleanup, as the C code expects of ModelicaError (it does not return).
Called when the package loads. An error raised on a thread that Julia did not start has no Julia caller to catch it.