function x = wave_cent(sp, wv_sp)
% function wave_cent(sp, wv_sp)
%	Replaces the subroutine "weight" from the old Fortran code
%	(SHIFT1.FOR, line 67). Calculates the "centre of gravity"
%	of the input spectrum sp binned on the wavelength grid wv_sp.

%	ARGUMENTS:
%		sp				input spectrum
%		wv_sp			wavelength grid for input spectrum
%	GLOBALS REQUIRED:
%		deg_calib	deg of slowly varying poly to subtract off
%
%	CALLS:			none
%
%	CALLED BY: 		resid.m
%
%	LAST MODIFIED:	July 14 / 00


global deg_calib
%deg_calib = 2;

p = polyfit(wv_sp, sp, deg_calib);
sp = sp - polyval(p, wv_sp);		% note: recall that MatLab never modifies
											% vectors by reference, only by value.
s1 = sum(wv_sp.*(sp.^2));
s2 = sum(sp.^2);
x = s1/s2;			% output the wavelength "centre of gravity" for the spectrum


