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
14 module procedure json_key_fallback_string
15 module procedure json_key_fallback_json
24 function json_key_fallback_string(json, lookup, fallback)
result(string)
25 type(json_file),
intent(inout) :: json
26 character(len=*),
intent(in) :: lookup
27 character(len=*),
intent(in) :: fallback
28 character(len=:),
allocatable :: string
30 if ((lookup .in. json))
then
32 else if (fallback .in. json)
then
38 end function json_key_fallback_string
44 function json_key_fallback_json(lookup_json, fallback_json, key) &
46 type(json_file),
target,
intent(inout) :: lookup_json
47 type(json_file),
target,
intent(inout) :: fallback_json
48 character(len=*),
intent(in) :: key
49 type(json_file),
pointer :: json_pointer
51 if ((key .in. lookup_json))
then
52 json_pointer => lookup_json
53 else if (key .in. fallback_json)
then
54 json_pointer => fallback_json
56 json_pointer => lookup_json
59 end function json_key_fallback_json
65 function json_read_file(filename)
result(json)
66 character(len=*),
intent(in) :: filename
67 type(json_file) :: json
69 logical :: mpi_is_initialized
70 integer :: rank, ierr, length
71 character(len=:),
allocatable :: json_buffer
72 character(len=4) :: suffix
75 call filename_suffix(filename, suffix)
77 if (trim(suffix) .ne.
'json' .and. trim(suffix) .ne.
'case' )
then
78 call neko_error(
'Invalid case file')
83 mpi_is_initialized = .false.
86 call mpi_initialized(mpi_is_initialized, ierr)
87 if (mpi_is_initialized)
call mpi_comm_rank(mpi_comm_world, rank, ierr)
91 call json%load_file(filename = trim(filename))
95 if (mpi_is_initialized)
then
96 if (rank .eq. 0)
call json%print_to_string(json_buffer)
98 length = len(json_buffer)
99 call mpi_bcast(length, 1, mpi_integer, 0, mpi_comm_world, ierr)
101 if (rank .ne. 0)
allocate(
character(len=length) :: json_buffer)
102 call mpi_bcast(json_buffer, length, mpi_character, 0, mpi_comm_world, &
105 if (rank .ne. 0)
then
106 call json%load_from_string(json_buffer)
107 deallocate(json_buffer)
111 end function json_read_file
113end module json_utils_ext