Quick links:

Getting started:

G95 can be installed without root permission but currently requires a symbolic link from a specific directory to your install directory.
  1. Unpack the downloaded tarball (e.g. g95-x86-linux.tgz) in a directory of your choice:

       tar -zxvf g95-x86-linux.tgz
    
  2. For your convenience, you can create another symbolic link from a directory in your $PATH (e.g. ~/bin) to the executable
       ln -s $PWD/g95-install/bin/*g95* ~/bin/g95
    
You should now be able to run g95 and create executables. Run a g95-compiled program with the argument "--help" to get a list of environment variables and error code numbers.


Running G95

Basic options:

-c Compile only, do not run the linker.
-o Specify the name of the output file, either an object file or the executable.
Multiple source and object files can be specified at once. Fortran files are indicated by names ending in ".f", ".F", ".for", ".FOR", ".f90", ".F90", ".f95", and ".F95". Multiple source files can be specified. Object files can be specified as well and will be linked to form an executable.

Files ending in uppercase letters are preprocessed with the C preprocessor by default, files ending in lowercase letters are not preprocessed by default.

Files ending in ".f", ".F", ".for", and ".FOR" are assumed to be fixed form source compatible with old f77 files. Files ending in ".f90", ".F90", ".f95" and ".F95" are assumed to be free source form.

Simple examples:
g95 -c hello.f90 Compiles hello.f90 to an object file named hello.o.
g95 hello.f90 Compiles hello.f90 and links it to produce an executable a.out.
g95 -c h1.f90 h2.f90 h3.f90 Compiles multiple source files. If all goes well, object files h1.o, h2.o and h3.o are created.
g95 -o hello h1.f90 h2.f90 h3.f90 Compiles multiple source files and links them together to an executable file named 'hello'.

Preprocessor options

G95 can handle files that contain C preprocessor constructs.
-cpp Force the input files to be run through the C preprocessor
-no-cpp Prevent the input files from being preprocessed
-Dname[=value]Define a preprocessor macro
-UnameUndefine a preprocessor macro
-EShow preprocessed source only
-Idirectory Append 'directory' to the include and module files search path

Fortran options

-WallEnable most warning messages
-Wimplicit-noneSame as -fimplicit-none
-Wline-truncationWarn about truncated source lines
-Wno=numbers Disable a comma separated list of warning numbers
-Wunused-vars Warn about unused variables
-Wunset-vars Warn about unset variables
-Wunused-module-vars Warn about unused module variables. Useful for ONLY clauses
-Wprecision-loss Warn about precision loss in implicit type conversions
-fbackslash Interpret backslashes in character constants as escape codes. Use -fno-backslash to treat backslashes literally.
-fdollar-ok Allow dollar signs in entity names
-ffixed-form Assume that the source file is fixed form
-ffixed-line-length-132 132 character line width in fixed mode
-ffixed-line-length-80 80 character line width in fixed mode
-ffree-form Assume that the source file is free form
-fimplicit-none Specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements
-fmod=directory Put module files in directory
-fmodule-private Set default accessibility of module-entities to PRIVATE
-M Produce a Makefile dependency line on standard output
-std=F Warn about non-F features
-std=f2003 Strict fortran 2003 checking
-std=f95 Strict fortran 95 checking
-i8 Set kinds of integers without kind specifications to double default precision
-r8 Set kinds of reals without kind specifications to double precision
-d8Implies -i8 and -r8.

Code generation options

-fcase-upper Make all public symbols uppercase
-fleading-underscore Add a leading underscore to public names
-fonetrip Execute DO-loops at least once. (Buggy fortran 66)
-fpack-derived Try to layout derived types as compact as possible. Requires less memory, but may be slower
-fqkind=n Set the kind for a real with the 'q' exponent to n
-fsecond-underscore Append a second trailing underscore in names having an underscore (default). Use -fno-second-underscore to suppress.
-funderscoring Append a trailing underscore in global names (default). Use -fno-underscoring to suppress.
-fstatic Put local variables in static memory where possible.
-max-frame-size=n How large a single stack frame will get before arrays are allocated dynamically

Running g95 programs

The g95 runtime environement provides many options for tweaking the behaviour of your program once it runs. These are controllable through environment variables. Running a g95-compiled program with the --help option will dump all of these options to standard output.

The values of the various variables are always strings, but the strings can be interpreted as integers or boolean truth values. Only the first character of a boolean is examined and must be 't', 'f', 'y', 'n', '1' or '0' (uppercase OK too). If a value is bad, no error is issued and the default is used.

G95_STDIN_UNITInteger Unit number that will be preconnected to standard input. No preconnection if negative, default is 5.
G95_STDOUT_UNITInteger Unit number that will be preconnected to standard output. No preconnection if negative, default is 6.
G95_STDERR_UNITInteger Unit number that will be preconnected to standard error. No preconnection if negative, default is 0.
G95_USE_STDERRBoolean Sends library output to standard error instead of standard output. Default is Yes.
G95_ENDIANString Endian format to use for I/O of unformatted data. Values are BIG, LITTLE or NATIVE. Default is BIG.
G95_CRBoolean
Output carriage returns for formatted sequential records. Default true on windows, false elsewhere.
G95_IGNORE_ENDFILEBoolean Ignore attempts to read past the ENDFILE record in sequential access mode. Default false
G95_TMPDIRString Directory for scratch files. Overrides the TMP environment variable. If TMP is not set /var/tmp is used. No default
G95_UNBUFFERED_ALLBoolean If TRUE, all output is unbuffered. This will slow down large writes but can be useful for forcing data to be displayed immediately. Default is False.
G95_SHOW_LOCUSBoolean If TRUE, print filename and line number where runtime errors happen. Default is Yes.
G95_OPTIONAL_PLUSBoolean Print optional plus signs in numbers where permitted. Default FALSE.
G95_DEFAULT_RECLInteger Default maximum record length for sequential files. Most useful for adjusting line length of preconnected units. Default is 50000000.
G95_LIST_SEPARATORString Separator to use when writing list output. May contain any number of spaces and at most one comma. Default is a single space.
G95_EXPAND_UNPRINTABLEBoolean For formatted output, print otherwise unprintable characters with \-sequences. Default No.
G95_QUIETBoolean Suppress bell characters (\a) in formatted output. Default No.
G95_SYSTEM_CLOCKInteger Number of ticks per second reported by the SYSTEM_CLOCK() intrinsic in microseconds. Zero disables the clock. Default 100000.
G95_SEED_RNGBoolean If true, seeds the random number generator with a new seed when the program is run. Default false.
G95_MINUS_ZEROBoolean If true, allows minus zeros to be printed correctly, contrary to the standard. Default TRUE.
G95_MEM_INITString How to initialize allocated memory. Default value is NONE for no initialization (faster), NAN for a Not-a-Number with the mantissa 0x40f95 or a custom hexadecimal value.
G95_MEM_SEGMENTSInteger Maximum number of still-allocated memory segments to display when program ends. 0 means show none, less than 0 means show all. Default 25
G95_MEM_MAXALLOCBoolean If true, shows the maximum number of bytes allocated in user memory during the program run. Default No.
G95_MEM_MXFASTInteger Maximum request size for handing requests in from fastbins. Fastbins are quicker but fragment more easily. Default 64 bytes.
G95_MEM_TRIM_THRESHOLDInteger Amount of top-most memory to keep around until it is returned to the operating system. -1 prevents returning memory to the system. Useful in long-lived programs. Default 262144.
G95_MEM_TOP_PADInteger Extra space to allocate when getting memory from the OS. Can speed up future requests. Default 0.
G95_SIGHUPString Whether the program will IGNORE, ABORT or SUSPEND on SIGHUP. Default ABORT.
G95_SIGINTString Whether the program will IGNORE or ABORT or SUSPEND on SIGINT. Default ABORT
G95_FPU_ROUNDString Set floating point rounding mode. Values are NEAREST, UP, DOWN, ZERO. Default is NEAREST.
G95_FPU_PRECISIONString Precision of intermediate results. Value can be 24, 53 and 64. Default 64. Only available on x86 and IA64 compatibles.
G95_FPU_DENORMALBoolean Raise a floating point exception when denormal numbers are encountered. Default no.
G95_FPU_INVALIDBoolean Raise a floating point exception on an invalid operation. Default No.
G95_FPU_ZERODIVBoolean Raise a floating point exception when dividing by zero. Default No.
G95_FPU_OVERFLOWBoolean Raise a floating point exception on overflow. Default No.
G95_FPU_UNDERFLOWBoolean Raise a floating point exception on underflow. Default No.
G95_FPU_INEXACTBoolean Raise a floating point exception on precision loss. Default No
G95_FPU_EXCEPTIONSBoolean Whether masked floating point exceptions should be shown after the program ends. Default No
G95_UNIT_xString Overrides the default unit name for unit x.
G95_UNBUFFERED_xBoolean If true, unit x is unbuffered

Runtime error codes

-2 End of record
-1 End of file
0 Successful return
Operating system errno codes (1 - 199)
200 Conflicting statement options
201 Bad statement option
202 Missing statement option
203 File already opened in another unit
204 Unattached unit
205 FORMAT error
206 Incorrect ACTION specified
207 Read past ENDFILE record
208 Corrupt unformatted sequential file
209 Bad value during read
210 Numeric overflow on read
211 Out of memory
212 Array already allocated
213 Deallocated a bad pointer
214 Bad record read on input
© 2004 Free Software Foundation