I would appreciate advice on how to write one dimensional array into two dimensional array.
I have one dimensional array (lets name it aWhole) and the length of this array is known. I need to separate this array in smaller groups so I divide length of one dimensional array with arbitrarily no. of groups and got new array aDivided with the lengths: Width and Groups. Anyone has an idea how to write first array into second one?
Length is not necessary divided with Groups (in that case we round it to get whole no. of Width but idk what we do with the rest part of aWhole).
aWhole : ARRAY [0..Main.Length] OF REAL;
aDivided : ARRAY [0..Main.Width,0..Main.Groups] OF REAL;
You have two options.
First, you can do the "safe way" with two FOR cycles (assuming Main.Length + 1 = (Main.Width + 1) * (Main.Groups + 1) based on how you declared the two arrays)
FOR i := 0 TO Main.Width DO
FOR j := 0 TO Main.Groups DO
aDivided[i, j] := aWhole[i * (Main.Groups+1) + j];
Second, you can use CAA Memory Library functions like
MEM.MemMove(pSource := ADR(aWhole), pDestination := ADR(aDivided[0,0]), uiNumberOfBytes := Main.Length+1);
Thank you for suggestion. I managed to write 1D array into 2D as needed.
I think you can simply declare both at the same fixed memory address, e.g.
aWhole AT %MB100: ARRAY [0..Main.Length] OF REAL;
aDivided AT %MB100: ARRAY [0..Main.Width,0..Main.Groups] OF REAL;
and use whichever you want, a change in one will automatically be reflected in the other.
Log in to post a comment.