GithubHelp home page GithubHelp logo

interkosmos / fortran-unix Goto Github PK

View Code? Open in Web Editor NEW
28.0 5.0 1.0 246 KB

Fortran 2008 interface bindings to selected POSIX and SysV procedures

License: ISC License

Makefile 5.27% C 1.54% Fortran 93.19%
unix linux freebsd posix fortran fpm fortran-package-manager fortran-2008

fortran-unix's Introduction

fortran-unix

Build

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,
  • file and 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 14 (GNU Fortran 13),
  • Debian 12 (GNU Fortran 12, Intel oneAPI 2024).

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. Link your Fortran application with libfortran-unix.a, and optionally with -lpthread to access POSIX threads, or -lrt to access POSIX message queues.

Make

On FreeBSD, run:

$ make freebsd

On Linux, run instead:

$ make linux

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

$ make OS=linux PREFIX=/usr

For Intel oneAPI, run:

$ make CC=icx FC=ifx PPFLAGS=

Optionally, install libfortran-unix.a and the associated module files system-wide:

$ make install PREFIX=/opt
--- Installing libfortran-unix.a to /opt/lib/ ...
--- Installing module files to /opt/include/libfortran-unix/ ...

Fortran Package Manager

Using FPM, a preprocessor flag has to be passed to GNU Fortran. On FreeBSD:

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

On Linux:

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

Source Code Documentation

The source code documentation of the library has to be created with FORD. Install the Python package with:

$ python3 -m pip install -U ford

In the source repository, either run:

$ make freebsd_doc

Or:

$ make linux_doc

The HTML files will be written to directory doc/. Open index.html in a web browser.

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)).
  • stat reads and outputs status of a file.
  • 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

fortran-unix's People

Contributors

explosiontime202 avatar interkosmos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fortran-unix's Issues

add binding to 'pthread_detach'

Hi, just to let you know I've just added a binding to the C pthread_detach function to unix_pthread.F90 (residing within my project):

public :: c_pthread_detach

! int pthread_detach(pthread_t thread);
function c_pthread_detach(thread) bind(c, name='pthread_detach')
   import :: c_int, c_ptr, c_pthread_t
   implicit none
   type(c_pthread_t), intent(in), value :: thread
   integer(kind=c_int)                  :: c_pthread_detach
end function c_pthread_detach

support for pthread_mutex_t

A very useful library. Have you got plans to add support for POSIX mutexes? Somehow cannot find pthread_mutex_t neither in the examples nor in the source code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.