    Subroutine sub_coo_to_csr_sparse
    USE, INTRINSIC :: ISO_C_BINDING , ONLY : C_INT, C_DOUBLE_COMPLEX
    USE MKL_SPBLAS
!   *****************************************************************************
    IMPLICIT NONE
!   *****************************************************************************
    INTEGER M, N, NNZ, i, info
    INTEGER(C_INT)::nrow,ncol, j, ipos1, ipos2
!   *****************************************************************************
!   Inspector-executor Sparse BLAS operation testing    
!   Sparse representation of the matrix A
!
!                 |   1       -1      0   -3     0   |
!                 |  -2        5      0    0     0   |
!   A    =        |   0        0      4    6     4   |,
!                 |  -4        0      2    7     0   |
!                 |   0        8      0    0    -5   |
!
!   Define the matrix [A] using COO format and base 1
!   Convert it to CSR format and output the matrix [A] to screen as CSR format    
!   *****************************************************************************
    INTEGER, ALLOCATABLE :: coo_Row_ptr(:), coo_Col_ptr(:)
    Integer, Allocatable:: rows_start(:), rows_end(:), col_indx(:)
    COMPLEX*16, ALLOCATABLE :: csrVal(:)
    COMPLEX(C_DOUBLE_COMPLEX), ALLOCATABLE :: csrA_value(:)
!   Matrix descriptor
    TYPE(MATRIX_DESCR) descrA     ! Sparse matrix descriptor
!   CSR matrix representation 
    TYPE(SPARSE_MATRIX_T) csrA, cooA  ! Structure with sparse matrix
!   *****************************************************************************
!   Declaration of local variables:
!   *****************************************************************************
    M = 5
    N = 5
    NNZ = 13
    ALLOCATE(coo_Row_ptr(NNZ))
    ALLOCATE(coo_Col_ptr(NNZ))
    ALLOCATE(csrVal(NNZ))
    
    ALLOCATE(rows_start(M+1), rows_end(M+1), col_indx(2*NNZ),csrA_value(2*NNZ))
    
    coo_Row_ptr = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5]
    coo_Col_ptr = [1, 2, 4, 1, 2, 3, 4, 5, 1, 3, 4, 2, 5]
    csrVal = (/ (1.0,0.0),(-1.0,0.0),(-3.0,0.0),(-2.0,0.0),(5.0,0.0),(4.0,0.0),(6.0,0.0),(4.0,0.0),(-4.0,0.0),(2.0,0.0),(7.0,0.0),&
                (8.0,0.0),(-5.0,0.0) /)

    print*,'EXAMPLE PROGRAM FOR Tetsing '
    print*,'---------------------------------------------------'
    print*,''
    print*,'MKL_SPARSE_Z_CREATE_COO(...)'
    print*,'mkl_sparse_convert_csr(...)'
    print*,'mkl_sparse_z_export_csr'
    print*,''

!   Create COO matrix
    i = MKL_SPARSE_Z_CREATE_COO(cooA,SPARSE_INDEX_BASE_ONE,M,N,NNZ,coo_Row_Ptr,coo_col_Ptr,csrVal)
    Print*,'MKL_SPARSE_Z_CREATE_COO(...), return code =',i
    
!   Convert to CSR matrix
    i = mkl_sparse_convert_csr (cooA, SPARSE_OPERATION_NON_TRANSPOSE, csrA)
    Print*,'mkl_sparse_convert_csr(...), return code =',i
    
!   Export to CSR format
    info = mkl_sparse_z_export_csr (csrA, i, nrow, ncol, rows_start,rows_end,col_indx,csrA_value)
    Print*,'Call mkl_sparse_z_export_csr (...), error code =', info

!   Output to screen for checking    
    print*,'Sparse matrix [A] in CSR format, four arrays'
    print*,'---------------------------------------------------'
    Print*,'indexing =',i
    Print*,'nrow, ncol =', nrow, ncol
    print*,''
    print*,'OUTPUT DATA FOR [A] in CSR Format = '
    print*,'rows_start(1:M) = '
    print*, rows_start(1:nrow)
    print*,'rows_end(1:M) = '
    print*, rows_end(1:nrow)
    print*,'col_indx(1:NNZ) = '
    print*, col_indx(1:nnz)
    print*,'csr_AB_value(1:NNZ) = '
    print*, csrA_value(1:nnz)
!    
!   Release internal representation of CSR matrix
    info = MKL_SPARSE_DESTROY(cooA)
    info = MKL_SPARSE_DESTROY(csrA)

    print*,'---------------------------------------------------'
    
    End Subroutine