FUNCTION FindBreaks, array, NOTREG = notReg

;+ 
; NAME: 
;	Find Breaks 
; PURPOSE:
;	Returns the index number of each break in the 
;	regularity in the axis.
; CALLING SEQUENCE:
;	result = FindBreaks( array )
; INPUT PARAMETERS:
;	array: a 1D real array
; KEYWORD:
; 	NOTREG: if set, only the first break is searched;
;		if found, returns -1, else returns the first
;		and last elements of the array
; RESULT OF FUNCTION:
;	result of function: a 1D array with the indices number:
;	[0... i, i+1, ... n-1] where i is the last pixel in the regular
;	band left and i+1 the first in the regular band right.
;
; MODIFICATION HISTORY:
;	Created by A.Csillaghy in October 1991
;		Inst. of Astronomy, ETH Zurich
;	NOTREG in april, 1995
;       Simplified in January 1998 ACs
;       Reduced accuracy, Spring 2000 PM
;-

  n = N_Elements( array )
  array =  Double(array)

  IF n EQ 2 THEN RETURN, [0,1] $
  ELSE IF n EQ 1 THEN RETURN, [0,0]

  breaks = 0
  diff = Abs( array - shift( array, 1 ) )
  i = 1L
  WHILE i LT n-1 DO BEGIN 
     IF diff(i) LT diff(i+1)*0.99 OR diff(i) GT diff(i+1)*1.01 THEN BEGIN
         IF i EQ 1 THEN BEGIN 
             breaks = [ breaks, i ]
             i = i+1
         ENDIF ELSE BEGIN
             breaks = [ breaks, i, i+1 ]
             i = i+2
         ENDELSE
         IF Keyword_Set( NOTREG ) THEN RETURN,-1
     ENDIF ELSE i = i+1
 ENDWHILE

 breaks = [ breaks, n-1 ] 
 RETURN, breaks

END ; Find Breaks 
