Skip to content

Commit c6b54e1

Browse files
authored
Merge pull request #662 from jvdp1/extract_demo
Extraction of the demo programs from the specs in the directory example
2 parents 5a2028a + d0aeb90 commit c6b54e1

File tree

280 files changed

+4017
-3496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+4017
-3496
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_subdirectory(src)
7171
if(BUILD_TESTING)
7272
enable_testing()
7373
add_subdirectory(test)
74+
add_subdirectory(example)
7475
endif()
7576

7677
install(EXPORT ${PROJECT_NAME}-targets

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ To build the standard library run
149149
cmake --build build
150150
```
151151

152-
To test your build, run the test suite after the build has finished with
152+
To test your build, run the test suite and all example programs after the build has finished with
153153

154154
```sh
155155
cmake --build build --target test
156156
```
157157

158+
To test only the test suite, run
159+
```sh
160+
ctest --test-dir build/test
161+
```
162+
158163
Please report failing tests on our [issue tracker](https://github.com/fortran-lang/stdlib/issues/new/choose) including details of the compiler used, the operating system and platform architecture.
159164

160165
To install the project to the declared prefix run
@@ -179,6 +184,15 @@ git checkout stdlib-fpm
179184
fpm build --profile release
180185
```
181186

187+
You can run the examples with `fpm` as:
188+
189+
```sh
190+
fpm run --example prog
191+
```
192+
193+
with `prog` being the name of the example program (e.g., `example_sort`).
194+
195+
182196
To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file:
183197
```toml
184198
[dependencies]

ci/fpm-deployment.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ minor=$(cut -d. -f2 VERSION)
3939
patch=$(cut -d. -f3 VERSION)
4040
fyflags="${fyflags} -DPROJECT_VERSION_MAJOR=${major} -DPROJECT_VERSION_MINOR=${minor} -DPROJECT_VERSION_PATCH=${patch}"
4141

42-
mkdir -p "$destdir/src" "$destdir/test"
42+
mkdir -p "$destdir/src" "$destdir/test" "$destdir/example"
4343

4444
# Preprocess stdlib sources
4545
find src -maxdepth 1 -iname "*.fypp" \
@@ -49,6 +49,7 @@ find src -maxdepth 1 -iname "*.fypp" \
4949
find src -maxdepth 1 -iname "*.f90" -exec cp {} "$destdir/src/" \;
5050
find test -name "test_*.f90" -exec cp {} "$destdir/test/" \;
5151
find test -name "*.dat" -exec cp {} "$destdir/" \;
52+
find example -name "example_*.f90" -exec cp {} "$destdir/example/" \;
5253

5354
# Include additional files
5455
cp "${include[@]}" "$destdir/"

doc/specs/stdlib_array.md

+2-16
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,7 @@ Returns an array of default integer size, with a maximum length of `size(array)`
4646
#### Examples
4747

4848
```fortran
49-
program demo_trueloc
50-
use stdlib_array, only : trueloc
51-
implicit none
52-
real, allocatable :: array(:)
53-
allocate(array(500))
54-
call random_number(array)
55-
array(trueloc(array > 0.5)) = 0.0
56-
end program demo_trueloc
49+
{!example/array/example_trueloc.f90!}
5750
```
5851

5952

@@ -90,12 +83,5 @@ Returns an array of default integer size, with a maximum length of `size(array)`
9083
#### Examples
9184

9285
```fortran
93-
program demo_falseloc
94-
use stdlib_array, only : falseloc
95-
implicit none
96-
real, allocatable :: array(:)
97-
allocate(array(-200:200))
98-
call random_number(array)
99-
array(falseloc(array < 0.5), lbound(array)) = 0.0
100-
end program demo_falseloc
86+
{!example/array/example_falseloc.f90!}
10187
```

doc/specs/stdlib_ascii.md

+5-29
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ The result is an intrinsic character type of the same length as `string`.
5151
#### Example
5252

5353
```fortran
54-
program demo_to_lower
55-
use stdlib_ascii, only : to_lower
56-
implicit none
57-
print'(a)', to_lower("HELLo!") ! returns "hello!"
58-
end program demo_to_lower
54+
{!example/ascii/example_ascii_to_lower.f90!}
5955
```
6056

6157
### `to_upper`
@@ -87,11 +83,7 @@ The result is an intrinsic character type of the same length as `string`.
8783
#### Example
8884

8985
```fortran
90-
program demo_to_upper
91-
use stdlib_ascii, only : to_upper
92-
implicit none
93-
print'(a)', to_upper("hello!") ! returns "HELLO!"
94-
end program demo_to_upper
86+
{!example/ascii/example_ascii_to_upper.f90!}
9587
```
9688

9789
### `to_title`
@@ -128,13 +120,7 @@ The result is an intrinsic character type of the same length as `string`.
128120
#### Example
129121

130122
```fortran
131-
program demo_to_title
132-
use stdlib_ascii, only : to_title
133-
implicit none
134-
print*, to_title("hello there!") ! returns "Hello There!"
135-
print*, to_title("'enquoted'") ! returns "'Enquoted'"
136-
print*, to_title("1st") ! returns "1st"
137-
end program demo_to_title
123+
{!example/ascii/example_ascii_to_title.f90!}
138124
```
139125

140126
### `to_sentence`
@@ -169,13 +155,7 @@ The result is an intrinsic character type of the same length as `string`.
169155
#### Example
170156

171157
```fortran
172-
program demo_to_sentence
173-
use stdlib_ascii, only : to_sentence
174-
implicit none
175-
print*, to_sentence("hello!") ! returns "Hello!"
176-
print*, to_sentence("'enquoted'") ! returns "'Enquoted'"
177-
print*, to_sentence("1st") ! returns "1st"
178-
end program demo_to_sentence
158+
{!example/ascii/example_ascii_to_sentence.f90!}
179159
```
180160

181161
### `reverse`
@@ -207,9 +187,5 @@ The result is an intrinsic character type of the same length as `string`.
207187
#### Example
208188

209189
```fortran
210-
program demo_reverse
211-
use stdlib_ascii, only : reverse
212-
implicit none
213-
print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH"
214-
end program demo_reverse
190+
{!example/ascii/example_ascii_reverse.f90!}
215191
```

0 commit comments

Comments
 (0)