{"id":18627837,"url":"https://github.com/cmbant/forutils","last_synced_at":"2026-02-23T20:35:02.212Z","repository":{"id":33892559,"uuid":"37605759","full_name":"cmbant/forutils","owner":"cmbant","description":"Fortran 2008 utility functions and reusable classes","archived":false,"fork":false,"pushed_at":"2025-08-22T09:25:47.000Z","size":126,"stargazers_count":19,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-30T19:44:23.799Z","etag":null,"topics":["fortran-library","utility-classes"],"latest_commit_sha":null,"homepage":null,"language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmbant.png","metadata":{"files":{"readme":"Readme.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-06-17T16:07:30.000Z","updated_at":"2025-08-22T09:25:51.000Z","dependencies_parsed_at":"2022-08-17T19:55:17.650Z","dependency_job_id":"088d229b-7054-4fd6-bcb0-3bca12a8fb73","html_url":"https://github.com/cmbant/forutils","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/cmbant/forutils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmbant%2Fforutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmbant%2Fforutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmbant%2Fforutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmbant%2Fforutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmbant","download_url":"https://codeload.github.com/cmbant/forutils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmbant%2Fforutils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29754468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T19:23:13.917Z","status":"ssl_error","status_checked_at":"2026-02-23T19:23:11.618Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran-library","utility-classes"],"created_at":"2024-11-07T04:44:18.829Z","updated_at":"2026-02-23T20:35:02.155Z","avatar_url":"https://github.com/cmbant.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"===================\nForUtils\n===================\n:ForUtils: Various fortran 2003/2008 utility classes.\n:Version: 1.0\n:Author: Antony Lewis\n:Homepage: https://github.com/cmbant/forutils\n:Code documentation: https://cosmologist.info/forutils/\n\n.. contents:: Table of Contents\n   :depth: 2\n\nDescription\n============\n\nForUtils is a modern Fortran utility library that provides essential tools for\nscientific computing and data processing. It offers Python-like convenience\nfunctions and object-oriented interfaces for common programming tasks in\nFortran 2003/2008 programs.\n\n**Key Features:**\n\n* ArrayUtils - Find (minimal/maximal) index of an element in an array.\n* FileUtils - Classes for handling file access, python-like loadtxt/savetxt functions\n* IniObjects - Read/Write name=value configuration files with inheritance, array and default value support.\n* MatrixUtils - Read/Write matrices and interface to some BLAS/LAPACK routines.\n* MiscUtils - Utility functions for optional arguments.\n* MpiUtils - Wrappers for MPI-routines to compile with(out) MPI library.\n* ObjectLists - Lists of arbitrary objects including specializations for vectors.\n* RandUtils - Some functions to generate random numbers.\n* RangeUtils - Maintain sets of equally spaced intervals, e.g. for integration ranges.\n* StringUtils - Utilities for strings, like concat of distinct types a.s.o.\n\nFor a class summary see the `class trees \u003chttps://cosmologist.info/forutils/classes/_index.html\u003e`_.\n\nGetting Started\n================\n\nClone this git repository::\n\n    $ git clone https://github.com/cmbant/forutils\n\nCompile::\n\n    $ make all\n\nThis generates the subdirectories Debug and Release and when an MPI library is\navailable also DebugMPI and ReleaseMPI. Each directory contains a libforutils.a\narchive, which can be used directly for static linking on the compiler command\nline by giving the absolute filename::\n\n    forutils/\u003cRTYPE\u003e/libforutils.a\n\nor by specifying it as a library::\n\n    -Lforutils/\u003cRTYPE\u003e -lforutils\n\nSpecify one of Debug, DebugMPI, Release, or ReleaseMPI for \u003cRTYPE\u003e. The Debug\nrelease types contain debug symbols and use no optimization, while the Release\ntypes use a reasonable level of optimization.\n\n\nUsage Examples\n===============\n\nFile I/O Operations\n-------------------\n\n**Reading and writing text files:**\n\n.. code-block:: fortran\n\n    use FileUtils\n    Type(TTextFile) :: F\n    character(LEN=:), allocatable :: line\n\n    ! Write to file\n    call F%CreateFile('output.txt')\n    call F%Write('#comment header')\n    call F%Write('name = ', 3.04)\n    call F%Write('test values')\n    call F%Close()\n\n    ! Read file line by line, skipping comments\n    do while (F%ReadNextContentLine('output.txt', line))\n        print *, 'Read: ', line\n    end do\n\n**Python-like loadtxt/savetxt functions:**\n\n.. code-block:: fortran\n\n    use FileUtils\n    real(kind(1.d0)), allocatable :: matrix(:,:), vector(:)\n\n    ! Load data from text file (like numpy.loadtxt)\n    call File%LoadTxt('data.txt', matrix)\n    call File%LoadTxt('vector.txt', vector)\n\n    ! Save data to text file (like numpy.savetxt)\n    call File%SaveTxt('output_matrix.txt', matrix)\n    call File%SaveTxt('output_vector.txt', vector)\n\nString Manipulation\n-------------------\n\n**String formatting and manipulation:**\n\n.. code-block:: fortran\n\n    use StringUtils\n    character(LEN=:), allocatable :: result, joined\n\n    ! Format strings (printf-style)\n    result = FormatString('Test %d for %f %s', 91, 3.04, 'result')\n    ! result = 'Test 91 for 3.0400 result'\n\n    ! Join strings with separator\n    joined = Join(',', 'apple', 'banana', 'cherry')\n    ! joined = 'apple,banana,cherry'\n\n    ! Case conversion\n    print *, UpperCase('hello world')  ! 'HELLO WORLD'\n    print *, LowerCase('HELLO WORLD')  ! 'hello world'\n\nObject Lists\n------------\n\n**Working with string lists:**\n\n.. code-block:: fortran\n\n    use ObjectLists\n    Type(TStringList) :: strings\n\n    ! Add strings to list\n    call strings%Add('here')\n    call strings%Add('there')\n    call strings%Add('alpha')\n\n    ! Sort the list\n    call strings%Sort()\n\n    ! Access items\n    print *, strings%Item(1)  ! 'alpha' (first after sorting)\n    print *, strings%Item(3)  ! 'there'\n\n    ! Find index of item\n    print *, strings%IndexOf('here')  ! returns index or -1 if not found\n\n    ! Key-value pairs\n    call strings%Clear()\n    call strings%Add('key1', 'value1')\n    call strings%Add('key2', 'value2')\n    print *, strings%ValueOf('key1')  ! 'value1'\n\n**Working with numeric lists:**\n\n.. code-block:: fortran\n\n    use ObjectLists\n    Type(TRealList) :: numbers\n    Type(TRealArrayList) :: arrays\n    integer :: i\n\n    ! Add numbers to list\n    call numbers%Add(0.5d0)\n    call numbers%Add(-3.0d0)\n    call numbers%Add(12.0d0)\n    do i = 1, 10\n        call numbers%Add(i * 1.0d0)\n    end do\n\n    ! Sort and access\n    call numbers%Sort()\n    print *, numbers%Item(1)  ! smallest value\n    print *, numbers%AsArray()  ! convert to regular array\n\n    ! Lists of arrays\n    call arrays%Add([0.5d0])\n    call arrays%Add([-3.0d0, 1.0d0])\n    print *, arrays%Item(1,1)  ! first element of first array\n    print *, arrays%Item(2,2)  ! second element of second array\n\nConfiguration Files\n--------------------\n\n**Reading INI-style configuration files:**\n\n.. code-block:: fortran\n\n    use IniObjects\n    Type(TIniFile) :: ini\n    real :: x\n    double precision :: y\n    character(LEN=:), allocatable :: path\n\n    ! Read from file\n    call ini%Open('config.ini')\n\n    ! Read different types\n    path = ini%Read_String('parameter')\n    call ini%Read('x', x)\n    call ini%Read('x', y)  ! automatic type conversion\n\n    call ini%Close()\n\n    ! Environment variable expansion\n    ! If config contains: parameter = test$(PATH)/mypath\n    ! It will expand $(PATH) with the actual PATH environment variable\n\nArray Utilities\n---------------\n\n**Dynamic array reallocation:**\n\n.. code-block:: fortran\n\n    use ArrayUtils\n    real, allocatable :: arr(:)\n    integer, allocatable :: iarr(:)\n\n    ! Initial allocation\n    allocate(arr(3), source = [1.0, 2.0, 3.0])\n\n    ! Reallocate (preserves existing data)\n    call reallocate(arr, 5)  ! expand to 5 elements\n    call reallocate(arr, 2)  ! shrink to 2 elements\n\n    ! Works with different types\n    call reallocate(iarr, 10)\n    iarr(5) = 42\n    call reallocate(iarr, 20)  ! iarr(5) still equals 42\n\nInterpolation\n-------------\n\n**Cubic spline interpolation:**\n\n.. code-block:: fortran\n\n    use Interpolation\n    Type(TCubicSpline) :: spline\n    Type(TRegularCubicSpline) :: reg_spline\n    real(kind(1.d0)), allocatable :: x(:), f(:)\n    real(kind(1.d0)) :: test_x, interpolated_value, derivative\n    integer :: i\n\n    ! Prepare data points\n    allocate(x(100), f(100))\n    do i = 1, 100\n        x(i) = 0.5367d0 * real(i, kind(1.d0)) + 0.3d0\n        f(i) = (x(i)/47.2d0)**3 + (x(i)/5.5d0)**2 + x(i)*3.5d0 + 4.4579d0\n    end do\n\n    ! Initialize irregular spline\n    call spline%Init(x, f)\n\n    ! Initialize regular spline (evenly spaced x values)\n    call reg_spline%Init(x(1), x(size(x)), 100, values=f)\n\n    ! Interpolate at any point\n    test_x = 13.2623d0\n    interpolated_value = spline%Value(test_x)\n    derivative = spline%Derivative(test_x)\n\n    ! Interpolate arrays of values\n    real(kind(1.d0)) :: test_points(3) = [7.3d0, 9.0d0, 34.34643d0]\n    real(kind(1.d0)) :: results(3)\n    call reg_spline%Array(test_points, results)\n\nAdvanced File Operations\n------------------------\n\n**Binary file I/O and object serialization:**\n\n.. code-block:: fortran\n\n    use FileUtils, ObjectLists\n    Type(TBinaryFile) :: bf\n    Type(TStringList) :: list\n\n    ! Save object to binary file\n    call list%Add('item1')\n    call list%Add('item2')\n\n    call bf%CreateFile('data.bin')\n    call list%SaveBinary(bf%unit)\n    call bf%Close()\n\n    ! Load object from binary file\n    call list%Clear()\n    call bf%Open('data.bin')\n    call list%ReadBinary(bf%unit)\n    call bf%Close()\n\n**File utility functions:**\n\n.. code-block:: fortran\n\n    use FileUtils\n    logical :: exists\n    character(LEN=:), allocatable :: path, name, ext\n\n    ! Check file existence\n    exists = File%Exists('myfile.txt')\n\n    ! Extract file components\n    path = File%ExtractPath('/home/user/data.txt')    ! '/home/user/'\n    name = File%ExtractName('/home/user/data.txt')    ! 'data.txt'\n    ext = File%ExtractExt('/home/user/data.txt')      ! '.txt'\n\n    ! Get file information\n    print *, File%Size('myfile.txt')     ! file size in bytes\n    print *, File%TxtFileLines('data.txt')   ! number of lines\n    print *, File%TxtFileColumns('data.txt') ! number of columns\n\nTesting Your Code\n==================\n\nForUtils includes comprehensive unit tests. To run them::\n\n    $ cd tests\n    $ make\n    $ ./run_tests.sh\n\nThe tests demonstrate practical usage patterns and can serve as additional examples for learning the library.\n\nQuick Reference\n================\n\n**Most commonly used modules and types:**\n\n* **FileUtils**: ``TTextFile``, ``TBinaryFile``, ``File%LoadTxt()``, ``File%SaveTxt()``\n* **StringUtils**: ``FormatString()``, ``Join()``, ``UpperCase()``, ``LowerCase()``\n* **ObjectLists**: ``TStringList``, ``TRealList``, ``TRealArrayList``\n* **IniObjects**: ``TIniFile`` for configuration files\n* **ArrayUtils**: ``reallocate()`` for dynamic arrays\n* **Interpolation**: ``TCubicSpline``, ``TRegularCubicSpline``\n\n**Basic usage pattern:**\n\n.. code-block:: fortran\n\n    program example\n        use FileUtils\n        use StringUtils\n        use ObjectLists\n        implicit none\n\n        Type(TTextFile) :: file\n        Type(TStringList) :: items\n        character(LEN=:), allocatable :: formatted\n\n        ! Create and write to file\n        call file%CreateFile('example.txt')\n        call file%Write('# Example data file')\n        call file%Write(FormatString('Value: %f', 3.14159))\n        call file%Close()\n\n        ! Read and process\n        call items%AddFromFile('example.txt', nodups=.false.)\n        call items%WriteItems()  ! print all items\n\n    end program example\n\nDependencies\n=============\n* Fortran 2008 compatible compiler - E.g., ifort 14+, gfortran 6 or higher.\n* MPI library - Only when you want the MpiUtils fully functional. Without an MPI library MpiUtils compile, but the functions are merely no-ops and the makefile target DebugMPI and ReleaseMPI can not be built.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmbant%2Fforutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmbant%2Fforutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmbant%2Fforutils/lists"}