
  MODULE wrapper

    IMPLICIT NONE

    PUBLIC F04ATF_W

    CONTAINS

    SUBROUTINE F04ATF_W(a, b, x, i_fail)

      DOUBLE PRECISION, DIMENSION(:, :), INTENT(IN) :: a
      DOUBLE PRECISION, DIMENSION(:), INTENT(IN)    :: b
      DOUBLE PRECISION, DIMENSION(:), INTENT(OUT)   :: x

      INTEGER, INTENT(INOUT) :: i_fail    !...error flag;

        INTEGER :: n         !...we solve an n*n system;
        INTEGER :: ia, ilu

        DOUBLE PRECISION, DIMENSION(SIZE(b), SIZE(b)) :: lu
        DOUBLE PRECISION, DIMENSION(SIZE(b))          :: workspace_1, &
                                                         workspace_2

        n = SIZE(b)        

        ia  = n
        ilu = n

        ! -- F04ATF :
        !
        !    to solve Ax = b...
        !    
        !    a      : on entry the n*n matrix A;
        !    ia     : first dimension of a  (ia >= n);
        !    b      : on entry the rhs (vector b);
        !    n      : the order of matrix a;
        !    x      : on exit the solution vector, x;
        !    lu     : on exit L and U (the triangular factors);
        !    ilu    : on entry the first dimension of lu (ilu >= n);
        !
        !    i_fail : on entry, -1, 0 or 1;
        !             on exit, 0 unless an error is detected;
        !
        !    workspace_1, workspace_2 : workspace, dimension at least n;

        WRITE (*,*) "n = ", n

        CALL F04ATF(a, ia, b, n, x, lu, ilu, &
                    workspace_1, workspace_2, &
                    i_fail)

    ENDSUBROUTINE F04ATF_W


  ENDMODULE wrapper
