带有数字/标签的Fortran IF语句而不是其他语句 [英] Fortran IF statement with numbers/labels rather than another statement

查看:876
本文介绍了带有数字/标签的Fortran IF语句而不是其他语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个Fortran代码是什么意思:

  IF(J1-3)20,20,21 
21 J1 = J1-3
20 IF(J2-3)22,22,23
23 J2 = J2- 3
22继续

我在旧项目中看到过,我不知道这个IF如何用数字(标签)表示。

解决方案

这是 arithmetic if 语句。改编自FORTRAN 77规范(重点介绍):


算术 IF 语句的形式为:

IF(e)s1,s2,s2




  • 其中: e 是一个整数,实数或双精度表达式


  • s1 s2 s3 都是出现在同一个程序中的可执行语句的语句标签m单位作为算术 IF 语句。相同的语句标签可能会在同一个算法 IF 语句中出现多次。


    执行算术 IF 语句会导致评估表达式 e ,然后传递控制权。 s1 s2 s3 ,因为 e 的值分别小于零,等于零或大于零。


对于你问题中的例子,从上面的最后一句话来看,


  • 如果 J1-3<如果 J1-3 = 0 语句20也将被执行

  • / li>
  • 如果 J1-3> 0 语句21将被执行



编辑:现代化和更多如果(J1-3> 0)J1 = J1-3
,则可读的方式如下:

  if如果(J2-3> 0)J2 = J2  -  3 


What does this Fortran code mean:

   IF (J1-3) 20, 20, 21
21 J1 = J1 - 3
20 IF (J2-3) 22, 22, 23
23 J2 = J2 - 3
22 CONTINUE

I've seen in old project and I don't have any idea what this IF with numbers (labels) means.

解决方案

This is an arithmetic if statement from FORTRAN 77. Adapted from the FORTRAN 77 specification (emphasis mine):

The form of an arithmetic IF statement is:

IF (e) s1 , s2 , s2

  • where: e is an integer, real, or double precision expression

  • s1, s2, and s3 are each the statement label of an executable statement that appears in the same program unit as the arithmetic IF statement. The same statement label may appear more than once in the same arithmetic IF statement.

Execution of an arithmetic IF statement causes evaluation of the expression e followed by a transfer of control. The statement identified by s1, s2, or s3 is executed next as the value of e is less than zero, equal to zero, or greater than zero, respectively.

For the example in your question, from the last sentence above,

  • If J1-3 < 0 statement 20 will be executed
  • If J1-3 = 0 statement 20 will also be executed
  • If J1-3 > 0 statement 21 will be executed

Edit: A modern and much more readable way to write this would be:

if (J1-3 > 0) J1 = J1 - 3
if (J2-3 > 0) J2 = J2 - 3

这篇关于带有数字/标签的Fortran IF语句而不是其他语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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