Last week, an XLF user asked a question in the comp.lang.fortran newsgroup about how to get make to compile some Fortran files with fixed form and others with free form. There are several ways of doing this in XLF:
- If you use the ".f" file extension only for FORTRAN 77 files, you can use the generic "xlf" command to compile. The "xlf" command checks the file extension of the source file, and chooses default options, including source form, that are appropriate for that extension. For example, if you compile with:
The compiler will assume you have a FORTRAN 77 file. It will assume that the source is in fixed form. It will also assume other FORTRAN 77 defaults, such as the FORTRAN 77 way of formatting floating-point output, local variables being static, ... etc.
Alternatively, if you compile with:
The compiler will assume you have a Fortran 90 file. It will assume that the source is in free form. It will also assume Fortran 90 defaults, such as the Fortran 90 way of formatting floating-point output, local variables being automatic, zero being unsigned, ... etc.
XLF recognizes the following file extensions:
|extension||meaning||xlf will be equivalent to the|
following specific command
|.f, .f77, .F, .F77||FORTRAN 77 file||fort77|
|.f90, .F90||Fortran 90 file||xlf90|
|.f95, .F95||Fortran 95 file||xlf95|
|.f03, .F03||Fortran 2003 file||xlf2003|
The file extensions that start with a capital F mean that the compiler is to run the files through the preprocessor before compiling them.
- If you want to override the default source form, but don't want to change any other defaults, you can use compiler options to force fixed form or free form. The -qfixed compiler option enables fixed form. The -qfree=f90 compiler option enables free form.
- If you don't want to change the file extension or your Makefile, you can use compiler directives to specify the source form. For example, you can add:
anywhere in your source file to force the compiler to process all source following the directive using fixed form. Similarly,
forces the compiler to process all source following the directive using free form.