@@ -464,40 +464,40 @@ Sorting a related rank one array:
464
464
! Sort `a`, and also sort `b` to be reorderd the same way as `a`
465
465
integer, intent(inout) :: a(:)
466
466
integer(int32), intent(inout) :: b(:) ! The same size as a
467
- integer(int32), intent(out) :: work(:)
468
- integer(int_size), intent(out) :: index(:)
469
- integer(int_size), intent(out) :: iwork(:)
470
- ! Find the indices to sort a
467
+ integer(int32), intent(out) :: work(:)
468
+ integer(int_size), intent(out) :: index(:)
469
+ integer(int_size), intent(out) :: iwork(:)
470
+ ! Find the indices to sort a
471
471
call sort_index(a, index(1:size(a)),&
472
472
work(1:size(a)/2), iwork(1:size(a)/2))
473
- ! Sort b based on the sorting of a
474
- b(:) = b( index(1:size(a)) )
475
- end subroutine sort_related_data
473
+ ! Sort b based on the sorting of a
474
+ b(:) = b( index(1:size(a)) )
475
+ end subroutine sort_related_data
476
476
```
477
477
478
478
Sorting a rank 2 array based on the data in a column
479
479
480
480
``` Fortran
481
- subroutine sort_related_data( array, column, work, index, iwork )
482
- ! Reorder rows of `array` such that `array(:, column)` is sorted
483
- integer, intent(inout) :: array(:,:)
484
- integer(int32), intent(in) :: column
485
- integer(int32), intent(out) :: work(:)
486
- integer(int_size), intent(out) :: index(:)
487
- integer(int_size), intent(out) :: iwork(:)
488
- integer, allocatable :: dummy(:)
489
- integer :: i
490
- allocate(dummy(size(array, dim=1)))
491
- ! Extract a column of `array`
492
- dummy(:) = array(:, column)
493
- ! Find the indices to sort the column
494
- call sort_index(dummy, index(1:size(dummy)),&
495
- work(1:size(dummy)/2), iwork(1:size(dummy)/2))
496
- ! Sort a based on the sorting of its column
497
- do i=1, size(array, dim=2)
498
- array(:, i) = array(index(1:size(array, dim=1)), i)
499
- end do
500
- end subroutine sort_related_data
481
+ subroutine sort_related_data( array, column, work, index, iwork )
482
+ ! Reorder rows of `array` such that `array(:, column)` is sorted
483
+ integer, intent(inout) :: array(:,:)
484
+ integer(int32), intent(in) :: column
485
+ integer(int32), intent(out) :: work(:)
486
+ integer(int_size), intent(out) :: index(:)
487
+ integer(int_size), intent(out) :: iwork(:)
488
+ integer, allocatable :: dummy(:)
489
+ integer :: i
490
+ allocate(dummy(size(array, dim=1)))
491
+ ! Extract a column of `array`
492
+ dummy(:) = array(:, column)
493
+ ! Find the indices to sort the column
494
+ call sort_index(dummy, index(1:size(dummy)),&
495
+ work(1:size(dummy)/2), iwork(1:size(dummy)/2))
496
+ ! Sort a based on the sorting of its column
497
+ do i=1, size(array, dim=2)
498
+ array(:, i) = array(index(1:size(array, dim=1)), i)
499
+ end do
500
+ end subroutine sort_related_data
501
501
```
502
502
503
503
Sorting an array of a derived type based on the data in one component
0 commit comments