EIRAM
atomic and molecular data in form of polynomial fits
json.f90
Go to the documentation of this file.
1 
6 
7 ! Copyright (c) 2016 Forschungszentrum Juelich GmbH
8 ! Markus Brenneis, Vladislav Kotov
9 !
10 ! This file is part of EIRAM.
11 !
12 ! EIRAM is free software: you can redistribute it and/or modify
13 ! it under the terms of the GNU General Public License as published by
14 ! the Free Software Foundation, either version 3 of the License, or
15 ! (at your option) any later version.
16 !
17 ! EIRAM is distributed in the hope that it will be useful,
18 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ! GNU General Public License for more details.
21 !
22 ! You should have received a copy of the GNU General Public License
23 ! along with EIRAM. If not, see <http://www.gnu.org/licenses/>.
24 !
25 
26  module json
27 
28  implicit none
29 
31 
32  contains
33 
35  function eiram_json_getarrayasjson(arr, length, itol)
36 
37  real(8), dimension(:), intent(in) :: arr
39  integer, intent(out) :: length
41  integer,intent(in) :: itol
42  character(size(arr)*(itol+9)+2) :: eiram_json_getArrayAsJson
43  integer :: c, i, lfld
44  character(16) :: frm
45 
46  eiram_json_getarrayasjson = " "
47  eiram_json_getarrayasjson(1:1) = "["
48  c = 2
49  lfld=itol+8
50  write(frm,'(A3,i2.2,A1,i2.2,A3)') '(Es',lfld,'.',itol,'E3)'
51  do i = 1, size(arr)
52  if(i > 1) then
53  eiram_json_getarrayasjson(c:c) = ","
54  c = c+1
55  end if
56  if(abs(arr(i)) < huge(1d0)) then
57  write(eiram_json_getarrayasjson(c:c+lfld),frm) arr(i)
58  else
59  write(eiram_json_getarrayasjson(c:c+lfld), '(A)') "null"
60  end if
61  c = c+lfld
62  end do
63  eiram_json_getarrayasjson(c:c) = "]"
64  length = len_trim(eiram_json_getarrayasjson)
65  end function eiram_json_getarrayasjson
66 
68  function eiram_json_jsonescape(str, length)
69 
70  character(*), intent(in) :: str
72  integer, intent(out) :: length
73  character(len_trim(str)*2) :: eiram_json_jsonEscape
74  integer :: s
75  length = 1
76  foreachchar: do s = 1, len_trim(str)
77  if(str(s:s) == '"') then
78  eiram_json_jsonescape(length:length+1) = '\'
79  length = length + 2
80  else if(str(s:s) == ') then
81  eiram_json_jsonescape(length:length+1) = '\\'
82  length = length + 2
83  else
84  eiram_json_jsonescape(length:length) = str(s:s)
85  length = length + 1
86  end if
87  end do foreachchar
88  eiram_json_jsonescape(length:) = " "
89  length = length - 1
90  end function eiram_json_jsonescape
91 
93  subroutine eiram_json_writejsonstringproperty(name, value, jsonString, ind)
94 
95  character(*), intent(in) :: name
97  character(*), intent(in) :: value
99  character(*), intent(inout) :: jsonString
102  integer, intent(inout) :: ind
103  integer :: length
104  intrinsic trim,len_trim,max
105  jsonstring(ind:) = ',"'//trim(eiram_json_jsonescape(trim(name), length))//'":"'
106  ind = ind+length+5
107  jsonstring(ind:) = trim(eiram_json_jsonescape(trim(value), length))
108  ind = ind+length
109  jsonstring(ind:ind) = '"'
110  ind = ind+1
112 
113  end module json
character(len_trim(str)*2) function, public eiram_json_jsonescape(str, length)
Return the input string where »\« and »"« are escaped with backslashes.
Definition: json.f90:69
Definition: json.f90:26
subroutine, public eiram_json_writejsonstringproperty(name, value, jsonString, ind)
Write a pair of the JSON property-(string-)values into a string, including leading comma...
Definition: json.f90:94
character(size(arr)*(itol+9)+2) function, public eiram_json_getarrayasjson(arr, length, itol)
Return a JSON array string (ie. "[…]") with the elements of the given array arr. ...
Definition: json.f90:36