The back end and libraries are now up for general testing on a variety of boxes and operating systems. The tarball is usually updated as the web page is. To download and install g95 on unix systems, run the following command (originally from Joost Vandevondele):

wget -O - http://ftp.g95.org/g95-x86-
linux.tgz | tar xvfz -

This will create a directory named 'g95-install' in the current directory. Run (or better yet make an appropriate symbolic link to) ./g95-
install/bin/i686-pc-linux-gnu-
g95 in order to run g95.

Quick Links:


How to configure emacs for
g95 error messages (Helge Avlesen)

Add the following lines to your .emacs file:

;; add g95 to compilation mode
(eval-after-load "compile"
'(setq compilation-error-regexp-alist
(cons '("^In file \\(.+\\):\\([0-9]+\\)" 1 2)
compilation-error-regexp-alist)))

This will allow emacs to find the next error message in compile mode.

How to link shared g95
programs with R

  1. Make "libf95.so"

    After installing g95 find the file "libf95.a". Copy this to an empty subdirectory and extract all of the objects: "ar -x libg95.a". Then create a shared library: "gcc -shared -o libg95.so *.o". It is useful to put the file "libg95.so" somewhere where users can make use of it (i.e. /usr/local/lib)

  2. Compile your source files with g95 as follows: g95 -c -fPIC mylib.f and make the objects into your own shared library: gcc -shared -o mylib.so mylib.o That's it! Use the library in R as follows:
    >  dyn.load("/path-to/libg95.so",local=FALSE)
    > dyn.load("/path-to/mylib.so")

    Example: ( square a vector ) myib.f:

        subroutine fsquv(n, x)

    integer n
    double precision x(n)
    integer i

    do 100 i = 1, n
    x(i) = x(i) ** 2
    100 continue
    End

    After the steps above in R:

    > dyn.load("/path-to/libg95.so",local=FALSE)
    > dyn.load("/path-to/mylib.so")

    then define a "wrapper" function in R to make it easier

    squarevector <- function(x) {
    if (!is.numeric(x)) stop("argument x must be numeric")
    out <- .Fortran("fsquv",n=as.integer(length(x)),
    x=as.double(x))
    return(out$x)
    }

    Then use your wrapper function:

    >  squarevector(1:5)
    [1] 1 4 9 16 25

How to use mkmf with g95

  • Last update: 7 March 2007
  • This Howto includes contributions from Hani Andreas Ibrahim and Mohammad Rahmani
  • Further suggestions are welcome!

mkmf is a tool written in perl5 that will construct a Makefile. It is available from <http://www.gfdl.noaa.gov/fms/pubrel/k/am2/bin/mkmf.html>. mkmf understands dependencies in f90 (modules and use), the fortran include statement, and the cpp #include statement in any type of source. Detailed information on using mkmf is provided at the link provided above.

Perl 5 must be installed in order to use mkmf. If using Windows, Perl is included in the msysDTK package. Download and install both "msys" and "msysDTK" from www.mingw.org. Include the mingw\bin and Msys\1.0\bin directories in your PATH.

1. Download the mkmf script and save it somewhere in your system (e.g. c:\mingw\bin).

2. mkmf currently only distinguishes .f, .F, .f90, and .F90 source filename extensions. If you wish to add support other Fortran extensions, change lines 59 to 82 in the mkmf perl script as follows, otherwise skip to step 3.

#some constants
my $endline = $/;
my @src_suffixes = ( q/\.F/, q/\.FOR/, q/\.F90/, q/\.F95/,q/\.F03/, q/\.c/, q/\.f/, q/\.for/,q/\.f90/, q/\.f95/, q/\.f03/ );
my @inc_suffixes = ( q/\.H/, q/\.fh/, q/\.h/, q/\.inc/ );
# push @inc_suffixes, @src_suffixes; # sourcefiles can be includefiles too: DISALLOW, 6 May 2004
my %compile_cmd = ( # command to create .o file from a source file suffix
q/.F/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) -c/,
q/.FOR/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) -c/,
q/.F90/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) -c/,
q/.F95/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) -c/,
q/.F03/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) -c/,
q/.c/ => q/$(CC) $(CPPDEFS) $(CPPFLAGS) $(CFLAGS) -c/,
q/.f/ => q/$(FC) $(FFLAGS) -c/,
q/.for/ => q/$(FC) $(FFLAGS) -c/,
q/.f90/ => q/$(FC) $(FFLAGS) -c/,
q/.f95/ => q/$(FC) $(FFLAGS) -c/,
q/.f03/ => q/$(FC) $(FFLAGS) -c/ );
my %delim_match = ( q/'/ => q/'/, # hash to find include file delimiter pair
q/"/ => q/"/,
q/</ => q/>/ );
#formatting command for MAKEFILE, keeps very long lines to 256 characters

3. Create a template file for your compiler to adapt to user environment.

Below is an example template file for g95:
FC = g95
LD = g95
FFLAGS = -I c:/mingw/include
LDFLAGS = $(LIBS)
# add your libraries after LIBS= , e.g. -lblas
LIBS = c:/mingw/lib

Give a name to the above template file (e.g. g95_args) and save it as c:\mingw\bin\g95_args

4. The syntax for using mkmf is:

mkmf [-a abspath] [-c cppdefs] [-d] [-f] [-m makefile] [-p program] [-t template] [-v] [-x] [args]
-a abspath attaches the abspath at the front of all relative paths to source files;
cppdefs is a list of cpp #defines to be passed to the source files: affected object files will be selectively removed if there has been a change in this state;
-d is a debug flag to mkmf (much more verbose than -v, but probably of use only if you are modifying mkmf itself);
-f is a formatting flag to restrict lines in the makefile to 256 characters. This allows editing makefiles using vi. Lines longer than that will use continuation lines as needed;
makefile is the name of the makefile written (default Makefile);
template is a file containing a list of make macros or commands written to the beginning of the makefile;
program is the name of the final target (default a.out, change to a.exe for Windows systems);
-v is a verbosity flag to mkmf;
-x executes the makefile immediately;
args are a list of directories and files to be searched for targets and dependencies.

5. Usage

5.1. To use mkmf with the g95 compiler to create a Makefile, go to the directory containing your source files and issue the following command:

Perl c:\mingw\bin\mkmf -t c:\mingw\bin\g95_args

5.2. To create a makefile and execute it immediately with an optional target name, do as follows:

mkmf -t c:\mingw\bin\g95_args -p myproj.exe -x

Here "myproj.exe" is the name of the final target (output)

6. To make using mkmf much easier, create a script file (e.g. mkmf-g95.bat on Windows) and put it in c:\mingw\bin. (Make sure you have this in your PATH.) The script file should contain the following (modify to fit your setup):

Echo off
REM This file can be called from anywhere to create a Makefile
REM based on the Fortran source files in that location.
REM a.exe is the name of final output. Change it to fit your needs.
REM If ignored, the mkmf script will use a.out by default.
REM g95_args is the name of a template file used to set user
REM environment variables. Change it as you wish.
REM
REM Perl c:\mingw\bin\mkmf -t c:\mingw\bin\g95_args -p a.exe
If (%1)==() (
Perl c:\mingw\bin\mkmf -t c:\mingw\bin\g95_args -p a.exe
) Else (
Perl c:\mingw\bin\mkmf -t c:\mingw\bin\g95_args -p %1
)
REM The above allows the target name to be passed as an argument

In the above code, if you pass a target name as an argument to mkmf-g95.bat, it will generate a Makefile with the target name as its output. Otherwise the script will produce a Makefile with a.exe as the output target.

7. Change a.out to a.exe [Only on Windows machines]. The mkmf script creates Makefiles with a.out as the target, which is not suitable for Windows so it is necessary to modify the mkmf to produce "a.exe" as the default output instead of "a.out". To do this, open the mkmf script file in a text editor and replace all a.out with a.exe.

How to use Photran with G95

  • Last update: 7 March 2007
  • This install guide has been tested successfully with Photran 3.1 Beta 2 for Windows
  • This Howto includes contributions from Hani Andreas Ibrahim (25/01/2007) and Mohammad Rahmani (9/02/2007)
  • The g95 compiler, and Perl should be in your PATH
  • Further suggestions for improvements and/or corrections are welcome!

Now you can develop your Fortran programs with g95 using Photran, a full featured Fortran IDE based on Eclipse. It is available for both Windows and Linux systems. This is a summary of the steps required to setup Photran and g95 on a Windows XP system.

1. If you use MinGW it is useful to download and install "msys" and "msysDTK" from www.mingw.org. The Msys bin directory has to be in your path.

2. Generating a g95 Makefile automatically

(Skip this section if you don’t want to use mkmf for auto creation of Makefile)

Set up mkmf by carefully following all the directions provided in How to use mkmf with with g95. If your paths are different from those used in the install instructions make appropriate adjustments to the paths used in the following steps.

In order to use mkmf in Photran, Perl 5 must be installed. If using Windows, Perl is included in the msysDTK package from www.mingw.org.

2.1 Open Photran and click the menu "Run -> External tools -> External tools..."

2.1.1 On the Main Tab fill out the form as follows:

Name: g95 make Makefile
Location: c:/mingw/bin/mkmf-g95.bat
Working directory: ${container_loc}
Arguments: ${project_name}

Note: The file c:\mingw\bin\mkmf-g95.bat is the batch file for running the mkmf Perl script described in Section 6 of How to use mkmf with with g95

2.1.2 Refresh Tab

For refresh tab fill the form as follows:

[x] Refresh resources upon completion

(x) The folder containing the selected resources

[x] Recursively include sub-folders

2.1.3 Common Tab

(x) Local file

Display in favorite menu

[x] External Tools

[x] Launch in background

2.1.4. Click "Apply"

2.2 On the Photran toolbar click the menu "Run -> External tools -> External tools..."

2.2.1 Start a new configuration.

2.2.2 On the Main Tab fill out the form as follows:

Name: g95 build
Location: c:/msys/1.0/bin/make.exe
Working directory: ${container_loc}
Arguments: all

2.2.3 Fill out the Refresh Tab as in 2.1.2 and the Common Tab as in section 2.1.3

2.2.4 Click "Apply"

2.3 On the Photran toolbar click the menu "Run -> External tools -> External tools..."

2.3.1 Start a new configuration.

2.3.2 On the Main Tab fill out the form as follows:

Name: Run
Location: ${container_loc}/${resource_name}
Working directory: ${container_loc}
Arguments: 

2.3.3 Fill out the Refresh Tab as in 2.1.2 and the Common Tab as in section 2.1.3

2.3.4 Click "Apply"

3. Click on menu Windows->Preferences->C/C++->Make->Makefile Editor->New Make Projects.

Choose Tab 'Binary Parser'. Enable 'PE Windows Parser' and disable all others. Click on the OK button.

4. Setup is done.

To edit, compile and run Fortran programs do the following:

1. File->New->Standard Make Fortran Project. Give a name to your project in the 'Project Name' field. Click 'Finish'.

2. Make sure that your project name is highlighted in the 'Fortran Projects' or 'Navigator' frame on the left. Click File->New->Source File. Fill out the 'Source File' field (e.g. myprogram.f90). Click 'Finish'.

3. Type your code in the new editor tab and save it (File->Save)

4. Add further source files if necessary.

5. Click on one of your source files in the Navigator or Fortran projects frame.

6. Create Makefile

6.1. If you have set up mkmf (see section 2) do as follows:

6.1.1. Click menu "Run->External tools->External tools ..."

6.1.2. Choose (e.g.) "g95 make Makefile" and click the "Run" button. In the Navigator/Fortran Projects frame you should see the "Makefile" file in your project section. (After the first run of "g95 make Makefile" it will appear in the root section of the External tools submenu or toolbar icon for easy invocation.)

6.2. If you have not set up mkmf on your system you will need to code the Makefile yourself

7. Select one of your source files in the Navigator/Fortran Projects frame again.

8. Click menu "Run->External tools->External tools ..." and select "g95 build".

9. After compilation you should see "myprogram.exe" in your Navigator/Fortran Projects frame.

10. Select "myprogram.exe" in the Navigator/Fortran Projects frame, then click on the menu "Run->External tools->External tools ..." and select "Run". The program output will display in the Console.

For information on setting up Photran with Cygwin, see: ftp://ftp.swcp.com/pub/walt/F/photran.pdf

How to configure LAPACK for g95

The only change that needs to be made to correctly build LAPACK for x86 machines is to set the NOOPT macro in make.inc:

NOOPT=-ffloat-store  

This prevents optimizations from interfering with the subroutines that are trying to query various characteristics of the floating point unit.

How to compile ARPACK with g95
(Guglielmo Pasa)

Use ARmakeg95.inc and Makefileg95.make and OBjectg.make in this tarball to build a static and a dynamic library for arpack.

How to configure MPICH2-1.0.1
with g95 (Guglielmo Pasa)

For bash/sh, you can use:

alias f77=g95 -ffixed-form -fno-underscoring
alias f90=g95 -ffree-form -fno-underscoring

or for csh/tcsh:

Setenv F90
Setenv F77
Setenv CC

Verify that it detects the right compilers and then run

$ ./configure --prefix=/usr/local --enable-f77 --enable-f90 \
--with-pm=smpd --with-pmi=smpd
$ make
$ make install

Try some tests. You can use the MPICH2 WinXP service binary distro found on the MPICH2 site with it. An alternate procedure (Patti Michelle) is to configure with:

$ F77=/path/to/g95 F90=/path/to/g95 ./configure
$ make
$ make install

How to configure BLACS with
g95 (Guglielmo Pasa)

If BLACS source tree is in $(HOME)/BLACS Edit Bmake.inc and change

TOPdir=$(HOME)/BLACS

COMMLIB = MPI
PLAT = g95xp # for example

MPIdir = /usr/local # root installation directory of MPICH
MPILIBdir = $(MPIdir)/lib
MPIINCdir = $(MPIdir)/include
MPILIB = -L$(MPILIBdir) -lmpich -lpmpich -lmpich -lcrypto
....
INTFACE = -DNoChange # leaves symbols of C objects the same form as g95 ones
# i.e. no underscores and lower case
...
TRANSCOMM = -DCSameF77
...
F77 = g95
F77NO_OPTFLAGS = -ffixed-form -fno-underscoring
...
RANLIB = ranlib

Once this is done go to SRC/MPI and modify Makefile

In
Clong = ...

If you are on windows, change all the .C extensions with .Z as windows isn't case sensitive to copy/write files, so even if cygwin is case sensitive sometimes it fails to distinguish .C and .c

...
Cintobj = $(comm.:.o=.Z) $(supp:.o=.Z) $(Clong)
...
clean:
rm -f ... $(long:.o=.Z)
...
Cblacs_gridinit_.C : etc change all extension .C to .Z
...
.SUFFIXES: .o .Z
.c.Z:
$(CC) -o C$*.o -c $(CCFLAGS) $(BLACSDEFS) -DCallFromC $<
mv C$*.o $*.Z

Then go to the root of BLACS and do

make mpi  

and install libraries by hand.

How to configure SCALAPACK
with g95 (Guglielmo Pasa)

Edit and modify SLmake.inc

home = $(HOME)/SCALAPACK  # where is the SCALAPACK source tree
PLAT = g95xp # just for coherence in choices ;o)

BLACSdir = /usr/local/lib # where BLACS has been put

USEMPI = -DUsingMpiBlacs
SMPLIB = -L/usr/local/lib -lmpich -lpmpich -lmpich -lcrypto
...
F77 = g95 -ffixed-form -fno-underscoring
...
CDEFS = -DNoChange $(USEMPI)
...
RANLIB = ranlib

# I use LAPACK3 and its BLAS distro as ATLAS has bad performance(see below)
# _sf77 stands for s=static (I have _f77.dll too) and f77 for
...f77(aka 95)

BLASLIB = -L/usr/local/lib -lblas_sf77
# it's only necessary for tests apps

How to configure SUPERLU-3.0
with g95 (Guglielmo Pasa)

Modify the Makefile:

PLAT = g95xp 
BLASLIB = -L/usr/local/lib -lblas_sf77
RANLIB = ranllib
FORTRAN = g95 -ffixed-form -fno-underscoring
CDEFS = -DNoChange

How to configure UMFPACK
with g95 (Guglielmo Pasa)

Edit and modify UMFPACKv4.4/AMD/Make/Make.include

F77 = g95
F77FLAGS = -ffixed-form -fno-underscoring
...
CONFIG = -DBLAS_NO_UNDERSCORE
...
include ../Make/Make.cygwin

Next, still in AMD/Make copy Make.linux to Make.cygwin and modify

CC = gcc
CFLAGS = -O2
...
LIB = -L/usr/local/lib -lblas_sf77 -lf95 # you have to copy libf95.a to /lib

# or /usr/local/lib first !! It is needed by gcc on linking with C progs

Next go to AMD/ and run make (if you want to use matlab also, I don't know how to include it correctly yet ! so disable it or you'll get an error after the library libamd.a has been built. If you just want the library that's fine! the error just appears as make doesn't find mex)

Next go to UMFPACK and run

make hb  

that builds libumfpack.a and the hb example. Next you can copy the libraries to /usr/local/lib and the include files to /usr/local/include.

How to configure METIS-4.0
with g95 (Guglielmo Pasa)

Edit Makefile.in

RANLIB = ranlib  

Run make and copy libmetis.a to /usr/local/lib/libmetis-4.0.a.

How to configure MUMPS-4.3.2
with g95 (Guglielmo Pasa)

Copy Makefile.inc.generic and Makefile.inc.generic.SEQ from Make.inc/ to the root of MUMPS source tree as Makefile.inc and Makefile.inc.SEQ respectively and edit Makefile.inc (parallel version, edit SEQ accordingly with MPI indications cited in the file)

LMETISDIR = /usr/local/lib
LMETIS = -$(LMETISDIR) -lmetis-4.0

ORDERINGS = -Dmetis -Dpord
ORDERINGSF = -Dpord -Dmetis
...
FC = g95
RANLIB = ranlib

SCALAP = -lscalapack \
/usr/local/lib/blacs_MPI-g95xp-0.a \
/usr/local/lib/blacsF77init_MPI-g95xp-0.a \
/usr/local/lib/blacs_MPI-g95xp-0.a

# INCLUDE DIRECTORY FOR MPI
INCPAR = -I/usr/local/include

# LIBRARIES USED BY THE PARALLEL VERSION OF MUMPS: $(SCALAP) and MPI
LIBPAR = $(SCALAP) -L/usr/local/lib -lmpich -lpmpich -lmpich -lcrypto

# DEFINE HERE YOUR BLAS LIBRARY
LIBBLAS = -lblas_sf77

CDEFS = # empty !!

#COMPILER OPTIONS
OPTF = -O -fno-underscoring

How to configure Aztec 2.1
with g95 (Guglielmo Pasa)

Download the required files (look in get_packages/netlib_mail to see which one are required, pay attention that dblas1.f etc. are not real sources so you have to look inside those files to see which one are really needed) and put them in get_packages. Make rip.exe and run the script process_netlib.

Edit lib/Makefile.template

COMM    = SERIAL
MACHINE = GENERIC
MPI_INCLUDE_DIR = -I/usr/local/include
MPI_LIB = -L/usr/local/lib -lmpich -lpmpich -lmpich -lcrypto -lm
...
CC_TFLOP = gcc

FC_TFLOP = g95

AR_TFLOP = ar

RANLIB_TFLOP = ranlib
TIME_TFLOP = md_timer_sun.c

CFORT_TFLOP = -Dmatched

CFLAGS_TFLOP = -O2

FFLAGS_TFLOP = -O2 -ffixed-form -fno-underscoring

The end of Makefile.template should look like:

aztec: $(OBJ)
@echo "Building library $(TARGET)"
@rm -f libaztec$(COMM).a
$(AR) ruv libaztec$(COMM).a $(OBJ)
@$(RNLIB) libaztec$(COMM).a

The first few lines of Makefile.template should be: 1) for an MPI library

COMM    = MPI
MACHINE = TFLOP
MPI_INCLUDE_DIR = -I/usr/local/include
MPI_LIB = -L/usr/local/lib -lmpich -lpmpich -lmpich -lcrypto -lm

2) for a SERIAL library

COMM    = SERIAL
MACHINE = TFLOP
MPI_INCLUDE_DIR =
MPI_LIB =

Don't change anything else. Do the same in app/

./set_makefiles 
cd lib
make
cp libaztec.a /usr/local/lib
cp *.h /usr/local/include
cd ..
cd app
make

Run the demos.

How to link g95 programs
with MATLAB (Aaron Schmidt)

MATLAB provides an easy way of incorporating C or Fortran code. The programmer must write a small subroutine called a gateway which passes variables back and forth between C/Fortran and MATLAB. The code is then compiled, usually using the MATLAB command 'mex', which calls an external compiler. The compiled code can then be used exactly like a MATLAB function. Details on creating mex files can be found in the help files.

Although G95 is not an officially supported compiler, it appears to work fine. The Fortran compiler is specified in the mexopts.sh file, which is stored in [MATLAB root]/bin, or in a local copy kept somewhere in ~/.matlab. To use G95, open mexopts.sh and go the section relevant for your OS. Change the variable 'FC' to specify the full path to G95. Also, it is necessary to link to libf95.a or MATLAB will crash when attempting to use certain intrinsics, so add that to the 'FLIBS' variable. The other variables should be set to whatever additional flags and optimization options you want. As an example, on Mac OS X and MATLAB 7, the relevant section of mexopts.sh looks like:

FC='/usr/local/g95-install/bin/powerpc-apple-darwin6.8-g95' 
FFLAGS='-ffree-form'
FLIBS='-L/usr/local/g95-install/lib/gcc-lib/powerpc-apple-darwin6.8/4.0.0/ -lf95'
FOPTIMFLAGS='-O'
FDEBUGFLAGS='-g'

Notes

  • The simplest way to pass data to and from MATLAB is through the %VAL() construct or the F2003 VALUE attribute.
  • I have only tested G95 with MATLAB 7 and Mac OS X, so there are probably things I've missed. Information on using MATLAB and other Fortran90 compilers is on the web and may be helpful.
  • Use -fexceptions in FFLAGS if fortran code uses extern "C" c++ function that throw c++ exceptions so MATLAB won't crash. (Dimitry Markman)

Using g95 and MATLAB under
windows (Ivo Houtzager)

You need the following programs:

Install G95-MinGW in the root directory of MinGW (for example C:\MinGW) Install Gnumex (for example in C:\Gnumex) Copy the patch to C:\Gnumex and patch the files gnumex.m and linkmex.pl:

patch -l < gnumex.patch  

In Matlab add the path C:\Gnumex

>>path(path,'C:\Gnumex')  

Call "gnumex" in Matlab. Select Mingw for linking and G95 in the "language for compilation?" drop box. If C:\MinGW is not your MinGW root directory adjust the "Mingw root path". See for more information gnumex.sourceforge.net Comments on Gnumex and MinGW: The versions of gcc-3.4.4 and gcc-3.3.3 and lower works fine, but I get for the versions 3.4.0, 3.4.1 and 3.4.2 and the compiler setting pentium4 bad results. The cause is the compiler optimization -mfpmath=sse. I added the setting "pentium4 -f" which has this optimization removed.

How to use IRIX modules with g95
(Charles Castevens)

  1. As root, create a module file called 'g95' for the users to load:
    touch /opt/modulefiles/g95 
    chmod a+r /opt/modulefiles/g95
    vi /opt/modulefiles/g95

    #%Module################################################# 
    # http://ftp.g95.org/g95-mips-irix.tgz default modulefile
    # IRIX version Fri Jul 21 21:14:30 EDT 2006
    #
    proc ModulesHelp { } {
    puts stderr "The g95 modulefile defines the default path needed to use
    #g95"
    puts stderr "Type \"module load g95\" to load g95 and then"
    puts stderr "\"module list\" to verify that the g95 modulefile is
    #loaded."
    }
    set _module_name [module-info name]
    set is_module_rm [module-info mode remove]
    set G95_CURPATH /opt/g95/bin
    prepend-path PATH $G95_CURPATH
  2. Copy http://ftp.g95.org/g95-mips-irix.tgz to /usr/tmp then
    cd /usr/tmp  
    mkdir -p /opt/g95/bin
    mkdir -p /opt/g95/lib/gcc-lib/mips-sgi-irix6.5/4.0.1
    gunzip -c g95-mips-irix.tgz | tar -xvf -
    cd g95-install/bin
    mv mips-sgi-irix6.5-g95 /opt/g95/bin
    cd ../lib/gcc-lib/mips-sgi-irix6.5/4.0.1
    mv * /opt/g95/lib/gcc-lib/mips-sgi-irix6.5/4.0.1
    cd /opt/g95
    chown -R nobody.nobody . *
    chmod a+rx . bin
    cd bin
    ln -s mips-sgi-irix6.5-g95 g95
    cd ../lib/gcc-lib
    chmod a+rx . ..
    cd mips-sgi-irix6.5/4.0.1
    chmod a+rx . .. *
    chmod a-x *.a *.o *.1
  3. From a user prompt once they do the usual
    source /opt/modules/modules/init/csh
    module load modules

    at a prompt or in their .cshrc or .tcshrc; see

    grelnotes modules &  

    and click on "Next Chapter" for more info. Once you have modules working on the machine, the users should be able to go straight to

    module load g95  

    once they log in and then g95 will be ready:

    g95 -O3 -s program.f -o program 
    ./program

How to use g95 with SciTE
(Doug Cox)

The free SciTE editor works with many programming languages, including Fortran. SciTE is available for both Linux and Windows systems. The Windows version is configured for the Lahey compiler by default. On systems with a working version of make, which is included in Msys/MinGW and in Cygwin on Windows, SciTE can be used for editing fortran files, compiling with g95, and testing executables. Here is how to set up SciTE for use with g95:

  1. Download SciTE from: http://scintilla.sourceforge.net/SciTEDownload.html
  2. Install by unpacking in some convenient directory.
  3. Edit the fortran.properties file listed under the Options menu. Change the compiler names to:
    fc77=g95  
    fc90=g95
  4. Change the lines in the fortran.properties file containing the commands for compiling to something like the following:
    command.compile.*.f=$(fc77) -I.\ -L.\ $(1) $(2) -c $(FileNameExt) $(3) $(4) -info 
    command.compile.*.for=$(fc77) -I.\ -L.\ $(1) $(2) -c $(FileNameExt) $(3) $(4) -info
    command.compile.*.f90=$(fc90) -I.\ -L.\ $(1) $(2) -c $(FileNameExt) $(3) $(4) -info
    command.compile.*.f95=$(fc90) -I.\ -L.\ $(1) $(2) -c $(FileNameExt) $(3) $(4) -info
  5. For Windows systems with MinGW and Msys, add the c:\Msys\1.0\bin directory (or the equivalent on your system) to the PATH so that SciTE can find the Msys make program, and if necessary, add the c:\mingw\bin directory to the PATH so that SciTE can find g95.
  6. SciTE allows you to compile and execute your code from the Tools menu. There are commands for compiling a file, building a project using make, and running the executable in a SciTE shell.

Using g95's -M option

When compiling with g95, the -M option can be used for writing Makefiles. The use of this option causes g95 to write out dependencies in the form required by a Makefile. The output can be used in the Makefile needed by the make program. This feature makes writing makefiles for g95 easier. Put the Makefile in the same directory as your source files. Simply click 'Build' under the 'Tools' menu in SciTE to run make. If the build is successful, clicking 'Go' runs the compiled program.

How to interface with
Python programs (Bill McLean)

Suppose we want to call a subroutine foo with the interface:

subroutine foo(n, a) 
integer, intent(in) :: n
real, intent(out) :: a(n,n)
end subroutine foo

