[Fortran] 纯文本查看 复制代码
Program Readdata
Implicit None
Character (Len=64) :: str ! //修改为64
Type :: OneRec
Real (Kind=8) :: time, totenergy, poten, kinet, inter, temp
Real (Kind=8) :: pressure, density, dipole
End Type OneRec
Integer :: ierr, count, i
Type (OneRec), Allocatable :: myrec(:)
Open (10, File='mdstat.txt', Status='old')
Open (11, File='mdstat.tem', Status='unknown')
count = 0 !// 初值为 0
Do
Read (10, '(a16)', Iostat=ierr) str ! //修改为16
If (ierr/=0) Exit
If (str(1:16)==' Simulation Time') count = count + 1 ! //前面加个空格
End Do
Allocate (myrec(count))
Rewind (10)
i = 1
Do
Read (10, '(a64)', Iostat=ierr) str
If (ierr/=0) Exit
If (str(1:16)==' Simulation Time') Then
Read (str(22:), *) myrec(i)%time
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%totenergy
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%poten
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%kinet
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%inter
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%temp
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%pressure
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%density
Read (10, '(a64)', Iostat=ierr) str
Read (str(22:), *) myrec(i)%dipole
i = i + 1
End If
End Do
Do i = 1, count
Write (11, '(3x,9f14.4)') myrec(i)
End Do
End Program Readdata