What Should a Fortran Standard Library Contain? Part 1

One of Fortran’s major drawbacks is its lack of a standard library, a formally defined set of components outside the language core which are supplied along with the compiler. Recent revisions of the Fortran standard have defined several standard modules (ISO_C_BINDING and ISO_FORTRAN_ENV are the two best known) but these do little more than define constants and data types. As of 2017, there are no standard libraries for (say) operating system or filesystem access, string handling, searching and sorting, or networking.

Since Fortran is primarily used for numerical computing, the lack of a standard network library may not be a great disadvantage. However the lack of filesystem tools and text manipulation and parsing tools severely limit the utility of the language.

Before asking what should be in hypothetical Fortran Standard Library, it might be helpful to review what’s in the standard libraries of other languages such as C and Python.

The C Standard Library contains the following functionality in 29 header files:

  • assert.h: Conditionally compiled macro that compares its argument to zero
  • complex.h: Complex number arithmetic
  • ctype.h: Functions to determine the type contained in character data
  • errno.h: Macros reporting error conditions
  • fenv.h: Floating-point environment
  • float.h: Limits of float types
  • inttypes.h: Format conversion of integer types
  • iso646.h: Alternative operator spellings
  • limits.h: Sizes of basic types
  • locale.h: Localization utilities
  • math.h: Common mathematics functions
  • setjmp.h: Nonlocal jumps
  • signal.h: Signal handling
  • stdalign.h: alignas and alignof convenience macros
  • stdarg.h: Variable arguments
  • stdatomic.h: Atomic types
  • stdbool.h: Boolean type
  • stddef.h: Common macro definitions
  • stdint.h: Fixed-width integer types
  • stdio.h: Input/output
  • stdlib.h: General utilities: memory management, program utilities, string conversions, random numbers
  • stdnoreturn.h: noreturn convenience macros
  • string.h: String handling
  • tgmath.h: Type-generic math (macros wrapping math.h and complex.h)
  • threads.h: Thread library
  • time.h: Time/date utilities
  • uchar.h: UTF-16 and UTF-32 character utilities
  • wchar.h: Extended multibyte and wide character utilities
  • wctype.h: Functions to determine the type contained in wide character data

A cursory examination shows libraries for I/O, math, string handling, date/time handling, elementary data types, threading, testing (assert.h), error reporting (errno.h), operating system signal handling (signal.h). Many of these elements are already available in modern Fortran (C99 implements the IEEE 754 floating point standard), some are irrelevant to the Fortran programming model (iso646.h, stdnoreturn.h, setjmp.h, threads.h), and some would be nice to have but would require changes to the core language (stdarg.h for variadic functions, that is, functions taking a variable number of arguments such as READ and WRITE).

By contrast, the Python 3 Standard Library identifies over 30 groups of modules providing the following:

  • Text Processing Services
  • Binary Data Services (packed binary data and codec tools)
  • Data Types (time/date, containers/collections, heaps, arrays, emumerations, deep/shallow copy tools, pretty printers)
  • Numeric and Mathematical Modules
  • Functional Programming Modules
  • File and Directory Access
  • Data Persistence
  • Data Compression and Archiving
  • File Formats (CSV, INI, rc)
  • Cryptographic Services
  • Generic Operating System Services (I/O, time, CLI argument processing, logging, OS detection, terminal/curses interface)
  • Concurrent Execution (thread and process management, scheduling and queuing)
  • Interprocess Communication and Networking
  • Internet Data Handling (JSON, mailbox manipulation, MIME and binary/text decoding)
  • Structured Markup Processing Tools (HTML and XML tools)
  • Internet Protocols and Support
  • Multimedia Services
  • Internationalization
  • Graphical User Interfaces with Tk
  • Development Tools (documentation, testing, tools for coverting Python 2 code to Python 3)
  • Debugging and Profiling
  • Software Packaging and Distribution
  • Python Runtime Services (operating system and Python processor information, garbage collection, traceback information, Python 2/3 compatibility)
  • Importing Modules (library resolution and importing tools)
  • Python Language Services (language/processor internals)
  • Miscellaneous Services (generic output formatting)
  • MS Windows Specific Services (installer, audio, system database/registry tools)
  • Unix Specific Services (POSIX, system database tools, file and I/O locking, pipes, logging)

A note about why these languages were used as examples: C was selected since it is a compiled language which is standardized through an ISO/IEC working group. Python was selected because it is a general purpose high level language increasingly used for numerical computing and because it is not standardized via ISO/IEC or similar NGO.

Both languages are popular and mature and both have relatively large and mature standard libraries. The C standard library is necessarily more limited, given the role of C as a low-level systems programming language and the formal ANSI standardization of the language. Python is less formally standardized and is intended more as a general-purpose high level language. Fortran lies somewhere between these two languages; it is higher level than C in terms of mathematical capability, array operations, and memory management (ignoring deprecated features like COMMON blocks and storage allocation) but it lacks Python’s dynamic capabilities. Like C, Fortran is formally standardized. Python is standardized but in a much looser sense; changes are made more rapidly within the Python ecosystem than in the ANSI-standardized world.¬†Both models have their advantages and disadvantages. Part of this stems from the age and origin of each language: FORTRAN was designed by IBM in 1956, C originated at Bell Labs in 1969, and Python 1.0 was released in 1994 and had been under development at several organizations before release.

Changes to the Python language and standard library are submitted by the community and approved by the Python core developers while changes to the Fortran and C standards are made by working groups (WG5 and WG14 of subcommittee SC22 of the ISO/IEC joint technical committee JTC1). How one becomes a member of these working groups is not entirely clear; the point is there is a much greater separation between the C and Fortran standards committee members and language implementors and users than in the Python community.

But back to the libraries themselves. The most immediately interesting aspects of the Python standard library are the rich set of text processing tools, generic support for operating system features, configuration file and data persistence tools, support for multiprocessing and concurrency, and development support features such as logging, testing, and packaging.

The next installment will look at standard libraries of other calculational languages (Julia and R) and Arjen Markus’ FLIBS libraries for Fortran. From there I’ll try to identify a reasonable set of capabilities we might want in a hypothetical Fortran Standard Library.

Leave a Comment