FLASH-X
Doxygen Generated Documentation From Interface Source Code
ut_convertToArrayIndicies.F90
Go to the documentation of this file.
1!! NOTICE
2!! Copyright 2022 UChicago Argonne, LLC and contributors
3!!
4!! Licensed under the Apache License, Version 2.0 (the "License");
5!! you may not use this file except in compliance with the License.
6!!
7!! Unless required by applicable law or agreed to in writing, software
8!! distributed under the License is distributed on an "AS IS" BASIS,
9!! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10!! See the License for the specific language governing permissions and
11!! limitations under the License.
12!!
39!*******************************************************************************
40
41subroutine ut_convertToArrayIndicies(dims, memoryOffset, arrayLBound, arrayUBound, elementCoord)
42
43 implicit none
44 integer, intent(IN) :: dims, memoryOffset
45 integer, dimension(1:dims), intent(IN) :: arrayLBound, arrayUBound
46 integer, dimension(1:dims), intent(OUT) :: elementCoord
47
48 integer, dimension(1:dims) :: elementCount, elementsToNextIndicy
49 integer :: i, j, memoryOffsetRemainder
50
51 !This is a count of the number of memory elements between successive array elements.
52 elementsToNextIndicy(1) = 1
53 do i = 2, dims, 1
54 elementsToNextIndicy(i) = elementsToNextIndicy(i-1) * (arrayUbound(i-1) - arrayLbound(i-1) + 1)
55 end do
56
57 memoryOffsetRemainder = memoryOffset
58 do j = dims, 2, -1
59 elementCount(j) = (memoryOffsetRemainder / elementsToNextIndicy(j))
60 memoryOffsetRemainder = memoryOffsetRemainder - (elementCount(j) * elementsToNextIndicy(j))
61 end do
62 elementCount(1) = memoryOffsetRemainder
63
64
65#ifdef DEBUG_MODE
66 do i = 1, dims, 1
67 if (elementCount(i) > (arrayUbound(i) - arrayLbound(i) + 1)) then
68 print *, "[ConvertToArrayIndicies]: Invalid data passed!"
69 return
70 end if
71 end do
72#endif
73
74 !Add the array lower bound so that the caller can pass a non-unit based array.
75 elementCoord(1:dims) = elementCount(1:dims) + arrayLBound(1:dims)
76
77end subroutine ut_convertToArrayIndicies
subroutine ut_convertToArrayIndicies(dims, memoryOffset, arrayLBound, arrayUBound, elementCoord)