SUBROUTINE twoabsmin(a,i,j)
  IMPLICIT NONE
  DOUBLE PRECISION, INTENT (in) :: a(:)
  INTEGER, INTENT (out) :: i
  INTEGER, INTENT (out) :: j

  INTEGER :: k
  
  ! A' tropos
  ! i = MINLOC(ABS(a), 1)

  ! B' tropos
  i = 1
  DO k = i+1,SIZE(a)
     IF (ABS(a(k)) < ABS(a(i))) i = k
  END DO


  j = 1
  IF (i == 1) j = 2
  DO k = j+1,SIZE(a)
     IF (k == i) CYCLE
     IF (ABS(a(k)) < ABS(a(j))) j = k
  END DO

END SUBROUTINE twoabsmin

PROGRAM askisi
  IMPLICIT NONE
  INTERFACE
     SUBROUTINE twoabsmin(a,i,j)
       IMPLICIT NONE
       DOUBLE PRECISION, INTENT (in) :: a(:)
       INTEGER, INTENT (out) :: i
       INTEGER, INTENT (out) :: j
     END SUBROUTINE twoabsmin
  END INTERFACE
  INTEGER :: i,j
  DOUBLE PRECISION :: a(5)
  a(1) = 2.1d0
  a(2) = 3.2d0
  a(3) = -5.1d0
  a(4) = -6.3d0
  a(5) = 1.4d0

  CALL twoabsmin(a,i,j)
  PRINT *, "oi dyo mikroteroi einai stis theseis ", i, j
  PRINT *, "einai oi ",a(i), a(j)
END PROGRAM askisi
