Function return type mismatch

人盡茶涼 提交于 2019-11-29 12:19:10
M. S. B.

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.

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.

replace double precision with:

REAL (Kind=8)
INTEGER (Kind=4)
COMPLEX (Kind=8)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!