Fortran返回语句 [英] Fortran return statement

查看:573
本文介绍了Fortran返回语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在gfortran下编译一些在g77下编译好的代码。这个问题似乎来自一个return语句:

ffuncs.f:934.13:

  RETURN E 
1

错误:在(1)需要一个SCALAR-INTEGER返回说明符

在代码中,任何东西E被指定为真实的* 8:



IMPLICIT REAL * 8(A - H,O - Z)

然而,E从来没有被赋予任何价值或事实上,直到返回语句才会看到它。我对fortran几乎一无所知。

谢谢。

解决方案<在FORTRAN中(我非常熟悉Fortran 77), RETURN n 不用于返回函数值;相反,它会像其他语言中的异常处理一样:退出到正常的代码位置。



您通常会调用这样的一个 SUBROUTINE FUNCTION 标签作为参数,例如



<$ $'$ $ $'$ $ $ $ $ $ $ $ $ $ $ $'$'$ $ $ $'$'$'$'$' 2'

如果MYSUB中出现错误,则您执行 RETURN 1 RETURN 2 (而不是普通的RETURN),你可以在调用例程中直接跳到标签998或999。



这就是为什么通常你需要一个返回的整数 - 它不是一个值,而是一个你想要的错误出口的索引。



RETURN E 对我来说听起来不对。除非有一种我不知道的语法,否则以前的编译器应该将其标记为错误。


I'm trying to get some code compiled under gfortran that compiles fine under g77. The problem seems to be from a return statement:

ffuncs.f:934.13:

  RETURN E
         1

Error: Alternate RETURN statement at (1) requires a SCALAR-INTEGER return specifier

In the code anything E was specified as real*8:

IMPLICIT REAL*8 ( A - H , O -Z )

However, E was never given a value or anything in fact you never see it until the return statement. I know almost nothing about fortran. What is the meaning of a return statement with an argument in fortran?

Thanks.

解决方案

In FORTRAN (up to Fortran 77, which I'm very familiar with), RETURN n is not used to return a function value; instead, it does something like what in other languages would be handled by an exception: An exit to a code location other than the normal one.

You'd normally call such a SUBROUTINE or FUNCTION with labels as arguments, e.g.

  CALL MYSUB(A, B, C, *998, *999)
...
998 STOP 'Error 1'
998 STOP 'Error 2'

and if things go wrong in MYSUB then you do RETURN 1 or RETURN 2 (rather than the normal RETURN) and you'd be hopping straight to label 998 or 999 in the calling routine.

That's why normally you want an integer on that RETURN - it's not a value but an index to which error exit you want to take.

RETURN E sounds wrong to me. Unless there's a syntax I'm unaware of, the previous compiler should have flagged that as an error.

这篇关于Fortran返回语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