PRO AdaptAxis, axis, int, dir, intDim

  int = FIX(int)
  intDim = LONG( N_Elements(axis) / int )
  axis = axis( 0: intDim* int - 1 )
  axis = RebIn( axis, intDim )

END ; Adapt Axis

PRO Integrate_2D, image, xAxis, yAxis, status, xMin, xMax, $
	yMin, yMax, $
	INTX = intX, INTY = intY
;+
;NAME:
;	Integrate_2D
; PURPOSE
;	2D integration of images. x- or y-profiles are averaged.
; CALLING SEQUENCE
;	Integrate_2D, image, [,xAxis, yAxis [, xMin, xMax,
;		yMin, yMax ] ]
; INPUT ARGUMENTS:
;	image: 2D array
;	xAxis, yAxis: 1D arrays, axes of the image.
;	xMin, xMax, yMin, yMax: the limits where the integration
;		should happen.
; OUTPUT ARGUMENTS:
;	image: the integrated image (2D real array)
;	xAxis, yAxis: the integrated axes (1D real arrays)
;	xMin, yMin: 0
;	xMax, yMax: number of elements minus one
; KEYWORDS:
;	INTX, INTY; The integration steps in x and in y.
;		If not present, they will be asked interactively.
; PROCEDURE:
;	The "Rebin" procedure is used to average the profiles.
;	If the number of profiles in the original image is
;	not a multiple of the integration steps, the last profiles
;	are lost.
;
; MODIFICATION HISTORY:
; 	Created in September 1991 by A.Csillaghy
;		Institute of Astronomy, ETH Zurich
;	xMin, etc. added in Jan. 93 for partial integration, A.Cs
;-

  IF N_Elements( xMin ) EQ 0 THEN BEGIN
    xMin = 0 & yMin = 0 
    xMax = N_Elements( image(*,0)) - 1 
    yMax = N_Elements( image(0,*)) - 1
  ENDIF

  image = image(xMin:xMax,yMin:yMax)
  xAxis = xAxis(xMin:xMax)
  yAxis = yAxis(yMin:yMax)

  nx = N_Elements(image(*,0)) & ny = N_Elements(image(0,*))
  IF N_Elements(intX) EQ 0 THEN BEGIN
    Read_Test,'Integration Step in X'  , 1,intX
    intX = FIX(intX)
  ENDIF
  IF N_Elements(intY) EQ 0 THEN BEGIN
    Read_Test,'Integration Step in Y' , 1,intY
    intY = FIX(intY)
  ENDIF
  IF N_Params() GT 1 THEN BEGIN
    AdaptAxis, xAxis, intx, 'X' , intDimX
    AdaptAxis, yAxis, inty, 'Y' , intDimY
  ENDIF ELSE BEGIN
    intDimX = LONG( nx / intX  )
    intDimY = LONG( ny / intY )
  ENDELSE

  IF intX GT 1 OR intY GT 1 THEN BEGIN
    image = Rebin( image( 0: (nx/intx)*intx-1, $
	0: (ny/inty)*inty-1 ), intDimX, intDimY )
    status = 'Done'
  ENDIF ELSE status = 'Not Done'

  xMin = 0 & yMin = 0
  xMax = intDimX-1
  yMax = intDimY-1

END ; Integrate