Noeud:Fortran, Noeud « Next »:, Noeud « Previous »:Java, Noeud « Up »:Integrated Languages



Fortran

The front end compiler for Fortran is g77. It is used to compile GNU Fortran programs; however, other Fortran dialects are also supported by a number of flags. For details of the GNU Fortran language, refer to <http://gcc.gnu.org/onlinedocs/g77_toc.html>.

Compiling a simple fortran source file

As with many of the other front-ends, you can use many of the C language options such as -o, -g, -v etc. The options here should be enough for you to compile many Frotran programs, although you should refer to the g77 documentation for a broader range of flags.

g77 Options

-ffree-form, -fno-fixed-form by default, compilation will vi for fixed form Fortran code, based on punched-card format. Specifying -ffree-form or -fno-fixed-form allows compilation of the new Fortran 90 free form source code.
-ff90 allow some Fortran 90 constructs; not all may be supported, depending on current support for the compiler you're using.
-I-, -IDIR Files included by the Fortran INCLUDE directive are not preprocessed; thus, use -IDIR to search for INCLUDE files in directory DIR. Do not put a space between the switch and the directory.
-x f77-cpp-input Ensure that the source file is preprocessed by the preprocessor, cpp. This enables you to pass -D options to the preprocessor inside the Fortran file (see Defining Constants), as well as be able to deal with #ifdef and #if statements etc. in your code.

Like the previous section on gcj, we'll illustrate a simple hello world program, outlined below in the new Fortran free form format, with a few preprocessor options in there:

     $ cat HelloWorld.for
           PROGRAM HELLOWORLD
     #if HELLO
           WRITE(6,*) 'Hello, world!'
     #else
           WRITE(6,*) 'Goodbye, world!'
     #endif
           END PROGRAM HELLOWORLD
     $
     

I compiled this program using the command g77 -x f77-cpp-input -DHELLO -ffree-form HelloWorld.for

You can well imagine the output of this program - so we'll not bother listing it. If we'd not have included the -DHELLO definition, the output would have been instead "Goodbye, world!".