Download Latest Version timsort-master.zip (22.0 kB)
Email in envelope

Get an email when there's a new version of Timsort For Fortran

Home
Name Modified Size InfoDownloads / Week
README.txt 2021-08-01 2.8 kB
timsort-impl.h 2021-08-01 25.5 kB
timsort.c 2021-08-01 12.0 kB
FortranTimsort.mak 2021-08-01 525 Bytes
TestRunResults.txt 2021-08-01 1.1 kB
timsort-master.zip 2021-08-01 22.0 kB
timsort.h 2021-08-01 2.6 kB
hcn_to_c_m.f08 2021-08-01 1.8 kB
program_test_hcn_timsort.f08 2021-08-01 2.8 kB
timsort_m.f08 2021-08-01 2.3 kB
hcn_m.f08 2021-08-01 6.0 kB
timsort_r.c 2021-08-01 648 Bytes
Totals: 12 Items   80.0 kB 0
Timsort for Fortran (not written in Fortran!)  
    July 31, 2021 by Clay B. Carley III

    This effort is just a small part of a larger project. I found that I had need to use Timsort in Fortran but could not find
    a Fortran implementation. What I did find was implementations in C and C++. My first effort was to (painfully) translate the
    C++ code into Fortran. Then, I decided it may be a bit easier to translate from the C code. Then I had an epiphany! Why not
    use the ISO_C_BINDING library and leave the C code alone. So, with a couple of false starts, I was finally successful. This 
    project contains my solution.

    To change the code for your defined type:
        Declare your type or use an intrinsic type - must have the relational operators defined
        Change the type of elements of the array
        Change the compare_it function for your type

Included files:
    I got a copy of these files from: https://github.com/patperry/timsort
    timsort-master.zip contains:
        AUTHORS
        LICENSE
        README.md
        stresstest.c
        timsort-impl.h
        timsort.c
        timsort.h
        timsort_r.c
        
    The following are needed in the directory where you want to do a test run:

    hcn_m.f08 - contains a Fortran module of a user defined type, hcn_type, with its defined relational operators

    hcn_to_c_m.f08 - contains a Fortran module of a defined compare function usable by timsort

    program_test_hcn_timsort.f08 - test usage of timsort on an array of hcn's.

    timsort_m.f08 - contains a Fortran module for the Fortran ISO_C_BINDINGs for timsort and timsort_r

    The timsort files from timsort-master.zip:
        timsort-impl.h
        timsort.c
        timsort.h
        timsort_r.c

    FortranTimsort.mak - make file to create the program_test_hcn_timsort executable


    What your results should look like after running the executable program_test_hcn_timsort:
        TestRunResults.txt

Programming Environment:

C Compiler:
    gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
    Copyright (C) 2017 Free Software Foundation, Inc.
         
Fortran Compiler (gfortran):
    GNU Fortran (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0
    Copyright (C) 2018 Free Software Foundation, Inc.
    
Operating System:
    Distributor ID:	LinuxMint
    Description:	Linux Mint 19.1 Tessa
    Release:	19.1
    Codename:	tessa


References:
    Timsort discussion and files:
    https://github.com/patperry/timsort

    ISO_C_BINDING, Interoperable Fortran and C types:
    https://www.ibm.com/docs/en/xcafbg/9.0.0?topic=SS3KZ4_9.0.0/com.ibm.xlf111.bg.doc/xlflr/interop-iso-c-binding-module.htm

    Interoperable Fortran and C - Hello World Example:
    https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html
    
       

Source: README.txt, updated 2021-08-01