!
Subroutine GEN_Solver
use Advertisement
use IMSLF90
integer*4 i, j
complex*16 sol(2*l_max,1), r_p(2*n_max, 1)
if (n_max.ne.l_max) then
  write (*,*) ' Number of equations should be equal to the number of unknowns!'
  stop
end if
c_e1=(0.d00,0.d00); c_e2=(0.d00,0.d00); c_o1=(0.d00,0.d00); c_o2=(0.d00,0.d00)
if (m.eq.0) then
  sol(1:2*l_max, 1)=(0.d00,0.d00); r_p(1:2*l_max, 1)=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_e1(i)
  end do
  call lin_sol_gen(MATRIX(1:n_max, 1:l_max), r_p, sol)
  do i=1, l_max
    c_e1(i)=sol(i,1)
  end do
  r_p(1:2*n_max, 1)=(0.d00,0.d00); sol(1:2*l_max, 1)=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_e2(i)
  end do
  call lin_sol_gen(MATRIX(n_max+1:2*n_max, l_max+1:2*l_max), r_p, sol)
  do i=1, l_max
    c_e2(i)=sol(i,1)
  end do
else
   r_p(1:2*n_max, 1)=(0.d00,0.d00); sol(1:2*l_max, 1)=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_e1(i)
    r_p(n_max+i,1)=a_o2(i)
  end do
  call lin_sol_gen(MATRIX(1:2*n_max, 1:2*l_max), r_p, sol)
  do i=1, l_max
    c_e1(i)=sol(i,1)
    c_o2(i)=sol(i+l_max,1)
  end do
  r_p(1:2*n_max, 1)=(0.d00,0.d00); sol(1:2*l_max, 1)=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_o1(i)
    r_p(n_max+i,1)=a_e2(i)
  end do
  do n=1, n_max
    do l=1, l_max
       MATRIX(n, l_max+l)=-MATRIX(n, l_max+l)
       MATRIX(n_max+n, l)=-MATRIX(n_max+n, l)
    end do
  end do
  call lin_sol_gen(MATRIX(1:2*n_max, 1:2*l_max), r_p, sol)
  do i=1, l_max
    c_o1(i)=sol(i,1)
    c_e2(i)=sol(i+l_max,1)
  end do
end if
End Subroutine GEN_Solver
!
Subroutine GEN_Solver_MM
use Advertisement
use IMSLF90
integer*4 i
complex*16 sol(2*l_max,1), r_p(2*n_max, 1)
if (n_max.ne.l_max) then
  write (*,*) ' Number of equations should be equal to the number of unknowns!'
  stop
end if
c_p1=(0.d00,0.d00); c_p2=(0.d00,0.d00); c_m1=(0.d00,0.d00); c_m2=(0.d00,0.d00)
if (m.eq.0) then
  sol=(0.d00,0.d00); r_p=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_p1(i)
  end do
  call lin_sol_gen(MATRIX(1:n_max, 1:l_max), r_p, sol)
  do i=1, l_max
    c_p1(i)=sol(i,1)
  end do
  r_p=(0.d00,0.d00); sol=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_p2(i)
  end do
  call lin_sol_gen(MATRIX(n_max+1:2*n_max, l_max+1:2*l_max), r_p, sol)
  do i=1, l_max
    c_p2(i)=sol(i,1)
  end do
else
   r_p=(0.d00,0.d00); sol=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_m1(i) !
    r_p(n_max+i,1)=a_m2(i) !
  end do
  call lin_sol_gen(MATRIX(1:2*n_max, 1:2*l_max), r_p, sol)
  do i=1, l_max
    c_m1(i)=sol(i,1) !
    c_m2(i)=sol(i+l_max,1) !
  end do
  r_p=(0.d00,0.d00); sol=(0.d00,0.d00)
  do i=1, n_max
    r_p(i,1)=a_p1(i) !
    r_p(n_max+i,1)=a_p2(i) !
  end do
  do n=1, n_max
    do l=1, l_max
       MATRIX(n, l_max+l)=-MATRIX(n, l_max+l)
       MATRIX(n_max+n, l)=-MATRIX(n_max+n, l)
    end do
  end do
  call lin_sol_gen(MATRIX(1:2*n_max, 1:2*l_max), r_p, sol)
  do i=1, l_max
    c_p1(i)=sol(i,1) !
    c_p2(i)=sol(i+l_max,1) !
  end do
end if
End Subroutine GEN_Solver_MM
!
Subroutine GEN_inversion_MM
use Advertisement
use IMSLF90
complex*16 sol(2*l_max,1), r_p(2*n_max, 1), &
                   BM0(n_max, l_max), BM(2*n_max, 2*l_max)
if (n_max.ne.l_max) then
  write (*,*) ' Number of equations should be equal to the number of unknowns!'
  stop
end if
c_p1=(0.d00,0.d00); c_p2=(0.d00,0.d00); c_m1=(0.d00,0.d00); c_m2=(0.d00,0.d00)
if (m.eq.0) then
  call lin_sol_gen(MATRIX(1:n_max, 1:l_max), r_p, sol, nrhs=0, ainv=BM0)
  MATRIX(1:n_max, 1:l_max)=BM0
  do l=1, l_max
    do n=1, n_max
	  c_p1(l)=c_p1(l)+BM0(l,n)*a_p1(n)
	end do
  end do
  call lin_sol_gen(MATRIX(n_max+1:2*n_max, l_max+1:2*l_max), r_p, sol, nrhs=0, &
                          ainv=BM0)
  MATRIX(n_max+1:2*n_max, l_max+1:2*l_max)=BM0
  do l=1, l_max
    do n=1, n_max
	  c_p2(l)=c_p2(l)+BM0(l,n)*a_p2(n)
	end do
  end do
else
  call lin_sol_gen(MATRIX, r_p, sol, nrhs=0, ainv=BM)
  do l=1, l_max
    do n=1, n_max
	  c_m1(l)=c_m1(l)+BM(l,n)*a_m1(n)+BM(l,n+n_max)*a_m2(n)
	  c_m2(l)=c_m2(l)+BM(l+l_max,n)*a_m1(n)+BM(l+l_max,n+n_max)*a_m2(n)
	end do
  end do
  MATRIX=BM
  do n=1, n_max
    do l=1, l_max
	  BM(n, l+l_max)=-BM(n, l+l_max)
	  BM(n+n_max, l)=-BM(n+n_max, l)
	end do
  end do
  do l=1, l_max
    do n=1, n_max
	  c_p1(l)=c_p1(l)+BM(l,n)*a_p1(n)+BM(l,n+n_max)*a_p2(n)
	  c_p2(l)=c_p2(l)+BM(l+l_max,n)*a_p1(n)+BM(l+l_max,n+n_max)*a_p2(n)
	end do
  end do
end if
End Subroutine GEN_inversion_MM