private subroutine that prints a vector in a format
Type | Intent | Optional | 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 |
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 |
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