Fortran Coder

xyz数据当中最后3列有0的部分不写入,但是其它部分正常写入

查看数: 10317 | 评论数: 2 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2015-11-24 10:57

正文摘要:

如题,我想让最后3列数据中,只要有数字0的就不输入到另一个文件中,比如正文第二行 1  C      6.079287   -0.155411   16.237832    82    ...

回复

978142355 发表于 2015-11-24 14:30:06
fcode 发表于 2015-11-24 12:26
也许这个代码是你需要的

[mw_shl_code=fortran,true]Program removezero

老大,这确实是我所需要的,还是你厉害啊。我在你写的这个代码中,有一项我不太懂,那就是pack(z,z/=0),虽然我也猜到了它的用途,不过它具体的用法和意思是什么?
fcode 发表于 2015-11-24 12:26:31
也许这个代码是你需要的

[Fortran] 纯文本查看 复制代码
01Program removezero
02Implicit none
03Integer::i,j
04Character(len=20)::name,name1,name2,name3(2),name4(1)
05Real(kind=kind(0.0d0))::a,b,c
06Integer::d,e,f,g,h,k,ierr
07write(*,*) 'Input the name of xyz:'
08Read(*,*) name
09name1=trim(adjustl(name))//'.xyz'
10name2=trim(adjustl(name))//'1.xyz'
11Open(12,file=name1)
12Open(13,file=name2)
13 
14Do i=1,1
15    read(12,*) name3(1),name3(2)
16    write(13,"(2x,a,2x,a)") trim(name3(1)),trim(name3(2))
17End Do
18 
19Do
20    read(12,*,iostat=ierr) k,name4(1),a,b,c,d,e,f,g,h
21    If(ierr==0) then
22        If (f==0 .or. g==0 .or. h==0 ) cycle
23        write(13,"(2x,I4,2x,a2,2x,F12.6,f12.6,f12.6,2x,I4,2x,I4,2x,I4,2x,I4,2x,I4)")k,&
24        trim(name4(1)),a,b,c,d,e,f,g,h
25    End if
26    If(ierr/=0) exit
27End Do
28Read(*,*)
29Close(12)
30Close(13)
31End

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2025-5-5 06:49

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

快速回复 返回顶部 返回列表