function x = darkcurrent(T, low_p, high_p, int_time)
% darkcurrent(T, low_p, high_p, int_time)
%	This function returns dark current noise for each pixel at temperature T
%	and integration time int_time. It requires that the script DC_FIT be 
%	run first to generate the file DC_LOOKUP.MAT containing the polynomials
%	that give dark current as a function of T for each pixel.

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

%p = [0.368 -268.45 65287 -5e+6];	% using series 4 fit from 11-bin average plot in
											% the file DC_temp_var.xls
                                 
% Polynomials to determine dark current are from the file DC_LOOKUP.MAT:
load dc_lookup
% now we have the matrix "p" containing the polynomials

%if (T < 240) | (T > 251)
%   disp('DARKCURRENT.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
   													% Additional note: is "vectorizing" a word?
   temp(m) = polyval(p(m + low_p - 1,:),T);
end
clear p
x = temp;
