本文介绍了使用格式化的Fortran`write(6,*)`输出时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将应用程序从Fortran移植到C,并且需要输出一些变量以比较结果.我对Fortran还是很陌生,尽管我了解代码并已移植了几千行,但我自己编写Fortran代码还是菜鸟.
这段代码:

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: 

除了真的很丑外,对我来说这没有多大意义,因为ìh被声明为integer*8而不是real.

Besides being really ugly, it doesn't make much sense to me, as ìh is declared as integer*8 and not as real.

那我该如何解决呢?

推荐答案

我在format语句中计算了6个字符和可变规范,但您要打印其中的8个.

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

更好地使用format语句是'(A,I3,7(A,E12.8))'

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

这篇关于使用格式化的Fortran`write(6,*)`输出时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 07:22