Here is a small problem: I called this function repeatly. If I change the last line "interp_value(i)=t" into "interp_value(i)=1.d0", the program would be much faster (with the other lines unchanged, including the line "t=(f_x...etc"). The time consumed by "interp_value(i)=1.d0" would be just one fourth of the one compared with "interp_value(i)=t".
Since both lines are giving some particular real number to interp_value(i), why would the speed differ so much?
Thank you very much!
real(kind=8):: x(N), f_x(N), xp(N),interp_value(N),t
x_index = minloc(abs(x-xp(i)),1)
t = (f_x(x_index+1)-f_x(x_index))/(x(x_index+1)-x(x_index))
end subroutine myinterp1