2

Linux マシンで使用する fortran 90 プログラムを作成し、gfortran を使用してコンパイルしました。gfortran を使用した Linux マシンでは問題なく動作しましたが、エラーが発生します

error 327 - In the INTERFACE to SECANTMETHOD (from MODULE SECMETH), the ninth dummy argument (F) was of type REAL(KIND=2) FUNCTION, whereas the actual argument is of type REAL(KIND=2)

Plato コンパイラ (FTN95) を使用する場合。Plato で動作するようにコードを変更する方法を知っている人はいますか? 私はこのエラーを読み込もうとしましたが、ポインタについての言及がありましたが、私が試したところ、うまくいきませんでした。私はいくつかの回避策を考え出しましたが、サブルーチンが引数として関数を受け入れないようにしています。これはほとんど役に立ちません。どんな助けでも大歓迎です。私のコードは以下です。

!--! A module to define a real number precision.
module types
  integer, parameter :: dp=selected_real_kind(15)
end module types

module secFuncs
  contains

  function colebrookWhite(T)
    use types

    real(dp) :: colebrookWhite
    real(dp), intent(in) :: T

    colebrookwhite=25-T**2

    return
  end function colebrookWhite
end module secFuncs

module secMeth
  contains

  subroutine secantMethod(xolder,xold,xnew,epsi1,epsi2,maxit,exitFlag,numit,f)
    use types
    use secFuncs
    implicit none

    interface
      function f(T)
        use types
        real(dp) :: f
        real(dp), intent(in) :: T
      end function f
    end interface

    real(dp), intent(in) :: epsi1, epsi2
    real(dp), intent(inout) :: xolder, xold
    real(dp), intent(out) :: xnew
    integer, intent(in) :: maxit
    integer, intent(out) :: numit, exitFlag
    real(dp) :: fxold, fxolder, fxnew
    integer :: i

    fxolder = f(xolder)
    fxold = f(xold)

    i = 0

    do
      i = i + 1

      xnew = xold - fxold*(xold-xolder)/(fxold-fxolder)

      fxnew = f(xnew)

      if (i == maxit) then
        exitFlag = 1
        numit = i
        return
      else if (abs(fxnew) < epsi1) then
        exitFlag = 2
        numit = i
        return
      else if (abs(xnew - xold) < epsi2) then
        exitFlag = 3
        numit = i
        return
      end if

      xolder = xold
      xold = xnew
      fxolder = fxold
      fxold = fxnew
    end do
  end subroutine secantMethod

end module secMeth

program secantRoots
  use types
  use secMeth
  use secFuncs
  implicit none

  real(dp) :: x1, x2, xfinal, epsi1, epsi2
  integer :: ioerror, maxit, numit, exitFlag

  do
    write(*,'(A)',advance="no")"Please enter two initial root estimates, 2epsi's, and maxit: "
    read(*,*,iostat=ioerror) x1, x2, epsi1, epsi2, maxit

    if (ioerror /= 0) then
      write(*,*)"Invalid input."
    else
      exit
    end if
  end do

  call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite)

  if (exitFlag == 1) then
    write(*,*)"The maximum number of iterations was reached."
  else if (exitFlag == 2) then
    write(*,'(a,f5.3,a,i3,a)')"The root is ", xfinal, ", which was reached in ", numit, " iterations."
  else if (exitFlag == 3) then
    write(*,'(a,i3,a)')"There is slow or no progress at ", numit, " iterations."
  end if

end program secantRoots
4

2 に答える 2

2

現在の gfortran は、関数名secantMethodの後に括弧があり、引数リストがないプロシージャの呼び出しでエラーを検出します。colebrookWhite

関数を引数として (関数を評価した結果ではなく) 渡したい場合は、ここでやりたいことですが、関数名の後に括弧のペアを付けません。

call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite )
!                                                                             ^
于 2014-09-21T06:07:23.553 に答える
0

結局、Plato から Geany IDE に切り替えて (数時間使用したので、実際には Geany WAY の方が気に入っています)、Geany で gfortran をセットアップすると、コードはそのセットアップで動作します。Plato でエラーが発生する理由は、そのコンパイラが実際には fortran95 コンパイラであるのに対し、gfortran は fortran90 コンパイラであるためだと推測しています。すべてが機能するまでにはしばらく時間がかかりましたが、gfortran 用の mingw-w64 をダウンロードし、パス ユーザー (システムではない) 環境変数を正しい場所に設定すると、すべてがうまく機能します。コードを FTN95 コンパイラで動作させる方法があるかどうかを知りたいと思っていますが、最終的には gfortran と Geany を使い続けています。

于 2014-09-22T02:02:34.227 に答える