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.
 
 
 
 
 
 

145 regels
9.0 KiB

  1. !*****************************************************************************************
  2. !> author: Jacob Williams
  3. ! license: BSD
  4. !
  5. ! Other parameters used by JSON-Fortran.
  6. ! This is a low-level module not meant to be used by a JSON-Fortran user.
  7. !
  8. !### License
  9. ! * JSON-Fortran is released under a BSD-style license.
  10. ! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
  11. ! file for details.
  12. module json_parameters
  13. use json_kinds
  14. implicit none
  15. public
  16. character(kind=CDK,len=*),parameter :: json_ext = '.json' !! JSON file extension
  17. ! The types of JSON data.
  18. integer(IK),parameter :: json_unknown = 0 !! Unknown JSON data type
  19. !! (see [[json_file_variable_info]] and [[json_info]])
  20. integer(IK),parameter :: json_null = 1 !! Null JSON data type
  21. !! (see [[json_file_variable_info]] and [[json_info]])
  22. integer(IK),parameter :: json_object = 2 !! Object JSON data type
  23. !! (see [[json_file_variable_info]] and [[json_info]])
  24. integer(IK),parameter :: json_array = 3 !! Array JSON data type
  25. !! (see [[json_file_variable_info]] and [[json_info]])
  26. integer(IK),parameter :: json_logical = 4 !! Logical JSON data type (`logical(LK)`)
  27. !! (see [[json_file_variable_info]] and [[json_info]])
  28. integer(IK),parameter :: json_integer = 5 !! Integer JSON data type (`integer(IK)`)
  29. !! (see [[json_file_variable_info]] and [[json_info]]).
  30. integer(IK),parameter :: json_real = 6 !! Real number JSON data type (`real(RK)`)
  31. !! (see [[json_file_variable_info]] and [[json_info]])
  32. integer(IK),parameter :: json_string = 7 !! String JSON data type (`character(kind=CK)`)
  33. !! (see [[json_file_variable_info]] and [[json_info]])
  34. integer(IK),parameter :: json_double = json_real !! Equivalent to `json_real` for
  35. !! backward compatibility.
  36. !special JSON characters
  37. character(kind=CK,len=*),parameter :: space = CK_' ' !! space character
  38. character(kind=CK,len=*),parameter :: start_object = CK_'{' !! start of a JSON object
  39. character(kind=CK,len=*),parameter :: end_object = CK_'}' !! end of a JSON object
  40. character(kind=CK,len=*),parameter :: start_array = CK_'[' !! start of a JSON array
  41. character(kind=CK,len=*),parameter :: end_array = CK_']' !! end of a JSON array
  42. character(kind=CK,len=*),parameter :: delimiter = CK_',' !! delimiter for JSON
  43. character(kind=CK,len=*),parameter :: colon_char = CK_':' !! colon character for JSON
  44. character(kind=CK,len=*),parameter :: start_array_alt = CK_'(' !! alternate start of JSON array for
  45. !! [[json_get_by_path_default]]
  46. character(kind=CK,len=*),parameter :: end_array_alt = CK_')' !! alternate end of JSON array for
  47. !! [[json_get_by_path_default]]
  48. character(kind=CK,len=*),parameter :: root = achar(36, kind=CK) !! (`$`) root for [[json_get_by_path_default]]
  49. character(kind=CK,len=*),parameter :: this = CK_'@' !! 'this' for [[json_get_by_path_default]]
  50. character(kind=CK,len=*),parameter :: dot = CK_'.' !! path separator for [[json_get_by_path_default]]
  51. character(kind=CK,len=*),parameter :: tilde = CK_'~' !! RFC 6901 escape character
  52. character(kind=CK,len=*),parameter :: single_quote = CK_"'" !! for JSONPath bracket-notation
  53. character(kind=CK,len=*),parameter :: quotation_mark = CK_'"' !! JSON special character
  54. character(kind=CK,len=*),parameter :: bspace = achar(8, kind=CK) !! JSON special character
  55. character(kind=CK,len=*),parameter :: horizontal_tab = achar(9, kind=CK) !! JSON special character
  56. character(kind=CK,len=*),parameter :: newline = achar(10, kind=CK) !! JSON special character
  57. character(kind=CK,len=*),parameter :: formfeed = achar(12, kind=CK) !! JSON special character
  58. character(kind=CK,len=*),parameter :: carriage_return = achar(13, kind=CK) !! JSON special character
  59. character(kind=CK,len=*),parameter :: slash = achar(47, kind=CK) !! JSON special character
  60. character(kind=CK,len=*),parameter :: backslash = achar(92, kind=CK) !! JSON special character
  61. !> default real number format statement (for writing real values to strings and files).
  62. ! Note that this can be overridden by calling [[json_initialize]].
  63. #ifdef REAL32
  64. character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E17.8E3)'
  65. #elif REAL128
  66. character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E46.35E5)'
  67. #else
  68. character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E27.17E4)'
  69. #endif
  70. character(kind=CK,len=*),parameter :: star = CK_'*' !! for invalid numbers and
  71. !! list-directed real output
  72. #if defined __GFORTRAN__
  73. !not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
  74. character(kind=CK,len=26),protected :: upper = CK_'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
  75. character(kind=CK,len=26),protected :: lower = CK_'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
  76. #else
  77. character(kind=CK,len=*),parameter :: upper = CK_'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
  78. character(kind=CK,len=*),parameter :: lower = CK_'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
  79. #endif
  80. #if defined __GFORTRAN__
  81. !not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
  82. character(kind=CK,len=4),protected :: null_str = CK_'null' !! JSON Null variable string
  83. character(kind=CK,len=4),protected :: true_str = CK_'true' !! JSON logical True string
  84. character(kind=CK,len=5),protected :: false_str = CK_'false' !! JSON logical False string
  85. #else
  86. character(kind=CK,len=*),parameter :: null_str = CK_'null' !! JSON Null variable string
  87. character(kind=CK,len=*),parameter :: true_str = CK_'true' !! JSON logical True string
  88. character(kind=CK,len=*),parameter :: false_str = CK_'false' !! JSON logical False string
  89. #endif
  90. integer, private :: i_ !! just a counter for `control_chars` array
  91. character(kind=CK,len=*),dimension(32),parameter :: control_chars = &
  92. [(achar(i_,kind=CK),i_=1,31), achar(127,kind=CK)] !! Control characters, possibly in unicode
  93. !find out the precision of the floating point number system
  94. !and set safety factors
  95. integer(IK),parameter :: rp_safety_factor = 1_IK
  96. integer(IK),parameter :: rp_addl_safety = 2_IK
  97. integer(IK),parameter :: real_precision = rp_safety_factor*precision(1.0_RK) + &
  98. rp_addl_safety
  99. !Get the number of possible digits in the exponent when using decimal number system
  100. integer(IK),parameter :: maxexp = maxexponent(1.0_RK)
  101. integer(IK),parameter :: minexp = minexponent(1.0_RK)
  102. integer(IK),parameter :: real_exponent_digits = floor( 1_IK + log10( &
  103. real(max(maxexp,abs(maxexp)),&
  104. kind=RK) ) )
  105. integer(IK),parameter :: max_numeric_str_len = real_precision + real_exponent_digits + 6_IK
  106. !! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
  107. character(kind=CDK,len=*),parameter :: int_fmt = '(ss,I0)' !! minimum width format for integers
  108. integer(IK),parameter :: max_integer_str_len = 256_IK !! maximum string length of an integer.
  109. !! This is totally arbitrary (any way
  110. !! to get the compiler to tell us this?)
  111. integer(IK),parameter :: chunk_size = 256_IK !! for allocatable strings: allocate chunks of this size
  112. integer(IK),parameter :: unit2str = -1_IK !! unit number to cause stuff to be
  113. !! output to strings rather than files.
  114. !! See 9.5.6.12 in the F2003/08 standard
  115. character(kind=CK,len=*),parameter :: blank_chunk = repeat(space, chunk_size) !! a blank string
  116. integer(IK),parameter :: seq_chunk_size = 256_IK !! chunk size for reading sequential files
  117. integer(IK),parameter :: stream_chunk_size = 256_IK !! chunk size for reading stream files
  118. integer(IK),parameter :: print_str_chunk_size = 1000_IK !! chunk size for writing JSON to a string
  119. integer(IK),parameter :: pushed_char_size = 10_IK !! size for `pushed_char`
  120. !! array in [[json_core(type)]]
  121. end module json_parameters
  122. !*****************************************************************************************