2
votes

I have a Modelica function that calls an external C function. At the moment, I am only able to run it with the setting Advanced.CompileWith64 = 2

I would like to wrap this function in a way that the flag Advanced.CompileWith64 is set to the value 2 before calling the external function, and afterwards it is set to its original value.

Conceptually, something like this:

function myFunctionWithWrapper
  ...
algorithm
  originalFlagValue := readFlag(CompileWith64)
  setFlag(CompileWith64, requiredFlagValue) "set Advanced.CompileWith64 = 2"
  myExternalFunction(...)
  setFlag(CompileWith64, originalFlagValue)
end myFunctionWithWrapper

Is there a way to read and to set a Dymola flag from a Modelica class?

2

2 Answers

5
votes

In functions with the annotation __Dymola_interactive=true you can simply access those flags using their regular path.

function setFlag

protected 
  Integer old_val;

algorithm 

  old_val :=Advanced.CompileWith64;
  Advanced.CompileWith64 :=2;
  // do something
  Advanced.CompileWith64 :=old_val;

  annotation(__Dymola_interactive=true);
end setFlag;
2
votes

There is likely another solution as well.

Setting Advanced.CompileWith64 :=2; mean compilation and linking for 64-bit. The likely reason it is needed is that some external library only exists as a 64-bit version.

It is possible to handle that case by changing the external code so that instead of having myExternalFunction.lib directly in the LibraryDirectory you have a sub-directory win64 containing that library. The absence of a win32 sub-directory and presence of win64 will force a 64-bit compilation and linking.

(Similarly for other platforms.)