Skip to content

Commit bfc8ccf

Browse files
committed
Merge branch 'release/1.0.3'
2 parents 32cf3bc + d2fd710 commit bfc8ccf

File tree

8 files changed

+113
-38
lines changed

8 files changed

+113
-38
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: fair-software
2+
3+
on: push
4+
5+
jobs:
6+
verify:
7+
name: "fair-software"
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: fair-software/howfairis-github-action@main
11+
name: Measure compliance with fair-software.eu recommendations
12+
env:
13+
PYCHARM_HOSTED: "Trick colorama into displaying colored output"
14+
with:
15+
MY_REPO_URL: "https://github.com/${{ github.repository }}"

CHANGELOG.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# Changelog
2-
Notable changes to the Fortran Error Handler will be documented here.
2+
Notable changes to the Fortran Error Handler are documented here.
33

44
## [Unreleased]
55

6+
## [1.0.3] - 2021-12-31
7+
8+
### Added
9+
- Added option to compile with fpm (Fortran Package Manager) and updated README.md accordingly.
10+
611
## [1.0.2] - 2020-11-11
712

813
No changes to code. Release is only to archive on Zenodo.
914

1015
## [1.0.1] - 2020-06-30
16+
1117
### Added
1218
- Option to turn off printing of non-critical (warning) errors on trigger. Configured by `triggerWarnings` parameter on `ErrorHandler%init(...)`.
1319
- This CHANGELOG.
1420

1521
### Fixed
1622
- A few corrections to documentation.
1723

18-
## [1.0] - 2020-06-05
24+
## [1.0.0] - 2020-06-05
25+
1926
### Added
2027
- First major release.
2128

22-
[Unreleased]: https://github.com/samharrison7/fortran-error-handler/tree/develop
23-
[1.0.2]: https://github.com/samharrison7/fortran-error-handler/tree/1.0.2
24-
[1.0.1]: https://github.com/samharrison7/fortran-error-handler/tree/1.0.1
25-
[1.0]: https://github.com/samharrison7/fortran-error-handler/tree/1.0
29+
[Unreleased]: https://github.com/samharrison7/fortran-error-handler/compare/1.0.3...HEAD
30+
[1.0.3]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.3
31+
[1.0.2]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.2
32+
[1.0.1]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.1
33+
[1.0.0]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0

README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Fortran Error Handler
22

3+
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4268263.svg)](https://doi.org/10.5281/zenodo.4268263)
4+
[![fair-software.eu](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B%20%20%E2%97%8F%20%20%E2%97%8B-orange)](https://fair-software.eu)
5+
36
Fortran error handling frameworks are few and far between, and those that do exist often implement only parts of the error handling process, or rely on pre-processors. The goal of this error handling framework is to provide a universal and comprehensive solution for applications requiring functional and robust error handling, utilising the power of modern object-oriented Fortran.
47

58
- [Getting started](#getting-started)
@@ -12,9 +15,42 @@ Fortran error handling frameworks are few and far between, and those that do exi
1215
<a name="getting-started"></a>
1316
## Getting started
1417

15-
If you wish to use the Fortran Error Handler in a project, the simplest way to do so is to include the source files (in `src/`) at the start of your compilation setup. Source files should be compiled in this order: `ErrorInstance.f90`, `ErrorHandler.f90`, `ErrorCriteria.f90`, `Result.f90`. An example [Makefile.example](./Makefile.example) is included, which can be altered according to your compiler and preferences.
18+
There are a few ways to get the Fortran Error Handler into your project.
19+
20+
### `fpm` - Fortran Package Manager
21+
22+
The simplest way is to use [fpm (Fortran Package Manager)](https://fpm.fortran-lang.org/en/index.html). You can either directly include the Fortran Error Handler as a dependency in your `fpm.toml` file:
23+
24+
```toml
25+
[dependencies]
26+
feh = { git = "https://github.com/samharrison7/fortran-error-handler" }
27+
```
28+
29+
Or you can clone the repo and build the library yourself using fpm:
1630

17-
The code can also be compiled using `cmake`, which creates an example executable (using `example/example_usage.f90`), an executable of unit tests (using `tests/run_tests.f90`), and a library of the framework:
31+
```bash
32+
$ git clone https://github.com/samharrison7/fortran-error-handler
33+
$ cd fortran-error-handler
34+
$ fpm build --flag="-fbackslash"
35+
```
36+
37+
A static library (e.g. `libfeh.a` on Linux) and `.mod` files will be generated in the `build` directory for you to use. An example executable (using `example/example_usage.f90`) will also be generated. Running `fpm test` will run tests (using `tests/run_tests.f90`) for the framework. The `-fbackslash` flag is a GFortran flag to enable coloured terminal output, and is only needed if the `bashColors` option is `.true.` (default). The equivalent `ifort` flag is `/assume:bscc`.
38+
39+
You can also get fpm to install the Fortran Error Handler locally (e.g. to `/home/<user>/.local`):
40+
41+
```bash
42+
$ fpm install --flag="-fbackslash"
43+
```
44+
45+
Fpm can easily be installed using Conda: `conda install -c conda-forge fpm`.
46+
47+
### Grab the files
48+
49+
Another simple method is to simple grab a copy of the source files (in `src/`) and include at the start of your compilation setup. Source files should be compiled in this order: `ErrorInstance.f90`, `ErrorHandler.f90`, `ErrorCriteria.f90`, `Result.f90`. An example [Makefile.example](./Makefile.example) is included, which can be altered according to your compiler and preferences.
50+
51+
### `cmake`
52+
53+
The code can also be compiled using `cmake`, which generates a library and `.mod` files, an example executable, and executable of unit tests.
1854

1955
```bash
2056
$ mkdir build
@@ -27,12 +63,6 @@ $ ./test
2763
$ ./example
2864
```
2965

30-
Whether the library is shared or not is specified by the `BUILD_SHARED_LIBS` variable. If you wish to build a shared library, then pass the `BUILD_SHARED_LIBS` option as on:
31-
32-
```bash
33-
$ cmake .. -DBUILD_SHARED_LIBS=ON
34-
```
35-
3666
The framework has been tested using GFortran 7 upwards and Intel Fortran 18.
3767

3868
<a name="usage"></a>
@@ -171,4 +201,4 @@ integer :: i = 1
171201
real :: r = 1.0
172202
real(dp) :: r_dp = 1.0_dp
173203
real(qp) :: r_qp = 1.0_qp
174-
```
204+
```

codemeta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747
"keywords": "Fortran, error handling",
4848
"license": "MIT",
4949
"title": "Fortran Error Handler",
50-
"version": "v1.0.0"
51-
}
50+
"version": "v1.0.3"
51+
}

example/CustomErrorCriteria.f90

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,27 @@ module CustomErrorCriteriaModule
2020
!! the parent ErrorCriteria (and thus ErrorHandler), setting custom errors
2121
!! and default error criteria errors.
2222
subroutine initCustomErrorCriteria(this, &
23-
errors, &
24-
criticalPrefix, &
25-
warningPrefix, &
26-
messageSuffix, &
27-
bashColors)
23+
errors, &
24+
criticalPrefix, &
25+
warningPrefix, &
26+
messageSuffix, &
27+
bashColors, &
28+
printErrorCode, &
29+
triggerWarnings, &
30+
on)
2831
class(CustomErrorCriteria), intent(inout) :: this !> This ErrorCriteria instance
2932
type(ErrorInstance), intent(in), optional :: errors(:) !> Custom defined errors
3033
character(len=*), intent(in), optional :: criticalPrefix !> Prefix to critical error messages
3134
character(len=*), intent(in), optional :: warningPrefix !> Prefix to warning error messages
3235
character(len=*), intent(in), optional :: messageSuffix !> Suffix to error messages
3336
logical, intent(in), optional :: bashColors !> Should prefixes be colored in bash shells?
37+
logical, intent(in), optional :: printErrorCode !! Should error messages be prefixed with the error code?
38+
logical, intent(in), optional :: triggerWarnings !! Should warnings be printing on trigger?
39+
logical, intent(in), optional :: on !! Should the ErrorHandler output errors?
3440

3541
!> We must initialise the parent ErrorCriteria for the default criteria to be set
36-
call this%ErrorCriteria%init(errors,criticalPrefix,warningPrefix,messageSuffix,bashColors)
42+
call this%ErrorCriteria%init(errors, criticalPrefix, warningPrefix, messageSuffix, bashColors, &
43+
printErrorCode, triggerWarnings, on)
3744
! Add our new error criterion. Make sure you include a function(s) that corresponds to this!
3845
call this%addErrorCriteria( &
3946
codes = [110,111], &
@@ -45,7 +52,7 @@ subroutine initCustomErrorCriteria(this, &
4552
end subroutine
4653

4754
!> Test whether an integer value is a factor of criterion
48-
pure function integerFactor(this, value, criterion, message, traceMessage) result(error)
55+
function integerFactor(this, value, criterion, message, traceMessage) result(error)
4956
class(CustomErrorCriteria), intent(in) :: this !> The ErrorCriteria class
5057
integer, intent(in) :: value !> The value to test
5158
integer, intent(in) :: criterion !> The value to test
@@ -86,7 +93,7 @@ pure function integerFactor(this, value, criterion, message, traceMessage) resul
8693
end function
8794

8895
!> Test whether an integer value is a multiple of criterion
89-
pure function integerMultiple(this, value, criterion, message, traceMessage) result(error)
96+
function integerMultiple(this, value, criterion, message, traceMessage) result(error)
9097
class(CustomErrorCriteria), intent(in) :: this !> The ErrorCriteria class
9198
integer, intent(in) :: value !> The value to test
9299
integer, intent(in) :: criterion !> The value to test

fpm.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name = "feh"
2+
version = "1.0.3"
3+
license = "MIT"
4+
author = "Sam Harrison"
5+
maintainer = "[email protected]"
6+
7+
[[ example ]]
8+
name = "example"
9+
source-dir = "example"
10+
main = "example_usage.f90"
11+
12+
[[ test ]]
13+
name = "tests"
14+
source-dir = "tests"
15+
main = "run_tests.f90"
16+
17+
[install]
18+
library = true

src/ErrorCriteria.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ module ErrorCriteriaModule
133133
!> Initialise the ErrorCriteria and at the same time initialise
134134
!! the parent ErrorHandler, setting custom errors.
135135
subroutine initErrorCriteria(this, &
136-
errors, &
137-
criticalPrefix, &
138-
warningPrefix, &
139-
messageSuffix, &
140-
bashColors, &
141-
printErrorCode, &
142-
triggerWarnings, &
143-
on)
136+
errors, &
137+
criticalPrefix, &
138+
warningPrefix, &
139+
messageSuffix, &
140+
bashColors, &
141+
printErrorCode, &
142+
triggerWarnings, &
143+
on)
144144
class(ErrorCriteria), intent(inout) :: this !! This ErrorCriteria instance
145145
type(ErrorInstance), intent(in), optional :: errors(:) !! Custom defined errors
146146
character(len=*), intent(in), optional :: criticalPrefix !! Prefix to critical error messages

src/ErrorInstance.f90

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,12 @@ function init(code, message, isCritical, trace) result(this)
5555
!! and https://stackoverflow.com/questions/44385909/adding-to-an-array-of-characters-in-fortran
5656
subroutine addToTrace(this, message)
5757
class(ErrorInstance), intent(inout) :: this
58-
character(len=*), intent(in) :: message
59-
character(len=256) :: tempMessage
60-
61-
tempMessage = message ! Make character length 256
58+
character(len=*), intent(in) :: message
6259
! Check if this is the first time something has been added to
6360
! the trace or not. If it is, allocate as null array.
6461
if (.not. allocated(this%trace)) allocate(this%trace(0))
6562
! Add the new node to the trace array.
66-
this%trace = [this%trace, tempMessage]
63+
this%trace = [character(len=256) :: this%trace, message]
6764
end subroutine
6865

6966
!> Return the error code.

0 commit comments

Comments
 (0)