PROGRAM SelectionSort
   IMPLICIT NONE

   INTEGER, PARAMETER  :: Low = 1, High = 20
   INTEGER, DIMENSION(Low:High) :: Data
   INTEGER, DIMENSION(1)        :: SmallLocArr
   INTEGER             :: SmallLoc
   INTEGER             :: Smallest, I 

   READ(*,*) (Data(I), I = Low, High)

   DO I = Low, High - 1

      Smallest = MINVAL( Data(I:High))
      SmallLocArr = MINLOC( Data(I:High))
      SmallLoc = SmallLocArr(1) + ( I - 1 )
   
      Data( SmallLoc) =  Data( I ) 
      Data(I) = Smallest

   END DO

   WRITE(*,*) (Data(I), I = Low, High)

END PROGRAM SelectionSort
