Fortran Coder

查看: 17255|回复: 8
打印 上一主题 下一主题

[文件读写] 将一个文件中的前几行内容放在另一个文件的前几行

[复制链接]

799

帖子

2

主题

0

精华

大宗师

F 币
3797 元
贡献
2270 点
楼主
发表于 2016-10-13 16:43:13 | 显示全部楼层
[Fortran] 纯文本查看 复制代码
program pot_head
USE IFPORT
implicit none
integer i, j, n, ierr
character(len=512) :: str = ''

open(11,file='aa.cube',status='old') 
open(12,file='temp1')
do i = 1, 10
    read(11,"(a)",iostat=ierr) str
    if(str(9:10)=='E' .or. ierr/=0) exit
		write(12,"(a)") trim(str)
end do
close(11)

open(13,file='pot.cub',status='old')
do
    read(13,"(a)",iostat=ierr) str
    if (ierr/=0) exit
    write(12,"(a)") trim(str)
end do
close(13,status='delete')
close(12)
! ivf扩展函数,改文件名
i = rename('temp1','pot.cub')
if(i==0) then 
	write(*,*) '成功'
else 
	write(*,*) '失败'
end if 
read(*,*)
end program pot_head

评分

参与人数 1贡献 +9 收起 理由
fcode + 9 李老师辛苦了

查看全部评分

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-8 13:35

Powered by Tencent X3.4

© 2013-2024 Tencent

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