Skip to content

Commit a95f645

Browse files
committed
Merge branch 'release/1.0.5'
2 parents 12daf57 + 4f03728 commit a95f645

File tree

9 files changed

+99
-42
lines changed

9 files changed

+99
-42
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
makefile
33
Makefile
44

5+
# Build dirs
6+
build*/
7+
58
# Sublime Text and Visual Studio project files
69
*.sublime-project
710
*.sublime-workspace
@@ -57,4 +60,3 @@ snip/
5760
*.out
5861
*.app
5962
bin/
60-
build/

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ Notable changes to the Fortran Error Handler are documented here.
33

44
## [Unreleased]
55

6+
## [1.0.5] - 2023-05-31
7+
8+
### Added
9+
- [meson.build](./meson.build) file to enable builds using meson. Added details to README.md.
10+
11+
### Removed
12+
- Removed need to specify `-fbackslash` (or equivalent for other compilers) by using `char(27)` for terminal escape character.
13+
14+
### Fixed
15+
- Removed whitespace in `fpm.toml` file table names to make compatible with latest fpm versions.
16+
617
## [1.0.4] - 2022-01-02
718

819
### Fixed
@@ -31,7 +42,8 @@ No changes to code. Release is only to archive on Zenodo.
3142
### Added
3243
- First major release.
3344

34-
[Unreleased]: https://github.com/samharrison7/fortran-error-handler/compare/1.0.4...HEAD
45+
[Unreleased]: https://github.com/samharrison7/fortran-error-handler/compare/1.0.5...HEAD
46+
[1.0.5]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.5
3547
[1.0.4]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.4
3648
[1.0.3]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.3
3749
[1.0.2]: https://github.com/samharrison7/fortran-error-handler/releases/tag/1.0.2

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ project(fortran_error_handler)
44
enable_language(Fortran)
55

66
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
7-
set(FLAGS "-O3 -fcheck=all -fbackslash -ffpe-trap=zero,invalid,overflow")
7+
set(FLAGS "-O3 -fcheck=all -ffpe-trap=zero,invalid,overflow")
88
endif()
99
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
10-
set(FLAGS "/O3 /fpe:0 /assume:bscc")
10+
set(FLAGS "/O3 /fpe:0")
1111
endif()
1212

1313
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FLAGS}")

Makefile.example

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FC=gfortran
22
WARNINGS = -Wall
3-
FCFLAGS = -O1 -fcheck=all -fbackslash -fopenmp ${WARNINGS}
3+
FCFLAGS = -O1 -fcheck=all -fopenmp ${WARNINGS}
44
DEBUGFLAGS = -g -ffpe-trap=zero,invalid,overflow,underflow -pg
55
EXEC_FILE = main
66
EXEC_PATH = ./bin/
@@ -21,12 +21,6 @@ VPATH = src \
2121
# make main: Compile and create exe.
2222
# make run: Run the compiled exe.
2323
# make clean: Remove compiled files.
24-
#
25-
# GFortran bug causes "character length mismatch in array constructor"
26-
# errors with allocatable character variables, even when they're the correct length.
27-
# -O1 or higher must be used. See
28-
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70231 and
29-
# https://stackoverflow.com/questions/44385909/adding-to-an-array-of-characters-in-fortran.
3024
$(EXEC_FILE): $(OBJECTS)
3125
$(FC) $(FCFLAGS) $(DEBUGFLAGS) -o $(EXEC_PATH)$@ $^
3226
%.o: %.f90

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Fortran error handling frameworks are few and far between, and those that do exi
1515
<a name="getting-started"></a>
1616
## Getting started
1717

18-
There are a few ways to get the Fortran Error Handler into your project.
18+
There are a few ways to get the Fortran Error Handler into your project. The following have been tested with recent version of the GFortran and Intel Fortran compiler (`ifort`, not `ifx`).
1919

2020
### `fpm` - Fortran Package Manager
2121

@@ -31,15 +31,14 @@ Or you can clone the repo and build the library yourself using fpm:
3131
```bash
3232
$ git clone https://github.com/samharrison7/fortran-error-handler
3333
$ cd fortran-error-handler
34-
$ fpm build --flag="-fbackslash"
34+
$ fpm build
3535
```
3636

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-
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.
3938
You can also get fpm to install the Fortran Error Handler locally (e.g. to `/home/<user>/.local`):
4039

4140
```bash
42-
$ fpm install --flag="-fbackslash"
41+
$ fpm install
4342
```
4443

