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

**URL:** <https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643>\
**Category:** Help\
**Created:** [March 16, 2024, 8:00am UTC](https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643 "2024-03-16T08:00:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bredsj](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@bredsj](https://fortran-lang.discourse.group/u/bredsj)\
**Post date:** [March 16, 2024, 8:00am UTC](https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643/1 "2024-03-16T08:00:50Z")

</div>

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](https://community.intel.com/t5/Intel-Fortran-Compiler/Couldn-t-use-a-integer-parameter-in-submodules/m-p/1373682)

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(🙂  
-----------^  
MatranUtil.f90(138): error #6683: A kind type parameter must be a compile-time constant. [WP]  
real(wp), pointer :: Ary(:,🙂  
-----------^  
MatranUtil.f90(158): error #6683: A kind type parameter must be a compile-time constant. [WP]  
complex(wp), pointer :: Ary(🙂  
--------------^  
MatranUtil.f90(175): error #6683: A kind type parameter must be a compile-time constant. [WP]  
complex(wp), pointer :: Ary(:, 🙂  
--------------^  
compilation aborted for MatranUtil.f90 (code 1)

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

---

<div class="post-metadata">

**Author:** ![mEm](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mEm](https://fortran-lang.discourse.group/u/mEm)\
**Post date:** [March 16, 2024, 8:59am UTC](https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643/2 "2024-03-16T08:59:52Z")

</div>

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:

```auto
#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

```

> [@bredsj](#):
>
> 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](https://community.intel.com/t5/Intel-Fortran-Compiler/Couldn-t-use-a-integer-parameter-in-submodules/m-p/1373682)

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/function`s, 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.

---

<div class="post-metadata">

**Author:** ![bredsj](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@bredsj](https://fortran-lang.discourse.group/u/bredsj)\
**Post date:** [March 16, 2024, 9:42am UTC](https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643/3 "2024-03-16T09:42:36Z")

</div>

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](https://www.cs.umd.edu/~stewart/matran/Matran.html)

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

---

<div class="post-metadata">

**Author:** ![mEm](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mEm](https://fortran-lang.discourse.group/u/mEm)\
**Post date:** [March 16, 2024, 10:35am UTC](https://fortran-lang.discourse.group/t/parameter-integer-declared-within-the-module-to-be-used-in-function-declarations/7643/4 "2024-03-16T10:35:34Z")

</div>

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

> [@bredsj](#):
>
> 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

From `ifort` help message:

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