各位有興趣不妨試試看下面的程式碼。將下面程式碼複製到檔名為getSnpFreqRange.py的文字檔當中,修改程式當中snp_dir的目錄,在AEDT當中執行。待工作結束即可在路徑當中找到output.txt(如圖一),當中記錄了目錄底下每個S參數及對應的頻率範圍。
import os
snp_dir = 'd:/demo2'
def getSnpRange(snp_path):
ext = snp_path.split('.')[-1]
N=int(ext[1:-1])
with open(snp_path) as f:
text = f.readlines()
unit_mapping = {'hz':1e0, 'khz':1e3, 'mhz':1e6, 'ghz':1e9}
values = []
for i in text:
if i[0] == '!':
continue
elif i[0] =='#':
unit = i.split()[1]
scale = unit_mapping[unit.lower()]
else:
x = i.split()
values += map(float, x)
freq = [i*scale for i in values[::N*N*2+1]]
freq_range = (freq[0], freq[-1])
return freq_range
files = os.listdir(snp_dir)
failed = []
result = []
for i in files:
try:
frange = getSnpRange(snp_dir+'/'+i)
result.append('{:80}:{}\n'.format(i, frange))
except:
failed.append(i)
with open(snp_dir + '/output.txt', 'w') as f:
f.writelines(result)
f.writelines('_'*120 + "\nFailed:\n{}".format('\n'.join(failed)))
沒有留言:
張貼留言