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