Fortran Coder

查看: 14102|回复: 11
打印 上一主题 下一主题

[通用算法] 求助思路(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-5-16 04:34

Powered by Tencent X3.4

© 2013-2024 Tencent

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