program readdata
implicit none
character(len=15)::str
real*8,allocatable::time(:),kinet(:),inter(:),temp(:),dipole(:), &
totenergy(:),poten(:),k(:),pressure(:),rd(:),density(:)
integer::ierr,count,i,j
open(10,file='mdstat.txt',status='old')
open(11,file='mdstat.tem',status='unknown')
count=1
do
read(10,"(a15)",iostat=ierr) str
if(ierr/=0) exit
if (str=='Simulation Time') then
count=count+1
end if
end do
allocate(time(count))
allocate(kinet(count))
allocate(inter(count))
allocate(temp(count))
allocate(dipole(count))
allocate(totenergy(count))
allocate(poten(count))
allocate(pressure(count))
allocate(density(count))
allocate(k(count))
allocate(rd(count))
rewind(10)
do i=1,count
do j=1,3
read(10,*)
end do
read(10,200) time(i)
read(10,200) totenergy(i)
read(10,200) poten(i)
read(10,200) kinet(i)
read(10,200) inter(i)
read(10,200) temp(i)
read(10,200) pressure(i)
read(10,200) density(i)
read(10,200) dipole(i)
! if(dipole(i).gt.32.0)then
! dipole(i)=dipole(i)-4.0
! endif
! if(dipole(i).lt.16.0)then
! dipole(i)=dipole(i)+4.0
! endif
end do
200 format(22x,f14.4)
do i=1,count
write(11,"(3x,9f14.4)") time(i),totenergy(i),poten(i),kinet(i),&
inter(i), temp(i),pressure(i),density(i),dipole(i)
end do
end program readdata
625.98 KB, 下载次数: 11
读取的文件
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
深流水静水流深 发表于 2016-4-1 11:55
呵呵,大哥所言极是!
深流水静水流深 发表于 2016-4-2 22:10
天天升群旗,唱群歌~守护群
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |