我用Fortran代碼,在我的輸入文件看起來像這樣的工作:跳過空行用Fortran
...
Binning n: 4, "Si2-Events", Event #: 12, Primary(s) weight 1.0000E+00
Number of hit cells: 3
488534 4.23038400E-05 489533 1.50734719E-04 489534 5.79968946E-05
Binning n: 4, "Si2-Events", Event #: 13, Primary(s) weight 1.0000E+00
Number of hit cells: 2
477500 3.04398331E-04 478500 1.13192732E-06
Binning n: 4, "Si2-Events", Event #: 14, Primary(s) weight 1.0000E+00
Number of hit cells: 2
512496 1.32522946E-05 513496 2.86743394E-04
Binning n: 4, "Si2-Events", Event #: 15, Primary(s) weight 1.0000E+00
Number of hit cells: 2
476539 1.95245666E-04 476540 2.37216373E-05
Binning n: 4, "Si2-Events", Event #: 16, Primary(s) weight 1.0000E+00
Number of hit cells: 9
502533 1.26090490E-05 502534 1.00212252E-04 503527 3.07000097E-04 503528 9.53662311E-06 503529 9.42530642E-06 503530 1.07992764E-05 503531 1.26466557E-05 503532 1.68176994E-05 503533 1.18242851E-05
...
換句話說,我有很多很多行的文件,每個顯示單元第三排的數量和能量,例如
488534 4.23038400E-05 489533 1.50734719E-04 489534 5.79968946E-05
我想寫一個Fortran代碼,只讀取此行,並寫入到輸出文件兩個colums細胞數量和能量,像
Line 1
Cells 488534
489533
489534
Energy
4.23038400E-05
1.50734719E-04
5.79968946E-05
Line 2
Cells 477500
478500
Energy 3.04398331E-04
1.13192732E-06
etc...
的問題是,數的細胞因行而異。 如何在讀取所有值時跳至下一行?
這裏是我測試出代碼的一點點:
open (unit=7, file="Si1.txt", action="read", access="sequential")
open (unit=8, file="output.txt", action="write")
do i = 1, 900
read (7,*) line1
read (7,*) line2
read (7,*) cell1, energy1, cell2, energy2
write(8,*) "Run = ", i, "and cells = ", cell1, cell2, "and energy = ", energy1, energy2
end do
問題是,這只是因爲有該行的兩個或多個值,而不是如果這是不到兩年的工作時間長達。
我有點失落(可能是一個noob在這裏),但有關如何使這項工作的任何建議?
非常感謝您的幫助! 它現在有效! – Daniel