function dedupe_sort, Array, index, data, Asort=Asort, info=info
;+
; NAME:
;	dedupe_sort
; PURPOSE:
;	Function to sort data into ascending order, and return the
;	ordered indices of non-duplicate data.
; CALLING SEQUENCE:  
;	result = dedupe_sort(array [, index, data, Asort=Asort, /info])
;	result = dedupe_sort(intsecarr(roadmap))
;	result = dedupe_sort(xxx,index,data,/info) ; This call will
;		return index and data time-ordered and with no duplicates.
; INPUT:
;	Array - array to be sorted
;	/INFO = optional keyword to cause brief message about # equal values.
; OPTIONAL INPUT/OUTPUT:
;	index - if index is given then Array is computed internally
;		from int2secarr(index).  Deduped and sorted index is returned.
;	data  - if both index and data are given then both are returned
;		deduped and sorted.
; OUTPUT:
;	result - sort subscripts are returned as function value
; OPTIONAL OUTPUT:
;	Asort - sorted array of non_redundant values of Array.
; HISTORY
;	11-May-95 LWA Adapted from Bsort.pro
;	12-May-95 LWA Added index, data capability
;-

if n_elements(index) ne 0 then array=int2secarr(index) else array=array

nnn=indgen(n_elements(array))
out=nnn

subs = sort(array)
Asort = array(subs)

weq = where( (shift( Asort, -1 ) eq Asort) , Neq ) 

if keyword_set( info ) then $
	message, strtrim( Neq, 2 ) + " Duplicate values Located",/CON,/INF

if (Neq gt 0) then begin
   out=delind(nnn(out),out(weq))
   Asort=array(subs(out))
endif

out=subs(out)
Asort=Array(out)

if n_elements(index) ne 0 then index=index(out)

; Get rid of duplicate images.

   if n_elements(data) ne 0 then begin
      siz=size(data)
      dat=bytarr(siz(1),siz(2),n_elements(out))
      case 1 of
         (siz(4) eq 2) : dat = fix(dat)
         (siz(4) eq 3) : dat = long(dat)
         (siz(4) eq 4) : dat = float(dat)
         else          : print
      endcase
      for i=0,n_elements(out)-1 do begin
         dat(0,0,i)=data(*,*,out(i))
      endfor
      data=0
      data=temporary(dat)
      dat=0
   endif

return, out

end
