Real vector to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | v |
real values |
|
character(len=*), | intent(in) | :: | fmt |
real format string |
||
character(len=:), | intent(out), | allocatable | :: | str |
real values stringified |
|
logical, | intent(in) | :: | use_numpy |
activate numpy python module usage |
||
logical, | intent(in), | optional | :: | is_tuple |
if true [default], use '()', if false use '[]' |
subroutine vec_to_string(v, fmt, str, use_numpy, is_tuple) real(wp), dimension(:), intent(in) :: v !! real values character(len=*), intent(in) :: fmt !! real format string character(len=:), allocatable, intent(out) :: str !! real values stringified logical, intent(in) :: use_numpy !! activate numpy python module usage logical,intent(in),optional :: is_tuple !! if true [default], use '()', if false use '[]' integer :: i !! counter integer :: istat !! IO status character(len=max_real_len) :: tmp !! dummy string logical :: tuple if (present(is_tuple)) then tuple = is_tuple else tuple = .false. end if if (tuple) then str = '(' else str = '[' end if do i=1, size(v) if (fmt=='*') then write(tmp, *, iostat=istat) v(i) else write(tmp, fmt, iostat=istat) v(i) end if if (istat/=0) then write(error_unit,'(A)') 'Error in vec_to_string' str = '****' return end if str = str//trim(adjustl(tmp)) if (i<size(v)) str = str // ',' end do if (tuple) then str = str // ')' else str = str // ']' end if !convert to numpy array if necessary: if (use_numpy) str = 'np.array('//str//')' end subroutine vec_to_string