|
| 1 | +#:include "common.fypp" |
| 2 | +#:set KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES |
| 3 | +submodule(stdlib_io) stdlib_io_print_array |
| 4 | + |
| 5 | + use, intrinsic :: iso_fortran_env, only: output_unit |
| 6 | + implicit none |
| 7 | + |
| 8 | +contains |
| 9 | + |
| 10 | + #:for k1, t1 in KINDS_TYPES |
| 11 | + module subroutine print_array_${t1[0]}$${k1}$(array, unit, fmt, delimiter, brief) |
| 12 | + ${t1}$, intent(in) :: array(:, :) |
| 13 | + integer, intent(in), optional :: unit |
| 14 | + character(len=*), intent(in), optional :: fmt |
| 15 | + character(len=1), intent(in), optional :: delimiter |
| 16 | + logical, intent(in), optional :: brief |
| 17 | + |
| 18 | + integer :: i, j, unit_, shape_(2) |
| 19 | + character(len=:), allocatable :: fmt_ |
| 20 | + character(len=1) :: delimiter_ |
| 21 | + character(len=3) :: delim_str |
| 22 | + logical :: brief_ |
| 23 | + |
| 24 | + shape_ = shape(array) |
| 25 | + if (any(shape_ == 0)) return |
| 26 | + unit_ = optval(unit, output_unit) |
| 27 | + delimiter_ = optval(delimiter, delimiter_default) |
| 28 | + delim_str = "'"//delimiter_//"'" |
| 29 | + brief_ = optval(brief, .true.) |
| 30 | + if (present(fmt)) then |
| 31 | + fmt_ = "(*"//fmt(1:len(fmt) - 1)//",:,"//delim_str//"))" |
| 32 | + else |
| 33 | + #:if 'real' in t1 |
| 34 | + fmt_ = "(*"//FMT_REAL_${k1}$ (1:len(FMT_REAL_${k1}$) - 1)//",:,"//delim_str//"))" |
| 35 | + #:elif 'complex' in t1 |
| 36 | + fmt_ = "(*"//FMT_COMPLEX_${k1}$ (1:11)//delim_str//FMT_COMPLEX_${k1}$ (14:23)//",:,"//delim_str//"))" |
| 37 | + #:elif 'integer' in t1 |
| 38 | + fmt_ = "(*"//FMT_INT(1:len(FMT_INT) - 1)//",:,"//delim_str//"))" |
| 39 | + #:endif |
| 40 | + end if |
| 41 | + |
| 42 | + if (brief_) then |
| 43 | + |
| 44 | + if (shape_(1) > 5) then |
| 45 | + if (shape_(2) > 5) then |
| 46 | + do i = 1, 3 |
| 47 | + write (unit_, fmt=fmt_, advance='no') array(i, :3) |
| 48 | + write (unit_, fmt='(a)', advance='no') delimiter_//"..."//delimiter_ |
| 49 | + write (unit_, fmt=fmt_) array(i, shape_(2)) |
| 50 | + end do |
| 51 | + write (unit_, fmt='(a)') ":" |
| 52 | + write (unit_, fmt=fmt_, advance='no') array(shape_(1), :3) |
| 53 | + write (unit_, fmt='(a)', advance='no') delimiter_//"..."//delimiter_ |
| 54 | + write (unit_, fmt=fmt_) array(shape_(1), shape_(2)) |
| 55 | + else |
| 56 | + do i = 1, 3 |
| 57 | + write (unit_, fmt=fmt_) array(i, :) |
| 58 | + end do |
| 59 | + write (unit_, fmt='(a)') ":" |
| 60 | + write (unit_, fmt=fmt_) array(shape_(1), :) |
| 61 | + |
| 62 | + end if |
| 63 | + else |
| 64 | + if (shape_(2) > 5) then |
| 65 | + do i = 1, shape_(1) |
| 66 | + write (unit_, fmt=fmt_, advance='no') array(i, :3) |
| 67 | + write (unit_, fmt='(a)', advance='no') delimiter_//"..."//delimiter_ |
| 68 | + write (unit_, fmt=fmt_) array(i, shape_(2)) |
| 69 | + end do |
| 70 | + else |
| 71 | + do i = 1, shape_(1) |
| 72 | + write (unit_, fmt=fmt_) array(i, :) |
| 73 | + end do |
| 74 | + end if |
| 75 | + end if |
| 76 | + |
| 77 | + else |
| 78 | + |
| 79 | + do i = 1, shape_(1) |
| 80 | + write (unit_, fmt=fmt_) array(i, :) |
| 81 | + end do |
| 82 | + |
| 83 | + end if |
| 84 | + |
| 85 | + end subroutine print_array_${t1[0]}$${k1}$ |
| 86 | + #:endfor |
| 87 | + |
| 88 | +end submodule stdlib_io_print_array |
0 commit comments