4

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

Aasmund Eldhuset
  • 37,289
  • 4
  • 68
  • 81
Kuo-Hsien Chang
  • 925
  • 17
  • 40

3 Answers3

5

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.

Community
  • 1
  • 1
M. S. B.
  • 28,968
  • 2
  • 46
  • 73
3

Alan Miller wrote a program called to_f90.f90 that takes care of this automatically for well-formed F77 code. There is a mirror of his website at:

http://jblevins.org/mirror/amiller/

The specific routine is located at:

http://jblevins.org/mirror/amiller/to_f90.f90

Kris Kuhlman
  • 301
  • 1
  • 5
  • 2
    +1; didn't know this tool existed. That inspired me to look around for some others: there's also Polyhedron Software's online tool, http://www.polyhedron.com/plusfortonline.php . – Jonathan Dursi Feb 15 '12 at 16:39
1

As said earlier, intent(inout) should always work.

I suggest, for intent(in) and intent(out) of variable X, to make a search (CTRL+F or whatever) for "X =" and "X=" in your subroutine. This way, you'll be able to check if the variable is modified or not during the execution of this subroutine. If not: intent(in). This will always be true BUT if the variable is modified in a sub function or a call to another routine. So first of all is to check if a call to a function or a routine is done in the subroutine you're translating.

max
  • 563
  • 4
  • 17