7
interpolate_coords.py Ndesired [scale] < coords_orig.raw > coords.raw
11
interpolate_coords.py 30118 3.0 < coords_orig.raw > coords.raw
13
# (Note: 30117 ~= 128000/4.25, but using 30118 makes interpolation cleaner.
14
# See the supplemental section of Naumova et al Science 2013, p 18.)
22
# Parse the argument list:
23
if len(sys.argv) <= 1:
24
sys.stderr.write("Error:\n\nTypical Usage:\n\n"+err_msg+"\n")
27
n_new = int(sys.argv[1])
30
scale = float(sys.argv[2])
36
lines = sys.stdin.readlines()
41
coords_orig.append(map(float, tokens))
44
n_orig = len(coords_orig)
47
sys.stderr.write("Error:\n\nInput file contains less than two lines of coordinates\n")
51
sys.stderr.write("Error:\n\nOutput file will contain less than two lines of coordinates\n")
54
coords_new = [[0.0 for d in range(0, g_dim)] for i in range(0, n_new)]
56
for i_new in range(0, n_new):
57
I_orig = (i_new) * (float(n_orig-1) / float(n_new-1))
58
i_orig = int(floor(I_orig))
59
i_remainder = I_orig - i_orig
62
for d in range(0, g_dim):
63
coords_new[i_new][d] = scale*(coords_orig[i_orig][d]
65
i_remainder*(coords_orig[i_orig+1][d]-
66
coords_orig[i_orig][d]))
68
for d in range(0, g_dim):
69
coords_new[i_new][d] = scale*coords_orig[n_orig-1][d]
72
for d in range(0, g_dim-1):
73
sys.stdout.write(str(coords_new[i_new][d]) + ' ')
74
sys.stdout.write(str(coords_new[i_new][g_dim-1]) + "\n")