2017-04-10 118 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