35 use mpi_f08,
only: mpi_comm_rank, mpi_initialized, mpi_bcast, &
77 function json_key_fallback_json(lookup_json, fallback_json, key) &
79 type(json_file),
target,
intent(inout) :: lookup_json
80 type(json_file),
target,
intent(inout) :: fallback_json
81 character(len=*),
intent(in) :: key
82 type(json_file),
pointer :: json_pointer
84 if ((key .in. lookup_json))
then
85 json_pointer => lookup_json
86 else if (key .in. fallback_json)
then
87 json_pointer => fallback_json
89 json_pointer => lookup_json
98 function json_read_file(filename)
result(json)
99 character(len=*),
intent(in) :: filename
100 type(json_file) :: json
102 logical :: mpi_is_initialized
103 integer :: rank, ierr, length
104 character(len=:),
allocatable :: json_buffer
105 character(len=4) :: suffix
108 call filename_suffix(filename, suffix)
110 if (trim(suffix) .ne.
'json' .and. trim(suffix) .ne.
'case' )
then
111 call neko_error(
'Invalid case file')
116 mpi_is_initialized = .false.
119 call mpi_initialized(mpi_is_initialized, ierr)
120 if (mpi_is_initialized)
call mpi_comm_rank(mpi_comm_world, rank, ierr)
123 if (rank .eq. 0)
then
124 call json%load_file(filename = trim(filename))
128 if (mpi_is_initialized)
then
129 if (rank .eq. 0)
call json%print_to_string(json_buffer)
131 length = len(json_buffer)
132 call mpi_bcast(length, 1, mpi_integer, 0, mpi_comm_world, ierr)
134 if (rank .ne. 0)
allocate(
character(len=length) :: json_buffer)
135 call mpi_bcast(json_buffer, length, mpi_character, 0, mpi_comm_world, &
138 if (rank .ne. 0)
then
139 call json%load_from_string(json_buffer)
140 deallocate(json_buffer)