4544
Fpm can easily be installed using Conda: `conda install -c conda-forge fpm`.
@@ -48,9 +47,29 @@ Fpm can easily be installed using Conda: `conda install -c conda-forge fpm`.
4847

4948
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.
5049

51-
### `cmake`
50+
### Meson
5251

53-
The code can also be compiled using `cmake`, which generates a library and `.mod` files, an example executable, and executable of unit tests.
52+
If you use [meson](https://mesonbuild.com/), a [meson.build](./meson.build) file is provided. For example, if you want to build into the `buildmeson` directory:
53+
54+
```bash
55+
$ meson buildmeson
56+
$ ninja -C buildmeson
57+
```
58+
59+
From meson 0.56, you can use the `meson compile` command instead of `ninja`. This will generate the example and test executables, a shared library and module files. You can run the tests directly using meson: `meson test -C buildmeson`.
60+
61+
By default, the library is built with a debug build type. To build for release (with `-O3` optimisations), specify this via the `--buildtype=release` option:
62+
63+
```bash
64+
$ meson buildrelease --buildtype=release
65+
$ ninja -C buildrelease
66+
```
67+
68+
Installing using meson (`meson install`) isn't recommended at the moment as `.mod` files are not installed - see [this issue](https://github.com/mesonbuild/meson/issues/5374).
69+
70+
### CMake
71+
72+
The code can also be compiled using CMake, which similarly generates a library and `.mod` files, an example executable, and executable of unit tests.
5473

5574
```bash
5675
$ mkdir build
@@ -63,8 +82,6 @@ $ ./test
6382
$ ./example
6483
```
6584

66-
The framework has been tested using GFortran 7 upwards and Intel Fortran 18.
67-
6885
<a name="usage"></a>
6986
## Usage
7087

@@ -187,9 +204,6 @@ Explore the documentation for each class to learn how to best use the framework,
187204
## Caveats and limitations <a name="caveats"></a>
188205

189206
- Error code must be less than 99999.
190-
- GFortran bugs:
191-
- `-O1` or higher must be used to avoid "character length mismatch in array constructor" errors with allocatable character variables.
192-
- `-fcheck=no-bounds` must be used to avoid errors on allocating rank-2 or higher arrays.
193207
- Result objects only support up to rank-4 (4 dimensional) data.
194208
- Limited support for different kinds, due to Fortran's lack of kind polymorphism. In particular, ErrorCriteria only accept 4-byte integers and single precision, double precision and quadruple precision reals, as such:
195209

codemeta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
"identifier": "",
4242
"codeRepository": "https://github.com/samharrison7/fortran-error-handler",
4343
"datePublished": "2020-06-05",
44-
"dateModified": "2020-06-05",
44+
"dateModified": "2023-05-31",
4545
"dateCreated": "2020-06-05",
4646
"description": "Comprehensive error framework for applications requiring functional and robust error handling, utilising the power of modern object-oriented Fortran.",
4747
"keywords": "Fortran, error handling",
4848
"license": "MIT",
4949
"title": "Fortran Error Handler",
50-
"version": "v1.0.3"
50+
"version": "v1.0.5"
5151
}

fpm.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name = "feh"
2-
version = "1.0.4"
2+
version = "1.0.5"
33
license = "MIT"
44
author = "Sam Harrison"
55
maintainer = "[email protected]"
66
copyright = "Copyright 2022, Sam Harrison"
77

8-
[[ example ]]
8+
[[example]]
99
name = "example"
1010
source-dir = "example"
1111
main = "example_usage.f90"
1212

13-
[[ test ]]
13+
[[test]]
1414
name = "tests"
1515
source-dir = "tests"
1616
main = "run_tests.f90"

meson.build

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
project('feh', 'fortran', meson_version: '>=0.50')
2+
3+
# Compiler flags
4+
flags = ''
5+
if meson.get_compiler('fortran').get_id() == 'gcc'
6+
flags = ['-fbacktrace']
7+
endif
8+
if meson.get_compiler('fortran').get_id() == 'intel'
9+
flags = ['-traceback']
10+
endif
11+
add_global_arguments(flags, language : 'fortran')
12+
13+
# Files that are common to all build
14+
files = ['src/ErrorInstance.f90', 'src/ErrorHandler.f90',
15+
'src/ErrorCriteria.f90', 'src/Result.f90']
16+
17+
# Add example executable
18+
executable('example', files(files + ['example/example_usage.f90']))
19+
20+
# Add an exe for the test
21+
test = executable('testexe', files(files + ['tests/assert.f90',
22+
'tests/util.f90',
23+
'tests/tests_ErrorCriteria.f90',
24+
'tests/tests_ErrorInstance.f90',
25+
'tests/tests_Result.f90',
26+
'tests/run_tests.f90']))
27+
# Create the test itself
28+
test('test', test)
29+
30+
# Add the library and make it installable
31+
library('feh', files, install : true)

