SUBROUTINE dbcsr_printmat_matlab_z(matrix, rows, cols, r_offset, c_offset, iunit, tr, variable_name)
COMPLEX(KIND=real_8), DIMENSION(:), INTENT(IN) :: matrix
INTEGER, INTENT(IN) :: rows, cols, r_offset, c_offset, iunit
LOGICAL, INTENT(IN), OPTIONAL :: tr
CHARACTER(len=*), INTENT(in), OPTIONAL :: variable_name
INTEGER :: c, c_off, m, n, r, r_off
LOGICAL :: t
! ---------------------------------------------------------------------------
m = rows
n = cols
r_off = r_offset
c_off = c_offset
t = .FALSE.
IF (PRESENT(tr)) THEN
IF (tr) THEN
t = .TRUE.
m = cols
n = rows
r_off = c_offset
c_off = r_offset
END IF
END IF
DO c = 1, cols
DO r = 1, rows
IF (.NOT. t) THEN
IF (PRESENT(variable_name)) THEN
WRITE (iunit, '(A,I3,A,I3,A,E23.16,A,E23.16,A)') variable_name//'(', r + r_offset - 1, ',', &
c + c_offset - 1, ')=', &
REAL(matrix(r + (c - 1)*rows)), '+', AIMAG(matrix(r + (c - 1)*rows)), 'i;'
ELSE
WRITE (iunit, '(A,I3,A,I3,A,E23.16,A,E23.16,A)') 'a(', r + r_offset - 1, ',', c + c_offset - 1, ')=', &
REAL(matrix(r + (c - 1)*rows)), '+', AIMAG(matrix(r + (c - 1)*rows)), 'i;'
END IF
ELSE
IF (PRESENT(variable_name)) THEN
WRITE (iunit, '(A,I3,A,I3,A,E23.16,A,E23.16,A)') variable_name//'(', r + r_offset - 1, ',', &
c + c_offset - 1, ')=', &
REAL(matrix((r - 1)*cols + c)), '+', AIMAG(matrix((r - 1)*cols + c)), 'i;'
ELSE
WRITE (iunit, '(A,I3,A,I3,A,E23.16,A,E23.16,A)') 'a(', r + r_offset - 1, ',', c + c_offset - 1, ')=', &
REAL(matrix((r - 1)*cols + c)), '+', AIMAG(matrix((r - 1)*cols + c)), 'i;'
END IF
END IF
END DO
END DO
END SUBROUTINE dbcsr_printmat_matlab_z