Skip to content

Commit 8b3b72f

Browse files
Merge pull request #34 from jacobwilliams/33-real-kinds
added support for specifying real kind via preprocessor flag
2 parents f6b08a8 + aacc0a6 commit 8b3b72f

File tree

5 files changed

+71
-188
lines changed

5 files changed

+71
-188
lines changed

README.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,49 @@ Currently, this module can be used to generate simple plots from Fortran. Event
1414
The way it works is simply to generate a Python script with the plotting code, which
1515
is then executed from the command line using the Fortran ```execute_command_line``` function.
1616

17-
The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 features such as deferred-length strings). It should work fine with the latest gfortran or ifort compilers. A simple script ```build.sh``` is provided for building the library and test program (requires gfortran and [FoBiS](https://github.com/szaghi/FoBiS)). It will also build the HTML documentation if [FORD](https://github.com/Fortran-FOSS-Programmers/ford) is installed. A `fpm.toml` file is also provided for use with the [Fortran Package Manager](https://github.com/fortran-lang/fpm).
17+
### Compiling
18+
19+
The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 features such as deferred-length strings). It should work fine with the latest gfortran or ifort compilers.
20+
21+
A `fmp.toml` file is provided for compiling pyplot-fortran with the [Fortran Package Manager](https://github.com/fortran-lang/fpm). For example, to build:
22+
23+
```
24+
fpm build --profile release
25+
```
26+
27+
By default, the library is built with double precision (`real64`) real values. Explicitly specifying the real kind can be done using the following processor flags:
28+
29+
Preprocessor flag | Kind | Number of bytes
30+
----------------- | ----- | ---------------
31+
`REAL32` | `real(kind=real32)` | 4
32+
`REAL64` | `real(kind=real64)` | 8
33+
`REAL128` | `real(kind=real128)` | 16
34+
35+
For example, to build a single precision version of the library, use:
36+
37+
```
38+
fpm build --profile release --flag "-DREAL32"
39+
```
40+
41+
To run the unit tests:
42+
43+
```
44+
fpm test
45+
```
46+
47+
To use `pyplot-fortran` within your fpm project, add the following to your `fpm.toml` file:
48+
```toml
49+
[dependencies]
50+
pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git" }
51+
```
52+
53+
or, to use a specific version:
54+
```toml
55+
[dependencies]
56+
pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git", tag = "3.1.0" }
57+
```
58+
59+
To generate the documentation using [ford](https://github.com/Fortran-FOSS-Programmers/ford), run: ```ford pyplot-fortran.md```
1860

1961
### Supported plot types
2062

@@ -30,7 +72,7 @@ The module requires a modern Fortran compiler (it uses various Fortran 2003/2008
3072

3173
The following example generates a plot of the sine function:
3274

33-
```Fortran
75+
```fortran
3476
program test
3577
3678
use,intrinsic :: iso_fortran_env, only: wp => real64
@@ -57,7 +99,7 @@ The following example generates a plot of the sine function:
5799

58100
### Documentation
59101

60-
* The API documentation for the current ```master``` branch can be found [here](https://jacobwilliams.github.io/pyplot-fortran/). This is generated by processing the source files with [FORD](https://github.com/Fortran-FOSS-Programmers/ford). Note that the build script will also generate these files automatically in the ```doc``` folder, assuming you have FORD installed.
102+
* The API documentation for the current ```master``` branch can be found [here](https://jacobwilliams.github.io/pyplot-fortran/). This is generated by processing the source files with [FORD](https://github.com/Fortran-FOSS-Programmers/ford).
61103

62104
### See also
63105

build.sh

-37
This file was deleted.

pyplot.fobis

-144
This file was deleted.

src/pyplot_module.f90 src/pyplot_module.F90

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,39 @@
88
!
99
!# See also
1010
! * Inspired by: [EasyPlot](https://pypi.python.org/pypi/EasyPlot)
11+
!
12+
!@note The default real kind (`wp`) can be
13+
! changed using optional preprocessor flags.
14+
! This library was built with real kind:
15+
#ifdef REAL32
16+
! `real(kind=real32)` [4 bytes]
17+
#elif REAL64
18+
! `real(kind=real64)` [8 bytes]
19+
#elif REAL128
20+
! `real(kind=real128)` [16 bytes]
21+
#else
22+
! `real(kind=real64)` [8 bytes]
23+
#endif
1124

1225
module pyplot_module
1326

14-
use, intrinsic :: iso_fortran_env, only : real64, error_unit
27+
use, intrinsic :: iso_fortran_env
1528

1629
implicit none
1730

1831
private
1932

20-
integer, parameter, private :: wp = real64 !! Default real kind [8 bytes].
33+
#ifdef REAL32
34+
integer,parameter,public :: pyplot_wp = real32 !! real kind used by this module [4 bytes]
35+
#elif REAL64
36+
integer,parameter,public :: pyplot_wp = real64 !! real kind used by this module [8 bytes]
37+
#elif REAL128
38+
integer,parameter,public :: pyplot_wp = real128 !! real kind used by this module [16 bytes]
39+
#else
40+
integer,parameter,public :: pyplot_wp = real64 !! real kind used by this module [8 bytes]
41+
#endif
42+
43+
integer,parameter :: wp = pyplot_wp !! local copy of `pyplot_wp` with a shorter name
2144

2245
character(len=*), parameter :: tmp_file = 'pyplot_module_temp_1234567890.py' !! Default name of the temporary file
2346
!! (this can also be user-specified).

tests/test.f90

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
program test
99

10-
use, intrinsic :: iso_fortran_env, only : wp => real64
11-
use pyplot_module, only : pyplot
10+
use pyplot_module, only : pyplot, wp => pyplot_wp
1211

1312
implicit none
1413

0 commit comments

Comments
 (0)