fortran语言里a(1)和a(2),代表什么意思啊,有什么区别啊?
2个回答
展开全部
I was so surprised to find there is still the one who makes fortran language alive!!!
That's good news for me at least.
I am here to try fortran 95 to explain your question (assumed you use this version other rather 77) under linux OS environment.
For more detail in I/O statement, fortran documentation is always a good place to give it a go!
[open] ---> open a file called 'out' and mark it as integer 1.
[write] ---> write a string 'input: m' into file 'out' supposed, despite 1 should replace *.
[read] ---> read the content from your target file, which is supposed to be file marked as 1
for the sake of better understanding fortran I/O statement, I wrote a sample code combined with above command.
program write4read
implicit none
!
integer, parameter :: n=4;
integer :: i;
integer, dimension(1:n) :: a;
!
open(unit=10,file='data.txt',status='old')
! |
! |--- file status
! |--- existed file
open(unit=20,file='data-copy.txt',status='new')
! |
! |--- file status
! |--- new file
do i=1,n
read(10,100) a(i)
! read 'data.txt'
!
write(20,100) a(i)
! write a(i) into 'data-copy.txt'
print*, a(i)
! print a(i) on terminal screen
!
100 format (I3)
enddo
!
close(10)
! close 'data.txt'
!
close(20)
! close 'data-copy.txt'
!
end program write4read
Before you run this code, just ensure you save 'data.txt' file in the same directory of this fortran code.
'data.txt'
123
234
345
456
The running result should display as
That's good news for me at least.
I am here to try fortran 95 to explain your question (assumed you use this version other rather 77) under linux OS environment.
For more detail in I/O statement, fortran documentation is always a good place to give it a go!
[open] ---> open a file called 'out' and mark it as integer 1.
[write] ---> write a string 'input: m' into file 'out' supposed, despite 1 should replace *.
[read] ---> read the content from your target file, which is supposed to be file marked as 1
for the sake of better understanding fortran I/O statement, I wrote a sample code combined with above command.
program write4read
implicit none
!
integer, parameter :: n=4;
integer :: i;
integer, dimension(1:n) :: a;
!
open(unit=10,file='data.txt',status='old')
! |
! |--- file status
! |--- existed file
open(unit=20,file='data-copy.txt',status='new')
! |
! |--- file status
! |--- new file
do i=1,n
read(10,100) a(i)
! read 'data.txt'
!
write(20,100) a(i)
! write a(i) into 'data-copy.txt'
print*, a(i)
! print a(i) on terminal screen
!
100 format (I3)
enddo
!
close(10)
! close 'data.txt'
!
close(20)
! close 'data-copy.txt'
!
end program write4read
Before you run this code, just ensure you save 'data.txt' file in the same directory of this fortran code.
'data.txt'
123
234
345
456
The running result should display as
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询