46 use json_module,
only : json_file, json_value, json_core
75 module procedure json_get_or_lookup_real, json_get_or_lookup_double, &
76 json_get_or_lookup_real_array, json_get_or_lookup_double_array, &
77 json_get_or_lookup_integer, json_get_or_lookup_integer_array
81 module procedure json_get_or_lookup_or_default_real, &
82 json_get_or_lookup_or_default_double, &
83 json_get_or_lookup_or_default_integer
91 module subroutine json_get_or_lookup_real(json, name, val)
92 type(json_file),
intent(inout) :: json
93 character(len=*),
intent(in) :: name
94 real(kind=
sp),
intent(out) :: val
95 end subroutine json_get_or_lookup_real
97 module subroutine json_get_or_lookup_double(json, name, val)
98 type(json_file),
intent(inout) :: json
99 character(len=*),
intent(in) :: name
100 real(kind=
dp),
intent(out) :: val
101 end subroutine json_get_or_lookup_double
103 module subroutine json_get_or_lookup_integer(json, name, val)
104 type(json_file),
intent(inout) :: json
105 character(len=*),
intent(in) :: name
106 integer,
intent(out) :: val
107 end subroutine json_get_or_lookup_integer
109 module subroutine json_get_or_lookup_or_default_real(json, &
111 type(json_file),
intent(inout) :: json
112 character(len=*),
intent(in) :: name
113 real(kind=
sp),
intent(out) :: val
114 real(kind=
sp),
intent(in) :: default
115 end subroutine json_get_or_lookup_or_default_real
117 module subroutine json_get_or_lookup_or_default_double(json, &
119 type(json_file),
intent(inout) :: json
120 character(len=*),
intent(in) :: name
121 real(kind=
dp),
intent(out) :: val
122 real(kind=
dp),
intent(in) :: default
123 end subroutine json_get_or_lookup_or_default_double
125 module subroutine json_get_or_lookup_or_default_integer(json,&
127 type(json_file),
intent(inout) :: json
128 character(len=*),
intent(in) :: name
129 integer,
intent(out) :: val
130 integer,
intent(in) :: default
131 end subroutine json_get_or_lookup_or_default_integer
133 module subroutine json_get_or_lookup_real_array(json, name, val)
134 type(json_file),
intent(inout) :: json
135 character(len=*),
intent(in) :: name
136 real(kind=
sp),
allocatable,
intent(inout) :: val(:)
137 end subroutine json_get_or_lookup_real_array
139 module subroutine json_get_or_lookup_double_array(json, name, val)
140 type(json_file),
intent(inout) :: json
141 character(len=*),
intent(in) :: name
142 real(kind=
dp),
allocatable,
intent(inout) :: val(:)
143 end subroutine json_get_or_lookup_double_array
145 module subroutine json_get_or_lookup_integer_array(json, name, val)
146 type(json_file),
intent(inout) :: json
147 character(len=*),
intent(in) :: name
148 integer,
allocatable,
intent(inout) :: val(:)
149 end subroutine json_get_or_lookup_integer_array
158 subroutine json_get_real(json, name, value)
159 type(json_file),
intent(inout) :: json
160 character(len=*),
intent(in) :: name
161 real(kind=
sp),
intent(out) ::
value
165 call json%info(name, found = found, var_type = var_type)
166 if (.not. found)
then
167 call neko_error(
"Parameter " // name //
" missing from the case file")
168 else if (var_type .ne. 6)
then
169 call neko_error(
"Parameter " // name //
" is not a real")
172 call json%get(name,
value)
173 end subroutine json_get_real
179 subroutine json_get_double(json, name, value)
180 type(json_file),
intent(inout) :: json
181 character(len=*),
intent(in) :: name
182 real(kind=
dp),
intent(out) ::
value
186 call json%info(name, found = found, var_type = var_type)
187 if (.not. found)
then
188 call neko_error(
"Parameter " // name //
" missing from the case file")
189 else if (var_type .ne. 6)
then
190 call neko_error(
"Parameter " // name //
" is not a real")
193 call json%get(name,
value)
194 end subroutine json_get_double
200 subroutine json_get_integer(json, name, value)
201 type(json_file),
intent(inout) :: json
202 character(len=*),
intent(in) :: name
203 integer,
intent(out) :: value
207 call json%info(name, found = found, var_type = var_type)
208 if (.not. found)
then
209 call neko_error(
"Parameter " // name //
" missing from the case file")
210 else if (var_type .ne. 5)
then
211 call neko_error(
"Parameter " // name //
" is not an integer")
214 call json%get(name,
value)
215 end subroutine json_get_integer
221 subroutine json_get_logical(json, name, value)
222 type(json_file),
intent(inout) :: json
223 character(len=*),
intent(in) :: name
224 logical,
intent(out) :: value
228 call json%info(name, found = found, var_type = var_type)
229 if (.not. found)
then
230 call neko_error(
"Parameter " // name //
" missing from the case file")
231 else if (var_type .ne. 4)
then
232 call neko_error(
"Parameter " // name //
" is not a logical")
235 call json%get(name,
value)
236 end subroutine json_get_logical
242 subroutine json_get_string(json, name, value)
243 type(json_file),
intent(inout) :: json
244 character(len=*),
intent(in) :: name
245 character(len=:),
allocatable,
intent(out) :: value
249 call json%info(name, found = found, var_type = var_type)
250 if (.not. found)
then
251 call neko_error(
"Parameter " // name //
" missing from the case file")
252 else if (var_type .ne. 7)
then
253 call neko_error(
"Parameter " // name //
" is not a string")
256 call json%get(name,
value)
257 end subroutine json_get_string
263 subroutine json_get_real_array(json, name, value)
264 type(json_file),
intent(inout) :: json
265 character(len=*),
intent(in) :: name
266 real(kind=
sp),
allocatable,
intent(out) :: value(:)
270 call json%info(name, found = found, var_type = var_type)
271 if (.not. found)
then
272 call neko_error(
"Parameter " // name //
" missing from the case file")
273 else if (var_type .ne. 3)
then
274 call neko_error(
"Parameter " // name //
" is not an array")
277 call json%get(name,
value)
278 end subroutine json_get_real_array
284 subroutine json_get_double_array(json, name, value)
285 type(json_file),
intent(inout) :: json
286 character(len=*),
intent(in) :: name
287 real(kind=
dp),
allocatable,
intent(out) :: value(:)
291 call json%info(name, found = found, var_type = var_type)
292 if (.not. found)
then
293 call neko_error(
"Parameter " // name //
" missing from the case file")
294 else if (var_type .ne. 3)
then
295 call neko_error(
"Parameter " // name //
" is not an array")
298 call json%get(name,
value)
299 end subroutine json_get_double_array
305 subroutine json_get_integer_array(json, name, value)
306 type(json_file),
intent(inout) :: json
307 character(len=*),
intent(in) :: name
308 integer,
allocatable,
intent(out) ::
value(:)
310 real(kind=
rp),
allocatable :: test_real(:)
313 if (.not. json%valid_path(name))
then
314 call neko_error(
"Parameter " // name //
" missing from the case file")
317 call json%get(name,
value)
318 end subroutine json_get_integer_array
324 subroutine json_get_logical_array(json, name, value)
325 type(json_file),
intent(inout) :: json
326 character(len=*),
intent(in) :: name
327 logical,
allocatable,
intent(out) ::
value(:)
331 call json%info(name, found = found, var_type = var_type)
332 if (.not. found)
then
333 call neko_error(
"Parameter " // name //
" missing from the case file")
334 else if (var_type .ne. 3)
then
335 call neko_error(
"Parameter " // name //
" is not a array")
338 call json%get(name,
value)
339 end subroutine json_get_logical_array
346 subroutine json_get_string_array(json, name, value, filler)
347 type(json_file),
intent(inout) :: json
348 character(len=*),
intent(in) :: name
349 character(len=*),
allocatable,
intent(out) ::
value(:)
350 character(len=*),
optional,
intent(in) :: filler
352 type(json_value),
pointer :: json_val, val_ptr
353 type(json_core) :: core
354 character(len=:),
allocatable :: string_value
355 integer :: i, n_children
358 call json%info(name, found = found, var_type = var_type, &
359 n_children = n_children)
360 if (.not. found)
then
361 call neko_error(
"Parameter " // name //
" missing from the case file")
362 else if (var_type .ne. 3)
then
363 call neko_error(
"Parameter " // name //
" is not an array")
366 if (.not.
allocated(
value))
then
367 allocate(value(n_children))
368 else if (len(
value) .lt. n_children)
then
370 allocate(value(n_children))
373 call json%get(name, json_val, found)
374 call json%get_core(core)
377 call core%get_child(json_val, i, val_ptr, found)
378 call core%get(val_ptr, string_value)
380 if (len(string_value) .gt. 0)
then
381 value(i) = string_value
382 else if (
present(filler))
then
387 end subroutine json_get_string_array
390 subroutine json_get_subdict(json, key, output)
391 type(json_file),
intent(inout) :: json
392 character(len=*),
intent(in) :: key
393 type(json_file),
intent(inout) :: output
395 type(json_value),
pointer :: ptr
396 type(json_core) :: core
398 character(len=:),
allocatable :: buffer
400 call json%get_core(core)
401 call json%get(key, ptr, found)
403 if (.not. found)
then
405 trim(key) //
" missing from the case file")
408 call core%print_to_string(ptr,
buffer)
409 call output%initialize(strict_type_checking = .true.)
412 end subroutine json_get_subdict
419 subroutine json_get_or_default_real(json, name, value, default)
420 type(json_file),
intent(inout) :: json
421 character(len=*),
intent(in) :: name
422 real(kind=
sp),
intent(out) ::
value
423 real(kind=
sp),
intent(in) :: default
427 call json%info(name, found = found, var_type = var_type)
429 if (found .and. (var_type .ne. 6))
then
430 call neko_error(
"Parameter " // name //
" present, but is not a real")
433 call json%get(name,
value, found)
435 if ((.not. found) .and. (.not. json_no_defaults))
then
437 call json%add(name,
value)
438 else if (.not. found)
then
439 call neko_error(
"Parameter " // name //
" missing from the case file")
441 end subroutine json_get_or_default_real
449 subroutine json_get_or_default_double(json, name, value, default)
450 type(json_file),
intent(inout) :: json
451 character(len=*),
intent(in) :: name
452 real(kind=
dp),
intent(out) ::
value
453 real(kind=
dp),
intent(in) :: default
457 call json%info(name, found = found, var_type = var_type)
459 if (found .and. (var_type .ne. 6))
then
460 call neko_error(
"Parameter " // name //
" present, but is not a real")
463 call json%get(name,
value, found)
465 if ((.not. found) .and. (.not. json_no_defaults))
then
467 call json%add(name,
value)
468 else if (.not. found)
then
469 call neko_error(
"Parameter " // name //
" missing from the case file")
471 end subroutine json_get_or_default_double
478 subroutine json_get_or_default_integer(json, name, value, default)
479 type(json_file),
intent(inout) :: json
480 character(len=*),
intent(in) :: name
481 integer,
intent(out) :: value
482 integer,
intent(in) :: default
486 call json%info(name, found = found, var_type = var_type)
488 if (found .and. (var_type .ne. 5))
then
489 call neko_error(
"Parameter " // name //
" present, but " // &
493 call json%get(name,
value, found)
495 if ((.not. found) .and. (.not. json_no_defaults))
then
497 call json%add(name,
value)
498 else if (.not. found)
then
499 call neko_error(
"Parameter " // name //
" missing from the case file")
501 end subroutine json_get_or_default_integer
508 subroutine json_get_or_default_logical(json, name, value, default)
509 type(json_file),
intent(inout) :: json
510 character(len=*),
intent(in) :: name
511 logical,
intent(out) :: value
512 logical,
intent(in) :: default
516 call json%info(name, found = found, var_type = var_type)
518 if ((found) .and. (var_type .ne. 4))
then
519 call neko_error(
"Parameter " // name //
" present, but is not a logical")
522 call json%get(name,
value, found)
524 if ((.not. found) .and. (.not. json_no_defaults))
then
526 call json%add(name,
value)
527 else if (.not. found)
then
528 call neko_error(
"Parameter " // name //
" missing from the case file")
530 end subroutine json_get_or_default_logical
537 subroutine json_get_or_default_string(json, name, value, default)
538 type(json_file),
intent(inout) :: json
539 character(len=*),
intent(in) :: name
540 character(len=:),
allocatable,
intent(out) :: value
541 character(len=*),
intent(in) :: default
545 call json%info(name, found = found, var_type = var_type)
547 if (found .and. (var_type .ne. 7))
then
549 " present, but is not a string")
552 call json%get(name,
value, found)
554 if ((.not. found) .and. (.not. json_no_defaults))
then
556 call json%add(name,
value)
557 else if (.not. found)
then
558 call neko_error(
"Parameter " // name //
" missing from the case file")
560 end subroutine json_get_or_default_string
567 subroutine json_extract_item_from_array(core, array, i, item)
568 type(json_core),
intent(inout) :: core
569 type(json_value),
pointer,
intent(in) :: array
570 integer,
intent(in) :: i
571 type(json_file),
intent(inout) :: item
572 type(json_value),
pointer :: ptr
574 character(len=:),
allocatable :: buffer
576 call core%get_child(array, i, ptr, found)
577 call core%print_to_string(ptr,
buffer)
578 call item%initialize(strict_type_checking = .true.)
579 call item%load_from_string(
buffer)
581 end subroutine json_extract_item_from_array
588 subroutine json_extract_item_from_name(json, name, i, item)
589 type(json_file),
intent(inout) :: json
590 character(len=*),
intent(in) :: name
591 integer,
intent(in) :: i
592 type(json_file),
intent(out) :: item
594 type(json_core) :: core
595 type(json_value),
pointer :: array
596 type(json_value),
pointer :: ptr
598 character(len=:),
allocatable :: buffer
600 call json%get_core(core)
601 call json%get(name, array, found)
603 if (.not. found)
then
604 call neko_error(
"Parameter " // name //
" missing from the case file")
607 call core%get_child(array, i, ptr, found)
608 call core%print_to_string(ptr,
buffer)
609 call item%initialize(strict_type_checking = .true.)
610 call item%load_from_string(
buffer)
612 end subroutine json_extract_item_from_name
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Generic buffer that is extended with buffers of varying rank.
Utilities for retrieving parameters from the case files.
subroutine json_extract_item_from_name(json, name, i, item)
Extract ith item from a JSON array as a separate JSON object.
subroutine json_get_logical(json, name, value)
Retrieves a logical parameter by name or throws an error.
subroutine json_get_or_default_string(json, name, value, default)
Retrieves a string parameter by name or assigns a provided default value. In the latter case also add...
subroutine json_get_real_array(json, name, value)
Retrieves a real array parameter by name or throws an error.
subroutine json_get_subdict(json, key, output)
Extract a sub-object from a json object.
subroutine json_extract_item_from_array(core, array, i, item)
Extract ith item from a JSON array as a separate JSON object.
subroutine json_get_string(json, name, value)
Retrieves a string parameter by name or throws an error.
subroutine json_get_or_default_real(json, name, value, default)
Retrieves a real parameter by name or assigns a provided default value. In the latter case also adds ...
subroutine json_get_or_default_double(json, name, value, default)
Retrieves a double precision parameter by name or assigns a provided default value....
subroutine json_get_or_default_logical(json, name, value, default)
Retrieves a logical parameter by name or assigns a provided default value. In the latter case also ad...
subroutine json_get_double_array(json, name, value)
Retrieves a double precision array parameter by name or throws an error.
subroutine json_get_or_default_integer(json, name, value, default)
Retrieves an integer parameter by name or assigns a provided default value. In the latter case also a...
subroutine json_get_double(json, name, value)
Retrieves a double precision real parameter by name or throws an error.
subroutine json_get_string_array(json, name, value, filler)
Retrieves a string array parameter by name or throws an error.
subroutine json_get_logical_array(json, name, value)
Retrieves a logical array parameter by name or throws an error.
subroutine json_get_real(json, name, value)
Retrieves a real parameter by name or throws an error.
logical, public json_no_defaults
If true, the json_get_or_default routines will not add missing parameters.
subroutine json_get_integer(json, name, value)
Retrieves an integer parameter by name or throws an error.
subroutine json_get_integer_array(json, name, value)
Retrieves a integer array parameter by name or throws an error.
integer, parameter, public dp
integer, parameter, public sp
integer, parameter, public rp
Global precision used in computations.