@@ -9811,8 +9811,8 @@ algorithm
98119811 arrayDimensions = List.map(List.lastN(numArrayElement,listLength(arraySubscripts)), stringInt);
98129812 varIndices = arrayCreate(List.fold(arrayDimensions, intMul, 1), 0);
98139813 end if;
9814- //print("Num of array elements {" + stringDelimitList(List.map(arrayDimensions, intString), ",") + "} : " + intString(listLength(arraySubscripts)) + "arraySubs "+ExpressionDump.printSubscriptLstStr(arraySubscripts) + "arrayDimensions[ "+stringDelimitList(List.map(arrayDimensions,intString),",")+"]\n");
9815- (( arrayIndex,_,_)) = List.fold (arraySubscripts, getUnrolledArrayIndex, (0, 1, arrayDimensions) );
9814+ //print("Num of array elements {" + stringDelimitList(List.map(arrayDimensions, intString), ",") + "} : " + intString(listLength(arraySubscripts)) + " arraySubs "+ExpressionDump.printSubscriptLstStr(arraySubscripts) + " arrayDimensions[ "+stringDelimitList(List.map(arrayDimensions,intString),",")+"]\n");
9815+ arrayIndex = getUnrolledArrayIndex (arraySubscripts,arrayDimensions);
98169816 arrayIndex = arrayIndex + 1;
98179817 //print("VarIndices: " + intString(arrayLength(varIndices)) + " arrayIndex: " + intString(arrayIndex) + " varIndex: " + intString(varIdx) + "\n");
98189818 varIndices = arrayUpdate(varIndices, arrayIndex, varIdx);
@@ -9949,8 +9949,7 @@ algorithm
99499949 if(BaseHashTable.hasKey(varName, iVarToArrayIndexMapping)) then
99509950 ((arrayDimensions,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping);
99519951 arraySize := arrayLength(varIndices);
9952-
9953- ((concreteVarIndex,_,_)) := List.fold(arraySubscripts, getUnrolledArrayIndex, (0, 1, arrayDimensions));
9952+ concreteVarIndex := getUnrolledArrayIndex(arraySubscripts,arrayDimensions);
99549953 //print("SimCodeUtil.getVarIndexInfosByMapping: Found variable index for '" + ComponentReference.printComponentRefStr(iVarName) + "'. The value is " + intString(concreteVarIndex) + "\n");
99559954 for arrayIdx in 0:(arraySize-1) loop
99569955 idx := arrayGet(varIndices, arraySize-arrayIdx);
@@ -10022,8 +10021,16 @@ algorithm
1002210021 oIsConsecutive := consecutive;
1002310022end isVarIndexListConsecutive;
1002410023
10024+ protected function getUnrolledArrayIndex"author: waurich
10025+ wrapper for getUnrolledArrayIndex1 to reverse the list order to be conform to the cpp runtime array adressing"
10026+ input list<DAE.Subscript> arraySubs;
10027+ input list<Integer> arrayTypeDimensions;
10028+ output Integer arrayIndex;
10029+ algorithm
10030+ ((arrayIndex,_,_)) := List.fold(listReverse(arraySubs), getUnrolledArrayIndex1, (0, 1, listReverse(arrayTypeDimensions)));
10031+ end getUnrolledArrayIndex;
1002510032
10026- protected function getUnrolledArrayIndex "author: marcusw
10033+ protected function getUnrolledArrayIndex1 "author: marcusw
1002710034 Calculate a flat array index, by the given subscripts. E.g. [2,1] for array of size 3x3 will lead to: 2."
1002810035 input DAE.Subscript iCurrentSubscript;
1002910036 input tuple<Integer,Integer,list<Integer>> iCurrentRowIdxRes; //<result, currentOffset, remainingRows>
@@ -10050,7 +10057,7 @@ algorithm
1005010057 end if;
1005110058 then (index, currentOffset, tail);
1005210059 end match;
10053- end getUnrolledArrayIndex ;
10060+ end getUnrolledArrayIndex1 ;
1005410061
1005510062public function createIdxSCVarMapping "author: marcusw
1005610063 Create a mapping from the SCVar-Index (array-Index) to the SCVariable, as it is used in the c-runtime."
0 commit comments