[Fortran] 纯文本查看 复制代码
Program Getdata
Implicit None
Character(len=125)::str
Real*8,Allocatable::bands1(:),bands2(:),bands3(:),bands4(:),bands5(:),bands6(:),&
bands7(:),bands8(:),kpoint1(:),kpoint2(:),kpoint3(:)
Integer::i,ierr,count,n
Open(11,file=' 123.txt' )
Open(12,file=' shuju.txt' )
count=0
Do
Read(11," ( a125 ) ",iostat=ierr) str
If(ierr/=0) Exit
If( str(11:13)== 'k = ' ) Then
count=count+1
End If
End Do
Allocate(bands1(count))
Allocate(bands2(count))
Allocate(bands3(count))
Allocate(bands4(count))
Allocate(bands5(count))
Allocate(bands6(count))
Allocate(bands7(count))
Allocate(bands8(count))
Allocate(kpoint1(count))
Allocate(kpoint2(count))
Allocate(kpoint3(count))
Rewind(11)
i=1
Do
Read(11,' (a125) ' ,iostat=ierr) str
If(ierr/=0) Exit
If(str(11:13)== 'k =' ) Then
Read(str(14:35),*) kpoint1(i),kpoint2(i),kpoint3(i)
Read(11,*)
Read(11,' (a125) ',iostat=ierr) str
Read(str(5:75),*) bands1(i),bands2(i),bands3(i),bands4(i),&
bands5(i),bands6(i),bands7(i),bands8(i)
i=i+1
End If
End Do
Do i=1,count
Write(12,"(a3,3f7.4,1x,a9,8(f7.4,1x)) ") 'k=',kpoint1(i),kpoint2(i),kpoint3(i),'bands(ev) ',&
bands1(i),bands2(i),bands3(i),bands4(i),bands5(i),bands6(i),bands7(i),bands8(i)
End Do
Close(11)
Close(12)
End Program Getdata