Search code examples
openmodelica

Error failed to expand the variable


I have a model to read a file and do some operation on it and print the output in to a file. I got an error which I'm unable resolve it. The below code shows the declaration and assignment of the input data to an 2d array.

Real Data_2D[:,:]"data from input file as 2D matrix";
 length := Streams.countLines(Infile)"length of the input file";

  /*collect the data from input file in to 2D matrix */
    for i in 1:length loop
        currentLine := Streams.readLine(Infile, indexDataStart+i-1);
        nextIndex := 1;
        for j in 1:noColumns loop
            (Data_2D[i,j],nextIndex) := Strings.scanReal(currentLine, startIndex=nextIndex,unsigned=false, message="readCoefficientsHawc2.mo c[i,j] : Real scan not successful");
        end for;
    end for;

I got the following error "Failed to expand the vairable Data_2D"

It would be verymuch helpful if I get a solution.


Solution

  • Modelica tools in general do not like unknown dimensions during compilation. Modelica Specification says that all arrays sizes should be known at compile time.

    In your case Data_2D has unknown dimensions. Also, from your code I don't see what type of component is length and Data_2D. Are they parameters, constants?

    In your case it might be possible to use Modelica.Blocks.Tables.CombiTable2D to read the table from file.