35 use mpi_f08,
only: mpi_comm_rank, mpi_initialized, mpi_bcast, &
78 function json_key_fallback_json(lookup_json, fallback_json, key) &
80 type(json_file),
target,
intent(inout) :: lookup_json
81 type(json_file),
target,
intent(inout) :: fallback_json
82 character(len=*),
intent(in) :: key
83 type(json_file),
pointer :: json_pointer
85 if ((key .in. lookup_json))
then
86 json_pointer => lookup_json
87 else if (key .in. fallback_json)
then
88 json_pointer => fallback_json
90 json_pointer => lookup_json
99 function json_read_file(filename)
result(json)
100 character(len=*),
intent(in) :: filename
101 type(json_file) :: json
103 logical :: mpi_is_initialized
104 integer :: rank, ierr, length
105 character(len=:),
allocatable :: json_buffer
106 character(len=4) :: suffix
109 call filename_suffix(filename, suffix)
111 if (trim(suffix) .ne.
'json' .and. trim(suffix) .ne.
'case' )
then
112 call neko_error(
'Invalid case file')
117 mpi_is_initialized = .false.
120 call mpi_initialized(mpi_is_initialized, ierr)
121 if (mpi_is_initialized)
call mpi_comm_rank(neko_comm, rank, ierr)
124 if (rank .eq. 0)
then
125 call json%load_file(filename = trim(filename))
129 if (mpi_is_initialized)
then
130 if (rank .eq. 0)
call json%print_to_string(json_buffer)
132 length = len(json_buffer)
133 call mpi_bcast(length, 1, mpi_integer, 0, neko_comm, ierr)
135 if (rank .ne. 0)
allocate(
character(len=length) :: json_buffer)
136 call mpi_bcast(json_buffer, length, mpi_character, 0, neko_comm, ierr)
138 if (rank .ne. 0)
then
139 call json%load_from_string(json_buffer)
140 deallocate(json_buffer)