Free FORTRAN Compilers



There are a number of free Fortran 77 and 90 compilers available on the net. The one that I have been using in all my Fortran courses at York is GNU g77, which implements Fortran 77 and adds several Fortran 90 features. You can download the 1996 version of this compiler from this page.

  Please note that this version does not run under Windows XP and does not come with a library (beyond the intrinsics). It is therefore highly recommended that you use instead the 1999 version, which can be downloaded from this page.

The needed files are less than 1.44MB each:

To install it, create a new folder immediately under the root of your hard disk and call it Fortran. You can do this by double-clicking MyComputer, then double-clicking your hard drive (usually C:), and then selecting New Folder from the File menu and calling the folder Fortran. Next, download the four files above by simply right- clicking each and choosing Save Target As.... In the Save As window that appears, locate the Fortran folder, and save the files in it (one by one) under their default names.

Next, run MS-DOS (using Start | Programs | Command Prompt) and type the following:

    cd \Fortran
    pkunzip -d g77dos.zip
    pkunzip -d g77doc.zip
    cd EMX
If you get an error message (e.g. Path not found) after the first command, then you haven't created the Fortran folder under the root (but perhaps under desktop or some other folder). And if you get an error message after the 2nd or 3rd command (e.g. File not found), then you haven't downloaded the files into the Fortran folder. Finally, if you get an error message (e.g. Path not found) after the 4th command, then you forgot the -d switch of the pkunzip command. In all these cases, repeat the above steps.

Next, we need to make changes to a couple of environment variables, and this depends on your operating system:

Finally, close the DOS window (by clicking its close box or typing exit) and then restart your computer (to allow these changes to take effect).

This almost completes the installation procedure. To facilitate using the compiler, however, the following three files, albeit not essential, are very helpful as they shorten the invocation command, redirect the error messages, if any, to the screen, and pause after a screenful of errors:

Download each and store in \fortran\emx\bin. You can now invoke the compiler to compile a program like Test.FOR using the command: fcomp test or the command: fcomp2 test (fcomp stands for Fortran Compile). Note that you no longer need to specify neither the free-form switch nor the .for extension.

If you are new to Fortran, go through the 12 on-line Labs; otherwise, use the Guide as a quick reference. Both are available from this site.

The text files in the EMX directory give a detailed reference to the language. Note, in particular, that:

  1. The gnu compiler uses ! for both full-line and in-line comments.
  2. To continue a statement on the next line, make its last character an ampersand &.
  3. gnu does not have a LEN_TRIM function. Need to write your own.
  4. The OPEN statement does not have an 'append' option
  5. The path separator is a forward slash rather than a back slash (to be used in the file=' ' parameter of the OPEN statement). This is because \ denotes an escape sequence in gnu and, hence, an alternate way to specify a path is to use two backslashes: \\.
  6. Not all unit numbers are allowed in the OPEN statement. In particular, unit 5 is "pre-connected" to the keyboard. Units 10 through 99 seem to work well with disk files.

Professor H. Roumani,
Dept. of Computer Science, York University, Toronto, Canada, Email: roumani@cs.yorku.ca