All Projects → scivision → fortran-filesystem

scivision / fortran-filesystem

Licence: MIT License
Object-oriented Fortran filesystem path manipulation library, based on C++17 filesystem.

Programming Languages

fortran
972 projects
C++
36643 projects - #6 most used programming language
CMake
9771 projects
Meson
512 projects
Batchfile
5799 projects
shell
77523 projects
Makefile
30231 projects

Fortran filesystem

DOI ci_cmake oneapi-linux oneapi-windows ci_meson

Platform independent (Linux, macOS, Windows), object-oriented Fortran filesystem path manipulation library. This Fortran library uses C++17 filesystem internally. Also inspired by Python pathlib.

Fortran "filesystem" module contains one Fortran type "path_t" that contains properties and methods. The "path_t" type uses getter and setter procedure to access the path as a string character(:), allocatable.

use filesystem, only : path_t

type(path_t) :: p

p = path_t("my/path")  !< setter

print *, "path: ", p%path() !< getter

Due to compiler limitations, currently Fortran-filesystem only officially supports ASCII characters.

Compiler support

Full C++17 filesystem support and hence full Fortran-filesystem features are available with any of these compilers:

  • GCC ≥ 8
  • Clang ≥ 7
  • Intel oneAPI (icx, ifx, icpc, ifort, icl)

Fortran-filesystem has a large subset of features when used with older compilers that have C++17 "experimental" filesystem support, such as:

  • GCC 7
  • Clang 6

Expected to work with other C++17 compilers and Fortran 2008 compilers yet to be tested. E.g. Cray, IBM XL, NAG, et al.

Build

Fortran-filesystem can be built with CMake or Meson.

[lib]filesystem.a is the library binary built that contains the Fortran "filesystem" module--it is the only binary you need to use in your project.

Please see the API docs for extensive list of functions/subroutines.

CMake:

cmake -B build
cmake --build build
# optional
ctest --test-dir build

Meson:

meson setup build
meson compile -C build
# optional
meson test -C build

Command line

For user convenience, we provide a demo executable "filesystem_cli" that allows simple testing of what the filesystem routines do. To build the filesystem_cli utility:

cmake -B build -DBUILD_UTILS=on
cmake --build build

Usage from other projects

The examples directory contains a use pattern from external projects. One can either cmake --install build or use ExternalProject from the other project. ffilesystem.cmake would be included from the other project to find or build Fortran-filesystem automatically. It provides the appropriate imported targets for shared or static builds, including Windows DLL handling.

Notes

A few topics on unsupported features:

non-ASCII characters

The UCS selected_char_kind('ISO_10646'), is an optional feature of Fortran 2003 standard. Intel oneAPI does not support selected_char_kind('ISO_10646') as of this writing.

filesystem currently uses the default Fortran character kind, which is ASCII. This means that UTF-8 / UTF-16 / UTF-32 strings are not supported. You may find a particular compiler and computer passes some non-ASCII strings, but this is not supported.

Unsupported compilers

At this time, these compilers aren't supported for reasons including:

Nvidia HPC-SDK

nvfortran 22.1 does not support character(:), allocatable from Fortran 2003, which is used everywhere in filesystem. nvc++ 22.1 does not support C++17 filesystem, which is essential for filesystem. New Fortran language standard features aren't being added to nvfortran until the Flang f18 LLVM project is ready to use. I would estimate this as being in a couple years from now.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].