fortran90编程,要将一个原本单个处理通过循环实现批量读入、输出。在读入、输出时遇到问题
发布网友
发布时间:2022-05-20 04:30
我来回答
共1个回答
热心网友
时间:2023-10-24 07:52
给楼主编了一个
楼主可以试一试哈
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