Search code examples
fortranprecisionfunction-declaration

Using fortran kind in function declaration


I have a program that has many functions that use 'kind' in the declaration, such as

real(kind=db) function vnorme(v)

Each declaration of this sort causes errors during compile with pgf90 (however ifort works ok):

PGF90-S-0087-Non-constant expression where constant expression required (general.f: 3161) PGF90-S-0081-Illegal selector - KIND parameter has unknown value for data type (general.f: 3161) 0 inform, 0 warnings, 2 severes, 0 fatal for vnorme

db is defined in a module contained in a separate source code file:

integer, parameter:: db = selected_real_kind(15)

The code compiles correctly when I replace 'db' with '8'. It seems like the compiler doesn't think that db has been declared, even though the function vnorme uses the module in which db is declared. Is there a way to fix this?


Solution

  • db isn't yet visible when parsing the 1st line of the function definition.

    Try

    
    function vnorme(v)
      use module_with_db
      implicit none
      real(db) :: vnorme
      ...
    end function vnorme