function specslope=driver_ag_fit(a_g,wl)

% This function calculates spectral slope. Use an absorbance vector
% (preferably a median) and a wavelength vector as inputs.  NEEDS
% least_squares.m TO FUNCTION!!!  Last edit by ENA 7/10/2013.

%setting options for fminsearch
opts = optimset('fminsearch');      
opts = optimset(opts,'MaxIter',4000); 
opts = optimset(opts,'MaxFunEvals',2000);   % usually 100*number of params
opts = optimset(opts,'TolFun',1e-9);
%opts = optimset('LevenbergMarquardt','on');

%guess for paramters (amplitude at 532 and slope)
x0=[1.0, 0.03];

%minimization routine
x1 = fminsearch(@least_squares,x0,opts,a_g,wl)

specslope=x1(2)

%plot data and fit
plot(wl, a_g, '.k', wl, x1(1)*exp(-x1(2)*(wl-440)),'b')