next up previous contents
Next: Summation Example Up: Vector Subscripts / MAXLOC Previous: Vector Subscripts / MAXLOC

Solution

The program

    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.


next up previous contents
Next: Summation Example Up: Vector Subscripts / MAXLOC Previous: Vector Subscripts / MAXLOC

©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997
Not for commercial use.