TXT檔案中部分內容如下:
3.981E+00 3.288E-08 26.304|*********|*********|****** | | | | | | | |
5.012E+00 4.443E-08 35.551|mmmmmmmmm|mmmmmmmmm|mmmmmmmmm|mmmmmm | | | | | | |
6.310E+00 5.748E-08 45.989|*********|*********|*********|*********|****** | | | | | |
7.943E+00 7.110E-08 56.893|*********|*********|*********|*********|*********|******* | | | | |
1.000E+01 8.298E-08 66.392|*********|*********|*********|*********|*********|*********|****** | | | |
1.259E+01 9.413E-08 75.316|*********|*********|*********|*********|*********|*********|*********|***** | | |
1.585E+01 1.019E-07 81.558|*********|*********|*********|*********|*********|*********|*********|*********|** | |
1.995E+01 1.093E-07 87.427|*********|*********|*********|*********|*********|*********|*********|*********|******* | |
2.512E+01 1.165E-07 93.178|*********|*********|*********|*********|*********|*********|*********|*********|*********|*** |
3.162E+01 1.203E-07 96.227|*********|*********|*********|*********|*********|*********|*********|*********|*********|****** |
3.981E+01 1.224E-07 97.946|*********|*********|*********|*********|*********|*********|*********|*********|*********|******** |
5.012E+01 1.242E-07 99.362|*********|*********|*********|*********|*********|*********|*********|*********|*********|*********|
6.310E+01 1.242E-07 99.362|*********|*********|*********|*********|*********|*********|*********|*********|*********|*********|
7.943E+01 1.242E-07 99.362|*********|*********|*********|*********|*********|*********|*********|*********|*********|*********|
1.000E+02 1.250E-07 100.000|*********|*********|*********|*********|*********|*********|*********|*********|*********|*********|
total 1.24979E-07 100.000:--------10--------20--------30--------40--------50--------60--------70--------80--------90-------100
1tally 42 nps = 3574556
tally type 2 particle flux averaged over a surface.
particle(s): neutron
number of histories used for normalizing tallies =************
this tally is modified by a dose function.
this tally is all multiplied by 1.00000E-12
areas
surface: 30
7.85398E+01
surface 30
energy
1.0000E-02 2.38783E-21 0.0290
2.0000E+01 2.51935E-22 0.0524
total 2.63977E-21 0.0284
1analysis of the results in the tally fluctuation chart bin (tfc) for tally 42 with nps = 3574556 print table 160
我想要的是藍色部分的資料,關鍵字是紅色部分。我想先找到紅色部分所在的行的行號,然后加上10,就是資料所在的行的行號(他們之間的間距是固定的),然后開始讀取資料,通過判斷total來決定讀取是否結束(資料的下一行開頭是total)。
求助各位大神,這是我第一次用python,拜托拜托了!
uj5u.com熱心網友回復:
你這是,MCNP?uj5u.com熱心網友回復:
直接用 find 然后記錄一下行號就好了,
with open('test.txt', 'r') as f:
context = f.readlines()
target_line = 0
for l in context:
if l.find('1tally 42 nps') != -1:
break
target_line += 1
print(context[target_line+15])
print(context[target_line+16])
輸出:
1.0000E-02 2.38783E-21 0.0290
2.0000E+01 2.51935E-22 0.0524
uj5u.com熱心網友回復:
確實是MCNPuj5u.com熱心網友回復:
哈哈哈,我也在找用Python讀MCNP檔案的方法,沒想到能看到MCNP的輸出檔案!你也是中核單位下的同事嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/89429.html
