anchor.diff:      IMPLICIT NONE
       TYPE(QuTree), POINTER       :: qA,qB,qC
       REAL(DOUBLE),OPTIONAL       :: tolerance
  -    REAL(DOUBLE)                :: Saved_tolerance,norm
  +    REAL(DOUBLE)                :: Saved_tolerance,norm,TrueError,fricnfrac
       INTEGER                     :: SpAMM_count
  +    REAL(DOUBLE),ALLOCATABLE,DIMENSION(:,:) :: dA,dB,dC
  +
  +
       IF(PRESENT(tolerance))THEN
          Saved_tolerance=SpAMM_tolerance
          SpAMM_tolerance=tolerance
  
positive.code:        CALL SpAMM_Mat2Quad(A(1:I/2  ,J/2+1:J)  , qA%Quad01 )
         CALL SpAMM_Mat2Quad(A(I/2+1:I,1:J/2  )  , qA%Quad10 )
         CALL SpAMM_Mat2Quad(A(I/2+1:I,J/2+1:J)  , qA%Quad11 )
         !
         qA%Norm=qA%Quad00%Norm+qA%Quad01%Norm+qA%Quad10%Norm+qA%Quad11%Norm
         !
         qA%Quad00%Norm=SQRT(qA%Quad00%Norm)
         qA%Quad01%Norm=SQRT(qA%Quad01%Norm)
         qA%Quad10%Norm=SQRT(qA%Quad10%Norm)
         qA%Quad11%Norm=SQRT(qA%Quad11%Norm)
      ENDIF
      !
    END SUBROUTINE SpAMM_Mat2Quad
  
negative.code:   NULLIFY(qTmp2)
    CALL NewQuNode(qTmp1,init=.TRUE.)
    CALL NewQuNode(qTmp2,init=.TRUE.)
    !--------------------------------------------------
    SpAMM_average_multiplies=Zero
    IF(.NOT.DoFilter)THEN
       SpAMM_tolerance=SpAMM_tolerance*SQRT(Two/DBLE(Nel))
    ENDIF
    !--------------------------------------------------
    Occ0 = 0.D0;Occ1 = 0.D0;Occ2 = 0.D0;Occ3 = 0.D0
    DO I=1,TC2_cycles
       IF(DoFilter)THEN
          CALL TC2_filter(qP,qTmp1,qTmp2,Half*FLOAT(NEl),Occ0,I)
       ELSE
          CALL TC2(qP,qTmp1,qTmp2,Half*FLOAT(NEl),Occ0,I)
       ENDIF
       Occ3 = Occ2;Occ2 = Occ1;Occ1 = Occ0
       SpAMM_average_multiplies=SpAMM_average_multiplies+SpAMM_multiplies
    ENDDO
    !
    IF(DoFilter)THEN
       CALL Filter_qutree(qF,SpAMM_tolerance)
       CALL Multiply_qutree_tms_qutree(qP,qF,qTmp1,tolerance=1D-100)
    ELSE
       CALL Multiply(qP,qF,qTmp1)
    ENDIF
    TrE=Trace(qTmp1)
    RelativeErrorE=ABS(TrE-TargetTrE)/ABS(TargetTrE)
    RelativeErrorN=ABS(Occ0-Half*DBLE(Nel))/(Half*DBLE(Nel))
    !
    SpAMM_average_multiplies=SpAMM_average_multiplies+SpAMM_multiplies
    SpAMM_average_multiplies=SpAMM_average_multiplies/DBLE(TC2_cycles+1)
    !
    WRITE(*,66)N_old,N,SpAMM_BLOCK_SIZE,SpAMM_tolerance,RelativeErrorE,RelativeErrorN, &
               SpAMM_average_multiplies
  66 FORMAT(I6,", ",I6,", ",I3,", ",E8.2,7(", ",E18.8))
    !
  END PROGRAM SpAMM_TEST
  