;+ ; NAME: ; is_sorted ; ; ; PURPOSE: ; determine if an array is sorted ; ; ; INPUTS: ; array: the array to test if it is sorted. ; ; ; OUTPUTS: ; 1-sorted, 0-not sorted ; ; ; EXAMPLE: ; IDL> print, is_sorted([1,2,3,3,4,5,5]) ; 1 ; IDL> print, is_sorted([1,2,3,3,2,4,5,5]) ; 0 ; ; ; ; MODIFICATION HISTORY: ; ; Fri Aug 29 12:46:51 2008, Brian Larsen ; written and tested ; ;- FUNCTION is_sorted, array IF n_elements(array) EQ 0 THEN BEGIN message, 'Must input an array' ENDIF ;; instead of doing the sorting subtract them and see if the sign is ;; always the same diff = array - array[1:*] sign = sign(diff) max = max(sign, min = min) IF abs(max-min) EQ 2 THEN $ return, 0 $ ; array is not sorted ELSE return, 1 ; array is sorted return, !values.f_nan ; should neve rget here END