write_json_real_array Subroutine

public subroutine write_json_real_array(iunit, name, x, last)

Write a JSON name and real array ("name": [x1, x2, ...], followed by a comma unless it is the last one) to a file opened for unformatted stream access. The array is formatted in parallel, in chunks, and written in order.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iunit

the file unit (stream access)

character(len=*), intent(in) :: name

the variable name

real(kind=wp), intent(in), dimension(:) :: x

the array

logical, intent(in) :: last

if this is the last variable in the object (no comma after it)


Calls

proc~~write_json_real_array~~CallsGraph proc~write_json_real_array write_json_real_array proc~add_real_list text_buffer%add_real_list proc~write_json_real_array->proc~add_real_list proc~add_str text_buffer%add_str proc~write_json_real_array->proc~add_str proc~clear text_buffer%clear proc~write_json_real_array->proc~clear proc~add_real_list->proc~add_str proc~add_real text_buffer%add_real proc~add_real_list->proc~add_real proc~reserve text_buffer%reserve proc~add_real_list->proc~reserve proc~add_str->proc~reserve proc~add_real->proc~add_str proc~add_real->proc~reserve proc~add_digits add_digits proc~add_real->proc~add_digits proc~scaled scaled proc~add_real->proc~scaled proc~add_digits->proc~add_str proc~two_prod two_prod proc~scaled->proc~two_prod proc~split split proc~two_prod->proc~split

Called by

proc~~write_json_real_array~~CalledByGraph proc~write_json_real_array write_json_real_array proc~generate_eclipse_data mission_type%generate_eclipse_data proc~generate_eclipse_data->proc~write_json_real_array proc~halo_solver_main halo_solver_main proc~halo_solver_main->proc~generate_eclipse_data

Source Code

    subroutine write_json_real_array(iunit, name, x, last)

    integer,intent(in) :: iunit !! the file unit (stream access)
    character(len=*),intent(in) :: name !! the variable name
    real(wp),dimension(:),intent(in) :: x !! the array
    logical,intent(in) :: last !! if this is the last variable in the object (no comma after it)

    integer,parameter :: chunk = 16384 !! numbers per chunk
    integer,parameter :: n_buf = 256   !! chunks formatted at a time (in parallel)

    type(text_buffer),dimension(:),allocatable :: buf
    integer :: n_chunks, ic1, ic2, ic, i1, i2

    write(iunit) new_line('a')//'  "'//name//'": ['
    n_chunks = (size(x) + chunk - 1) / chunk
    allocate(buf(min(n_buf, max(1,n_chunks))))
    do ic1 = 1, n_chunks, n_buf
        ic2 = min(ic1 + n_buf - 1, n_chunks)
!$OMP PARALLEL DO PRIVATE(i1,i2)
        do ic = ic1, ic2
            i1 = (ic-1)*chunk + 1
            i2 = min(ic*chunk, size(x))
            associate (b => buf(ic-ic1+1))
                call b%clear()
                if (ic > 1) call b%add_str(', ')
                call b%add_real_list(x(i1:i2))
            end associate
        end do
!$OMP END PARALLEL DO
        do ic = ic1, ic2
            associate (b => buf(ic-ic1+1))
                write(iunit) b%s(1:b%n)
            end associate
        end do
    end do
    if (last) then
        write(iunit) ']'
    else
        write(iunit) '],'
    end if

    end subroutine write_json_real_array