module base_chains_mod
  implicit none

contains

  subroutine base_chain2_oper(op1, op2, adj, add, m, d, t1)
    interface
      integer function op1(adj,add,m,d)
        logical            :: adj, add
        real, dimension(:) :: m, d
      end function 
      integer function op2(adj,add,m,d)
        logical            :: adj, add
        real, dimension(:) :: m, d
      end function
    end interface

    logical            :: adj, add
    real, dimension(:) :: m, d, t1 

    integer            :: stat

    if (adj) then 
       stat = op1( .true., .false., t1,  d)    !!.. t = A'd
       stat = op2( .true.,     add,  m, t1)    !!.. m = B't = B'A'd
    else
       stat = op2(.false., .false.,  m, t1)    !!.. t1 = Bm
       stat = op1(.false.,     add,  t1, d)    !!.. d = At1 = ABm
    end if
    return
  end subroutine


end module
