Viewing contents of file '../idllib/ghrs/pro/calhrs_stow.pro'
pro calhrs_stow,samples,order,dc,wave
;
;+
;			calhrs_stow
;
; Procedure to compute wavelengths from photocathode sample positions
;
; CALLING SEQUENCE:
;	calhrs_stow,samples,order,dc,wave
;
; INPUTS:
;	samples - photocathode sample positions
;	order - spectral order
;	dc - dispersion coefficients
;
; INPUT/OUTPUT:
;	wave - wavelength vector
;		on input it has the starting guesses for the wavelengths
;
; OPERATIONAL NOTES
;	!err is returned with a negative value if the method
;	failed to converge after 10 iterations
;
; METHOD:
;	Newtons iterative method is used to solve the dispersion equation.
;
; HISTORY:
;	version 1  D. Lindler   Mar 89
;-
;----------------------------------------------------------------------------
 
	maxerr=0.01		;desired accuracy in sample units
	maxiter=10		;maximum number of iterations
 
;
;  determine coefficients relating sample position to wavelength for
;  the given order number
;
	m=long(order)
	m2=m^2
	m3=m^3
 
	a = dc(0) + dc(3)*m + dc(8)*m2
	b = dc(1)*m + dc(4) + dc(5)*m2
	c = dc(2)*m2 + dc(6)*m + dc(9)
	d = dc(7)*m3
 
;
; iterate
;
	iteration=0
	repeat begin
		iteration = iteration +1
		if iteration gt maxiter then begin
			!err=-1
			return
		endif
		wave2=wave^2
		wave3=wave^3
		scomp = a + b*wave + c*wave2 + d*wave3
		dsdw = b + 2*c*wave + 3*d*wave2		;derivative
		wave=wave+(samples-scomp)/dsdw
	 end until max(abs(scomp-samples)) lt maxerr
return
end