function UNIQ, ARRAY, IDX, $
    FIRST=FIRST, OLDWAY=OLDWAY, EPSILON=EPSILON

; Check the arguments.
  default, epsilon, 0.0
  epsilon = abs(epsilon)
  isstring =  datatype(array,/tname) eq 'STRING'
  oldway=keyword_set(oldway)
  s = size(ARRAY)
  first=keyword_set(first)

  if (s(0) eq 0) then begin
   val=0
   if oldway then val=[val]
   return,val
  endif

  shifts=([-1,1])(first)   ;slf - shift direction -> first/last
  if n_params() ge 2 then begin     ;IDX supplied?
   q = array(idx)
   if epsilon eq 0 or isstring then $
    indices = where(q ne shift(q,shifts), count) else $
    indices = where(abs(q - shift(q,shifts)) gt abs(q)*epsilon, count)
   if (count GT 0) then return, idx(indices) else begin
    val=(n_elements(q)-1) * (1-first)
    if oldway then val=[val]
    return,val
   endelse
  endif else begin
   if epsilon eq 0 or isstring then $
    indices = where(array ne shift(array, shifts), count) else $
    indices = where(abs(array - shift(array,shifts)) gt abs(array)*epsilon, count)
   if (count GT 0) then return, indices else begin
    val=(n_elements(ARRAY)-1) * (1-first)
    if oldway then val=[val]
    return,val
   endelse
  endelse

  end