Avoid newline in list-directed output with Intel Fortran compiler

ぃ、小莉子 提交于 2019-12-18 07:45:06

问题


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.


回答1:


Since verson 14, intel fortran compiler has the wrap-margin function. By default, the record is wrapped after 80 characters. For disabling this restriction, you should specify:

on Linux: -no-wrap-margin

on WIndows: /wrap-margin-

See more on Intel Fortran's reference guide




回答2:


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.




回答3:


Look into edit descriptors in your favorite Fortran book or online documentation. You can use fmt specifier in the write statement to specify edit descriptors. For example:

write(*,fmt='(5(F6.4,3X))') (r1(i), i =1,5)

should output something similar to:

3.1623   4.4721   5.4772   6.3246   7.0711   



回答4:


See https://software.intel.com/en-us/forums/topic/401555

Specify FORT_FMT_RECL or use write (,"(G0,1X))"



来源:https://stackoverflow.com/questions/17407232/avoid-newline-in-list-directed-output-with-intel-fortran-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!