while trying to implement a function LA_func that returns an array, I am getting the error: Error: Incompatible ranks 0 and 1 in assignment at (1)
My function is inside a separate file and I managed to compile it with gfortran, so I can call it from another fortran file. It looks liks this:
module procedures
implicit none
contains
!-----LA_func----------------------------------------------------
!
! Function to compute the area and perimeter of a circle of given radius
!
!----------------------------------------------------------------------
FUNCTION LA_func(r)
IMPLICIT NONE
REAL :: LA_func(2)
REAL, INTENT(IN) :: r
! Declare local constant Pi
REAL, PARAMETER :: Pi = 3.1415927
LA_func = [Pi * r * r, 2 * Pi * r]
END FUNCTION LA_func
end module
The function is already declared to be of size (2), correct? What am I missing? Thanks, all the best
I don’t see any problem with the source you provided. I am confused as to what you did that got the error, since you said you managed to compile it. My guess is that the source with the error has something you haven’t shown us.
Thank you both vmagnin and sblionel for your remarks. Actually I am trying to call this function from within the numerical bifurcation software AUTO-07p. There, I only have access to one .f90 file where subroutines are placed…and this is where I write the use procedures
It seems the software picks these subroutines and finds the “use” command there…instead of at the beginning of the software code (?)
I am trying it now on windows on a dummy file, where I just compiled the suggestion of vmagnin with gfortran. How can one run the .o file that resulted from the compilation? I guess from the command terminal?
Yes - you must first compile sources that are modules, and in an order so that you don’t compile a source that USEs a module before that module is compiled. Some compilers will let you get away with a module that occurs later in the same source file, but others won’t, so it’s a good practice to keep the modules separate and compile them first.
When you compile a module, it creates a file (usually with a .mod file type, but that can vary.) The compiler typically looks for these in the same directory it looks for INCLUDE files. They’ll also generate object (.o) files that have to be named in the command that builds the executable, as you found.