2014-09-21 3 views
2

Linux 컴퓨터에서 사용하고 gfortran을 사용하여 컴파일 한 fortran 90 프로그램을 만들었습니다. 그것은 gfortran와 리눅스 시스템에서 잘 작동하지만, 플라톤 컴파일러 (FTN95)를 사용할 때 오류인터페이스를 사용하는 서브 루틴에 인수로 함수를 전달하는 기능이 Plato Fortran 90에서 작동하지 않습니다.

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에서 작동하도록 변경해야하는 방법을 알고 있습니까? 이 오류에 대해 읽으려고했지만 포인터에 대한 언급이 있지만 작동하지 않는 부분에서 언급했습니다. 몇 가지 해결 방법을 알아 냈지만 서브 루틴이 더 이상 인수로 함수를 받아들이지 못하게 만듭니다. 이는 거의 쓸모가 없습니다. 어떤 도움이라도 대단히 감사하겠습니다. 내 코드는 아래와 같습니다.

!--! 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 

답변

2

현재 gfortran은 colebrookWhite 함수 이름 다음에 괄호가있는 secantMethod 절차에 대한 호출에서 오류,하지만 인수 목록을 검색합니다.

함수를 인수로 전달하려는 경우 (함수를 평가 한 결과와 반대), 괄호 쌍으로 함수 이름을 따르지 않습니다.

call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite) 
!                   ^
+0

죄송합니다. 포함 시키려고하지 않았습니다. 실제로 디버깅하려고 할 때 추가했습니다. (원래의 게시물에서 삭제했습니다.) 괄호가 없으면 프로그램이 실행되고 입력 사항을 묻습니다. 입력을 입력 할 때 "프로 시저가 필요할 때 인수가 9 인 실제 (kind = 2) 루틴을 호출하려고 시도합니다"라는 오류가 발생하면 오류의 세부 정보는 "SECMETH! SECANTMETHOD - 파일 secantnew .f90 라인 19 [+ 00a4] SECANTROOTS - 파일 secantnew.f90의 100 행 [+0274] "에 있습니다. 이 오류가 발생하는 이유와 플라톤에서 작동하도록 수정하는 방법에 대한 아이디어가 있습니까? 도와 주셔서 감사합니다! – ryanDavid

0
난 그냥 Geany와 gfortran을 설정, IDE를 (I 실제로 더 나은 지금은 몇 시간 동안 그것을 사용했다고 Geany WAY 등) Geany하는 플라톤로 전환하고, 코드가 설치 작동 결국

. 플라톤에 오류가 발생하는 이유는 추측합니다. 컴파일러는 실제로 fortran95 컴파일러이고 gfortran은 fortran90 컴파일러입니다. 모든 것을 작동 시키려면 시간이 걸렸지 만 일단 gfortran 용 mingw-w64를 다운로드하고 경로 사용자 (시스템 아님) 환경 변수를 올바른 위치로 설정하면 모든 것이 잘 작동합니다. 여전히 코드가 FTN95 컴파일러로 작동하도록하는 방법이 있는지 알고 싶지만, 결국에는 gfortran과 Geany를 사용하고 있습니다.

+2

gfortran은 Fortran 90을 지원하지만 "Fortran 90"컴파일러 일뿐만 아니라 Fortran 95, 2003 년 일부 및 2008 년 일부를 지원합니다. 고정 FORTRAN 77 형식도 이해합니다. – casey