C/C++ and Fortran

 View Only

Specifying source form in XLF

By Archive User posted Wed October 19, 2011 03:35 PM

  

Originally posted by: Rafik_Zurob


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:
    xlf test.f
    

    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:

    xlf test.f90
    

    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:

    extensionmeaningxlf will be equivalent to the
    following specific command
    .f, .f77, .F, .F77FORTRAN 77 filefort77
    .f90, .F90Fortran 90 filexlf90
    .f95, .F95Fortran 95 filexlf95
    .f03, .F03Fortran 2003 filexlf2003

    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:
    !IBM* SOURCEFORM(FIXED)
    
    anywhere in your source file to force the compiler to process all source following the directive using fixed form. Similarly,
    !IBM* SOURCEFORM(FREE(F90))
    
    forces the compiler to process all source following the directive using free form.

0 comments
0 views

Permalink