c	file inv7.f
c	Solves the inverse resistor problem.
c	Takes lambda, produces gamma.

	implicit double precision (a-h,o-z)
	dimension glam(80,80),v(20,20),gh(20,21),gv(21,20)
	dimension alph(20),c(20,20),work(20),iwork(20)
	dimension xi(20)
	dimension tarray(2)

	lda=20
	read(3,*)n
	n2=2*n
	n3=3*n
	n4=4*n
	no2=n/2
	nm12=(n-1)/2
	np12=(n+1)/2
	do 5 j=1,n4
	  do 6 i=1,n4
	    read(3,*)glam(i,j)
6	  continue
5	continue
	tm=dtime(tarray)
	print *, 'read time  =  ',tm
	do 7 j=1,n
	  do 8 i=1,n+1
	    gv(i,j)=1
8	  continue
7	continue
	do 71 j=1,n+1
	  do 81 i=1,n
	    gh(i,j)=1
81	  continue
71	continue
	do 10 j=1,n
	  do 11 i=1,n
	    c(i,j)=glam(n4-n+i,n+j)
	    write(8,*)c(i,j)
11	  continue
10	continue
	do 12 i=1,n
	 alph(i)=-glam(n4-n+i,n-n+1)
12	continue
	itask=1
	ii=n
	call dgefs(c,lda,ii,alph,itask,ind,work,iwork)
	write(9,*)ind
	do 15 i=1,n
	  write(9,*)alph(i)
15	continue
	write(9,*)
	do 20 i=1,n
	  a=glam(n-n+i,n-n+1)
	  do 19 j=1,n
	    a=a+glam(n-n+i,n+j)*alph(j)
19	  continue
	  write(10,*)a
	  xi(i)=a
20	continue
	v(1,2)=-xi(1)/gh(1,2)
	write(11,*)v(1,2)
	do 101 j=3,2*no2
	  v(1,j)=-xi(j)/gv(1,j)
	write(11,*)v(1,j)
101	continue
	write(11,*)
	do 102 j=3,2*no2-1
	  v(2,j)=v(1,j)-(-gv(1,j)*v(1,j)+gh(1,j)*(v(1,j-1)-v(1,j))+
     1	  gh(1,j+1)*(v(1,j+1)-v(1,j)))/gv(2,j)
	write(11,*)v(2,j)
102	continue
	write(11,*)
	do 103 i=3,no2
	  do 104 j=1+i,2*no2+1-i
	   v(i,j)=v(i-1,j)-(gv(i-1,j)*(v(i-2,j)-v(i-1,j))+
     1	   gh(i-1,j)*(v(i-1,j-1)-v(i-1,j))+ 
     2	   gh(i-1,j+1)*(v(i-1,j+1)-v(i-1,j)))/gv(i,j)
	write(11,*)v(i,j)
104	  continue
	write(11,*)
103	continue
	print *, v(no2,no2+1)
	tm=dtime(tarray)
	print *, 'compute and write time  =  ',tm
	stop
	end
