function x = bias(T, low_p, high_p)
% bias(T, low_p, high_p)
%	This function returns the CCD bias noise for each pixel at temperature T.
%	It requires that the script BIAS_FIT be  run first to generate the file 
%	BIAS_LOOKUP.MAT containing the polynomials that give bias as a function 
%	of T for each pixel.

%	ARGUMENTS:
%		T				mean temperature of CCD when spectrum was taken
%		low_p			lower absolute pixel # at which to calculate noise
%		high_p		upper absolute pixel # at which to calculate noise
%
%	INPUT FILES:
%		bias_lookup.mat	gives the matrix p, which contains the polynomials 
%	VARIABLES:
%
%	OUTPUT:
%		row vector containing a bias noise value for each pixel (yup,
%		all 2000 of them).
%	
%	CALLS:			none
%
%	CALLED BY:		slit_fn.m

% Polynomials to determine dark current are from the file DC_LOOKUP.MAT:                                 
load bias_lookup
% now we have the matrix "p" containing the polynomials

%if (T < 240) | (T > 251)
%   disp('BIAS.M: Error, invalid temperature')
%   x = -1;
%   return
%end

clear temp m
temp = zeros(1, high_p - low_p + 1);		% Preallocate temp to speed things up

for m = 1:1:(high_p - low_p + 1)				% Note: vectorizing this loop doesn't work
   temp(m) = polyval(p(m + low_p - 1,:),T);
end
clear p
x = temp;
