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.
| Type | Intent | Optional | 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) |
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