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

Loop in algorithm is failing

Loop in algorithm is failing

I am trying to make a loop in an algorithm section.  My actual intent is to find the maximum value of the contents of items in an array.  But, I have reduced my example to the simple case that is below (that doesn't do anything useful, except demonstrate my problem)

Here is the error that I am getting:
TestLoop.ItemB.c:155:13: warning: implicit declaration of function '$Pa$lB' is invalid in C99 [-Wimplicit-function-declaration]
      $Pp = $Pa$lB(modelica_integer)$Pi$rB$Pp;
            ^
TestLoop.ItemB.c:155:20: error: unexpected type name 'modelica_integer': expected expression
      $Pp = $Pa$lB(modelica_integer)$Pi$rB$Pp;
                   ^
1 warning and 1 error generated.
make: *** [TestLoop.ItemB.o] Error 1
make: *** Waiting for unfinished jobs....
TestLoop.ItemB_06inz.c:146:13: warning: implicit declaration of function '$Pa$lB' is invalid in C99 [-Wimplicit-function-declaration]
      $Pp = $Pa$lB(modelica_integer)$Pi$rB$Pp;
            ^
TestLoop.ItemB_06inz.c:146:20: error: unexpected type name 'modelica_integer': expected expression
      $Pp = $Pa$lB(modelica_integer)$Pi$rB$Pp;
                   ^
1 warning and 1 error generated.
make: *** [TestLoop.ItemB_06inz.o] Error 1
Compilation process exited with code 2


And here is the simple test case that is giving it to me:

package TestLoop
  model ItemA
    Real p;
  end ItemA;

  model ItemB
    ItemA a[n];
    parameter Integer n = 5;
    Real p;
  equation
    for i in 1:n loop
      a[i].p = time;
    end for;
  algorithm
    for i in 1:n loop
      p := a[i].p;
    end for;
  end ItemB;
  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end TestLoop;

If I change the assignment of p to a fixed value, I don't get an error (p:=a[1].p).  Any suggestions for what is wrong with this?  I am using OpenModelica r23951. 

There are 0 guests and 0 other users also viewing this topic
You are here: