Skip to content

Explosiontime202/fortran-unix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fortran-unix

A work-in-progress collection of Fortran 2008 ISO C binding interfaces to selected POSIX and SysV types, functions, and routines on 64-bit Unix-like operating systems:

  • standard input/output,
  • directory access,
  • clocks and timers,
  • signals,
  • processes,
  • pipes,
  • serial port input/output,
  • terminal control,
  • POSIX threads,
  • POSIX mutexes and semaphores,
  • POSIX regular expressions,
  • BSD sockets,
  • UNIX System V message queues,
  • POSIX message queues.

Similar libraries for modern Fortran:

Currently, only Linux (glibc) and FreeBSD are supported. The library has been tested on:

  • FreeBSD 13 (GNU Fortran 13),
  • Debian 12 (GNU Fortran 12).

Preprocessor macros are used to achieve platform-independent interoperability. Therefore, your Fortran compiler has to support at least GNU preprocessor conditionals (#ifdef …).

Build Instructions

Run either GNU/BSD make or fpm to build the static library libfortran-unix.a. On FreeBSD:

$ make freebsd

On Linux:

$ make linux

Or, instead, set parameter OS to either linux or FreeBSD, and PREFIX to /usr or /usr/local, for instance:

$ make FC=gfortran OS=linux PREFIX=/usr

Using fpm, preprocessor flags have to be passed to GNU Fortran:

$ fpm build --profile=release --flag="-D__linux__"

Or:

$ fpm build --profile=release --flag="-D__FreeBSD__"

Link your Fortran application with libfortran-unix.a, and optionally with -lpthread to access POSIX threads or -lrt to access POSIX message queues.

Examples

Examples are provided in directory examples/:

  • dirent prints the contents of a file system directory.
  • fifo creates a named pipe for IPC.
  • fork forks a process and uses anonymous pipes for IPC.
  • irc implements a basic IRC bot, based on BSD sockets.
  • key reads single key-strokes from standard input.
  • mqueue creates a POSIX message queue.
  • msg shows message passing with UNIX System V message queues.
  • mutex demonstrates threaded access to variable using a mutex.
  • os returns the name of the operating system (Linux, macOS, FreeBSD, ...).
  • pid outputs the process id.
  • pipe creates anonymous pipes for bidirectional IPC.
  • pthread runs a Fortran subroutine inside multiple POSIX threads.
  • regex calls POSIX regex functions.
  • semaphore tests POSIX semaphores.
  • serial shows some basic serial port input reading (requires socat(1) and minicom(1)).
  • signal catches SIGINT (CTRL + C).
  • socket creates a TCP/IP connection to a local netcat server (requires nc(1)).
  • time prints out the results of time functions.
  • uname prints OS information from uname().
  • uptime outputs system uptime.

To compile the example programs, either run:

$ make freebsd_examples

Or:

$ make linux_examples

Licence

ISC

About

Fortran 2008 interface bindings to selected POSIX and SysV procedures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Fortran 94.3%
  • Makefile 4.7%
  • C 1.0%