print_vector_in_format Subroutine

private subroutine print_vector_in_format(vec, format_type, n_elements)

private subroutine that prints a vector in a format

Arguments

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

format can be mathematica or numpy

integer(kind=default_int), intent(in), optional :: n_elements

Called by

proc~~print_vector_in_format~~CalledByGraph proc~print_vector_in_format print_vector_in_format proc~print_vector print_vector proc~print_vector->proc~print_vector_in_format proc~print_vector_n print_vector_n proc~print_vector_n->proc~print_vector_in_format interface~print_array print_array interface~print_array->proc~print_vector interface~print_array_with_bounds print_array_with_bounds interface~print_array_with_bounds->proc~print_vector_n

Variables

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

Source Code

   subroutine print_vector_in_format(vec, format_type, n_elements)
    !! private subroutine that prints a vector in a format
      real(kind=dp), intent(in) :: vec(:)
      character(len=*), intent(in) :: format_type
        !! format can be mathematica or numpy
      integer(kind=default_int), intent(in), optional :: n_elements
      character(len=1) :: open_bracket, close_bracket
      integer(kind=default_int) :: i, loop_bound_i

      if (present(n_elements)) then
         loop_bound_i = n_elements
      else
         loop_bound_i = size(vec)
      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 vector in the selected format
      print *, "Vector (", trim(format_type), " format):"
      print *, open_bracket
      do i = 1, loop_bound_i
         if (i == loop_bound_i) then  ! Last element in the vector
            write (*, fmt_edge, advance="no") vec(i)
         else  ! Elements in between
            write (*, fmt_in, advance="no") vec(i)
         end if
      end do
      print *, close_bracket
   end subroutine print_vector_in_format