Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json_kinds.F90 5.6 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. !*****************************************************************************************
  2. !> author: Jacob Williams
  3. ! license: BSD
  4. !
  5. ! JSON-Fortran kind definitions.
  6. !
  7. !### License
  8. ! * JSON-Fortran is released under a BSD-style license.
  9. ! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
  10. ! file for details.
  11. !
  12. !@note ```-DUSE_UCS4``` is an optional preprocessor flag.
  13. ! When present, Unicode support is enabled. Note that this
  14. ! is currently only supported with the gfortran compiler.
  15. ! Example: ```gfortran -DUSE_UCS4 ... ```
  16. #ifdef USE_UCS4
  17. # pragma push_macro("USE_UCS4")
  18. # undef USE_UCS4
  19. ! The documentation given here assumes ```USE_UCS4``` **is** defined.
  20. # pragma pop_macro("USE_UCS4")
  21. #else
  22. ! The documentation given here assumes ```USE_UCS4``` **is not** defined.
  23. #endif
  24. !
  25. !@warning ```CK``` and ```CDK``` are the JSON-Fortran character kind and JSON-Fortran default
  26. ! character kind respectively. Client code **MUST** ensure characters of ```kind=CK```
  27. ! are used for all character variables and strings passed to the JSON-Fortran
  28. ! library *EXCEPT* for file names which must be of ```'DEFAULT'``` character kind,
  29. ! provided here as ```CDK```. In particular, any variable that is a: json path, string
  30. ! value or object name passed to the JSON-Fortran library **MUST** be of type ```CK```.
  31. !
  32. !@note Most string literal constants of default kind are fine to pass as arguments to
  33. ! JSON-Fortran procedures since they have been overloaded to accept ```intent(in)```
  34. ! character arguments of the default (```CDK```) kind. If you find a procedure which does
  35. ! not accept an ```intent(in)``` literal string argument of default kind, please
  36. ! [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. ! .
  62. !
  63. !@note In addition to the real kind specified by `RK`, interfaces for
  64. ! the real kinds with less precision are also provided in the library,
  65. ! but all are converted to `real(RK)` variables internally.
  66. module json_kinds
  67. use,intrinsic :: iso_fortran_env
  68. implicit none
  69. private
  70. ! used for the reals with less precision
  71. ! than the default precision:
  72. #ifndef REAL32
  73. public :: real32
  74. #endif
  75. #ifdef REAL128
  76. public :: real64
  77. #endif
  78. #ifdef REAL32
  79. integer,parameter,public :: RK = real32 !! Default real kind [4 bytes]
  80. #elif REAL64
  81. integer,parameter,public :: RK = real64 !! Default real kind [8 bytes]
  82. #elif REAL128
  83. integer,parameter,public :: RK = real128 !! Default real kind [16 bytes]
  84. #else
  85. integer,parameter,public :: RK = real64 !! Default real kind if not specified [8 bytes]
  86. #endif
  87. #ifdef INT8
  88. integer,parameter,public :: IK = int8 !! Default integer kind [1 byte]
  89. #elif INT16
  90. integer,parameter,public :: IK = int16 !! Default integer kind [2 bytes]
  91. #elif INT32
  92. integer,parameter,public :: IK = int32 !! Default integer kind [4 bytes]
  93. #elif INT64
  94. integer,parameter,public :: IK = int64 !! Default integer kind [8 bytes]
  95. #else
  96. integer,parameter,public :: IK = int32 !! Default integer kind if not specified [4 bytes]
  97. #endif
  98. !*********************************************************
  99. !>
  100. ! Processor dependent 'DEFAULT' character kind.
  101. ! This is 1 byte for the Intel and Gfortran compilers.
  102. integer,parameter,public :: CDK = selected_char_kind('DEFAULT')
  103. !*********************************************************
  104. !*********************************************************
  105. !>
  106. ! Default logical kind.
  107. ! This is 4 bytes for the Intel and Gfortran compilers
  108. ! (and perhaps others).
  109. ! The declaration ensures a valid kind
  110. ! if the compiler doesn't have a logical_kinds(3).
  111. integer,parameter,public :: LK = logical_kinds(min(3,size(logical_kinds)))
  112. !*********************************************************
  113. !*********************************************************
  114. !>
  115. ! String kind preprocessor macro.
  116. #if defined __GFORTRAN__ && defined USE_UCS4
  117. ! gfortran compiler AND UCS4 support requested:
  118. character(kind=CDK,len=*),parameter :: json_fortran_string_kind = 'ISO_10646'
  119. #else
  120. ! this is the string kind to use unless compiling with GFortran AND
  121. ! UCS4/ISO 10646 support is requested
  122. character(kind=CDK,len=*),parameter :: json_fortran_string_kind = 'DEFAULT'
  123. #endif
  124. !*********************************************************
  125. !*********************************************************
  126. !>
  127. ! Default character kind used by JSON-Fortran.
  128. ! If ISO 10646 (UCS4) support is available, use that,
  129. ! otherwise, gracefully fall back on 'DEFAULT' characters.
  130. ! Currently only gfortran >= 4.9.2 will correctly support
  131. ! UCS4 which is stored in 4 bytes.
  132. ! (and perhaps others).
  133. integer,parameter,public :: CK = selected_char_kind(json_fortran_string_kind)
  134. !*********************************************************
  135. end module json_kinds
  136. !*****************************************************************************************