Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

io - Avoid newline in list-directed output with Intel Fortran compiler

I have noticed the results of list-directed output write(*,*) in Fortran is compiler dependent.

Indeed, with the code:

program one
real(8), dimension(5):: r1
do i=1,5
    r1(i)=sqrt(i*10.0)
end do
write(*,*) (r1(i), i =1,5)
end program one

intel compiler ifort gives standard output broken by a newline:

   3.16227769851685        4.47213602066040        5.47722530364990     
   6.32455539703369        7.07106781005859     

while gfortran gives the equivalent one line result:

    3.1622776601683795        4.4721359549995796        5.4772255750516612        6.3245553203367590        7.0710678118654755     

I think that ifort is writing maximum 3 items per line (when floating real numbers). Is there any way to make the ifort output be like gfrotran, i.e. avoid the newline? Ideally, I would like to keep list-directed output (*,*) instructions, so I am looking for something like a compiler option or so, if any.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. List-directed (free-format) output provides convenience, but you give up control. Various aspects of the output are unspecified and allowed to be chosen to the compiler. If you want full control, you have to use formatted output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...