Hi everyone

I need my function to produce a matrix, then I called the function in the main program by its name to give the matrix to the main program, but it does not work at all, I mean the matrix is computed correctly in the function but I failed to call it to the main program, here what I have in my code

Code:
main_program
c
complex*16 A(m1,m2), Mat
EXTERNAL Mat
c
A = MainMat(n,m)
.
..
end
c  here is the function
complex*16 function Mat(n,m)
c calculate the elements of Mat
Mat = A
.
end
I need to return the matrix Mat, which I computed by the function to the main program

any help