FLIBS - A collection of Fortran modules

The FLIBS project provides a collection of individual Fortran modules that perform particular tasks, such as:

The source code and documentation can be found here, a series of observations about Fortran can be found here.

I am also collecting guidelines for code reviews. Comments welcome!

Latest version: 0.9 - released december 2008. Newer modules available via the CVS repository

Some experimental programs that may be of interest appear in the directory experiments.

Furthermore the directory app contains several complete programs and the directory chksys contains programs that focus on such aspects as compiler diagnostics run time behaviour (note: the programs were developed with FORTRAN 77 in mind).

Book: Modern Fortran in practice

My book "Modern Fortran in practice" contains a number of examples. They are available here.

Small experiment with variables having physical units

A recent discussion (october 2012) on the LinkedIn Fortran group made me consider Van Snyder's technical proposal regarding support of physical (and other) units. (The document can be found at www.j3-fortran.org, document 04-122r1.ps)

It inspired me to write a small set of programs. This "proof of concept" is certainly not as ambitious and encompassing as Van's proposal, but it seems a practical, if only partial, solution that does not require direct support from the compiler.

News

To get an overview of the changes to the collection, please have a look at this page.

Contents of the collection

Currently, FLIBS consists of the following modules:

DirectoryModulePurpose
SQLitesqlite Module to provide an easy-to-use interface to the SQLite library, a light-weight database management system.
Lemonflemon Lemon is a parser generator comparable to Yacc and Bison and flemon is an adaptation to generate Fortran code
MySQLmysql First version of a module to interface with the MySQL database system. The code has been provided by Daniel Kraft.
ODBCodbc First version of a module to interface with the ODBC database facilities. Modelled after the SQLite interface.
dbasedbasefile Module to read dBase III files. Note that there are a number of limitations (no support for memos for instance of dBase IV files).
Strings glob_matching Match strings to (simplified) glob patterns, such as "*.f90". The module does not support character classes yet.
csv_file Write comma-separated-values (CSV) files. The module takes care of quotation marks in strings and provides a simple interface to write individual data as well as one-dimensional arrays and matrices
filedir Manipulate directory and file names. It contains routines to split a full path into directories and file names, to smoothly join directory and file names and so on.
edit_text, singleline_text, multiline_text, multiline_text_functions Modules that provide storage and manipulation facilities for arbitrary-length strings and collections thereof. The emphasis is on storage, not on providing a full-featured varying-string-length module.
tokenize Module to split a string into pieces according to certain fairly basic, but common criteria.
tokenlists Module to handle a list of tokens as found in a string (builds on tokenize.
string_manipulations Module with simple string manipulations like, reversing the characters, changing the case to upper or lower case, generating random words.
m_vstring Module for handling strings with a dynamic length. It contains a set of high-level facilities to manipulate such strings.
m_vstringlist Module for handling lists of strings with a dynamic length. Individual elements can easily be accessed or changed.
m_vstringformat Module for formatting strings with a dynamic length.
FCRE mod_regex High-level module for string matching using regular expressions. The module uses a lower-level module (fcre) that provides an interface to the PCRE library.
Data structures linked_lists Generic source code for implementing linked lists. The test program illustrates how the genericity is achieved.
binary_trees Generic source code for implementing binary trees. Balancing is not taken care of.
queues Generic source code for implementing queue of fixed size.
dictionaries Generic source code for implementing a mapping of strings to data. New: Implemented via a simple hash table (the original used a linked list).
vectors Generic source code for implementing an expandable array of data.
sets Generic source code for implementing unordered sets - collections of data objects that support operations like union and intersection.
sorting Generic source code that implements a combined QuickSort/InsertionSort algorithm for fast sorting arrays (contributed by Joe Krahn).
memory pool Generic source code that implements a straightforward memory pool. Use this to reduce the number of individual allocations and deallocations of data items of a fixed type.
indexset Implementation of a bit array using the bit manipulation functions of Fortran 90/95. Useful for handling sets that consist of integers or can be mapped to integers.
Computational facilities automatic_differentiation General technique for determining the first derivative of a function via mathematical, not numerical means.
select_precision Auxiliary module for selecting the precision of real variables.
fundamental_constants Numerical values of mathematical and physical constants.
timing Small module for timing parts of a program. This may be used to detect which part is taking most computing time or to compare different algorithms
decimal_arithmetic Module for implementing decimal arithmetic, as opposed to floating-point numbers.
interval_simple Module implementing interval arithmetic in a straightforward manner.
m_coordinates Basic coordinate transformations, such as spherical to cartesian.
pointsets Collection of routines to generate sets of points in one, two or three dimensions with certain properties.
combinations Routines for random permutations and other combinatorial functions. (Very limited at the moment)
enumerate_space Enumerate grid points in one-, two- or three-dimensional space. The points close to the origin are visited first. This can be useful in finding solutions for Diophantine equations.
traverse_grid Traverse an N-dimensional grid, either systematically or in a quasi-random way. The second method can be used for instance to compute N-dimensional integrals with less data points than required for a Monte Carlo approach.
backtracking Module to implement backtracking algorithms. It offers a single routine that controls the generation and checking of possible solutions. The user must supply a small number of routines and a single data type to implement the specific problem.
simulated_annealing Use the technique of simulated annealing to minimize a function of several variables.
genetic_algorithms Straightforward implementation of a genetic algorithm to minimize a function of several variables.
libdate Module for manipulating date and time information.
unsigned_integers Module providing operations on unsigned integers.
leadzero Flexible implementation of the F0 format. Allows specification of sign and number of digits.
random_generators Small collection of pseudo-random number generators.
random_permutations Randomly permute the elements of an integer array or provide an array for random permutation.
minimisation Two general minimisation routines (NEWUOA and BOBYQA) by M. Powell, wrapped into modules for robustness and ease of use.
Streams binary streams Module to read and write files as a "stream" of bytes. Some caution: it relies on certain assumptions about the sizes of integers and reals and on the treatment of direct-access files.
Note that Fortran 2003 defines an access="stream" option to the open statement that makes this module superfluous
text streams Module to read ordinary text files as a "stream" of words and numbers. It is not without limitations, but it may be a practical approximation to the real thing.
Note that Fortran 2003 defines an access="stream" option to the open statement that makes this module superfluous
read characters Module to read ordinary text files character by character.
Unit testing ftnunit Module and auxiliary scripts that implement a unit testing framework akin to JUnit
gentabletest.tcl Tcl program to generate a test program based on a tabular description
testmake Program to create complete test programs based on specifications. See also: the article on this program
IPC ipc_file Module for exchanging information (inter-process communication) between two or more programs (processes) via files on disk. Preliminary version!
Checking checking Module and auxiliary program that instrument source code to trace what subroutines are called and what files are opened. It helps understand a program written by others.
chksys Collection of test programs to detect all manner of properties of the Fortran compiler - like what unit is used for the record length of direct access files and many other portability aspects.
Wrapper Wrapping C functions Auxiliary program to scan a C header file and produce code so that you can easily use the C functions in a Fortran program.
Files and directories filedir Collection of portable routines to manipulate files and directories or retrieve detailed information
m_vfile Collection of portable routines to manipulate files and directories or retrieve detailed information in an object-oriented fashion
m_fileunit Routines to manage logical unit numbers
Platform platform Portable routines (as far as possible) to run external programs and to find out details of the operating system
platform Platform-dependent routines and features (uses variable-length strings)
Reporting reporting Set of routines with a common interface to write report files in HTML, Latex and RTF formats
m_logger Module for writing log files
m_multilog Module for writing to several log files at once (flexible selection of messages)
m_exception Module for handling assertions and treating exceptions (to a certain extent) Note: preliminary version - some changes to the interface will be made
Control structures Finite state machines Facilities to help set up a finite state machine
messages Facilities for dealing with "messages", for instance in the context of discrete event simulations
Tools editcode Preprocessor for Fortran code meant for such things as replacing types by other types, assertions and other preprocessing tasks. Not a C-style preprocessor though!
CGI cgi_protocol Facilitate the interaction between Fortran programs and web servers using the CGI protocol
Fast CGI Interact with web servers via the fast-CGI protocol (by Ricolindo Carino). Detailed instructions on how to use a Fast-CGI library for the Nginx webserver in combination with this module are available.
dynlib dynamic_libraries Load routines from a DLL or a shared library. Requires Fortran 2003 features - Work in Progress
sysutils sysutils Small set of system utilities. For now: merely get the process ID
password_facilities Read a password from the keyboard (Windows, Linux/Cygwin)
images bmp_files Load and save Windows BMP files

Note: Most modules come with test/example programs. The test/example programs should provide at least some indication on how to use the modules.

Though making the modules and test programs should be straightforward, there are no formal makefiles yet to actually make them - most development and testing so far has been done on Windows with Compaq Visual Fortran, which uses so-called project files.

Ideas still to be implemented


Experiments

The directory "experiments" contains several programs that simply try out a few ideas:

Applications and utilities

The directory "app" contains several programs that can be useful:

Compiler diagnostics and run-time behaviour

While Fortran is a very portable language, certain aspects are left to the discretion of the compiler. The programs in the subdirectory chksys explore this:
-- Arjen Markus, dd. june 2013