【问题标题】:Fortran compile error 764 nesting errorFortran 编译错误 764 嵌套错误
【发布时间】:2017-04-10 21:33:05
【问题描述】:
    !subroutine No.10: to calculate positive capilary pressure required 

    subroutine Pcow_positive1(sigma_ow,R,alpha,b,teta_ow,Pcow_positive,r1,time)

    implicit none

    !dummy argument declarations 

    double precision,intent(in)::sigma_ow
    double precision,intent(in)::R
    double precision,intent(in)::alpha
    double precision,intent(in)::b
    double precision,intent(in)::teta_ow
    double precision,intent(out)::Pcow_positive
    double precision,intent(out)::r1
    double precision::omega_eff
    double precision::A_eff
    double precision::beta
    double precision::Pcow
    double precision::r2
    double precision::error
    double precision::error1
    double precision::abeta
    integer,intent(out)::time

    !calculate Pcow_positive

       time=0
       r1=R

    700 if (time>1500) then

    goto 950

    else 

    abeta=((b*(sin(alpha)))/(r1))
    if (abeta>1.0) then

    goto 900

    else 

    end if
    beta=asin(abeta)
    time=time+1
    A_eff=(((R**2.0)/(2.0*tan(alpha))))-(((r1)*(b)*(sin(alpha+beta)))/2.0) & 
  +(((((r1)**2)*(beta))/2.0))
    omega_eff=(((((R)*(1.0/(tan(alpha))))-b)*(cos(teta_ow)))+((r1*beta)))
    Pcow=(((sigma_ow)*(omega_eff))/(A_eff))
    r2=(sigma_ow)/(Pcow)

    error=abs(r2-r1)
    error1=abs((sigma_ow/r2)-(sigma_ow/r1))
    if (error<=0.01 .or. error1<=0.01) then

          goto 800

          else 
          r1=r2
          goto 700

          end if

    800   r1=r2
          Pcow_positive=Pcow
          goto 1000

    900   r1=(b*(sin(alpha)))
          Pcow_positive=(sigma_ow)/(r1)
          goto 1000

    950   r1=(sigma_ow)/(0.0005)
          Pcow_positive = 0.0005

    1000  end subroutine Pcow_positive1

当我编译代码时,我在end subroutine Pcow_positive1 收到一条错误消息,我无法修复。 非常感谢任何帮助。

编译错误:错误 764 - 嵌套错误 - 第 4079 行的块 IF 构造尚未终止

第 4079 行:

700 if (time>1500) then

【问题讨论】:

  • 缩进你的代码。你所有的if 语句都有对应的endifs 吗?
  • 您应该使用缩进来更好地查看代码的结构。您可能错过了end if 或类似的信息。
  • 非常感谢...!calculate Pcow_positive time=0 r1=R 700 if (time&gt;1500) then goto 950 else end if

标签: fortran gfortran fortran95


【解决方案1】:

此代码存在一些问题。最直接的是,你错过了一个结束如果。您看不到这一点,因为如前所述,您没有始终如一地缩进您的代码。您的编辑器应该自动为您执行此操作,并且可以很容易地发现这一点 - 我将您的代码剪切并粘贴到 emacs 中,自动缩进子程序并且问题很清楚。但是 endif 应该去的地方不是,所以在接下来的内容中我不得不猜测把它放在哪里,而且由于你没有提供完整的程序,所以很难测试我所做的事情,但即使我做了一个错误我希望我所做的事情背后的想法很清楚。

无论如何,下一个问题是不要使用 GOTO!很少有任何需要,它通常会导致混乱,就像这里一样,所谓的意大利面条代码。相反,学习你的控制结构并使用它们。一个 do 循环和一些 EXIT 将很好地整理它。

接下来所有的常量都是单精度的。然而,你所有的变量都是双精度的。因此,您的例行程序不会像您想要的那样精确。在双精度代码中,如果您看到没有其他限定符的 1.0,则几乎总是有问题。

那么如何解决这个问题。好吧,Double Precision 是 1980 年代,所以改为了解种类,在 stackoverflow 上多次详细介绍,或者查看你的 Fortran 书(你有一本吗?)并使用它们。无论如何,将所有这些与上述警告放在一起(而且我只花了 5 分钟,实际上我会进一步整理,但早餐正在召唤)我会写你的例程类似于

    !subroutine No.10: to calculate positive capilary pressure required 

Subroutine Pcow_positive1(sigma_ow,R,alpha,b,teta_ow,Pcow_positive,r1,time)

  Implicit None

  !dummy argument declarations 

  Integer, Parameter :: wp = Selected_real_kind( 12, 70 )

  Real( wp ),Intent(in)::sigma_ow
  Real( wp ),Intent(in)::R
  Real( wp ),Intent(in)::alpha
  Real( wp ),Intent(in)::b
  Real( wp ),Intent(in)::teta_ow
  Real( wp ),Intent(out)::Pcow_positive
  Real( wp ),Intent(out)::r1
  Real( wp )::omega_eff
  Real( wp )::A_eff
  Real( wp )::beta
  Real( wp )::Pcow
  Real( wp )::r2
  Real( wp )::error
  Real( wp )::error1
  Real( wp )::abeta
  Integer,Intent(out)::time

  !calculate Pcow_positive

  time=0
  r1=R


  Do

     If (time>1500) Then


        r1=(sigma_ow)/(0.0005_wp)
        Pcow_positive = 0.0005_wp

        Exit

     End If

     abeta=((b*(Sin(alpha)))/(r1))
     If (abeta>1.0_wp) Then

        r1=(b*(Sin(alpha)))
        Pcow_positive=(sigma_ow)/(r1)
        Exit

     Else 

     End If
     beta=Asin(abeta)
     time=time+1
     A_eff=(((R**2.0_wp)/(2.0_wp*Tan(alpha))))-(((r1)*(b)*(Sin(alpha+beta)))/2.0_wp) & 
          +(((((r1)**2)*(beta))/2.0_wp))
     omega_eff=(((((R)*(1.0_wp/(Tan(alpha))))-b)*(Cos(teta_ow)))+((r1*beta)))
     Pcow=(((sigma_ow)*(omega_eff))/(A_eff))
     r2=(sigma_ow)/(Pcow)

     error=Abs(r2-r1)
     error1=Abs((sigma_ow/r2)-(sigma_ow/r1))
     r1=r2
     If (error<=0.01_wp .Or. error1<=0.01_wp) Then

        Pcow_positive=Pcow
        Exit

     End If

  End Do

End Subroutine Pcow_positive1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 2022-11-20
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    相关资源
    最近更新 更多