Is it possible to output a variable with zero value as blank in Fortran?

你。 提交于 2019-12-02 03:39:21

No, not with a format statement, but this is reasonably easy to do by writing the values to a string and processing. Below is a demo. Probably better to put into a subroutine.

program demo

   real, dimension (6) :: values = [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ]
   character (len=100) :: string
   integer :: pos

   write (string,'( 6 (1X, F4.1 ) )' )  values
   write (55, '(A)' )  trim (string)

   MakeBlanks: do

      pos = index (string, "0.0")

      if ( pos < 1 )  exit MakeBlanks

      string (pos:pos+2) = "   "

   end do MakeBlanks

   write (55, '(A)' )  trim (string)

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