Last active
August 21, 2020 17:00
-
-
Save nobodyzxc/974c1b6947b8e2adac8a3332329e216c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs, csv, sys, os | |
def extract(text, head, tail): | |
beg = text.find(head) | |
offset = text[beg + len(head):].find(tail) | |
return text[beg + len(head):beg + len(head) + offset] | |
def interpolate(x0, y0, x1, y1, x2): | |
# (x1 - x0) / (x2 - x0) = (y1 - y0) / (y2 - y0) | |
y2 = (y1 - y0) / ((x1 - x0) / (x2 - x0)) + y0 | |
return y2 | |
def val_from_file(fn): | |
text = codecs.open(fn, 'r', 'iso-8859-1').read() | |
mobility = float(extract(text, 'MAX MOBILITY: ', ' cm²')) | |
threshold = float(extract(text, 'Gate voltage Threshold V_T = ', ' V')) | |
lines = text.split('\n') | |
tab_beg, tab_end = [idx for idx, line in enumerate(lines) \ | |
if line.startswith('V_Gate') or line.startswith('End TC Curves')] | |
tab = [l for l in lines[tab_beg + 1:tab_end] if l.strip()] | |
tab = [[float(v) for v in r.split()] for r in tab] | |
c355 = tab[-1][-1] | |
for ar, br in zip(tab, tab[1:]): | |
if ar[0] >= 0 and br[0] <= 0: | |
v0, _, i0 = ar | |
v1, _, i1 = br | |
interpolation = interpolate(v0, i0, v1, i1, 0) | |
break | |
return mobility, threshold, interpolation / c355 | |
argv = list(enumerate(sys.argv)) | |
groups = [argv[i: i + 5] for i in range(1, len(sys.argv), 5)] | |
with open('OFET.csv', 'w', newline='') as csvfile: | |
writer = csv.writer(csvfile) | |
for gidx, fns in enumerate(groups): | |
writer.writerow(['Cell{}'.format(gidx), 'Device', 'mobility(cm^2/V*S)', 'V_T', 'on/off ratio', 'filename']) | |
vals = [('', idx, *val_from_file(fn), os.path.basename(fn)) for idx, fn in fns] | |
for val in vals: writer.writerow(val) | |
#['', '1', '檔案一數值一', '檔案一數值二', '檔案一數值三', '檔案一的檔名'] | |
valsT = list(zip(*vals)) | |
writer.writerow(['', 'avg.', *[sum(valsT[i]) / len(fns) for i in range(2, 5)], '']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment