Friday, November 6, 2009

F77 Column Indentation Rules -- المسافات

When writing the F77 source code you have to follow some rules, so that the compiler understand the written code, and therefore it will be translated in the right way. In FORTRAN 77 each specific statements are inserted in specific columns, the following rules summarizes these rules.

            Here is a simple example program before getting into the rules:



Rules:



  • Column 1: This column designates comments, when you insert a (C) or a (!) or any other character the rest of this line is ignored. C & ! are the ISO, other characters may be used as well. Comments are very important when writing large blocks of codes, if you write more than 100 lines of code, I bet you will forget why you wrote some instructions after about one month. SO a neatly commented code surely helps the programmer and those who help him.

  • Column 2-5: This block is reserved for inserting numerical labels these labels are used to mark this line, so that you can jump back to it, via GOTO statements, or after finishing a DO loop, or even in subroutines. Some experienced programmers follow a neat sequence of multiples of 10. For example 100, 110, 120, 130, 140, 150, ... and so on.

  • Column 6: This column is reserved for inserting a character usually a (+), which is the continue notation for F77 . For example sometimes you may need to write a long line in F77 and you can't exceed column 73, so you insert a + in column 6 and continue writing your code.

  • Column 7-73: This block is where you write your instruction source code and statements that are translated by the compiler.
  •  
Why such limited width ? Well, Fortran was born many years ago when the final stage of coding was always punching a card which contained binary instruction code for nu-merically controlled devices. The standard punched card had 80 columns, numbered 1 to 80 from left to right. Each column could hold one character, encoded as some combination of punches in the 12 rows of the card; more on this at http://www.cs.uiowa.edu/~jones/cards/codes.html. Although many modern compilers can read your code beyond the 73th character, we will strictly cut our source code to appear within column 7 and 73. If your line would extend beyond the 73th character, you
have to break it and place the symbol + in column 6 of each continuation line.(Taken from Roman Gro ger's tutorial)