Given an order vector, sort a real or integer vector
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(*), | intent(inout), | dimension(n) | :: | tab_inout |
array to sort |
|
integer(kind=I4), | intent(inout), | dimension(n) | :: | order |
order vector |
|
integer(kind=I4), | intent(in) | :: | n |
size of the arrays |
subroutine change_array_order(tab_inout, order, n) !! Given an order vector, sort a real or integer vector implicit none integer(kind=I4), intent(in) :: n !! *size of the arrays* class(*) , intent(inout), dimension(n) :: tab_inout !! *array to sort* integer(kind=I4), intent(inout), dimension(n) :: order !! *order vector* integer(kind=I4) :: i integer(kind=I4), allocatable, dimension(:) :: tab_int real(kind=R8), allocatable, dimension(:) :: tab_real select type(tab_inout) type is( integer(kind=I4) ) allocate( tab_int(1:n) ) tab_int(1:n) = tab_inout(1:n) do i = 1, n tab_inout( i ) = tab_int( order(i) ) enddo deallocate( tab_int ) type is( real(kind=R8) ) allocate( tab_real(1:n) ) tab_real(1:n) = tab_inout(1:n) do i = 1, n tab_inout( i ) = tab_real( order(i) ) enddo deallocate( tab_real ) endselect return endsubroutine change_array_order