1 | #!@PYTHON@
|
---|
2 | #
|
---|
3 | # Creates an Analysis matrix for a number of nanotubes (n,m) with stress files
|
---|
4 |
|
---|
5 | import sys, random, math
|
---|
6 | wrout = sys.stdout.write
|
---|
7 | wrerr = sys.stdout.write
|
---|
8 |
|
---|
9 | # check arguments
|
---|
10 | if len(sys.argv) < 2:
|
---|
11 | print "Usage: "+sys.argv[0]+" <input> <output>"
|
---|
12 | sys.exit(1)
|
---|
13 |
|
---|
14 | if sys.argv[1] in sys.argv[2]:
|
---|
15 | print "Please state two different files!"
|
---|
16 | sys.exit(1)
|
---|
17 | input = open(sys.argv[1], "r")
|
---|
18 | output = open(sys.argv[2], "w")
|
---|
19 |
|
---|
20 | # parse lines into array
|
---|
21 | chiralities=[ ]
|
---|
22 | runs=[ ]
|
---|
23 | defects=[ ]
|
---|
24 | values=[ ]
|
---|
25 | for line in input:
|
---|
26 | if "#" in line:
|
---|
27 | continue
|
---|
28 | entries=line.split()
|
---|
29 | if not entries[0] in chiralities:
|
---|
30 | chiralities.append(entries[0])
|
---|
31 | if not entries[1] in runs:
|
---|
32 | runs.append(entries[1])
|
---|
33 | if not entries[2] in defects:
|
---|
34 | defects.append(entries[2])
|
---|
35 | values.append([entries[0], entries[1], entries[2], entries[3:]])
|
---|
36 | for n in range(len(values[-1])):
|
---|
37 | wrout("%s\t" % (values[-1][n]))
|
---|
38 | wrout("\n")
|
---|
39 | input.close()
|
---|
40 |
|
---|
41 | # sum values
|
---|
42 | avg_values=[ ]
|
---|
43 | for i in range(len(values)):
|
---|
44 | if (values[i][1] == runs[0]):
|
---|
45 | tmp=[ ]
|
---|
46 | for j in range(len(values[i][3])): # create array initialised to 0
|
---|
47 | tmp.append(0.)
|
---|
48 | avg_values.append([values[i][0],values[i][2],tmp[:]])
|
---|
49 | # look for corresponding index to i in avg_value
|
---|
50 | j=0
|
---|
51 | while (j < len(avg_values)):
|
---|
52 | if ((avg_values[j][0] == values[i][0]) and (avg_values[j][1] == values[i][2])):
|
---|
53 | break
|
---|
54 | j+=1
|
---|
55 | if j < len(avg_values):
|
---|
56 | for n in range(len(values[i][3])/2):
|
---|
57 | avg_values[j][2][2*n]+=float(values[i][3][2*n]) # value
|
---|
58 | avg_values[j][2][2*n+1]+=float(values[i][3][2*n+1])*float(values[i][3][2*n+1]) # value
|
---|
59 | else:
|
---|
60 | wrerr("Cannot sort in values for %s, %s, %s!\n" % (values[i][0], values[i][1], values[i][2]))
|
---|
61 |
|
---|
62 | # output values
|
---|
63 | oldm=-1
|
---|
64 | output.write("#n\tm\tdefect\tPoss\tError\tYoungPot\tError\tYoungLag\tError\tPossLag\tError\tYoungLog\tError\tPossLog\tError\tEModulus\tError\n")
|
---|
65 | for i in range(len(avg_values)):
|
---|
66 | chiral=avg_values[i][0].split("-")
|
---|
67 | if oldm != chiral[1]:
|
---|
68 | if oldm != -1:
|
---|
69 | output.write("\n\n")
|
---|
70 | oldm=chiral[1]
|
---|
71 | output.write("%s\t%s\t%s\t" % (chiral[0],chiral[1],avg_values[i][1]))
|
---|
72 | for n in range(0,len(avg_values[i][2])/2):
|
---|
73 | output.write("%s\t%s\t" % (avg_values[i][2][2*n]/len(runs),math.sqrt(avg_values[i][2][2*n+1])))
|
---|
74 | output.write("\n")
|
---|
75 | output.close()
|
---|
76 |
|
---|