I have a FORTRAN 95 code where, in the main program, these variables are declared:
integer :: i
real(8) :: dx
real(8), allocatable :: X(:), Y(:), Z(:)
The following function uses these values at some point during the program:
function Funcion_ceros(var_4)
implicit none
real(8), intent(in) :: var_4(2)
real(8) :: Funcion_ceros(2)
Funcion_ceros(1) = var_4(1) - Y(i) - dx*var_4(2)
Funcion_ceros(2) = var_4(2) - Z(i) - dx*F(X(i + 1), var_4(1), var_4(2))
end function Funcion_ceros
If I include this function in the contains section of the main program, there is no compiling issue. However, when separating it into a module, it loses access to these variables. I attempt to specify the same variabes written above in the module aswell, and get the following error:
Symbol 'i' at (1) conflicts with symbol from module 'Module_Name', use associated at (2).
How do I separate this function into a module, allowing at the same time its access to the variables it uses from the main program?
You can put the variables into the module as well, then the
usestatement makes them available to the main program as well.Output:
Update: I noticed that you said you put the variables in the module 'as well' -- If you have them in the module, they will be made available to the main program by the
usestatement. If you then declare another variable with the same name, it will conflict. Declare the variables only in the module, and they will be available to both.