If you push the button below, I'll put some more files into the ``examples'' subdirectory of your home directory.
Look at the program ``examples/sample2.f'' in Emacs (or view it directly). You should have learned from your reading the general form of simple Fortran programs, so the example should look somewhat familiar.
Every line in the program is either blank, is a comment, or is a Fortran statement. Blank lines are included to improve readability, just as when writing English. Comment lines (which begin with a C in the first column of the line) are there to aid human readers of a program and are ignored by the Fortran compiler. All other lines are Fortran statements.
It is important to include comments with each program that summarize what the program does, who initially created it, and who subsequently modified it. For small programs this may seem pedantic, but it is essential for larger programs so it's a good habit to learn. It should be possible to tell what a program does (though not necessarily how it does it) by reading the comments at the beginning of a program.
Every statement must begin with at least 6 spaces and must contain no more than 72 characters. (This is a requirement that dates back to the days when Fortran programs were punched on cards.) A program begins with a ``PROGRAM'' statement (which also contains the name you are giving the program) and ends with an ``END'' statement. In between is where the action is.
When editing a Fortran program with Emacs, it is easy to make the mistake of going past the 72nd column. There's an easy way to avoid this problem: resize Emacs so that it is exactly 72 columns wide. (When you resize a window, the window's dimensions are displayed in the upper-left-hand corner of the screen.) Before working on a Fortran program, you should get into the habit of resizing Emacs. It'll save you a lot of trouble in the long run!
Each of the statements is executed in turn. In this case, the program begins by printing a message to the display. It then reads two numbers X and Y (typed by the user), divides the numbers and stores the result in Z, prints out the quotient, and stops. In all, four kinds of statements are used in this program---print, read, assignment, and stop. As you learn more kinds of statements, you will be able to write more interesting programs.
Hamlet Project