Fortran/Fortran structure and style
From Wikibooks, the open-content textbooks collection
< Fortran
[edit] Style
Older versions of Fortran had strict guidelines on how a program was formatted. However new versions, especially Fortran 90 and above have modernized, allowing more flexability.
It has become a bit customary, though completely unnecessary to put fortran commands in ALL CAPS in order to make the program easier to read.
PROGRAM test IMPLICIT NONE INTEGER four four = 4 WRITE (*,*) four END PROGRAM
Whitespace and empty lines usually won't matter in F90 or above, but in rare cases errors will pop up. However, unlike many other languages such as C, C++, and Java, the line delimiter ';' is optional, so each line of code may stay on its own line!
[edit] Structure
- There is a GOTO command, but don't use it too much.
- Use DO loops early and often.
- Encapsulate your code into functions and subroutines making it easier to program at higher levels, and allowing others to understand whats going on.
- Comment your code well. Don't comment every line, but explain how everything works.