I have some general questions regarding the arguments passed to a subroutine/function in Fortran, in particolar when it comes to naming of non-local variables.
Given this main program
program xfunc
implicit none
real, dimension(5) :: var1, var2
integer, var3
...
call my_subroutine(var1(i),var2,var3)
SUBROUTINE my_subroutine(arg1,var2,arg3)
!inout variable not matching the var1 declared in main
real, intent(inout) :: arg1
!matches the name and dimension of variable in main, is this needed?
real, intent(inout), dimension(5) :: var2
!should arg3 be named var3 since it overwrites the values in var3? And should arg3 have a corresponding variable in the main program
integer, intent(out) :: arg3
end my_subroutine
- In the declaration the names are simply "labels", correct? They don't need to match the names of the variables in the main program.
- The type dimension of the arguments also don't need to match the ones in the main program, correct? So arg1 (an array) inside the subroutine can be just a real also in the case of an inout variable? They just need to match the declaration INSIDE the subroutine? Does this apply only for intent(in) arguments?
- Do the variables need to be declared inside the subroutine even if they are "inout" and match exactly the ones in the main program?
- What's good practice when naming the arguments and variables of subroutines or functions? Should different names be used to distinguish them from the main program? I am curious about this question especially for all variables that are (inout and out).