Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int32), | intent(in) | :: | array(:,:) |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | private | :: | i | ||||
integer, | private | :: | j | ||||
integer, | private | :: | ncols | ||||
integer, | private | :: | nrows | ||||
character(len=50), | private | :: | temp_str | ||||
integer, | private | :: | total_len |
function to_string_matrix_int32(array) result(trimmed_str) integer(int32), intent(in) :: array(:, :) character(len=:), allocatable :: trimmed_str character(len=50) :: temp_str integer :: i, j, total_len, nrows, ncols nrows = size(array, 1) ncols = size(array, 2) ! Estimate total length needed total_len = 10 ! for outer brackets and newlines do i = 1, nrows total_len = total_len + 3 ! for row brackets and comma do j = 1, ncols write (temp_str, '(I0)') array(i, j) total_len = total_len + len_trim(temp_str) + 2 ! +2 for ", " end do end do ! Allocate result string allocate (character(len=total_len) :: trimmed_str) ! Build the string trimmed_str = "[" do i = 1, nrows if (i > 1) trimmed_str = trimmed_str//", " trimmed_str = trimmed_str//"[" do j = 1, ncols write (temp_str, '(I0)') array(i, j) if (j < ncols) then trimmed_str = trimmed_str//trim(temp_str)//", " else trimmed_str = trimmed_str//trim(temp_str) end if end do trimmed_str = trimmed_str//"]" end do trimmed_str = trimmed_str//"]" end function to_string_matrix_int32