function [SFV, err] = ProcessSpectrum(specfile, Templates, LT, m, R, G, B, l_rgb, lmin, lmax)

% SFV = SpectralFeatureVector(specfile, Templates, LT, m, R, G, B, l_rgb)
%		spectrum = full path + name of spectral file
%		Templates = cell array of feature templates (1 nm spacing)
%		LT = array of starting wavelengths (nm) of feature templates
%		R, G, B, l_rgb are R,G,B filter fns, along with wavelength vector l_rgb (1nm spacing)
%		lmin, lmax = wavelength range (nm).

% Liam Pedersen, NASA ARC/CMU, August 1998

% set for plotting of spectra and spectral features.
plotspecfeatures = 1;

if (specfile(1) == '*')
   err = 1;
   SFV = -1;
   return;
end

[spectrum,lambda] = ReadSpectrum(specfile);

if (spectrum(1) == -1)  % spectrum not read successfully!
   disp(['Error reading spectrum file ' specfile]);
   err = 1;
   SFV = -1;
   return
end
err = 0;

% compute spectral feature vector
SFV = SpectralFeatureVector(spectrum, lambda, Templates, LT, R, G, B, l_rgb, lmin, lmax);

if (plotspecfeatures)
   figure(1);
   clf;
   PlotSpectra(lambda,spectrum,specfile);
   hold on
   SF = SFV(1:length(m));
   plot(m,SF,'k*');
   
   r = SFV(length(m)+1);
   g = SFV(length(m)+2);
   I = SFV(length(m)+3);
   
   bar([550 600 650],[0 0 r],'r');
	bar([550 600 650],[0 g 0],'g');
 	bar([550 600 650],[I 0 0],'c');
   hold off
end
