@@ -9,16 +9,11 @@ Examples
99The following standalone codes demonstrate how Flibcpp can be used in native
1010Fortran code.
1111
12- String conversion and sort
12+ Random numbers and sorting
1313==========================
1414
15- This example:
16-
17- - Introspects the Flibcpp version;
18- - Converts a user input to an integer, validating it with useful error
19- messages;
20- - Fills an array with normally-distributed real numbers; and
21- - Sorts the array before printing the first few entries.
15+ This simple example generates an array of normally-distributed double-precision
16+ reals, sorts them, and then shuffles them again.
2217
2318.. literalinclude :: ../example/sort.f90
2419 :linenos:
@@ -32,6 +27,39 @@ from native Fortran strings.
3227.. literalinclude :: ../example/vecstr.f90
3328 :linenos:
3429
30+ .. _example_generic :
31+
32+ Generic sorting
33+ ===============
34+
35+ Since sorting algorithms often allow :math: `O(N)` algorithms to be written in
36+ :math: `O(\log N)`, providing generic sorting routines is immensely useful in
37+ applications that operate on large chunks of data. This example demonstrates
38+ the generic version of the :ref: `modules_algorithm_argsort ` subroutine by
39+ sorting a native Fortran array of native Fortran types using a native Fortran
40+ subroutine. The only C interaction needed is to create C pointers to the
41+ Fortran array entries and to provide a C-bound comparator that converts those
42+ pointers back to native Fortran pointers.
43+
44+ .. literalinclude :: ../example/sort_generic.f90
45+ :linenos:
46+
47+ .. _example_utils :
48+
49+ Example utilities module
50+ ========================
51+
52+ This pure-Fortran module builds on top of functionality from Flibcpp. It
53+ provides procedures to:
54+
55+ - Format and print the Flibcpp version;
56+ - Converts a user input to an integer, validating it with useful error
57+ messages;
58+ - Reads a dynamically sized vector of strings from the user.
59+
60+ .. literalinclude :: ../example/example_utils.f90
61+ :linenos:
62+
3563.. ############################################################################
3664.. end of doc/examples.rst
3765.. ############################################################################
0 commit comments