First method: using ctypes:

  1. Install numpy (>=version 1.0).
  2. If your Python version is < 2.5, then either install ctypes or install the current python version (which include ctypes in the standard library). Note that "make altinstall" allows you to use a new python version alongside an existing, older version to avoid possible problems with python-dependent packages.
  3. Compile foo.f95 into a shared library:
    g95 -shared -fPIC foo.f95 -o foo.so  
    and check the name of the routine's symbol
    nm foo.so | grep foo  
    This name will be foo_ if foo is an external procedure, but will be bar_MP_foo_ is foo in contained in a module bar. You can use the BIND(C) feature to control the symbol's actual name.
  4. Write a python wrapper for foo as follows:
    from numpy  import * 
    from ctypes import c_int, POINTER, byref

    foolib = ctypeslib.load_library('foo', '.')
    _foo = foolib.foo_ # or _foo = foolib.bar_MP_foo_
    _foo.restype = None

    def foo(n):
    a = zeros((n,n,), dtype=float32, order='FORTRAN')
    arg = ctypeslib.ndpointer(dtype=float32, shape=(n,n,), flags='FORTRAN')
    _foo.argtypes = [POINTER(c_int), arg]
    cn = c_int(n)
    _foo(byref(cn), a)
    return a

    a = foo(4)

Second method: using f2py

  1. Install numpy (version>=1.0), which includes f2py, a fortran-to-python interface generator. Do
    f2py -c --help-fcompiler  
    to check that f2py recognizes g95.
  2. Use f2py to generate a signature file foo.pyf:
    f2py foo.f95 -m foo -h foo.pyf  
    In more complicated examples, you might have to manually adjust foo.pyf.
  3. Use f2py again to automagically create a python extension module foo.so:
    f2py -c --fcompiler=g95 foo.pyf foo.f95  
    Here, if you omit the --fcompiler flag then f2py uses the default compiler as determined by the _default_compilers variable in the file numpy/distutils/fcompiler/__init__.py (currently g77).
  4. Calling foo from python is now easy.
    from numpy import * 
    import foo

    print foo.foo.__doc__ # shows python interface generated by f2py
    a = foo.foo(4)

Using Scons with g95 (Doug Cox)

The Scons build system can be obtained from http://www.scons.org. Scons signifies 'Software Construction'. It is an alternative to 'make'. Scons requires Python to be installed. When invoked without any arguments Scons looks for a file named 'SConstruct', which is also a Python script.

By default, the Windows version of Scons is set up to work with the Microsoft C compiler, but it can be used to build many other kinds of projects. Below is an example of an SConstruct file that works with the MinGW version of g95 in an Msys shell. In this example, the files foo1.f90 .. foo4.f90 are module files, and foo.f90 is a main program which uses the modules. The file foo4.f90 contains a module which is required by foo2.f90, so it is listed before foo2.f90. Scons detects which source files have been modified since a previous build, and only rebuilds the ones that are needed. 

# Example build script for Scons in Msys/MinGW
# In a Msys shell, cd to the source directory
# Save this script with the filename SConstruct
# To build, type 'c:/python25/scripts/scons'

import os
env = Environment( platform = 'win32',
  ENV = os.environ,
  tools = ['mingw'],
FORTRAN = 'g95',
  FORTRANFLAGS = '-O3',
  CC = 'gcc',
  LINK = 'g95' )
env.Program( target = 'foo.exe',
  source = [
    'foo1.f90',  # module source file
    'foo4.f90',  # module source file used in foo2.f90
    'foo2.f90',  # module source file
   'foo3.f90',  # module source file
    'foo.f90'    # main program
])

# For information see:
# http://www.scons.org/doc/HTML/scons-man.html

Configuring MATRAN with g95

  1. Grab matran source from http://www.cs.umd.edu/~stewart/matran/Matran.tar
  2. tar -xvf Matran.tar wherever you see fit.
  3. cd Matran/Matran
  4. edit Makefile and change the following lines
    FC = f95  $(FC) -c -fpp -D$(PREC) $< 
    to
    FC = g95 $(FC) -c -cpp -D$(PREC) $<
  5. Be sure to have the libs blas.a and lapack.a in some directory that g95 can find. If the names of libs are different, be sure to change them in the Makefile
  6. Issue "make all" and then "make arch"
  7. Copy (and rename) Matran.a to the desired location.

How to use PGPLOT with g95

Aleksander Schwarzenberg-Czerny contributed a set of configuration files for PGPLOT. Clive Page has instructions for windows.