      PROGRAM Test
!      INCLUDE 'mkl_dss.f77'
      INCLUDE 'mkl_dss.fi'
      
      INTEGER tIU(:), tJU(:), Idum(:), ITER
      DOUBLE PRECISION tUM(:), tXDIFF(:), tX(:)
      ALLOCATABLE tIU, tJU, tUM, tXDIFF, tX, Idum
      
      INTEGER nNonZeros,nRow
      
      INTEGER*8 handle
      INTEGER error
	    
		character*198  buf

      !OPEN (UNIT=10, FILE='testInfo.dat') 
      !READ (10,7004) nNonZeros, nRow
      !CLOSE(10)
    
      nRow=2
      nNonZeros=4
	  	    
      ALLOCATE(tIU(nRow+1))
      ALLOCATE(tXDIFF(nRow))
      ALLOCATE(tX(nRow))
      ALLOCATE(tJU(nNonZeros))
      ALLOCATE(tUM(nNonZeros))
      ALLOCATE(Idum(nRow))

      tJU(1)=1
      tJU(2)=2
      tJU(3)=1
      tJU(4)=2
      tIU(1)=1
      tIU(2)=3
      tIU(3)=5
      tUM(1)=0.0751
      tUM(2)=0.0116
      tUM(3)=0.0116
      tUM(4)=-0.0751
      tXDIFF(1)=1
      tXDIFF(2)=0
      
      !OPEN (UNIT=10, FILE='columns.dat') 
      !READ (10,7002) (tJU(II),II=1,nNonZeros)
      !CLOSE(10)
      !
      !OPEN (UNIT=10, FILE='rowIndex.dat') 
      !READ (10,7002) (tIU(II),II=1,nRow+1)
      !CLOSE(10)
      !
      !OPEN (UNIT=10, FILE='values.dat') 
      !READ (10,7001) (tUM(II),II=1,nNonZeros)
      !CLOSE(10)
      !
      !OPEN (UNIT=10, FILE='loadVector.dat')
      !READ (10,7001) (tXDIFF(II),II=1,nRow)
      !CLOSE(10)   

		call mkl_get_version_string(buf)
		write(*,'(a)') buf

      ITER=1
C---------------------------------------------------------------------------
C Initialize the solver
C---------------------------------------------------------------------------
      error = dss_create(handle, MKL_DSS_DEFAULTS+MKL_DSS_OOC_VARIABLE) ! original
!      error = dss_create(handle, MKL_DSS_DEFAULTS)
      IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
C---------------------------------------------------------------------------
		WRITE(*,*) ' (1)...dss_create == ',error
C---------------------------------------------------------------------------
C Define the non-zero structure of the matrix
C---------------------------------------------------------------------------
         !    error = dss_define_structure( handle, MKL_DSS_SYMMETRIC,
         !& tIU, nRow, nRow, tJU, nNonZeros )
        error = dss_define_structure( handle, MKL_DSS_NON_SYMMETRIC,
     & tIU, nRow, nRow, tJU, nNonZeros )
      IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
	  WRITE(*,*) ' (2)...dss_define_structure == ',error
C---------------------------------------------------------------------------

C---------------------------------------------------------------------------
C Reorder the matrix
C---------------------------------------------------------------------------

      IF (ITER.EQ.1) THEN
          error = dss_reorder( handle,  MKL_DSS_GET_ORDER, Idum)
          IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
		  
		  WRITE(*,*) ' (3)...dss_reoder == ',error
      ELSE
          error = dss_reorder( handle, MKL_DSS_MY_ORDER, Idum)
          IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
      ENDIF

C---------------------------------------------------------------------------
C Factor the matrix
C---------------------------------------------------------------------------
      error = dss_factor_real( handle, MKL_DSS_DEFAULTS, tUM)
      IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
	  WRITE(*,*) ' (4) ...dss_factor_real == ',error
      
C---------------------------------------------------------------------------
C Get the solution vector
C---------------------------------------------------------------------------
      error = dss_solve_real( handle, MKL_DSS_DEFAULTS,
     & tXDIFF, 1, tX)
      IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
	  WRITE(*,*) '(5)...dss_solve_real == ',error
C---------------------------------------------------------------------------
     
C---------------------------------------------------------------------------
C Deallocate solver storage
C---------------------------------------------------------------------------
      error = dss_delete( handle, MKL_DSS_DEFAULTS )
      IF (error .NE. MKL_DSS_SUCCESS ) GOTO 999
	  WRITE(*,*) '(6)...dss_delete == ',error
C---------------------------------------------------------------------------

      OPEN (UNIT=10, FILE='OutValues.dat') 
      WRITE (10,7005) (tX(II),II=1,nRow)
      CLOSE(10)
      GOTO 1999
      
7001  FORMAT(1X,D)     
7002  FORMAT(1X,I5)
7003  FORMAT(1X,I,1X,D)
7004  FORMAT(1X,I,1X,I)
7005  FORMAT(1X,D)
      
999   WRITE(*,*) "Solver returned error code ", error
      
1999  DEALLOCATE(tIU,tJU,tUM,tXDIFF,tX,Idum)
      
      END
      
      