Error: Unexpected end of format string in format string in Fortran

你离开我真会死。 提交于 2019-12-02 08:59:29

问题


Getting this error while trying to compile a copied code from a Fortran 77 program.

code:

900 FORMAT(1H0,2X,'ABSOLUTE GRID LIMITS FOR DATA RETENTION FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, /3X,'WITH AZIMUTH LIMITS OF',2F8.2, 3X,'AND RANGE LIMITS OF',2F10.3,/)

compiler error:

messy21.f90:529.132:

N FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, /3X,(1)

Error: Unexpected end of format string in format string at (1)

I am not sure what the error means.


回答1:


My guess (on the basis of error position in the line, 132) would be: starting from Fortran 90 we use free source form (free-form source input). Each line may contain up to 132 character. And if your statement is even bigger you can use up to 39 (255 in current Fortran 2003 standard) continuation lines. Fortran 77 used fixed source form which is just another story.

Use so-called continuation mark (&) to divide your very long FORMAT statement, i.e.

900 FORMAT(1H0,2X,'ABSOLUTE GRID LIMITS FOR DATA RETENTION FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, &
/3X,'WITH AZIMUTH LIMITS OF',2F8.2, 3X,'AND RANGE LIMITS OF',2F10.3,/)

Read some Fortran 90/95/2003 book or associated section of Fortran standard. For example, in Fortran 2003 Standard (Final Committee Draft, PDF, 5MB) section "3.3 Source form" contains relevant information.




回答2:


Your line is too long.

In free form files (.f90) you can only use 132 character lines. You can break your line and continue on the next line. Put & character at the end of the line before continuing on the next line.

In fixed form Fortran (.f .for) you can only use 72 character lines. You can break your line and continue on the next line. Put any character to the fifth column on the present line.

There are compiler options which can loosen these restrictions.



来源:https://stackoverflow.com/questions/3874385/error-unexpected-end-of-format-string-in-format-string-in-fortran

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