def interpolate(xarray, yarray, x, rigid_limits=True):
if not len(xarray) == len(yarray):<EOL><INDENT>print("<STR_LIT>", len(xarray), len(yarray))<EOL>return None<EOL><DEDENT>if x < xarray[<NUM_LIT:0>] or x > xarray[-<NUM_LIT:1>]:<EOL><INDENT>if rigid_limits:<EOL><INDENT>print("<STR_LIT>" + str(x) + "<STR_LIT>" + str(min(xarray)) + "<STR_LIT>" + str(max(xarray)))<EOL>return None<EOL><DEDENT>else:<EOL><INDENT>if x < xarray[<NUM_LIT:0>]: return yarray[<NUM_LIT:0>]<EOL>else:             return yarray[-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>for n2 in range(<NUM_LIT:1>, len(xarray)):<EOL><INDENT>if x >= min(xarray[n2], xarray[n2-<NUM_LIT:1>]) and x <= max(xarray[n2], xarray[n2-<NUM_LIT:1>]):<EOL><INDENT>break<EOL><DEDENT>if n2 == len(xarray):<EOL><INDENT>print("<STR_LIT>")<EOL>return None<EOL><DEDENT><DEDENT>n1 = n2-<NUM_LIT:1><EOL>return yarray[n1] + (x-xarray[n1])*(yarray[n2]-yarray[n1])/(xarray[n2]-xarray[n1])<EOL>
returns the y value of the linear interpolated function
y(x). Assumes increasing xarray!

rigid_limits=False means when x is outside xarray's range,
use the endpoint as the y-value.