src/ErrorHandler.f90

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,22 @@ subroutine initErrorHandler(this, &
6767
printErrorCode, &
6868
triggerWarnings, &
6969
on)
70-
class(ErrorHandler), intent(inout) :: this !! This ErrorHandler instance
71-
type(ErrorInstance), intent(in), optional :: errors(:) !! List of ErrorInstances to add
72-
character(len=*), intent(in), optional :: criticalPrefix !! Prefix for error messages if they're critical
73-
character(len=*), intent(in), optional :: warningPrefix !! Prefix for error messages if they're warnings
74-
character(len=*), intent(in), optional :: messageSuffix !! Suffix for error messages
75-
logical, intent(in), optional :: bashColors !! Use bash colours or not?
76-
logical, intent(in), optional :: printErrorCode !! Should the error code be prepended to the prefix?
77-
logical, intent(in), optional :: triggerWarnings !! Should warnings be printed on trigger?
78-
logical, intent(in), optional :: on !! Turn the ErrorHandler on or off
79-
integer :: i ! Loop iterator.
80-
logical, allocatable :: mask(:) ! Logical mask to remove default errors from input errors array.
81-
type(ErrorInstance) :: defaultErrors(2) ! Temporary array containing default errors.
70+
class(ErrorHandler), intent(inout) :: this !! This ErrorHandler instance
71+
type(ErrorInstance), intent(in), optional :: errors(:) !! List of ErrorInstances to add
72+
character(len=*), intent(in), optional :: criticalPrefix !! Prefix for error messages if they're critical
73+
character(len=*), intent(in), optional :: warningPrefix !! Prefix for error messages if they're warnings
74+
character(len=*), intent(in), optional :: messageSuffix !! Suffix for error messages
75+
logical, intent(in), optional :: bashColors !! Use bash colours or not?
76+
logical, intent(in), optional :: printErrorCode !! Should the error code be prepended to the prefix?
77+
logical, intent(in), optional :: triggerWarnings !! Should warnings be printed on trigger?
78+
logical, intent(in), optional :: on !! Turn the ErrorHandler on or off
79+
integer :: i ! Loop iterator.
80+
logical, allocatable :: mask(:) ! Logical mask to remove default errors from input errors array.
81+
type(ErrorInstance) :: defaultErrors(2) ! Temporary array containing default errors.
82+
character(len=*), parameter :: ESC = char(27) ! Terminal escape character
83+
character(len=*), parameter :: COLOR_RED = ESC//"[91m" ! Escape sequence for red text
84+
character(len=*), parameter :: COLOR_BLUE = ESC//"[94m" ! Escape sequence for blue text
85+
character(len=*), parameter :: COLOR_RESET = ESC//"[0m" ! Escape sequence to reset text color
8286

8387
! Stop the program running is ErrorHandler is already initialised
8488
call this%stopIfInitialised()
@@ -137,8 +141,8 @@ subroutine initErrorHandler(this, &
137141

138142
! Set whether bash colors wanted or not, and add them to prefixes if so
139143
if (present(bashColors)) this%bashColors = bashColors
140-
if (this%bashColors .eqv. .true.) this%criticalPrefix = "\x1B[91m" // adjustl(trim(this%criticalPrefix)) // "\x1B[0m"
141-
if (this%bashColors .eqv. .true.) this%warningPrefix = "\x1B[94m" // adjustl(trim(this%warningPrefix)) // "\x1B[0m"
144+
if (this%bashColors .eqv. .true.) this%criticalPrefix = COLOR_RED // adjustl(trim(this%criticalPrefix)) // COLOR_RESET
145+
if (this%bashColors .eqv. .true.) this%warningPrefix = COLOR_BLUE // adjustl(trim(this%warningPrefix)) // COLOR_RESET
142146

143147
! Set whether we want the error code to be prefixed to the message and whether
144148
! we want warnings to be triggered

0 commit comments

Comments
 (0)