Fortran

Guide To Learn

functional-fortran: http://mng.bz/nP18

Summary

  • Procedures allow you to organize code into self-contained units of functionality, which you can then reuse whenever needed.
  • Fortran has two kinds of procedures: functions and subroutines.
  • Functions are invoked from expressions and return only one value as a result. They’re thus best suited for minimal bits of calculation that don’t cause any side effects.
  • Subroutines are invoked using a call statement; they can’t be invoked in expressions but can return any number of arguments as a result. In contrast to functions, subroutines are appropriate whenever you need to return more than one variable as a result, or for operations that cause side effects, such as modifying variables in-place and I/O.
  • You can define functions or subroutines as pure to prevent side effects. In general, this will allow you to write code that’s easier to understand and debug, as well as easier for the compiler to optimize.
  • You can also define functions or subroutines as elemental, which allows them to operate on both scalars and arrays of any rank and size.
  • Functions and subroutines are your first layer of abstraction–design them carefully and use them only if they make your program easier to read and understand.
Further reading

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top