2 use mpi_f08,
only: mpi_comm_rank, mpi_initialized, mpi_bcast, &
3 mpi_comm_world, mpi_integer, mpi_character
4 use json_file_module,
only: json_file
5 use json_value_module,
only: json_value
6 use utils,
only: neko_error, filename_suffix
11 public :: json_key_fallback, json_read_file
19 function json_key_fallback(json, lookup, fallback)
result(string)
20 type(json_file),
intent(inout) :: json
21 character(len=*),
intent(in) :: lookup
22 character(len=*),
intent(in) :: fallback
23 character(len=:),
allocatable :: string
25 if ((lookup .in. json))
then
27 else if (fallback .in. json)
then
33 end function json_key_fallback
39 function json_read_file(filename)
result(json)
40 character(len=*),
intent(in) :: filename
41 type(json_file) :: json
43 logical :: mpi_is_initialized
44 integer :: rank, ierr, length
45 character(len=:),
allocatable :: json_buffer
46 character(len=4) :: suffix
49 call filename_suffix(filename, suffix)
51 if (trim(suffix) .ne.
'json' .and. trim(suffix) .ne.
'case' )
then
52 call neko_error(
'Invalid case file')
57 mpi_is_initialized = .false.
60 call mpi_initialized(mpi_is_initialized, ierr)
61 if (mpi_is_initialized)
call mpi_comm_rank(mpi_comm_world, rank, ierr)
65 call json%load_file(filename = trim(filename))
69 if (mpi_is_initialized)
then
70 if (rank .eq. 0)
call json%print_to_string(json_buffer)
72 length = len(json_buffer)
73 call mpi_bcast(length, 1, mpi_integer, 0, mpi_comm_world, ierr)
75 if (rank .ne. 0)
allocate(
character(len=length) :: json_buffer)
76 call mpi_bcast(json_buffer, length, mpi_character, 0, mpi_comm_world, &
80 call json%load_from_string(json_buffer)
81 deallocate(json_buffer)
85 end function json_read_file
87end module json_utils_ext