Parameter integer declared within the module to be used in function declarations

I have legacy code that I need to compile in Ubuntu 22.04. I have compiled the code with Intel Fortran 11 way back, now with the latest Oneapi I get an error. The following is a snippet of the code, the code is do matrix manipulation.

module MatranUtil_m
implicit none

! Kind for double precision.

#ifdef sngl
integer, parameter :: wp = kind(1.0e0)
#endif

#ifdef dbl
integer, parameter :: wp = kind(1.0d0)
#endif

subroutine ReshapeAryR1(Ary, n)

! SJB added to avoid error
! SJB import :: wp

  real(wp), pointer   :: Ary(:)
  integer, intent(in) :: n

  if (associated(Ary)) then
     if (size(Ary)<n) then
        deallocate(Ary)
        allocate(Ary(n))
     end if
  else
     allocate(Ary(n))
  end if
  Ary = 0.0

end subroutine ReshapeAryR1

The following is my compile command following the make file of the legacy package

steph@sjb-pc: ifort -c -fpp MatranUtil.f90 MatranUtil.f90(123): error #6683: A kind type parameter must be a compile-time constant. [WP] real(wp), pointer :: Ary(:) -----------^ MatranUtil.f90(140): error #6683: A kind type parameter must be a compile-time constant. [WP] real(wp), pointer :: Ary(:,:) -----------^ MatranUtil.f90(160): error #6683: A kind type parameter must be a compile-time constant. [WP] complex(wp), pointer :: Ary(:) --------------^ MatranUtil.f90(177): error #6683: A kind type parameter must be a compile-time constant. [WP] complex(wp), pointer :: Ary(:, :) --------------^ compilation aborted for MatranUtil.f90 (code 1) steph@sjb-pc:

I have search Google and saw a recommendation to import the parameter explicitly, see Re: Couldn't use a integer parameter in submodules - Intel Community

I have tried this proposed solution (see import function commented out - this is where I tried it) with the following results.

steph@sjb-pc:$ ifort -c -fpp MatranUtil.f90
MatranUtil.f90(119): error #6483: IMPORT-name must be the name of an entity in the host scoping unit. [WP]
import :: wp
----------------^
MatranUtil.f90(121): error #6683: A kind type parameter must be a compile-time constant. [WP]
real(wp), pointer :: Ary(:slight_smile:
-----------^
MatranUtil.f90(138): error #6683: A kind type parameter must be a compile-time constant. [WP]
real(wp), pointer :: Ary(:,:slight_smile:
-----------^
MatranUtil.f90(158): error #6683: A kind type parameter must be a compile-time constant. [WP]
complex(wp), pointer :: Ary(:slight_smile:
--------------^
MatranUtil.f90(175): error #6683: A kind type parameter must be a compile-time constant. [WP]
complex(wp), pointer :: Ary(:, :slight_smile:
--------------^
compilation aborted for MatranUtil.f90 (code 1)

I’ll appreciate some guidance, this is the first time that I encounter this approach.

Hi @bredsj and welcome.

The problem in your case is that the kind parameter wp is never defined, since in your compilation command you do not define neither sngl nor dbl.
In such cases, it is always good to have a “default” case, when none of the controlling options are given.

So, I would change, keeping an order of importance:

#if (defined(dbl))
integer, parameter :: wp = kind(1.0d0)
#elif (defined(sngl))
integer, parameter :: wp = kind(1.0)
#else ! DEFAULT CASE here
integer, parameter :: wp = kind(1.0d0)  !<-- this for showing purposes only.
#endif

This case is different from yours. You only need to explicitly import when defining interfaces to external (external to the current program unit) procedures. Note that this does not apply when declaring interfaces to module subroutine/functions, later defined in a submodule (This is the case of the post you linked).
In your case, for everything that resides in the same program unit (by host association), or that has access to the wp parameter through use association, you don’t need to explicitly import.

Dear mEm, thank you very much for a prompt reply. I am referring to the MATRAN wrapper, see Matran: A Matrix Wrapper for Fortran 95

There are quite a few modules to compile so a full make file is available and the dbl is defined. I just reduced the problem by only showing the compile command for the one module.

I have now solved the problem by changing all f95 file extensions to f90 and adjust the make file accordingly, the program now compiled successfully, I have no explanation! See result below

steph@sjb-pc:$ make all
ifort -c -fpp -Ddbl MatranUtil.f90
ifort -c -fpp -Ddbl Rmat.f90
ifort -c -fpp -Ddbl Rdiag.f90
ifort -c -fpp -Ddbl RdiagDiag.f90
ifort -c -fpp -Ddbl RdiagJoin.f90
ifort -c -fpp -Ddbl RdiagProduct.f90
ifort -c -fpp -Ddbl RdiagSolve.f90
ifort -c -fpp -Ddbl RdiagSum.f90
ifort -c -fpp -Ddbl RmatBorder.f90
ifort -c -fpp -Ddbl RmatChol.f90
ifort -c -fpp -Ddbl RmatEig.f90
ifort -c -fpp -Ddbl RmatEye.f90
ifort -c -fpp -Ddbl RmatLudpp.f90
ifort -c -fpp -Ddbl RmatInv.f90
ifort -c -fpp -Ddbl RmatJoin.f90
ifort -c -fpp -Ddbl RmatNorm.f90
ifort -c -fpp -Ddbl RmatProduct.f90
ifort -c -fpp -Ddbl RmatSpec.f90
ifort -c -fpp -Ddbl RmatNorm2.f90
ifort -c -fpp -Ddbl RmatPivot.f90
ifort -c -fpp -Ddbl RmatPrint.f90
ifort -c -fpp -Ddbl RmatQR.f90
ifort -c -fpp -Ddbl RmatQRP.f90
ifort -c -fpp -Ddbl RmatRand.f90
ifort -c -fpp -Ddbl RmatRealSchur.f90
ifort -c -fpp -Ddbl RmatTranspose.f90
ifort -c -fpp -Ddbl RmatSVD.f90
ifort -c -fpp -Ddbl RmatSolve.f90
ifort -c -fpp -Ddbl RmatSubmatrix.f90
ifort -c -fpp -Ddbl RmatSum.f90
ifort -c -fpp -Ddbl MatranRealCore.f90

I see. In your original post there is apparently an error displaying the make command.
It is now clearer.

From ifort help message:

   usage: ifort [options] file1 [file2 ...] [/link linker_options]

      where options represents zero or more compiler options

      fileN is a Fortran source (.f .for .ftn .f90 .fpp .i .i90),
      assembly (.asm), object (.obj), static library (.lib), or
      other linkable file

Glad you managed to fix the issue!