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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With