      subroutine clubksb(a,n,np,indx,b)
c**********************************************************************
c**** Perform forward and backward substitution for LU             ****
c**** decomposition of a where a is complex                        ****
c**** Input:  a(np,np) in LU decomposition form from CLUDCMP       ****
c****         np phyiscal dimension                                ****
c****         n actual dimension                                   ****
c****         indx(n) contains all permutations                    ****
c****         b(n) contains RHS of a.x=b                           ****
c**** output: b(n) overwrite RHS of a.x=b with x                   ****
c**********************************************************************
      integer        n,np,indx(np)
      double complex a(np,np),b(np)
      integer        i,ii,j,ll
      double complex sum

      ii=0
      do 12 i=1,n
        ll=indx(i)
        sum=b(ll)
        b(ll)=b(i)
        if (ii.ne.0) then
          do 11 j=ii,i-1
            sum=sum-a(i,j)*b(j)
  11      continue
        else if (cdabs(sum).ne.0.0d0) then
          ii=i
        end if
        b(i)=sum
  12  continue
      do 14 i=n,1,-1
        sum=b(i)
        if (i.lt.n) then
          do 13 j=i+1,n
            sum=sum-a(i,j)*b(j)
  13      continue
        end if
        b(i)=sum/a(i,i)
  14  continue
      return

      end
