Fortran Standard Library
The Fortran Standard, as published by the
ISO, does not have a standard library,
like other programming languages. The
Fortran Standard Library
(stdlib
) is a community-driven de facto standard library
currently in development that contains additional algorithms, data structures,
as well as math and utility routines for Fortran 2008 and newer (table 1).
-
Module Description stdlib_ansi
Terminal color and style escape sequences stdlib_array
Index manipulation and array handling tasks stdlib_ascii
Handling of intrinsic character variables and constants stdlib_bitsets
Zero-based bitsets of size up to huge(0_int32)
stdlib_error
Catching and handling errors stdlib_hash_32bit
Hash functions and scalar hashes (32-bit) stdlib_hash_64bit
Hash functions and scalar hashes (64-bit) stdlib_hashmap_wrapper
Hash map wrapper procedures stdlib_hashmaps
Hash maps stdlib_io
File handling stdlib_io_npy
NPY file handling stdlib_kinds
Additional kind declarations stdlib_linalg
Various linear algebra procedures stdlib_logger
Logging types and procedures stdlib_math
Various math procedures stdlib_optval
Fallback values for optional procedure arguments stdlib_quadrature
Gaussian approximations stdlib_random
Random numbers stdlib_selection
Array element selections stdlib_sorting
Sorting algorithms stdlib_specialfunctions
Legendre functions stdlib_specialfunctions_gamma
Gamma functions stdlib_stats
Various statistical methods stdlib_stats_distribution_exponential
Exponential distribution functions stdlib_stats_distribution_normal
Normal distribution functions stdlib_stats_distribution_uniform
Uniform distribution functions stdlib_string_type
String type that holds an arbitrary sequence of characters stdlib_stringlist_type
String list implementation stdlib_strings
Basic string handling routines stdlib_version
Version information on stdlib - Tab. 1: Modules of the Fortran Standard Library
Installation
The library requires a Fortran 2008 compliant compiler and a build automation tool like fpm, make, or CMake:
$ git clone https://github.com/fortran-lang/fpm
$ git checkout stdlib-fpm
$ fpm build --profile release
The static library libstdlib.a
and the necessary module files
are written to build/<compiler>/stdlib/
. To include
stdlib
as a dependency to a fpm project, simply add the
following entry to your fpm.toml
:
[dependencies]
stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" }
stdlib_logger
The Fortran Standard Library provides a basic logger class to output messages to console and file:
! log.f90
program main
use, intrinsic :: iso_fortran_env, stderr => error_unit
use :: stdlib_logger, logger => global_logger
implicit none
integer :: fu, stat
call logger%configure(level=ALL_LEVEL)
call logger%add_log_unit(stderr, stat=stat)
call logger%add_log_file('log.txt', fu, stat=stat)
call logger%log_error(message = 'Example error log message', &
module = 'N/A', &
procedure = 'MAIN', &
stat = 0, &
errmsg = 'error message')
call logger%log_message('Message printed irrespective of the level')
call logger%log_debug('Debug message')
call logger%log_information('Information message')
call logger%log_warning('Warning message')
call logger%log_io_error('I/O error message')
call logger%configure(level=NONE_LEVEL)
call logger%log_error('Error message (not printed)')
end program main
Link the example program against libstdlib.a
and set the include
search path -I
the the directory containing the module files:
$ gfortran13 -I./build/gfortran/stdlib/ -o log log.f90 ./build/gfortran/stdlib/libstdlib.a
The log messages are printed to standard error and to file
log.txt
:
$ ./log
2021-10-04 23:04:46.090: N/A % MAIN: ERROR: Example error log message
With stat = 0
With errmsg = "error message"
2021-10-04 23:04:46.091: Message printed irrespective of the level
2021-10-04 23:04:46.091: DEBUG: Debug message
2021-10-04 23:04:46.091: INFO: Information message
2021-10-04 23:04:46.091: WARN: Warning message
2021-10-04 23:04:46.091: I/O ERROR: I/O error message
Similar Fortran Libraries
- flib: Fortran library of useful modules and procedures
- ForUtils: Package of Fortran 2003/2008 utility classes and convenience functions (arrays, file I/O, INI files, ranges, strings, …)
- Fortran-Library: mathematical and chemical routines, e. g., transformations, clustering, statistics, nonlinear optimisation
- Fortran General Library (FGL): Includes logging, exception handling, hash and list data structures, sorting, strings, JSON serialisation
- Fortran Utilities: Various Fortran utilities that can be included into any Fortran program (types, constants, sorting, meshes, cubic splines, PPM images, HDF5)
- fortranlib: Collection of algebra, array, I/O, probability density function, and vector routines
- Futility: Open-source utility package by University of Michigan and Oak Ridge National Laboratory (language extensions, file I/O, math, geometry, sorting, …)
- General-Purpose Fortran Repository: Libraries and modules for command-line parsing, string operations, numeric expression parsing, pixel graphics, message handling, POSIX, regular expressions, SQLite
References
- Fortran Standard Library: Official GitHub repository
- Fortran Standard Library documentation
< Intrinsic Procedures | [Index] | Formatted Input/Output > |