2017-04-10 90 views
-2
!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处收到一条错误消息,我无法修复。 任何帮助,不胜感激。Fortran编译错误764嵌套错误

Compile error: error 764 - Nesting error - the block IF construct on line 4079 has not been terminated

线4079:

700 if (time>1500) then 
+3

缩进你的代码。你所有的'if'语句都有相应的'endif's吗? – Ross

+0

您应该使用缩进来更好地查看代码的结构。很有可能你错过了“结束”或类似的事情。 –

+0

非常感谢......如果(时间> 1500),计算Pcow_positive时间= 0 r1 = R 700然后转到950 else else if' –

回答

0

有与此代码的几个问题。最直接的是,如果你错过了一个结局。你没有看到这个,因为如前所述,你并没有一直缩减你的代码。你的编辑器应该自动为你做这件事,并且会发现这很容易被发现 - 我将你的代码剪切并粘贴到emacs中,自动缩进子程序并且问题很明显。然而,endif应该去的地方不是,所以在接下来的我不得不猜测把它放在哪里,因为你还没有提供完整的程序,所以很难测试我已经做了什么,但即使我已经做了我希望我所做的背后的想法很明显。

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

接下来你所有的常量都是单精度的。然而,所有的变量都是双精度的。因此你的日常工作不会像你想的那么精确。在双精度代码中,如果您看到1.0而没有其他限定符,则几乎总是出现错误。

那么如何解决这个问题。那么双精度是如此的80年代,所以相反要学习种类,在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