This is part 2 of using Cube Voyager Multi-Dimensional Arrays with C++. To see part 1, click here.
Building on last weeks post, the below shows the modifications necessary in Cube. The first thing I added is the variable itself (else, you will get one of those inexplicable errors). In this case, I add MDARRAY2 as a variable that is the same dimensions as MDARRAY. The second part that I add (which is after the CALL statement) is just to report the values stored in MDARRAY2.
RUN PGM=MATRIX PRNFILE="C:\TEMP\DTMAT00B.PRN"
FILEO PRINTO[1] = "C:\TEMP\DEBUG.PRN"
PAR ZONES=1
ARRAY MDARRAY=5,5, MDARRAY2=5,5
LOOP _c=1,5
LOOP _r=1,5
MDARRAY[_c][_r]=RAND()
PRINT PRINTO=1 LIST='MDARRAY[',_c(1.0),'][',_r(1.0),']=',MDARRAY[_c][_r](8.6)
ENDLOOP
ENDLOOP
CALL DLL=DLLFILE(TableReader)
LOOP _c=1,5
LOOP _r=1,5
PRINT PRINTO=1 LIST='MDARRAY2[',_c(1.0),'][',_r(1.0),']=',MDARRAY2[_c][_r](8.6)
ENDLOOP
ENDLOOP
ENDRUN
In C++, I add a second variable for MDARRAY2 (called TableRecord2). It is critical that this is a double* variable, as this needs to be a pointer so Cube can access updated values of the variable. Similar with how I read MDARRAY into TableRecord, I do the same with MDARRAY2 and TableRecord2, which reads the pointers to MDARRAY2 into TableRecord2. Then, as I iterate through TableRecord, I set TableRecord2 to 10 * TableRecord. After this, the DLL is complete and Cube ultimately prints all the values to the print output.
int TableReader (Callstack* Stack){
double* TableRecord;
double* TableRecord2;
char message[100];
TableRecord=(double*)Stack->pfFindVar("MDARRAY",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24);
TableRecord2=(double*)Stack->pfFindVar("MDARRAY2",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24);
for(int x=0;x<=24;x++){ if(&TableRecord!=0){ sprintf(message,"TableRecord=%f",TableRecord[x]); Stack->pfPrnLine(1,message);
TableRecord2[x]=TableRecord[x]*10;
}
}
return 0;
}
Additional Considerations
If you decide to use this, you may want to pass the sizes of each dimension if it is important. Then, you can write a function to take the sequential value and return the column or row.
You must be logged in to post a comment.