Fortran Programming
Fortran continues to be used, albeit at a substantially reduced penetration,
in scientific and engineering fields which required heavy numbercrunching. I am
aware of continuing use in such disciplines as aerospace engineering and high
energy physics (please send me others if you know of them). There are free
software (Gnu) versions of Fortran 77, although none that I know of for later
versions such as Fortran 90 and 95. This is most unfortunate, and refleccts the
fact that most people are being trained in C/C++ now. However, it is worth
pointing out that during the 1980s, the most fashionable language was Pascal,
whose programmers also looked askance at the engineers still using that
"dinosaur" language, Fortran! Nowadays, I never see Pascal being used
for technical programming, although my experience is admittedly limited. I
suspect that C/C++ has passed the stage of being just a fashion and has, in
fact, replaced Fortran. But it is a fact that legacy Fortran code remains out
there and continues to be upgraded and maintained for the fast number-crunching
applications.
Because of the concentration on free software, this web site discusses only
Fortran 77. Hopefully someday, a free version of something later will appear.
To begin...
Use a text editor (I prefer PFE) to create a new file and type the following
lines:
![](images/fortran/fortran1.gif)
(Be sure to start each of these lines of text in column 7, as Fortran 77 does
not have free-form input the way C does.) Save the file and call it, say
helloworld.f. Compile it using the DOS command
g77 -o helloworld.exe helloworld.f
This can be done using a DOS window, or we can invoke DOS commands from
within the editor itself. Fortunately, graphically oriented text editors such as
PFE have facilities for compiling directly within the editor environment. I will
describe the procedure using PFE, but it is easily generalizable to the other
editors.
First we are assuming that the directory in which the editor is working has
already been designated. (In PFE, this is done by selecting the Change
Directory... option in the File menu.) Next we click on the Execute menu and
select the DOS Command to Window... option. Note also that the keystroke
shortcut for invoking this window is to simply press the F11 key, which is what
we'll do for the remainder of this explanation. Using either method, a dialog
box appears, looking like this:
![](images/fortran/fortran2.gif)
Note that we have typed the compiler invocation in the Command: window
already. This is a basic invocation of the compiler and, as you become more
proficient in using g77, you'll probably use others. This is enough to get your
started, though and what it means is this:
Note also that we have used the DOS symbol "." to denote the
present directory as the one in which the (i) the input file is to be found, and
(ii) the output executable file to be placed. The "present" directory
was defined using the Change Directory command above.
Note: invoking the Execute DOS
Command and Capture Output dialog box using the F11 key allows the capture of
the text printed in the DOS execution window which briefly appears. The
resulting captured text, appearing in the CommandOutput1 window in the PFE
workspace is not a DOS window. What looks like DOS command lines are not,
unfortunately. You cannot type in additional DOS commands at what looks like
the new DOS prompt. You'll still have to invoke the DOS command using the F11
key again.
To produce this executable now, press the OK button. You'll see a DOS window
open briefly, showing the progress of the compilation process. When g77 has
finished, the temporary DOS window will close and PFE will open a second window
in the PFE workspace showing what happened (i.e., it has "captured the
output").
![](images/fortran/fortran3.gif)
No error messages were produced and we can see that an executable file was
created by producing a listing of the files currently in the directory using the
F11 key:
![](images/fortran/fortran4.gif)
or using Windows
Explorer to see:
![](images/fortran/fortran5.gif)
We can now run the executable helloworld.exe by either double-clicking it in
the Windows Explorer or by executing a DOS command from within PFE using the F11
key:
![](images/fortran/fortran6.gif)
Press the OK button to see the result:
![](images/fortran/fortran7.gif)
Congratulations! You have a working Fortran compiler running on your laptop
PC!