gfortran 错误: (1) 处的格式字符串需要非负宽度
有问题的代码是这样的:
subroutine PG_TLab_Write(c30,r,d)
implicit none
character*30 c30,leftjust
real*4 r
integer*4 d,k
if (d.eq.0) then
write(c30,'(i30)') nint(r)
elseif (d.gt.0) then
write(c30,'(f30.<d>)') r
else
k = abs(d)
write(c30,'(1pe30.<k>') r
endif
c30 = leftjust(c30)
if (d.lt.0) then
k = index(c30,'E')
c30 = c30(1:k-1)//'x10\\u'//c30(k+1:24)
endif
return
end
它确实是旧的(坏的)代码,而且我不是 Fortran 程序员。 它给出的错误如下:
Error: Nonnegative width required in format string at (1) pg-util.f:561.26:
它给出了段中最后 2 个写入语句的错误。
我的问题是如何制作 d 和 k 无符号整数以便它可以编译?
The code in question is this:
subroutine PG_TLab_Write(c30,r,d)
implicit none
character*30 c30,leftjust
real*4 r
integer*4 d,k
if (d.eq.0) then
write(c30,'(i30)') nint(r)
elseif (d.gt.0) then
write(c30,'(f30.<d>)') r
else
k = abs(d)
write(c30,'(1pe30.<k>') r
endif
c30 = leftjust(c30)
if (d.lt.0) then
k = index(c30,'E')
c30 = c30(1:k-1)//'x10\\u'//c30(k+1:24)
endif
return
end
It's really old (bad) code, and I'm not a fortran programmer.
The error it gives is the following:
Error: Nonnegative width required in format string at (1) pg-util.f:561.26:
It gives errors on the last 2 write statements in the segment.
My question is how do I make d and k unsigned integers so it will compile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能使 d 和 k 无符号,因为 Fortran 没有无符号整数。
我的猜测是,假设错误消息中的第 561 行指的是您发布的代码片段中的倒数第二行,问题出在变量格式表达式(事物)中。变量格式表达式是 gfortran 不支持的标准扩展。请参阅gfortran 手册中有关变量格式表达式的部分示例如何以符合标准的方式做等效的事情。
You can't make d and k unsigned since Fortran does not have unsigned integers.
My guess, assuming that line 561 in the error message refers to the next-to-last line in the snippet you posted, is that the problem is in the variable format expression (the <k> thing). Variable format expressions is an extension to the standard which is not supported by gfortran. See the section about variable format expressions in the gfortran manual for an example how to do the equivalent thing in a standard conforming way.