fortran语言里这是什么意思

open (1,file = 'out')
write(*,*) 'input : m'
read(*,*) m
write(*,*) 'input : n'
read(*,*) n

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

温馨提示:答案为网友推荐,仅供参考
相似回答