错误:(1)格式字符串中所需的非负宽度 [英] Error: Nonnegative width required in format string at (1)

查看:1080
本文介绍了错误:(1)格式字符串中所需的非负宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 错误:非负数(1)
../src/powmes.f90:410.20:
write(lunit,'(I,E,E,E)')wavenum(k) (k),nmodes(k),errorexpan(k)

414 if(filepower_fold(1:1)/ ='#')then
415 fileout = trim(filepower_fold)// '.waven'
416 if(verbose)write(*,*)'Output'// trim(fileout)
417 open(file = fileout,form ='formatted',status ='unknown' ,unit = lunit,err = 2)
418 do k = 0,ngrid / 2
419 do ifold = 0,nfoldpow-1
420写(lunit,'(I,$) ')waven(k,ifold)
421 enddo
422写(lunit,'(I)')waven(k,nfoldpow)
423 enddo
424 close(lunit)

我该如何编译它?

解决方案

尝试将格式字符串 I 更改为 Iw code>其中 w 是一个正数。与 E 相同,只能使用 Ew.d

例如,此链接:
http:// www .cs.mtu.edu /〜shene / COURSES / cs201 / NOTES / chap05 / format.html



请注意:使用 I3 写出1234可能会打印 *** ,所以请确保您的格式足够宽。



编辑:请参阅@ MSB关于如何避免整数格式问题的答案。


I'm trying to compile a piece of code with gfortran and it's failing with the following error:

Error: Nonnegative width required in format string at (1)
../src/powmes.f90:410.20:
     write(lunit,'(I,E,E,E)') wavenum(k),power(k),nmodes(k),errorexpan(k)

414   if (filepower_fold(1:1) /= '#') then
415      fileout=trim(filepower_fold)//'.waven'
416      if (verbose) write(*,*) 'Output '//trim(fileout)
417      open(file=fileout,form='formatted',status='unknown',unit=lunit,err=2)
418      do k=0,ngrid/2
419         do ifold=0,nfoldpow-1
420            write(lunit,'(I,$)') waven(k,ifold)
421         enddo
422         write(lunit,'(I)') waven(k,nfoldpow)
423      enddo
424      close(lunit)

How can I compile this?

解决方案

Try changing the format string I to Iw where w is a positive number. Same with E, only use Ew.d.
For explanation see, for example, this link: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html

Beware though: using, say, I3 for writing out 1234 might print ***, so make sure your formats are wide enough.

EDIT: See @M.S.B.'s answer on how to avoid problems with integer formats.

这篇关于错误:(1)格式字符串中所需的非负宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