@@ -100,25 +100,26 @@ of pointers. See the json_example.f90 file for more examples.
100
100
101
101
``` fortran
102
102
program example2
103
+
104
+ use,intrinsic :: iso_fortran_env, only: wp => real64
103
105
104
106
use json_module
105
107
106
- type(json_value),pointer :: p, inp
108
+ type(json_value),pointer :: p, inp
107
109
logical :: found
108
- integer :: iunit
109
110
110
111
! initialize the module
111
112
call json_initialize()
112
113
113
114
! initialize the structure:
114
115
call json_value_create(p)
115
- call to_object(p,'test2.json' )
116
+ call to_object(p)
116
117
117
118
! add an "inputs" object to the structure:
118
119
call json_value_create(inp)
119
120
call to_object(inp,'inputs')
120
121
call json_value_add(p, inp) !add it to the root
121
-
122
+
122
123
! add some data to inputs:
123
124
call json_value_add(inp, 't0', 0.1_wp)
124
125
call json_value_add(inp, 'tf', 1.1_wp)
@@ -129,18 +130,45 @@ of pointers. See the json_example.f90 file for more examples.
129
130
call json_value_add(inp, 'logical_scalar', .true.)
130
131
call json_value_add(inp, 'logical_vector', [.true., .false., .true.])
131
132
nullify(inp) !don't need this anymore
132
-
133
+
133
134
! write the file:
134
- open(newunit=iunit, file='test2.json', status='REPLACE')
135
- call json_print(p,iunit)
136
- close(iunit)
135
+ call json_print(p,'test2.json')
137
136
138
137
!cleanup:
139
138
call json_destroy(p)
140
-
139
+
141
140
end program example2
142
141
```
143
142
143
+ The code above produces the file:
144
+
145
+ ``` Python
146
+ {
147
+ " inputs" : {
148
+ " t0" : 0.1000000000000000E+000 ,
149
+ " tf" : 0.1100000000000000E+001 ,
150
+ " x0" : 0.9999000000000000E+004 ,
151
+ " integer_scalar" : 787 ,
152
+ " integer_array" : [
153
+ 2 ,
154
+ 4 ,
155
+ 99
156
+ ],
157
+ " names" : [
158
+ " aaa" ,
159
+ " bbb" ,
160
+ " ccc"
161
+ ],
162
+ " logical_scalar" : true,
163
+ " logical_vector" : [
164
+ true,
165
+ false,
166
+ true
167
+ ]
168
+ }
169
+ }
170
+ ```
171
+
144
172
Documentation
145
173
--------------
146
174
0 commit comments