Repository for General-Purpose Fortran

The majority of the code described in these pages is in one tar(1) archive. To download it see the [DOWNLOAD PAGE]

This software repository contains (mostly) Fortran modules and procedures that focus on general-purpose interfaces such as CLI (Command Line Interface) utilities (e.g. command line argument parsers), calls to basic system routines (especially file system interfaces), string manipulation, date-time procedures, and other primarily non-numeric services.

A modern Fortran compiler is assumed. This code has been tested using GNU Fortran (GCC) 7.3.0.

An assembly of programs that use the collection are included. These range from useful utilities (a pre-processor, an SCCS-style meta-data reader, a makefile generator, regression testing utilities, ...) to simple example programs that exercise the modules.

Again, this collection is not a repository of routines solving complex analytical problems. This is a collection of those "other" Fortran procedures that solve the day-to-day non-numeric issues in programming. Large repositories of numeric algorithms written in Fortran exist at such sites as the netlib repository. The Fortran Wiki contains information on many Fortran resources (If you do not see a link there to your favorites please add them.) My own FAQ on Fortran is also available.

To help promote a collective development of this repository I am setting up ; but I prefer routines being added to this site at this time as the github site is not very easy to integrate with the build system used to maintain and test these routines.

source code documentation
Command Line Interface Code
Routine Categories Descriptions

command line arguments

M_KRACKEN(3fm): command line arguments The M_KRACKEN(3f) module makes cracking Unix-like arguments off the command line easy. This version is expanded to allow use in configuration files and interactive input as well, and incorporates additional modules. It requires many other components from the GPF collection, but is used to generate programs that use shell-like input as well as crack command lines.
M_GETOPT(3fm): command line arguments The M_GETOPT(3fm) module by Mark Gates supports cracking Unix-like arguments off the command line in much the same way as the C getopt(3c) procedure.
M_GETOPT_LONG(3fm): command line arguments The M_GETOPT_LONG(3fm) module by Joe Krahn supports cracking Unix-like arguments off the command line in much the same way as the SunOS getopt_long(3c) procedure.
NAMELIST-based command line parser Using new features in 2003/2008 Fortran such as reading NAMELIST groups from internal files and GET_COMMAND_ARGUMENT(3f), crack command line options using a standardized syntax and the least code.


M_STRINGS(3fm) convert case, change numbers to strings, strings to numbers, parse on delimiters,edit strings, ... .
M_REGEX(3fm) Interface to the POSIX Regular Expression library and related routines.

date and time

M_TIME(3fm) Calculate and display date and time values

expression parsers

M_CALCULATOR(3fm), M_CALCULATOR_PLUS(3fm) M_calculator(3fm) is a module for evaluating expressions. The primary routine is JUCALC(3f). JUCALC(3f) evaluates simple numeric and string expressions. This allows your input to use expressions and variable names instead of simple values. You will have to comment out or supply some of the functions called, depending on how f2003-compliant your compiler is.

M_calculator_plus(3fm) is a supplemental module containing convenience routines for using M_calculator(3fm).

command line recall and editing

M_HISTORY(3fm): An interactive input editor module Acting much like a line-mode editor, the REDO(3f) procedure lets you list, edit, save, and modify your interactively entered program input. Built-in help and no dependence on terminal control sequences makes this a simple-to-master and portable input history editor.
M_READLINE(3fm): calling readline(3c) from Fortran The readline(3c) routine lets you edit and then execute previously entered commands. An interface using a small C routine and the standard ISO_C_BINDING module lets the commonly available C routine be called from Fortran. The readline(3c) library is required.


M_JOURNAL(3fm), M_MESSAGES(3fm) journaling, logging, and general messaging routines that let you have a single routine filter output to journal files; display attention-grabbing messages or reformat messages.

unit testing, performance testing and debugging

M_DEBUG(3fm) These routines are useful for constructing unit tests for code and for adding debug modes to routines and applications.
M_STOPWATCH(3fm) Measure wallclock time and processor time spent in various code sections
Paranoid Compiler Test The PARANOID program converted into subroutines that can be called from your programs to verify compiler behavior.

flow control

M_LOGIC(3fm): conditionally select input The M_LOGIC(3f) module allows you to use if/else/elseif/endif directives in your input; allowing conditional selection of input lines. Requires an expression parser. It uses JUCALC(3f) by default.


M_IO(3fm) Input/Output

help utilities

Help Utility read USH-like Help files
VMS-like Help Utility read VMS-like Help files

hot keys

GETKEY(3f): read a character from the keyboard in "immediate mode" A simple C routine for most Unix and GNU/Linux systems that immediately reads a single character keystroke from the keyboard without waiting for a carriage return. An interface using the ISO_C_BINDING interface allows the routine to be called from Fortran.

Fortran/C calls

M_PROCESS(3fm) Read and write from a process using popen(3c)
  • Environment
  • Directories
  • Error code processing
  • Process management
  • File characteristics
Some simple but commonly called C routines interfaced to Fortran. Makes heavy use of the ISO_C_BINDING module introduced as part of Fortran 2003.

Fortran(2003) interface to the ncurses(3c) library

A Fortran module and a few related files create an interface from Fortran to the C ncurses(3c) library; allowing Fortran programs to read function keys and characters one at a time and to control the characters on the screen on a character-cell by character-cell basis.
Regular expressions
Signal management
modern Fortran language constructs
mixed language programming
threaded and SIMD parallel programming
template programming
unit testing

numeric utilities that are aware of their accuracy

M_COMPARE_FLOAT_NUMBERS(3fm) A Fortran module containing routines to perform equality and relational comparisons on floating point numbers. That is, you can more safetly compare real numeric values.


M_PIXEL(3fm) The M_pixel module is a PRELIMINARY collection of routines that use 2D-vector routines to create or modify a pixel array, which can then be written as a GIF file.
M_DRAW(3fm) The M_DRAW module is an interface to a C library of graphic routines, primarily used for creating low-level vector-based plot files and single-window interactive X11 applications.
M_DRAWPLUS(3fm) The M_DRAWPLUS module is a supplement to the M_DRAW module.
M_XYPLOT(3fm) The M_XYPLOT module is uses M_DRAW(3fm) and M_DRAWPLUS(3fm) to draw XY plots


M_COLOR(3fm) The M_color module is a collection of color-related procedures. Routines to convert between different color models, return RGB values given common X11 color names, and other simple color-related operations.

xterm(1) escape sequences

M_XTERM(3fm) The M_xterm module is a collection of routines for writing and reading xterm(1) escape sequences that can be used on most platforms to allow terminal colors, labels, and geometry to be easily changed, and to send hints to the X11 Windows manager to request windows be iconified, maximized, or moved.


M_SORT(3fm) sorting routines encapsulated in a module
sort_shell(3f) simple generic sort procedure
M_SWAP(3fm) swap two variables
sorting materials Miscellaneous sorting procedures

General Mathematics

M_MATH(3fm) A collection of routines for basic geometry, curve fitting and interpolation, basic statistics, ...

Unit Conversions

M_UNITS(3fm) A collection of unit conversions and constants. Allow degrees instead of radians in trig functions; convert between Celcius and Fahrenheit, ...

If you desire codes that do not require newer Fortran features some older versions of the above routines are available ...

expression parsers

JUEXPR(3f): Evaluate simple expressions JUEXPR(3f) is an older simpler FORTRAN77 version of JUCALC(3f) that should compile as-is with any Fortran compiler. It is useful when you want to allow simple expressions in your input instead of just numeric values.

command line arguments

M_KRACKEN(3fm): command line arguments The M_KRACKEN(3f) module makes cracking Unix-like arguments off the command line easy. This is the frozen simpler self-contained version.

An example program that combines many of the components into a simple calculator-like utility that parses command line arguments, evaluates Fortran-like expressions, has interactive command history recall and editing, and supports if/else/elseif/endif directives can be found in shell.ff. The program is available as expanded standard Fortran as part of the GPF download.

This program can process input files such as ...

   set A=10
   if gt(A,100)
      echo BAD
      set B=111111*sqrt(12)
      if eq(myvalue,0)
         echo myvalue is 0!
      elseif lt(myvalue,0)
         echo myvalue is less than 0!
      elseif gt(myvalue,0)
         echo myvalue is greater than 0!
         echo SHOULD NOT GET HERE
      set B=222222
      echo GOOD
   set $str("after first test B is ",B)
   set A=200
   if gt(A,100)
      set B=333333
      echo GOOD
      set myvalue=myvalue+3
      set B=444444
      echo BAD
   set $str("after second test B is ",B)
   set dump

An alternative version of the repository is at [GITHUB DOWNLOAD PAGE]

If this collection is moved, it will retain the UUID urbanjost-12527cb5-a7a0-4d10-9806-38ab5f0609ef
Site Map | Contact Us | Home |