The main documentation of the Generate_Shell_Partition Procedure contains additional explanation of this code listing.
subroutine Generate_Shell_Partition (c, i_of_c, j_of_c, k_of_c, &
NDimensions, NNodes_per_Side, Output)
! Input variables.
type(integer), intent(in) :: NDimensions ! Number of dimensions.
type(integer), intent(in) :: NNodes_per_Side ! Length of a side.
type(logical), intent(in) :: Output ! Output toggle.
! Output variables.
type(integer,3) :: c ! Cell numbers for each (i,j,k).
type(integer,1) :: i_of_c, j_of_c, k_of_c ! i,j,k values for each cell #.
! Internal variables.
type(integer) :: buff_loc ! Buffer location.
type(integer) :: i, j, k ! Loop counters.
type(integer) :: imax, jmax, kmax ! Maximum values for i, j, and k.
type(integer) :: maxij, maxijk ! Maximum of the current (i,j) or
! (i,j,k) set.
type(character,80) :: output_buffer ! Buffer for output.
type(logical) :: do_output ! Output toggle (PE-dependent).
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Determine whether or not to output.
do_output = this_is_IO_PE .and. Output
! Set boundaries.
imax = NNodes_per_Side
if (NDimensions > 1) then
jmax = imax
else
jmax = 1
end if
if (NDimensions > 2) then
kmax = imax
else
kmax = 1
end if
! Set cell numbers.
if (do_output) write (6,'(/,a,/)') 'Shell Partitioning:'
do k = kmax, 1, -1
do j = jmax, 1, -1
buff_loc = 1
do i = 1, imax
maxij = MAX(i,j)
maxijk = MAX(i,j,k)
select case (NDimensions)
case (1)
c(i,j,k) = i
case (2)
c(i,j,k) = i + &
(maxij - j) + &
(maxijk - 1)**NDimensions
case (3)
c(i,j,k) = i + &
(maxij - j) + &
(maxijk - 1)**NDimensions + &
(maxijk - k) * (2*maxijk - 1) + &
(maxij - 1)**(NDimensions-1)
end select
i_of_c(c(i,j,k)) = i
j_of_c(c(i,j,k)) = j
k_of_c(c(i,j,k)) = k
if (do_output) then
write (output_buffer(buff_loc:),'(i6)') c(i,j,k)
buff_loc = buff_loc + 6
if (buff_loc > 75) then
write (6,*) output_buffer(1:buff_loc-1)
buff_loc = 1
end if
end if
end do
if (do_output .and. buff_loc /= 1) then
write (6,*) output_buffer(1:buff_loc-1)
end if
end do
if (do_output) write (6,*)
end do
return
end subroutine Generate_Shell_Partition