Error: Nonnegative width required in format string at (1)

匿名 (未验证) 提交于 2019-12-03 02:11:02

问题:

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?

回答1:

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.



回答2:

As already answered, you need to specify widths. Something like ES14.5 might work well for the floating point format. There is a short cut for the integer format: I0 will cause the compiler to use the number of digits needed.



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