PROGRAM Sortish IMPLICIT NONE INTEGER, PARAMETER :: VSize = 100 REAL, DIMENSION(VSize) :: Vector INTEGER, DIMENSION(VSize) :: VSubs = 0 INTEGER i,itmp(1) CALL RANDOM_NUMBER(Vector) itmp = MAXLOC(Vector) VSubs(1) = itmp(1) DO i = 2,VSize itmp = MAXLOC(Vector,MASK=Vector.LT.Vector(VSubs(i-1))) VSubs(i) = itmp(1) END DO PRINT*, "Unsorted", Vector PRINT*, "Sorted", Vector(VSubs) END PROGRAM Sortish
Note that the result of MAXLOC is an array which has to be transformed to a scalar before assignment to VSubs.