开发者

problem using formatted Fortran `write(6,*)` output

开发者 https://www.devze.com 2023-02-19 04:48 出处:网络
I\'m currently porting an application from Fortran to C and need to output some variables to compare results. I\'m very new to Fortran, and although i understand the code and have now ported several t

I'm currently porting an application from Fortran to C and need to output some variables to compare results. I'm very new to Fortran, and although i understand the code and have now ported several thousand lines, I'm a noob at writing Fortran code myself.

This code:

  write(6,'(A,I3,A,E12.8,A,E12.8,A,E12.8,A,E12.8,A,E12.8)') 'iHyd:',
 &     ih,'; dzdr: ',dzdr,'; tauray:', tauRay,'; zRay: ',
 &     zray,'; ampRay: ',realpart(aray),'+j*',
 &     imagpart(aray),'; qRay: ',qray,'; width :',w

Compiles fine, but when run, the program exits with:

At line 296 of file calcpr.for (unit = 6, file = 'stdout')  
Fortran runtime error: Expected INTEGER for item 15 in formatted transfer, got REAL  
(A,I3,A,E12.8,A,E12.8,A,E12.8,A,E12.8,A,E12.8)  
   ^  
 q0:    1432.3944878270595     
 nArrayR:                   501 nArrayZ:                   201
iHyd:  1; dzdr: ************; tauray:************; zRay: ************; ampRay:          NaN+j*         NaN
; qRay: 

Besides being really ugly, it doesn't make much sense to me, as ìh is dec开发者_如何转开发lared as integer*8 and not as real.

So how can i solve this?


I'm counting 6 character&variable specifications in the format statement, but you're printing 8 of them.

edit:

a nicer use of the format statement would be '(A,I3,7(A,E12.8))'


Fortran "recycles" the format if there are more things to be printed than specified in the format statement. If a write statement gives results you don't understand, to diagonose the problem it may be helpful to remove the things printed one at a time until the error goes away.


It says "item 15", which I would take to be down near the end of your list, not ih at the beginning. It's clear that both "w" and "qray" are being printed as REAL; is either one of them an INTEGER? You may need to change the format specifier then.

0

精彩评论

暂无评论...
验证码 换一张
取 消