xyz数据当中最后3列有0的部分不写入,但是其它部分正常写入
如题,我想让最后3列数据中,只要有数字0的就不输入到另一个文件中,比如正文第二行 1C 6.079287 -0.155411 16.237832 82 2 3 7 0输入到另一个文件时,变成1C 6.079287 -0.155411 16.237832 82 2 3 7
我自己尝试编写程序,但是输出的结果变成了遇到后三列为0就不写入文件中了,请教各位如何实现我说的那个功能。
Program removezero
Implicit none
Integer::i,j
Character(len=20)::name,name1,name2,name3(2),name4(1)
Real(kind=kind(0.0d0))::a,b,c
Integer::d,e,f,g,h,k,ierr
write(*,*) 'Input the name of xyz:'
Read(*,*) name
name1=trim(adjustl(name))//'.xyz'
name2=trim(adjustl(name))//'1.xyz'
Open(12,file=name1)
Open(13,file=name2)
Do i=1,1
read(12,*) name3(1),name3(2)
write(13,"(2x,a,2x,a)") trim(name3(1)),trim(name3(2))
End Do
Do
read(12,*,iostat=ierr) k,name4(1),a,b,c,d,e,f,g,h
If(ierr==0) then
If (f==0 .or. g==0 .or. h==0 ) cycle
write(13,"(2x,I4,2x,a2,2x,F12.6,f12.6,f12.6,2x,I4,2x,I4,2x,I4,2x,I4,2x,I4)")k,&
trim(name4(1)),a,b,c,d,e,f,g,h
End if
If(ierr/=0) exit
End Do
Read(*,*)
Close(12)
Close(13)
End
也许这个代码是你需要的
Program removezero
Implicit none
Character(len=64):: name
Real(kind=kind(0.0d0))::a(3)
Integer:: z(5) , k , ierr
write(*,*) 'Input the name of xyz:'
Read(*,*) name
Open(12,file=trim(adjustl(name))//'.xyz')
Open(13,file=trim(adjustl(name))//'1.xyz')
read(12,'(a64)') name
write(13,"(2x,a)") trim(name)
Do
read(12,*,iostat=ierr) k,name,a,z
If(ierr/=0) exit
write(13,"(2x,i4,2x,a2,2x,3F12.6,5(2x,I4))") &
k , trim(name) , a , pack(z,z/=0)
End Do
Read(*,*)
Close(12)
Close(13)
End Program removezero fcode 发表于 2015-11-24 12:26
也许这个代码是你需要的
Program removezero
老大,这确实是我所需要的,还是你厉害啊。我在你写的这个代码中,有一项我不太懂,那就是pack(z,z/=0),虽然我也猜到了它的用途,不过它具体的用法和意思是什么?
页:
[1]