Well, let me say first why I want to do this. I frequently write code in C/C++, so for me it's very natural to define functions like:
vector<int> TestFunct (int a, int b){
<some code here>
return <result>;}
Now I'm learning Fortran, so I declare functions like this:
function TestFunc(a,b)
integer, dimension(:) :: TestFunc
integer :: a
integer :: b
<some code here>
endfunction TestFunc
But I recently learned that the data type of the result can be defined in the function statement, like: <data_type> function TestFunc(a,b)
, which is much more natural for me, because I'm used to the similar C++ declaration.
The issue is that, when I', trying to define a vector (actually a integer, dimension(:)
, strictly talking) as the result data type, I have the ifort
error #5082
(I will detail it in the next lines).
In an example, for the code:
real, dimension(:) function TestFunc(a,b)
integer, intent(in) :: a
integer, intent(in) :: b
<more code here>
endfunction Testfunc
I get the output:
main.f90(23): error #5082: Syntax error, found ',' when expecting one of: ( * ) ( :: %FILL , TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
real, dimension(:) function TestFunc(a, b)
----^
main.f90(23): error #5082: Syntax error, found IDENTIFIER 'FUNCTION' when expecting one of: * :: , <END-OF-STATEMENT> ; [ / = => WITH
real, dimension(:,:) function TestFunc(a, b)
---------------------^
Hope I had clearly explained my issue.
EDIT: So, in order to sum up what I just said in one question: How I declare a vector (i.e.:integer, dimension(:)
) as the returning data type in the function statement?