Real matrix (rank 2) 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 |
subroutine matrix_to_string(v, fmt, str, use_numpy) 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 integer :: i !! counter character(len=:),allocatable :: tmp !! dummy string str = '[' do i=1, size(v,1) !rows call vec_to_string(v(i,:), fmt, tmp, use_numpy) !one row at a time str = str//trim(adjustl(tmp)) if (i<size(v,1)) str = str // ',' end do str = str // ']' !convert to numpy array if necessary: if (use_numpy) str = 'np.array('//str//')' end subroutine matrix_to_string