Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » riccobene
  • » Profile

Posts

Posts

HI,

I'm sorry, as I mentioned before I'm new to Modelica... i think anyway that there is indeed an error of translation, because if I change _b into _b_ext and I compile manually with gcc the code compiles correctly. But I didn't know that was forbidden to use arrays in records, so my apologies!

My question is : can I have an output array from an external function? I had a look at the documentation you told me but if I couldn't make it, could you suggest me a thread or an example that does this?

Thank you again

Hi everybody,

I'm quite new to the modelica language and the OM environment, I'm having troubles with a call to an external function written in C.
The function is quite simple and returns a container class :

struct Container{
double *value;
};


Containter externalfunc(double value){
Container p;
p.value = new double[10];
for(int i=0;i<10;++i){
p.value[i] = i*value;}
return p;
}

When I use this function in OM I have the following call from the function class :
function extern1
  input Real a;
  output Container b;
external "C"   b = externalfunc(a);
end extern1;

where Container is a record that reads
record Container
Real value[10];
end Container;

The compiler gives the following error:

error: '_b' undeclared (first use in this function)

This error seems to be concerned with the translation in C by the OMC compiler.
if I look into the corresponding c file created by omc I have this line

  struct Container _b_ext;
  /* functionBodyExternalFunction: preExp */
  /* functionBodyExternalFunction: outputAlloc */
  alloc_real_array(&_b.value, 1, 10);

where clearly the difference is on the name of the variable to be allocated _b instead of _b_ext

I'm using the latest version 1.9.0_beta4 under linux ( ubuntu 12.10)
Do you have any suggestion? Where can I see the code that generates this wrong line?

Thank you
Chiara
chiara.riccobene@moxoff.com

  • Index
  • » Users
  • » riccobene
  • » Profile
You are here: