function [r_acc_min_val, r_acc_min_ind, access_resistance, input_resistance]=find_access_and_input_resistances_from_test_pulse(datacolumn,testpulseend,raitpd,samples_per_ms)
%made dec 1 2006
%for R_access: finds the downward peak due to the test pulse onset, skips a few values after that, fits a single decay exponential to the next values, and extrapolates back
%for R_input:

test_pulse_size=-.005;    %in volts
points_to_skip=2;
points_to_use=20;
lower_bounds=[0 0];
upper_bounds=[10000 10000];
optionz=optimset('display','off');
atrillion=1000000000000; %used in converting pA to A

[r_acc_min_val r_acc_min_ind]=min(datacolumn(testpulseend-(raitpd+1)*samples_per_ms:testpulseend-(raitpd-1)*samples_per_ms));
r_acc_min_ind=r_acc_min_ind+testpulseend-(((raitpd+1)*samples_per_ms)+1);  %this point will be plotted in the calling function
vals_to_fit=datacolumn(r_acc_min_ind+points_to_skip:r_acc_min_ind+points_to_skip+points_to_use-1);
[fitted_vals,resnorm,residual]=lsqcurvefit(@lsqfit_raccess_decay_curve_generator,[1 1],[1:length(vals_to_fit)],vals_to_fit',[lower_bounds],[upper_bounds],optionz);
reverse_time=[(1-points_to_skip):0];
extrapolated_current=-1*[fitted_vals(1)*exp(-reverse_time/fitted_vals(2))];
access_resistance=test_pulse_size/(extrapolated_current(1)/atrillion);

% figure
% decay_curve=lsqfit_raccess_decay_curve_generator(fitted_vals,[1:length(vals_to_fit)])
% full_curve=[extrapolated_current decay_curve];
% plot(datacolumn(r_acc_min_ind:r_acc_min_ind+length(full_curve)-1))
% hold on, plot(full_curve,'r')
% plot(extrapolated_current(1),'gh')

current_for_input_resistance=mean(datacolumn(testpulseend-(17*samples_per_ms):testpulseend-(3*samples_per_ms)));
current_for_input_resistance=current_for_input_resistance/atrillion;
input_resistance=test_pulse_size/current_for_input_resistance;