4. Salford Fortran 90 Compiler

4.1. Introduction

In principle this compiler, FTN90, has now been superseded by the Salford Fortran 95 Compiler, FTN95. However, whilst FTN90 happily links to all the NAg numerical libraries that we have installed on the Novell Network here at UMIST --- Fortran 77 and Fortran 90 --- FTN95 does not: it will link to the (Mark 19) F77 libraries, but not to the (Release 3) F90 libraries. (Correspondence with NAg suggests that in the near future this situation will not be "corrected".)

The Salford FTN90 compiler can be used to compile both Fortran 90 and Fortran 77 source files.

4.2. Menu Entries

In the PC Clusters one can start both a command-line interface to FTN90 and Plato --- the integrated development environment (IDE) --- by using the Start Menu:
     Start->Programs->Compilers->Salford FORTRAN
and then either Use Command Line FTN90 or Salford Plato. If you select Use Command Line FTN90 a "DOS box" will open (actually the Windows 32 cmd.exe equivalent) and your PATH environment variable will be set appropriately.

4.3. Ensuring Your Path is Set Correctly

In general, if you wish to use FTN90 at the command-line or through a batch-file, you will need to ensure your PATH environment variable is set correctly --- this is done for you if you use the Start Menu to start command-line FTN90 (see above). The FTN90 compiler, and its supporting libraries, are located at:
     M:\PROGRAMF\SALFORD_FTN90_<version>
where <version> is 2.191 at the time of writing (and hence the full path is M:\PROGRAMF\SALFORD_FTN90_v2_191.) The simplest way to use the FTN90 compiler is to ensure that the above location is on your path. This will ensure that executable files (including FTN90 and SLINK) and necessary libraries are found, and can be done by running a batch file called ftn90var.bat. To do this, at a command-line ("DOS box") type:
     M:\PROGRAM FILES\SALFORD_FTN90_<version>\FTN90VAR 
(no ".bat") and "hit return". Alternatively, you can check and set your path manually. Again, at a command-line:

  1. Type PATH and "hit return"; you should see something similar to this...
              PATH=C:\WINNT\system32;C:\WINNT;W:.;Z.;  
        
    ...possibly a rather longer line (or lines) of text.
  2. If this does not include M:\PROGRAM FILES\SALFORD_FTN90_<version> (it probably won't) then type exactly:
              PATH=M:\PROGRAM FILES\SALFORD_FTN90_<version>;%PATH%  
        
    and hit return; this will add the Salford compiler directory to your path --- you should now be able to use the FTN90 compiler at the command line.

4.4. Basic Usage

To compile a file, such as my_file.f90, the formal command is
     FTN90 <source-file> 
for example
     FTN90 my_file.f90 
or
     FTN90 my_file 
(either is fine). If there are no errors in the source file, my_file.f90, then an object file will be generated called my_file.obj. This needs to be linked to produce an executable file:
    SLINK
    $ LOAD my_file
    $ FILE
This will produce a file called my_file.exe which can be run in the usual way. These two steps can be combined by issuing the /LINK option to the compiler:
    FTN90 my_file /LINK
The latter works for an executable built from a single source file only.

4.5. An Example

For example, using your favourite text editor, save the following simple programme into a file called C:\work\hello.f90
    ! -- A simple Fortran 90 programme:  a greeting is printed at the 
    !    command line.

    PROGRAM hello
        PRINT *, "Hello world!"
    END PROGRAM hello
To compile and link the programme, within the directory/folder C:\work, type the command FTN90 hello.f90 /LINK, hit return and observe the output:
    C:\work>FTN90 hello.f90 /LINK
    [FTN90/WIN32 Version 2.191...
    ...
        NO ERRORS  [FTN90]
    Creating executable: hello.EXE
then, once the compilation/linking has finished run the programme by typing hello:
    C:\work>hello
     Hello world!

4.6. Programmes with Multiple Source Files

Any sizable project will consist of several source files. The following procedure shows how to compile and link a programme built from two source files and is easily generalised for more. Consider the following two source files, the first a library module, the second the "main" programme:
  MODULE strings

  IMPLICIT NONE
  CONTAINS

    SUBROUTINE print_string(string)
      IMPLICIT NONE
      CHARACTER(LEN=*), INTENT(IN) :: string
        PRINT *, string
    ENDSUBROUTINE print_string

  END MODULE strings
and
  PROGRAM hello
  USE strings
    CALL print_string("Hello world three!");
  END PROGRAM hello
In this rather artificial example, the library module provides a procedure which will print (to standard output) any given string. To compile and link these source files into an executable file, first compile each source file:
    C:\work>FTN90 strings 
    ...
        NO ERRORS  [FTN90]
    C:\work>FTN90 hello
    ...
        NO ERRORS  [FTN90]
then link the two object files, strings.obj and hello.obj into an executable:
    SLINK
    $ LOAD strings
    $ LOAD hello
    $ FILE
    Creating executable: C:\work\hello.EXE
Next, run the executable file produced as before:
    C:\work>hello
     Hello world!

4.7. .mod files and the /MOD_PATH option

When a Fortran 90 MODULE is compiled most (all?) compilers produce an auxiliary file, usually with a suffix of .mod. This file contains (amongst other things) the number and type of arguments expected by each SUBROUTINE and FUNCTION exported by the module. Using this, the compiler can check that each call to a subroutine/function by a client of the module is correct.

If the .mod files corresponding to USEd MODULEs are not in the current directory, the compiler needs to be told where to look (e.g., when using the NAg libraries --- see below). This is achieved by using the /MOD_PATH compiler option --- see below.

4.8. Important Compiler Options

/MOD_PATH
Tells the compiler where to look for .mod files, for example
    FTN90 /MOD_PATH M:\NAG\FNW3203D9\NAG_MOD_DIR NAG_FFT_EX01.F90


/FIXED and /FREE
These compiler options specify the source code format to be expected: /FIXED specifies Fortran 77-style fixed format; /FREE specifies Fortran 90-style free format. (The default for filenames with suffix .FOR is /FIXED; other wise free-format is expected.)


/CHECK_SUBS
By default the Salford FTN90 compiler does not check array bounds. This produces significantly faster code but means that programmes can behave in unpredictable, system-dependent ways (produce incorrect results or simply crash) owing to undetected bugs. The /CHECK_SUBS (check subscripts) option ensures array-bound-checking code is added to a programme.


4.9. Automating Builds

Compilation and linking of programmes built from multiple source-files though the command-line can become tedious. The simplest solution is to automate the procedure by means of a batch file. Here is an example:
    ftn90 /mod_path C:\work strings.f90
    if errorlevel 1 goto err2

    ftn90 /mod_path C:\work hello.f90
    if errorlevel 1 goto err2

    echo load strings.obj     > slink.lst
    echo load hello.obj       >> slink.lst
    echo file hello           >> slink.lst

    slink slink.lst

    :err1
    echo strings: failed to compile

    :err2
    echo hello: failed to compile

A more powerful option is to use Cygwin's make utility --- this is a port of the GNU make utility found on Unix systems.

4.10. On-disk Help

On-disk help is provided in the usual way for Windows applications. The help file may be found at
    M:\PROGRAM FILES\SALFORD\FTN90.HLP

...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_salford/_reml_grp/salford_compilers.reml
On: 25/7/2002 at 9:59:15
Options: reml2 -i noindex -l long -o html -p multiple