fortran90编程,要将一个原本单个处理通过循环实现批量读入、输出。在读入、输出时遇到问题
现把我的问题简化为模型:如在D盘,Fortran文件夹下,从文件夹A里依次读入1.txt,2.txt这两个文本,将1,2文本的内容都写入文件夹B里的文件data.txt里...
现把我的问题简化为模型:
如在D盘,Fortran文件夹下,从文件夹A里依次读入1.txt,2.txt这两个文本,将1,2文本的内容都写入文件夹B里的文件data.txt里。(注:最好是严格按从A文件夹读入,输出到B文件夹,而不在同一文件夹Fortran里进行)
这个小程序应该不是很难,求高手不吝赐教!!! 展开
如在D盘,Fortran文件夹下,从文件夹A里依次读入1.txt,2.txt这两个文本,将1,2文本的内容都写入文件夹B里的文件data.txt里。(注:最好是严格按从A文件夹读入,输出到B文件夹,而不在同一文件夹Fortran里进行)
这个小程序应该不是很难,求高手不吝赐教!!! 展开
1个回答
展开全部
给楼主编了一个
楼主可以试一试哈
program main
implicit none
character(len = 79) :: temp
logical :: alive1,alive2
integer :: status = 0
inquire(file = 'D:\\Fortran\\A\\1.txt', exist = alive1)
inquire(file = 'D:\\Fortran\\A\\1.txt', exist = alive2)
open(unit = 30, file = 'D:\\Fortran\\B\\data.txt')
if(alive1) then
open(unit = 10, file = 'D:\\Fortran\\A\\1.txt', &
access = 'sequential', status = 'old')
do while(.true.)
read(unit = 10, fmt ="(A79)", iostat = status) temp
if(status /= 0) exit
write(30,"(A79)") temp
end do
else
write(*,*) "D:\\Fortran\\A\\1.txt", "doesn't exist"
end if
if(alive2) then
open(unit = 20, file = 'D:\\Fortran\\A\\2.txt', &
access = 'sequential', status = 'old')
do while(.true.)
read(unit = 20, fmt ="(A79)", iostat = status) temp
if(status /= 0) exit
write(30,"(A79)") temp
end do
else
write(*,*) "D:\\Fortran\\A\\2.txt", "doesn't exist"
end if
close(10,status = 'KEEP' )
close(20,status = 'KEEP' )
close(30,status = 'KEEP' )!关闭并保持三个文件
stop
end program main
楼主可以试一试哈
program main
implicit none
character(len = 79) :: temp
logical :: alive1,alive2
integer :: status = 0
inquire(file = 'D:\\Fortran\\A\\1.txt', exist = alive1)
inquire(file = 'D:\\Fortran\\A\\1.txt', exist = alive2)
open(unit = 30, file = 'D:\\Fortran\\B\\data.txt')
if(alive1) then
open(unit = 10, file = 'D:\\Fortran\\A\\1.txt', &
access = 'sequential', status = 'old')
do while(.true.)
read(unit = 10, fmt ="(A79)", iostat = status) temp
if(status /= 0) exit
write(30,"(A79)") temp
end do
else
write(*,*) "D:\\Fortran\\A\\1.txt", "doesn't exist"
end if
if(alive2) then
open(unit = 20, file = 'D:\\Fortran\\A\\2.txt', &
access = 'sequential', status = 'old')
do while(.true.)
read(unit = 20, fmt ="(A79)", iostat = status) temp
if(status /= 0) exit
write(30,"(A79)") temp
end do
else
write(*,*) "D:\\Fortran\\A\\2.txt", "doesn't exist"
end if
close(10,status = 'KEEP' )
close(20,status = 'KEEP' )
close(30,status = 'KEEP' )!关闭并保持三个文件
stop
end program main
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询