# [FORTRAN] Runtime error

• Fortran
Gold Member

## Main Question or Discussion Point

Hi guys, I've been tinkering with this code for a while now, as you probably have seen from my other threads. Right now I am working on changing the code around so that it actually writes out the correct output instead of the old output.

I am getting this runtime error:
Code:
At line 2057 of file bulb-new.F90 (unit = 6, file = 'stdout')
Fortran runtime error: Expected INTEGER for item 26 in formatted transfer, got REAL
(a1,f15.10,i5,1p,20e15.7)
^
The code that is around line 2057 is this:
Code:
write(6,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor2,1:nflavor2)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor2,1:nflavor2)
close(7)
Now, I basically just copy-pasted this code from a previous iteration, so I don't know really what all those formatting things mean. The previous iteration worked fine and did not give this error. The part that I copy pasted looks like this in the previous iteration:

Code:
write(6,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
close(7)
As you can see, it is nearly identical except instead of printing xsum and xsumbar which are two nflavor by nflavor matrices, I have replaced it with printing an xsum that has been expanded to a nflavor2 by nflavor2 matrix (nflavor2=nflavor*2). So instead of printing 18 numbers, it should print 36 numbers.

Can anyone shed some light on what's happening? Maybe having a bigger matrix to print out is a problem?

Related Programming and Computer Science News on Phys.org
jedishrfu
Mentor
Not sure if this is right but the 20e15.7 format code maybe it needs to be increased?

Doesn't the 20 represent the number of columns of 15.7 formatted numbers?

Gold Member
Not sure if this is right but the 20e15.7 format code maybe it needs to be increased?

Doesn't the 20 represent th number of columns of 15.7 formatted number?
What do you mean by columns of 15.7? I really have no idea what that means...I definitely will look it up, but, the little carat in the terminal was pointing at the "i5" so I thought the error was there?
The problem is, the online resources on formatting the write statement...is not super helping me all that much here lol.

Last edited:
jedishrfu
Mentor
As I look at the formatting I see a1 for the 'x' and f15.10 for the r and i5 for the iter and 1p for dr and error and xsum are covered by the 20f15.7 and you said the original printed 18 values and so now you've doubled that to 36 so you haven't increased the format code for those added fields right?

Gold Member
As I look at the formatting I see a1 for the 'x' and f15.10 for the r and i5 for the iter and 1p for dr and error and xsum are covered by the 20f15.7 and you said the original printed 18 values and so now you've doubled that to 36 so you haven't increased the format code for those added fields right?
Yeah, I did not mess around with the formatting at all. The original has xsum+xsumbar being 18 values, and now I have a 36 valued xsum to print. I tried expanding to 36 and now the code is running...so...we'll see...? but maybe I should change it to 38?

jedishrfu
Mentor
I'd use 40 but to be accurate you have 1+36 values if you include the err field right?

Gold Member
I'd use 40 but to be accurate you have 1+36 values if you include the err field right?
How do you get 40 from 36+1?

What I guessed was before there were 18 values, and there was a "20" there, so I was guessing the write statement was taking into account 2 extra slots...for something...so I guessed 36+2=38 is what I should have.

But, now that I think about it, shouldn't the original code have 19? 1 for err and 18 for the 18 values inside xsum and xsumbar?

jedishrfu
Mentor
You can over specify formatted fields as then they don't get used and there's no error.

Gold Member
You can over specify formatted fields as then they don't get used and there's no error.
Ah! Thanks for that info! I will definitely put a little room for error then. I stopped the run and there was definitely some errors in the writing because I could no longer open the output file in gedit lol.

jedishrfu
Mentor
Yes, isn't programming wonderful? The simplest change can result in hours of trying to find why it didn't work.

Gold Member
Yes, isn't programming wonderful? The simplest change can result in hours of trying to find why it didn't work.
I have to say that I am learning quite a bit of programming from working this code...but it's definitely not my favorite thing in the world...

SteamKing
Staff Emeritus
Homework Helper
I am getting this runtime error:
Code:
At line 2057 of file bulb-new.F90 (unit = 6, file = 'stdout')
Fortran runtime error: Expected INTEGER for item 26 in formatted transfer, got REAL
(a1,f15.10,i5,1p,20e15.7)
^
The code that is around line 2057 is this:
Code:
write(6,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor2,1:nflavor2)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor2,1:nflavor2)
close(7)
Now, I basically just copy-pasted this code from a previous iteration, so I don't know really what all those formatting things mean. The previous iteration worked fine and did not give this error. The part that I copy pasted looks like this in the previous iteration:

