Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to sort out intent(in), intent(out) and intent(inout) in FORTRAN

Tags:

fortran

I am modifying the old source code written in F77 to F90. I suffer the pain to sort out the which variable is intent(in), intent(out) and intent(inout).

Do you have any guidelines or tips?

Any thoughts and suggestions are appreciated.

Michael

like image 217
Kuo-Hsien Chang Avatar asked Jan 17 '23 11:01

Kuo-Hsien Chang


1 Answers

intent (inout) will always work if the actual argument is a variable (see Fortran intent(inout) versus omitting intent), but provides the programmer and compiler with no information. Nor is an intent attribute required so you can gradually improve the code. If the variable only appears on the RHS of assignment statements, then intent (in) is best. If only on the LHS, then intent (out). It gets more complicated if the variable is used as an argument to one or more procedure calls because then you have to trace the usage in that procedure. Thus easiest if you start with the lowest level procedures and work your way up. Most compilers will warn of mistakes, e.g., assigning to an intent (in) argument. For the compiler to check consistency across procedures the interface of each called procedure needs to be explicit to the caller. The easiest way to make the interface known is to place your procedures into a module or modules and "use" that module. The interfaces are explicit between procedures in the same module.

like image 71
M. S. B. Avatar answered Mar 16 '23 00:03

M. S. B.