@@ -9,16 +9,11 @@ Examples
9
9
The following standalone codes demonstrate how Flibcpp can be used in native
10
10
Fortran code.
11
11
12
- String conversion and sort
12
+ Random numbers and sorting
13
13
==========================
14
14
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.
22
17
23
18
.. literalinclude :: ../example/sort.f90
24
19
:linenos:
@@ -32,6 +27,39 @@ from native Fortran strings.
32
27
.. literalinclude :: ../example/vecstr.f90
33
28
:linenos:
34
29
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
+
35
63
.. ############################################################################
36
64
.. end of doc/examples.rst
37
65
.. ############################################################################
0 commit comments