Skip to content

Commit 799936b

Browse files
Merge pull request #239 from jacobwilliams/specify-kinds
added support in the code for specifying the real and integer kinds
2 parents efac226 + fd6e1e0 commit 799936b

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

build.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# build.sh [--compiler {intel|gnu|<other>}] [--cflags '<custom compiler flags here>']
1212
# [--coverage [{yes|no}]] [--profile [{yes|no}]] [--skip-tests [{yes|no}]]
1313
# [--skip-documentation [{yes|no}]] [--enable-unicode [{yes|no}]] [--help]
14-
# [--clean]
14+
# [--clean] [--real-kind [{REAL32\REAL64\REAL128}]]
15+
# [--int-kind [{INT8\INT16\INT32\INT64}]]
1516
#
1617
# By default, if invoked without any flags, this build script will build the
1718
# JSON-Fortran library using gfortran,
@@ -22,6 +23,8 @@
2223
# with :
2324
# unit tests enabled
2425
# documentation (if FORD is installed)
26+
# real(REAL64) kinds
27+
# integer(INT32) kinds
2528
#
2629
# More recent (right-most) flags will override preceding flags
2730
# flags:
@@ -146,6 +149,18 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
146149
# no good way to check that the user didn't do something questionable
147150
shift
148151
;;
152+
--real-kind)
153+
REAL_KIND="-D$2"
154+
# warning: not checking for valid input
155+
# should be one of: REAL32, REAL64 [default], REAL128
156+
shift
157+
;;
158+
--int-kind)
159+
INT_KIND="-D$2"
160+
# warning: not checking for valid input
161+
# should be one of: INT8, INT16, INT32 [default], INT64
162+
shift
163+
;;
149164
--enable-unicode)
150165
case $2 in
151166
yes|Yes|YES)
@@ -178,7 +193,7 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
178193
;;
179194
esac
180195
;;
181-
--profile) #nable profiling
196+
--profile) #enable profiling
182197
case $2 in
183198
yes|Yes|YES)
184199
CODE_PROFILE="yes"
@@ -272,7 +287,7 @@ fi
272287
echo ""
273288
echo "Building library..."
274289

275-
FoBiS.py build -ch -compiler ${FCOMPILER} "${CUSTOM[@]}" -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
290+
FoBiS.py build -ch -compiler ${FCOMPILER} "${CUSTOM[@]}" -cflags "${FCOMPILERFLAGS} ${DEFINES} ${REAL_KIND} ${INT_KIND}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
276291

277292
#build the unit tests (uses the above library):
278293
if [[ $JF_SKIP_TESTS != [yY]* ]]; then

src/json_kinds.F90

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
!
55
! JSON-Fortran kind definitions.
66
!
7-
!## License
7+
!### License
88
! * JSON-Fortran is released under a BSD-style license.
99
! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
1010
! file for details.
@@ -34,24 +34,66 @@
3434
! character arguments of the default (```CDK```) kind. If you find a procedure which does
3535
! not accept an ```intent(in)``` literal string argument of default kind, please
3636
! [file an issue](https://github.com/jacobwilliams/json-fortran/issues/new) on GitHub.
37+
!
38+
!@note The default real kind (`RK`) and the default integer kind (`IK`) can be
39+
! changed using optional preprocessor flags. This library was built with kinds:
40+
#ifdef REAL32
41+
! real(kind=real32) [4 bytes]
42+
#elif REAL64
43+
! real(kind=real64) [8 bytes]
44+
#elif REAL128
45+
! real(kind=real128) [16 bytes]
46+
#else
47+
! real(kind=real64) [8 bytes]
48+
#endif
49+
! and
50+
#ifdef INT8
51+
! integer(kind=int8) [1 byte]
52+
#elif INT16
53+
! integer(kind=int16) [2 bytes]
54+
#elif INT32
55+
! integer(kind=int32) [4 bytes]
56+
#elif INT64
57+
! integer(kind=int64) [8 bytes]
58+
#else
59+
! integer(kind=int32) [4 bytes]
60+
#endif
61+
! .
3762

3863
module json_kinds
3964

40-
use,intrinsic :: iso_fortran_env, only: real64,int32,logical_kinds
65+
use,intrinsic :: iso_fortran_env
4166

4267
implicit none
4368

4469
private
4570

46-
integer,parameter,public :: RK = real64 !! Default real kind [8 bytes]
71+
#ifdef REAL32
72+
integer,parameter,public :: RK = real32 !! Default real kind [4 bytes]
73+
#elif REAL64
74+
integer,parameter,public :: RK = real64 !! Default real kind [8 bytes]
75+
#elif REAL128
76+
integer,parameter,public :: RK = real128 !! Default real kind [16 bytes]
77+
#else
78+
integer,parameter,public :: RK = real64 !! Default real kind if not specified [8 bytes]
79+
#endif
4780

48-
integer,parameter,public :: IK = int32 !! Default integer kind [4 bytes].
81+
#ifdef INT8
82+
integer,parameter,public :: IK = int8 !! Default integer kind [1 byte]
83+
#elif INT16
84+
integer,parameter,public :: IK = int16 !! Default integer kind [2 bytes]
85+
#elif INT32
86+
integer,parameter,public :: IK = int32 !! Default integer kind [4 bytes]
87+
#elif INT64
88+
integer,parameter,public :: IK = int64 !! Default integer kind [8 bytes]
89+
#else
90+
integer,parameter,public :: IK = int32 !! Default integer kind if not specified [4 bytes]
91+
#endif
4992

5093
!*********************************************************
5194
!>
5295
! Processor dependendant 'DEFAULT' character kind.
5396
! This is 1 byte for the Intel and Gfortran compilers.
54-
5597
integer,parameter,public :: CDK = selected_char_kind('DEFAULT')
5698
!*********************************************************
5799

@@ -62,14 +104,12 @@ module json_kinds
62104
! (and perhaps others).
63105
! The declaration ensures a valid kind
64106
! if the compiler doesn't have a logical_kinds(3).
65-
!
66107
integer,parameter,public :: LK = logical_kinds(min(3,size(logical_kinds)))
67108
!*********************************************************
68109

69110
!*********************************************************
70111
!>
71112
! String kind preprocessor macro.
72-
!
73113
#if defined __GFORTRAN__ && defined USE_UCS4
74114
! gfortran compiler AND UCS4 support requested:
75115
character(kind=CDK,len=*),parameter :: json_fortran_string_kind = 'ISO_10646'

0 commit comments

Comments
 (0)