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
265 subroutine json_get_real_array(json, name, value, expected_size)
266 type(json_file),
intent(inout) :: json
267 character(len=*),
intent(in) :: name
268 real(kind=
sp),
allocatable,
intent(out) :: value(:)
269 integer,
optional,
intent(in) :: expected_size
272 integer :: actual_size
274 call json%info(name, found = found, var_type = var_type, &
275 n_children = actual_size)
277 if (.not. found)
then
278 call neko_error(
"Parameter " // name //
" missing from the case file")
279 else if (var_type .ne. 3)
then
280 call neko_error(
"Parameter " // name //
" is not an array")
283 if (
present(expected_size))
then
284 call check_expected_size(name, actual_size, expected_size)
287 call json%get(name,
value)
288 end subroutine json_get_real_array
296 subroutine json_get_double_array(json, name, value, expected_size)
297 type(json_file),
intent(inout) :: json
298 character(len=*),
intent(in) :: name
299 real(kind=
dp),
allocatable,
intent(out) :: value(:)
300 integer,
optional,
intent(in) :: expected_size
303 integer :: actual_size
305 call json%info(name, found = found, var_type = var_type, &
306 n_children = actual_size)
308 if (.not. found)
then
309 call neko_error(
"Parameter " // name //
" missing from the case file")
310 else if (var_type .ne. 3)
then
311 call neko_error(
"Parameter " // name //
" is not an array")
314 if (
present(expected_size))
then
315 call check_expected_size(name, actual_size, expected_size)
318 call json%get(name,
value)
319 end subroutine json_get_double_array
327 subroutine json_get_integer_array(json, name, value, expected_size)
328 type(json_file),
intent(inout) :: json
329 character(len=*),
intent(in) :: name
330 integer,
allocatable,
intent(out) ::
value(:)
331 integer,
optional,
intent(in) :: expected_size
334 integer :: actual_size
336 call json%info(name, found = found, var_type = var_type, &
337 n_children = actual_size)
339 if (.not. found)
then
340 call neko_error(
"Parameter " // name //
" missing from the case file")
343 if (
present(expected_size))
then
344 call check_expected_size(name, actual_size, expected_size)
347 call json%get(name,
value)
348 end subroutine json_get_integer_array
356 subroutine json_get_logical_array(json, name, value, expected_size)
357 type(json_file),
intent(inout) :: json
358 character(len=*),
intent(in) :: name
359 logical,
allocatable,
intent(out) ::
value(:)
360 integer,
optional,
intent(in) :: expected_size
363 integer :: actual_size
365 call json%info(name, found = found, var_type = var_type, &
366 n_children = actual_size)
368 if (.not. found)
then
369 call neko_error(
"Parameter " // name //
" missing from the case file")
370 else if (var_type .ne. 3)
then
371 call neko_error(
"Parameter " // name //
" is not a array")
374 if (
present(expected_size))
then
375 call check_expected_size(name, actual_size, expected_size)
378 call json%get(name,
value)
379 end subroutine json_get_logical_array
386 subroutine json_get_string_array(json, name, value, filler)
387 type(json_file),
intent(inout) :: json
388 character(len=*),
intent(in) :: name
389 character(len=*),
allocatable,
intent(out) ::
value(:)
390 character(len=*),
optional,
intent(in) :: filler
392 type(json_value),
pointer :: json_val, val_ptr
393 type(json_core) :: core
394 character(len=:),
allocatable :: string_value
395 integer :: i, n_children
398 call json%info(name, found = found, var_type = var_type, &
399 n_children = n_children)
400 if (.not. found)
then
401 call neko_error(
"Parameter " // name //
" missing from the case file")
402 else if (var_type .ne. 3)
then
403 call neko_error(
"Parameter " // name //
" is not an array")
406 if (.not.
allocated(
value))
then
407 allocate(value(n_children))
408 else if (len(
value) .lt. n_children)
then
410 allocate(value(n_children))
413 call json%get(name, json_val, found)
414 call json%get_core(core)
417 call core%get_child(json_val, i, val_ptr, found)
418 call core%get(val_ptr, string_value)
420 if (len(string_value) .gt. 0)
then
421 value(i) = string_value
422 else if (
present(filler))
then
427 end subroutine json_get_string_array
430 subroutine json_get_subdict(json, key, output)
431 type(json_file),
intent(inout) :: json
432 character(len=*),
intent(in) :: key
433 type(json_file),
intent(inout) :: output
435 type(json_value),
pointer :: ptr
436 type(json_core) :: core
438 character(len=:),
allocatable :: buffer
440 call json%get_core(core)
441 call json%get(key, ptr, found)
443 if (.not. found)
then
445 trim(key) //
" missing from the case file")
448 call core%print_to_string(ptr,
buffer)
449 call output%initialize(strict_type_checking = .true.)
452 end subroutine json_get_subdict
456 subroutine json_get_subdict_or_empty(json, key, output)
457 type(json_file),
intent(inout) :: json
458 character(len=*),
intent(in) :: key
459 type(json_file),
intent(inout) ::
output
461 type(json_value),
pointer :: ptr
462 type(json_core) :: core
464 character(len=:),
allocatable ::
buffer
467 call output%initialize(strict_type_checking = .true.)
469 call json%get_core(core)
470 call json%get(key, ptr, found)
474 call core%print_to_string(ptr,
buffer)
478 end subroutine json_get_subdict_or_empty
485 subroutine json_get_or_default_real(json, name, value, default)
486 type(json_file),
intent(inout) :: json
487 character(len=*),
intent(in) :: name
488 real(kind=
sp),
intent(out) ::
value
489 real(kind=
sp),
intent(in) :: default
493 call json%info(name, found = found, var_type = var_type)
495 if (found .and. (var_type .ne. 6))
then
496 call neko_error(
"Parameter " // name //
" present, but is not a real")
499 call json%get(name,
value, found)
501 if ((.not. found) .and. (.not. json_no_defaults))
then
503 call json%add(name,
value)
504 else if (.not. found)
then
505 call neko_error(
"Parameter " // name //
" missing from the case file")
507 end subroutine json_get_or_default_real
515 subroutine json_get_or_default_double(json, name, value, default)
516 type(json_file),
intent(inout) :: json
517 character(len=*),
intent(in) :: name
518 real(kind=
dp),
intent(out) ::
value
519 real(kind=
dp),
intent(in) :: default
523 call json%info(name, found = found, var_type = var_type)
525 if (found .and. (var_type .ne. 6))
then
526 call neko_error(
"Parameter " // name //
" present, but is not a real")
529 call json%get(name,
value, found)
531 if ((.not. found) .and. (.not. json_no_defaults))
then
533 call json%add(name,
value)
534 else if (.not. found)
then
535 call neko_error(
"Parameter " // name //
" missing from the case file")
537 end subroutine json_get_or_default_double
544 subroutine json_get_or_default_integer(json, name, value, default)
545 type(json_file),
intent(inout) :: json
546 character(len=*),
intent(in) :: name
547 integer,
intent(out) :: value
548 integer,
intent(in) :: default
552 call json%info(name, found = found, var_type = var_type)
554 if (found .and. (var_type .ne. 5))
then
555 call neko_error(
"Parameter " // name //
" present, but " // &
559 call json%get(name,
value, found)
561 if ((.not. found) .and. (.not. json_no_defaults))
then
563 call json%add(name,
value)
564 else if (.not. found)
then
565 call neko_error(
"Parameter " // name //
" missing from the case file")
567 end subroutine json_get_or_default_integer
574 subroutine json_get_or_default_logical(json, name, value, default)
575 type(json_file),
intent(inout) :: json
576 character(len=*),
intent(in) :: name
577 logical,
intent(out) :: value
578 logical,
intent(in) :: default
582 call json%info(name, found = found, var_type = var_type)
584 if ((found) .and. (var_type .ne. 4))
then
585 call neko_error(
"Parameter " // name //
" present, but is not a logical")
588 call json%get(name,
value, found)
590 if ((.not. found) .and. (.not. json_no_defaults))
then
592 call json%add(name,
value)
593 else if (.not. found)
then
594 call neko_error(
"Parameter " // name //
" missing from the case file")
596 end subroutine json_get_or_default_logical
603 subroutine json_get_or_default_string(json, name, value, default)
604 type(json_file),
intent(inout) :: json
605 character(len=*),
intent(in) :: name
606 character(len=:),
allocatable,
intent(out) :: value
607 character(len=*),
intent(in) :: default
611 call json%info(name, found = found, var_type = var_type)
613 if (found .and. (var_type .ne. 7))
then
615 " present, but is not a string")
618 call json%get(name,
value, found)
620 if ((.not. found) .and. (.not. json_no_defaults))
then
622 call json%add(name,
value)
623 else if (.not. found)
then
624 call neko_error(
"Parameter " // name //
" missing from the case file")
626 end subroutine json_get_or_default_string
633 subroutine json_extract_item_from_array(core, array, i, item)
634 type(json_core),
intent(inout) :: core
635 type(json_value),
pointer,
intent(in) :: array
636 integer,
intent(in) :: i
637 type(json_file),
intent(inout) :: item
638 type(json_value),
pointer :: ptr
640 character(len=:),
allocatable :: buffer
642 call core%get_child(array, i, ptr, found)
643 call core%print_to_string(ptr,
buffer)
644 call item%initialize(strict_type_checking = .true.)
645 call item%load_from_string(
buffer)
647 end subroutine json_extract_item_from_array
654 subroutine json_extract_item_from_name(json, name, i, item)
655 type(json_file),
intent(inout) :: json
656 character(len=*),
intent(in) :: name
657 integer,
intent(in) :: i
658 type(json_file),
intent(out) :: item
660 type(json_core) :: core
661 type(json_value),
pointer :: array
662 type(json_value),
pointer :: ptr
664 character(len=:),
allocatable :: buffer
666 call json%get_core(core)
667 call json%get(name, array, found)
669 if (.not. found)
then
670 call neko_error(
"Parameter " // name //
" missing from the case file")
673 call core%get_child(array, i, ptr, found)
674 call core%print_to_string(ptr,
buffer)
675 call item%initialize(strict_type_checking = .true.)
676 call item%load_from_string(
buffer)
678 end subroutine json_extract_item_from_name
684 subroutine check_expected_size(name, actual_size, expected_size)
685 character(len=*),
intent(in) :: name
686 integer,
intent(in) :: actual_size, expected_size
687 character(len=32) :: str_actual, str_expected
689 if (actual_size /= expected_size)
then
690 write(str_actual,
'(I0)') actual_size
691 write(str_expected,
'(I0)') expected_size
692 call neko_error(
"Parameter '" // trim(name) // &
693 "' has incorrect size: got " // &
694 trim(str_actual) //
", but expected " // trim(str_expected))
696 end subroutine check_expected_size
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_get_integer_array(json, name, value, expected_size)
Retrieves a integer array parameter by name or throws an error.
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_real_array(json, name, value, expected_size)
Retrieves a real array parameter by name or throws an error.
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_double_array(json, name, value, expected_size)
Retrieves a double precision 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_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, public json_get_subdict_or_empty(json, key, output)
Extract a sub-object from a json object and returns an empty object if the key is missing.
subroutine json_get_string_array(json, name, value, filler)
Retrieves a string 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_logical_array(json, name, value, expected_size)
Retrieves a logical array parameter by name or throws an error.
integer, parameter, public dp
integer, parameter, public sp