! =================================================
! solving the matrix equation A*x=b using LAPACK
! =================================================
	PROGRAM Main

	  IMPLICIT NONE

   ! =================================================
   ! declarations, notice single precision
   ! =================================================
	  REAL    :: A(3,3), b(3)
	  INTEGER ::  i, j, pivot(3), ok

   ! =================================================
   ! define matrix A
   ! =================================================
	  A(1,1)=3.1; A(1,2)=1.3; A(1,3)=-5.7
	  A(2,1)=1.0; A(2,2)=-6.9; A(2,3)=5.8
	  A(3,1)=3.4; A(3,2)=7.2; A(3,3)=-8.8

   ! =================================================
   ! define vector b, make b a matrix and you can solve multiple
   ! equations with the same A but different b
   ! =================================================
	  b(1)=-1.3; b(2)=-0.1; b(3)=1.8

   ! =================================================
   ! find the solution using the LAPACK routine SGESV
   ! =================================================
	  call SGESV(3, 1, A, 3, pivot, b, 3, ok)
   ! =================================================
   !
   ! parameters in the order as they appear in the function call:
   !    - 3= order of matrix A, 
   !    - 1= number of right hand sides (b)
   !    - A= matrix A,
   !    - 3= leading dimension of A
   !    - pivot= array that records pivoting, 
   !    - b= result vector b on entry, solution x on exit, 
   !    - 3= leading dimension of b
   !    - ok= return value 	
   ! =================================================

   ! =================================================
   ! print the solution vector 
   ! =================================================
	  print *, b
	END

