简体   繁体   English

在Fortran中将DO和IF组合在一起时出错

[英]An error combining DO and IF in Fortran

This is a part of code that I am writing in Visual FORTRAN 6.6A: 这是我在Visual FORTRAN 6.6A中编写的代码的一部分:

  .
  .
  .
   DO 24 I=1,80
24 IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN
      ARRAY(1)=C1*0.99
      END IF
  .
  .
  .

and this error occurs when I compile it: 当我编译它时会发生此错误:

*--------------------Configuration: ovl30u_moon1 - Win32 Debug-------------------- * --------------------配置:ovl30u_moon1-Win32调试--------------------
Compiling Fortran... 编译Fortran ...
C:\\Documents and Settings\\XPMUser\\Desktop\\ovl30u_moon1.f C:\\ Documents and Settings \\ XPMUser \\ Desktop \\ ovl30u_moon1.f

C:\\Documents and Settings\\XPMUser\\Desktop\\ovl30u_moon1.f(567) : Error: This is not a valid termination statement for a DO construct. C:\\ Documents and Settings \\ XPMUser \\ Desktop \\ ovl30u_moon1.f(567):错误:这不是DO构造的有效终止语句。

24 IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN 24 IF((NODNUM(1).EQ.I).AND。(CAUCHY(3,2).LT。CTI(I + 12)))然后
---^ --- ^

C:\\Documents and Settings\\XPMUser\\Desktop\\ovl30u_moon1.f(569) : Error: An ENDIF occurred without a corresponding IF THEN or ELSE statement. C:\\ Documents and Settings \\ XPMUser \\ Desktop \\ ovl30u_moon1.f(569):错误:ENDIF发生而没有相应的IF THEN或ELSE语句。
END IF 万一
-----------^ ----------- ^

Error executing df.exe. 执行df.exe时出错。
ovl30u_moon1.obj - 2 error(s), 0 warning(s)* ovl30u_moon1.obj-2个错误,0个警告*

I also tried this but error exists yet: 我也尝试过这个,但是错误仍然存​​在:

   DO 24 I=1,80
24 IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN
      ARRAY(1)=C1*0.99
      END IF
   END DO

Any advice appreciated. 任何建议表示赞赏。

The termination of a do loop using a label is not valid the way you specify it. 使用标签终止do循环与指定标签的方式无效。 For FORTRAN 77 use: 对于FORTRAN 77,请使用:

   DO 24 I=1,80
      IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN
          ARRAY(1)=C1*0.99
      END IF
24 CONTINUE

In Fortran 90+ you could simply leave out the label: 在Fortran 90+中,您可以简单地省略标签:

   DO I=1,80
      IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN
          ARRAY(1)=C1*0.99
      END IF
   END DO

Or, if you depend on the label, you could use 或者,如果您依赖标签,则可以使用

   label: DO I=1,80
      IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) THEN
          ARRAY(1)=C1*0.99
      END IF
   END DO label

To add to Alexander Vogt's answer there is another way to restate your particular case. 要增加亚历山大·沃格特的答案,还有另一种方法可以重述您的特殊情况。

While it is not allowed to use an if construct as the termination of the non-block (labelled) do it is possible to use an if statement: 虽然它是不允许使用的if建设作为非块(标)的终止do就可以使用if语句:

   DO 24 I=1,80
24 IF ((NODNUM(1) .EQ. I) .AND. (CAUCHY(3,2) .LT. CTI(I+12))) ARRAY(1)=C1*0.99

You can, but you really shouldn't: use the block construct as in the other anwer. 您可以,但实际上不应该:与其他答案一样使用块构造。

For more detail, see Fortran 2008 8.1.6.3 and R214. 有关更多详细信息,请参见Fortran 2008 8.1.6.3和R214。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM