function [manpressave,horsesave]=rpmaveline2(manpress,horses,RPMvalue,RPMtest)
% RPM test is the RPM that you want to finea horsepower line for.
% RPMvalue is a vector of RPM values within the data (manpress,horses).
% manpress is a vector of manifiold pressures.
% horses is a vector of horsepower for the given manifold pressures.
% This function assumes the rpm values can de accessed using rpmline2.m.
i=find(RPMvalue>=RPMtest);
if isempty(i)
	disp('RPMtest is out of range')
end
imax1=i(1);
imax2=imax1-1;
if imax2<=0;
	imax2=1;
end
% itest,manpresstest,horsestest,RPMtest
[itest1,manpresstest1,horsestest1,RPMtest1]=rpmline2(imax1,manpress,horses,RPMvalue);
[itest2,manpresstest2,horsestest2,RPMtest2]=rpmline2(imax2,manpress,horses,RPMvalue);

%YI = INTERP1(X,Y,XI)
horsestest3=interp1(manpresstest2,horsestest2,manpresstest1);
manpressave=manpresstest1;
if imax1==imax2
	horsesave=horsestest1;
else
	f=(RPMtest-RPMvalue(imax2))/(RPMvalue(imax1)-RPMvalue(imax2));
	horsesave=(f*horsestest1+(1-f)*horsestest3);
end


