function [xave,hpave]=rpmaveline(x,hp,RPM,rpmtest)
i=find(RPM<=rpmtest);
if isempty(i)
	disp('rpmtest is out of range')
end

imax1=i(1);
imax2=imax1-1;

if imax2<=0;
	imax2=1;
end

[itest1,xtest1,hptest1,RPMtest1]=rpmline(imax1,x,hp,RPM);
[itest2,xtest2,hptest2,RPMtest2]=rpmline(imax2,x,hp,RPM);
hptest3=interp1(xtest1,hptest1,xtest2);
xave=xtest2;

if imax2==imax1
	hpave=hptest2;
else
	f=(rpmtest-RPM(imax1))/(RPM(imax2)-RPM(imax1));
	hpave=f*hptest2+(1-f)*hptest3;
end
