Question

I am trying to compile some Fortran code and I get the following errors,

WRITE(1,FMT='(A,I)') ' ncoefs= ',NFOUR  
                1
Error: Nonnegative width required in format string at (1)

and

WRITE(1,FMT='(A,100(F4.1,","))') ' spabnd= ',(SPABND(I),I=1,NLYR+1
                                                       1
Error: Expected a right parenthesis in expression at (1)

The weird thing about this second error is that in the actual code I have a bracket on the end of this expression, i.e., (SPABND(I),I=1,NLYR+1) is what it looks like.

Was it helpful?

Solution

The first one is self-explaining, use I0 or some positive number to set the field width. That is the number of characters that will be used to write the variable. Width 0 means the minimum number necessary to fit the value will be used. The A descriptor can be left as it is. In Fortran 2008 g0 also works.

In the other case it seems that you exceeded the maximum line length. It is 72 characters in fixed-form and 132 characters in free-form. Try to split the line and use proper line continuation according to the source form.

OTHER TIPS

The second code fragment can be written more concisely as

WRITE(1,FMT='(A,100(F4.1,","))') ' spabnd= ',SPABND(1:NLYR+1)

or

WRITE(1,FMT='(A,100(F4.1,","))') ' spabnd= ',SPABND(:NLYR+1)

if the lower bound or array SPABND is 1, as is usually the case in Fortran. The problem with your code likely has to do with line length, as Vladimir F wrote, but using more concise idioms is one way to avoid such errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top