Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"PROCEDURE attribute conflicts with INTENT attribute" when compiling simple Fortran program with module

I have a simple Fortran 95 program

include "sandboxlib.f95"
program sandbox
    implicit none
    write(*, *) 'abc'
end program

and a simple module containing a function

module sandboxlib

 integer, parameter :: dp = kind(1.d0)

contains
function cumsum(mat, m, n) result(c)
    implicit none
    real(dp), intent(in) :: mat
    integer, intent(in) :: m, n
    integer i, j
    real(dp), dimension(m, n) :: c

    c(:, 1) = 0.d0

    do i = 2, m
        do j = 1, n
            c(i, j) = c(i-1, j) + mat(i, j)
        end do
    end do
end function
end module

I compile sandbox.f95 with this command

/usr/bin/gfortran -O -std=gnu -Wfatal-errors -pedantic -Wall sandbox.f95 -o sandbox

which results in this error

sandboxlib.f95:6.23:
    Included at sandbox.f95:1:

    function cumsum(mat, m, n)
                       1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'mat' at (1)

I looked around and found a few questions that discuss modules, functions, etc. or an error like this, but I can't figure out why this won't compile.

like image 660
Michael A Avatar asked Sep 16 '25 08:09

Michael A


1 Answers

Your mat is declared scalar

  real(dp), intent(in) :: mat

but you use it as an array

  c(i, j) = c(i-1, j) + mat(i, j)

and the compiler parses this as a function call and assumes mat() is a function. And functions cannot have intent.

I assume the correct thing to do is to make mat an array in the declaration. Something like

  real(dp), intent(in) :: mat(:,:)

or

  real(dp), intent(in) :: mat(m,n) 

With the former you can avoid passing m and n as arguments.

like image 97
Vladimir F Героям слава Avatar answered Sep 18 '25 11:09

Vladimir F Героям слава