FLASH-X
Doxygen Generated Documentation From Interface Source Code
ut_convertToMemoryOffset.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!!
37!*******************************************************************************
38
39subroutine ut_convertToMemoryOffset(dims, elementCoord, arrayLBound, arrayUBound, memoryOffset)
40
41implicit none
42integer, intent(IN) :: dims
43integer, dimension(1:dims), intent(IN) :: elementCoord, arrayUBound, arrayLBound
44integer, intent(OUT) :: memoryOffset
45integer, dimension(1:dims) :: elementsToNextIndicy
46integer :: i
47
48#ifdef DEBUG_MODE
49do i = 1, dims, 1
50 if (elementCoord(i) < arrayLBound(i) .or. elementCoord(i) > arrayUBound(i)) then
51 print *, "[ConvertToMemoryOffset]: Invalid data passed!"
52 return
53 end if
54end do
55#endif
56
57!This is a count of the number of memory elements between successive array elements.
58elementsToNextIndicy(1) = 1
59do i = 2, dims, 1
60 elementsToNextIndicy(i) = elementsToNextIndicy(i-1) * (arrayUbound(i-1) - arrayLbound(i-1) + 1)
61end do
62
63!Make a cumulative count of the number of memory elements to reach the user-specified
64!element in each dimension. Notice that the lower limit of the target array is
65!taken into account so that the caller can pass a non-unit based array.
66memoryOffset = sum( (elementCoord(1:dims) - arrayLBound(1:dims)) * elementsToNextIndicy(1:dims) )
67
68end subroutine ut_convertToMemoryOffset
subroutine ut_convertToMemoryOffset(dims, elementCoord, arrayLBound, arrayUBound, memoryOffset)