OpenCMISS / iron

Source code repository for OpenCMISS-Iron
9 stars 62 forks source link

LIST_DETACH_AND_DESTROY #178

Open lorenzo-mechbau opened 5 years ago

lorenzo-mechbau commented 5 years ago

Since the returned array could contain inconsistent values if LIST%NUMBER_IN_LIST /= LIST%SIZE I added the line LIST_VALUES(:)=LIST_VALUES(1:NUMBER_IN_LIST) or LIST_VALUES(:,:)=LIST_VALUES(:,1:NUMBER_IN_LIST) after the CALL MOVE_ALLOC(...).

chrispbradley commented 5 years ago

I'm not sure what the above is trying to do? In general the LIST_VALUES size will be larger than the number in the list. Thus it maybe that the above lines result in an error as the left and right sides don't conform? It will also involve a copy of all the data to itself? When the list is returned the user should only access the 1:numberInList elements?

lorenzo-mechbau commented 5 years ago

First of all, my bad, the correct lines are without (:) or (:,:): LIST_VALUES=LIST_VALUES(1:NUMBER_IN_LIST) I found this trick in my Fortran tutorial under "adjusting an allocatable array" (picture attached).

If the returned array is larger than numberInList, then it could be possible to access elements that have no meaning. As you wrote, one should be very careful to access only the 1:numberInList elements. A workaround that I see at some places is: CALL LIST_DETACH_AND_DESTROY(BoundaryPlaneNodesList,NumberBoundaryPlaneNodes,IntegerArray,& & ERR,ERROR,*999) BoundaryPlaneNodes = IntegerArray(1:NumberBoundaryPlaneNodes) DEALLOCATE(IntegerArray) But that requires these two additional lines at every call, and an additional array.

20190523_111336