Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/de_gulch_old.pro'
function de_gulch, image_data, coef, DEGREE=degree, INTERACTIVE=int, PLOT=plot

;Frank Varosi STX @ NASA/GSFC 1991
;F.V. 1991, added interactive option (keyword /INT).

	image = filter_image( image_data, /SMOOTH,/ALL )
	sim = size( image )
	xsiz = sim(1)
	ysiz = sim(2)
	if N_elements( degree ) NE 1 then degree=1

	maxim = max( image, imax )
	xpeak = imax MOD xsiz
	ypeak = imax / xsiz
	rowC = image(*,ypeak)


	if (ypeak LT ysiz/3) then begin
		y = ypeak + ysiz/2
		rowE = ( image(*,y-3) + image(*,y-4) )/2
	  endif else if (ypeak GT 2*ysiz/3) then begin
		y = ypeak - ysiz/2
		rowE = ( image(*,y+2) +  image(*,y+3) )/2
	   endif else begin
		rowT = ( image(*,ysiz-3) + image(*,ysiz-4) )/2
		rowB = ( image(*,2) +  image(*,3) )/2
		rowE = (rowT+rowB)/2
	    endelse

	coef = transpose( poly_fit( rowC, rowE, degree ) )

	if keyword_set( int ) then begin
		print,coef
		print," default recommended % for de-gulch =", -coef(1)*100
		text = ""
		read," enter new %  (return for default) :", text
		if (text NE "") then coef(1)= -float( text )/100.
	   endif

	image = image_data - poly( rowC, coef ) # replicate( 1, sim(2) )

	if keyword_set( plot ) then begin
		plot,rowB
		oplot,rowT,LINE=2
		oplot,poly( rowC, coef ),LINE=1
	   endif

return, conv_vartype( image, TYPE=sim(sim(0)+1) )
end