Fortran Coder

楼主: hpa
打印 上一主题 下一主题

[通用算法] 求助思路(Fortran函数)

[复制链接]

812

帖子

2

主题

0

精华

大宗师

F 币
3841 元
贡献
2290 点
板凳
发表于 2020-3-1 11:08:02 | 只看该作者
如果是为了练习fortran,没问题。实际应用中,这个功能没意义,很多编辑器都可以显示行号,也可以连同行号一起复制,粘贴到其他位置。

2

帖子

0

主题

0

精华

新人

F 币
17 元
贡献
7 点
沙发
发表于 2020-3-1 10:06:06 | 只看该作者
彭国伦书上有一个程序可以给文件的每一行添加行号,可供你参考,程序如下:
[Fortran] 纯文本查看 复制代码
program ex0909
implicit none
integer,parameter :: inputfileid=10,outputfileid=11
integer,parameter :: maxbuffer=200
character(len=80) :: inputfile,outputfile
character(len=maxbuffer) buffer
integer count
integer error
logical alive

write(*,*) "Input Filename: "
read(*,"(A80)") inputfile
write(*,*) "Output Filename: "
read(*,"(A80)") outputfile

inquire(file=inputfile,exist=alive)
if(.not. alive) then
    write(*,*) trim(inputfile), " doesn't exist."
    stop
end if

open(unit=inputfileid,file=inputfile,status="old")
open(unit=outputfileid,file=outputfile,status="replace")
count=1
do while(.true.)
    read(inputfileid,"(A200)",iostat=error) buffer
    if(error/=0) exit
    write(outputfileid,"(I3,'. ',A)") count,trim(buffer)
    count=count+1
end do
close(inputfileid)
close(outputfileid)
pause
stop
end program ex0909
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-6-11 06:46

Powered by Tencent X3.4

© 2013-2024 Tencent

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