	Function halp, img, histo_scale=histo_scale, imgsize=imgsize, $
		deltar = deltar, peak_scale=peak_scale, interp=interp, $
		rm_limbdarken=rm_limbdarken
;	-----------------------------------------------------------------
;+                                                    10-Oct-94
;	Name: halp (halpha-prep)
;	Purpose: prepare h-alpha images for the movie.
;	Calling:
;		nimg = halp(img, histo_scale=histo_scale, deltar=deltar,
;			imgsize=imgsize, rm_limbdarken=rm_limbdarken])
;	RETURNS:
;		a prepared h-alpha image.
;       INPUT:
;		img		input h-alpha image
;		histo_scale	use histogram scaling for image.
;				default is no scaling.
;		imgsize 	user specified output image size, default
;				is approx. 150 pixels for the diameter.
;		interp		interpolation switch passed to congrid.
;		deltar		pad added to the computed radius for clipping
;				the image.  Default is 5 nibs.
;		rm_limbdarken	remove limb darkening.
;	
;	History: written 15-Sep-94, GAL
;		revamped  7-Oct-94, GAL
;                         9-oct-94, SLF - subscript range protection
;                        10-oct-94, SLF - same, opposite direction
;			 10-Oct-94, GAL - added option for removeal of 
;					  limb darkening.
;-
;	---------------------------------------------------------

	if (n_elements(imgsize) eq 0) then begin
	  imgsize = 150			; default image size
	endif

	isize = imgsize 		; default output disk-image size
	
	mimg = gbo_mask(img)		; clean up edges /but can 
					; introduce clipped disks!!!

	fit_limb,mimg,x,y,r,pixel=4.0,/quiet	; fit limb

	x0=fix(x+0.5) & y0=fix(y+0.5) & r0=fix(r+0.5)
	
	simg = size(img)		; dimensions of input
	if (n_elements(deltar) eq 0) then begin
	  dr = 5
	endif else dr = deltar
	r1 = r0+dr
  	  succuss = get_ciridx(simg(1), simg(2), x0, y0, r1, inidx=inidx, $
		outidx=outidx)	
	mimg(outidx) = 0b		; clip outside of disk
;       slf, 9/10-oct - added > 0 <imgsize check below 
	mimg = mimg(x0-r1:x0+r1,(y0-r1)>0:(y0+r1)<(size(mimg))(2)-1)	; trim image to disk

;	rebin to specified size:
	rimg = congrid(mimg, isize, isize,interp=interp)

	if (n_elements(rm_limbdarken) ne 0) then $
          rimg = rm_darklimb(rimg, /setback)

;       Rescale Image:
	if (n_elements(histo_scale) ne 0) then begin
	  ;	decompress fits file
	  mmax = hist_scale(rimg)
	  rimg = bytscl(rimg, min(mimg), mmax)
	endif else begin

;	  Rescale: via mean intensity and scale mean to 160.7
	  if (n_elements(peak_scale) ne 0) then begin
	    fit_limb, rimg, xcen, ycen, r0, pixel=1.0, /quiet, /fast

  	    succuss = get_ciridx(isize, isize, xcen, ycen, r0, inidx=inidx, $
		outidx=outidx)

	    Iave = total(rimg(inidx)) / n_elements(inidx)
	    Irat = 160.7/Iave
	    rimg = rimg * Irat		; dum rescaling...
	
	    print, "average Int: ", Iave
            rimg = bytscl(rimg, min=0, max=254)
	  endif
	endelse

	return, rimg
	end