Code:
write(6,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,20e15.7)')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
close(7)
As you can see, it is nearly identical except instead of printing xsum and xsumbar which are two nflavor by nflavor matrices, I have replaced it with printing an xsum that has been expanded to a nflavor2 by nflavor2 matrix (nflavor2=nflavor*2). So instead of printing 18 numbers, it should print 36 numbers.

Can anyone shed some light on what's happening? Maybe having a bigger matrix to print out is a problem?
I think you have to be careful and make sure the number of items in the output list of the WRITE statement matches the edit descriptors in the corresponding format string.

For example, you have specified 20 e15.7 fields to output the values of the XSUM and XBARSUM arrays. If you increase the number of array items you wish to output by changing the dimension of these arrays without changing the number of fields allocated in the format string, the WRITE statement will attempt to output the extra data by going back to the initial edit descriptor in the format string. This may not cause a problem until you try to write a floating point number using an I5 descriptor, which I think is why you are getting this particular error message.

Based on your comments about this problem, it is not clear if you are intending to print out all the values in the XSUM and XBARSUM arrays or just certain values. Normally, an implied DO loop would be used to print the values in an array in whole or in part.

Since your format string contains descriptors for printing single variables, the method normally used to force the formatting of an implied DO loop to start at a particular location in the format string is to enclose the repeated edit descriptors within another set of parentheses, in order to keep the format string from defaulting back to the initial edit descriptor if the number of output variables exceeds the number of edit descriptors.

For example,

Code:
write(6,'(a1,f15.10,i5,1p,(20e15.7))')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,(20e15.7))')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
close(7)
adding the extra set of parentheses around the 20E15.7 edit descriptor means that when 20 fields have been printed and more values are to be output, an additional set of 20 fields with the E15.7 descriptor will be printed, rather than rewinding all the way back to the A1 descriptor.

The FORMAT statement is one of the trickier statements to master in learning Fortran, but it can provide a flexible means of printing formatted data when it is learned. It might be better to experiment with a small program which does nothing but print various output so that you can get a feel for how the various features of the FORMAT statement interact with corresponding READ or WRITE statements. It may also help to use numbered FORMAT statements which stand separately from the READ or WRITE statements where the input or output is done.

Gold Member
I think you have to be careful and make sure the number of items in the output list of the WRITE statement matches the edit descriptors in the corresponding format string.

For example, you have specified 20 e15.7 fields to output the values of the XSUM and XBARSUM arrays. If you increase the number of array items you wish to output by changing the dimension of these arrays without changing the number of fields allocated in the format string, the WRITE statement will attempt to output the extra data by going back to the initial edit descriptor in the format string. This may not cause a problem until you try to write a floating point number using an I5 descriptor, which I think is why you are getting this particular error message.

Based on your comments about this problem, it is not clear if you are intending to print out all the values in the XSUM and XBARSUM arrays or just certain values. Normally, an implied DO loop would be used to print the values in an array in whole or in part.

Since your format string contains descriptors for printing single variables, the method normally used to force the formatting of an implied DO loop to start at a particular location in the format string is to enclose the repeated edit descriptors within another set of parentheses, in order to keep the format string from defaulting back to the initial edit descriptor if the number of output variables exceeds the number of edit descriptors.

For example,

Code:
write(6,'(a1,f15.10,i5,1p,(20e15.7))')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
open(unit=7,file='status')
write(7,'(a1,f15.10,i5,1p,(20e15.7))')'x',r,iter,dr,err, &
&  xsum(1:nflavor,1:nflavor),xbarsum(1:nflavor,1:nflavor)
close(7)
adding the extra set of parentheses around the 20E15.7 edit descriptor means that when 20 fields have been printed and more values are to be output, an additional set of 20 fields with the E15.7 descriptor will be printed, rather than rewinding all the way back to the A1 descriptor.

The FORMAT statement is one of the trickier statements to master in learning Fortran, but it can provide a flexible means of printing formatted data when it is learned. It might be better to experiment with a small program which does nothing but print various output so that you can get a feel for how the various features of the FORMAT statement interact with corresponding READ or WRITE statements. It may also help to use numbered FORMAT statements which stand separately from the READ or WRITE statements where the input or output is done.
This is useful information. Thanks! By changing 20 to 38, the code runs fine now and prints the correct values. :)