Fortran Coder

标题: write格式输出中g0是什么格式 [打印本页]

作者: tianrui    时间: 2022-5-8 12:46
标题: write格式输出中g0是什么格式
网站课程语法之文件读写上中有这样一个程序
[Fortran] 纯文本查看 复制代码
Program www_fcode_cn
  Use DFile_Mod
  Implicit None
  Real , allocatable :: a(:,:)
  Character(len=512) :: cStr
  Real    :: r  
  integer :: FILE_IN , i , nRow , nCol
  Open( NewUnit = FILE_IN , File = "text.txt" )
  nRow = GetFileN( FILE_IN ) - 2 !//获得文件行数
  Read( FILE_IN , * ) !//跳过第一行
  Read( FILE_IN , * ) !//跳过第二行
  Read( FILE_IN , '(a512)' ) cStr!//读取第三行
  nCol = GetDataN( cStr ) - 1 !//获得第三行有多少列
  write( *, '("Row:",g0," Col: ",g0)' ) nRow , nCol
  Allocate( a( nCol , nRow ) )
  Backspace( FILE_IN ) !//退回到第三行
  Do i = 1 , nRow
    Read( FILE_IN , * ) r , a( : , i )
    write( * , * ) a(:,i)
  End Do
  Deallocate( a )
  Close( FILE_IN )
End Program www_fcode_cn

请问其中write( *, '("Row:",g0," Col: ",g0)' ) nRow , nCol中g0是什么输出格式,我找到format中与之对应的格式是Gw.d其中d不能省略,我把g0改成g1之后报错了,所以不明白g0是什么输出格式
希望大家能为我这个新人答疑解惑

作者: fcode    时间: 2022-5-8 13:13
g0 就是让编译器自动选择使用合适的宽度,两侧不会有多余的空格(特别适合于想紧凑的输出内容时)。




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2