print_matrix_in_format Subroutine

private subroutine print_matrix_in_format(mat, format_type, n_cols, n_rows)

private subroutine to print a matrix in format

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: mat(:,:)
character(len=*), intent(in) :: format_type

format can be mathematica or numpy

integer(kind=default_int), intent(in), optional :: n_cols
integer(kind=default_int), intent(in), optional :: n_rows

Called by

proc~~print_matrix_in_format~~CalledByGraph proc~print_matrix_in_format print_matrix_in_format proc~print_matrix print_matrix proc~print_matrix->proc~print_matrix_in_format proc~print_matrix_m_n print_matrix_m_n proc~print_matrix_m_n->proc~print_matrix_in_format interface~print_array print_array interface~print_array->proc~print_matrix interface~print_array_with_bounds print_array_with_bounds interface~print_array_with_bounds->proc~print_matrix_m_n

Variables

Type Visibility Attributes Name Initial
character(len=1), private :: close_bracket
integer(kind=default_int), private :: i
integer(kind=default_int), private :: j
integer(kind=default_int), private :: loop_bound_i
integer(kind=default_int), private :: loop_bound_j
character(len=1), private :: open_bracket

Source Code

   subroutine print_matrix_in_format(mat, format_type, n_cols, n_rows)
    !! private subroutine to print a matrix in format
      real(kind=dp), intent(in) :: mat(:, :)
      character(len=*), intent(in) :: format_type
        !! format can be mathematica or numpy
      character(len=1) :: open_bracket, close_bracket
      integer(kind=default_int), intent(in), optional :: n_cols, n_rows
      integer(kind=default_int) :: i, j, loop_bound_i, loop_bound_j
      if (present(n_cols) .and. present(n_rows)) then
         loop_bound_i = n_cols
         loop_bound_j = n_rows
      else
         loop_bound_i = size(mat, 1)
         loop_bound_j = size(mat, 2)
      end if

      ! Select brackets based on format type
      if (format_type == "NUMPY") then
         open_bracket = "["
         close_bracket = "]"
      else if (format_type == "MATHEMATICA") then
         open_bracket = "{"
         close_bracket = "}"
      else
         print *, "Error: Unsupported format type. Defaulting to NumPy format."
         open_bracket = "["
         close_bracket = "]"
      end if

      ! Print the matrix in the selected format
      print *, "Matrix (", trim(format_type), " format):"
      print *, open_bracket
      do i = 1, loop_bound_i
         write (*, "(A)", advance="no") open_bracket  ! Start of a row
         do j = 1, loop_bound_j
            if (j == loop_bound_j) then  ! Last element in the row
               write (*, fmt_edge, advance="no") mat(i, j)
            else  ! Elements in between
               write (*, fmt_in, advance="no") mat(i, j)
            end if
         end do
         if (i == loop_bound_i) then
            print *, close_bracket  ! Close bracket without a comma for the last row
         else
            print *, close_bracket, ","  ! Close bracket with a comma for all other rows
         end if
      end do
      print *, close_bracket
   end subroutine print_matrix_in_format