Skip to content

Commit dca3576

Browse files
committed
added support for specifying real kind via preprocessor flag
Fixes #33
1 parent f6b08a8 commit dca3576

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/pyplot_module.f90 renamed to src/pyplot_module.F90

Lines changed: 25 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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)