Function return type mismatch

前端 未结 2 651
囚心锁ツ
囚心锁ツ 2020-12-20 04:15

I\'m attempting to recode an old C++ program in Fortran to make use of LAPACK (I\'m aware that C++ does have LAPACK++, but I\'m having a lot of trouble installing it, so I g

相关标签:
2条回答
  • 2020-12-20 04:38

    You are not declaring getS as a function in the subroutine createS. You need to add double precision, external :: getS in your variable declarations of the subroutine createS.

    0 讨论(0)
  • 2020-12-20 04:44

    Did you put your subroutines and functions into a module and use that module? Otherwise, probably what is occurring is that you are getting implicit typing of getS in subroutine createS as a single precision real but it actually returns a double precision. Another suggestion: always use implicit none to find undeclared variable. In case you forget to include implicit none in your source code, gfortran provides the compiler options -fimplicit-none. Implicit typing is pernicious and likely continued in Fortran to support legacy code.

    P.S. double precision is also obsolete but much less risky than implicit typing. If you have a recent version of gfortran you can use the following:

    use ISO_FORTRAN_ENV
    real (real64) ::
    

    See the gfortran manual.

    EDIT: The implicit none changed the type of getS from real(4) (by implicit typing) to unknown (no type declared, implicit typing disabled). If you place the procedures into a module, they will "know" each others types: function returns and argument types. This will fix this bug. It also helps the compiler find other bugs but enabling it to check the consistency of arguments between the call and the arguments of the procedure. See Correct use of modules, subroutines and functions in fortran and Computing the cross product of two vectors in Fortran 90 for examples.

    0 讨论(0)
提交回复
热议问题