c	file inv14.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),av(20)
	dimension tarray(2)

	lda=20
	read(3,99)n
99	format(i2)
	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,no2
	  do 11 i=1,n
	    c(i,j)=glam(n3+i,j+1)
11	  continue
10	continue
	do 12 j=1,no2
	  do 13 i=1,n
	    c(i,no2+j)=glam(n3+i,n+no2+j)
13	  continue
12	continue
	do 14 i=1,n
	 alph(i)=-glam(n3+i,1)
14	continue
	tm=dtime(tarray)
	print *,'set up time = ',tm
	itask=1
	call dgefs(c,lda,n,alph,itask,ind,work,iwork)

	av(1)=1
	do 17 i=2,no2+1
	  av(i)=alph(i-1)
17	continue
	do 18 i=no2+2,n
	  av(i)=0
18	continue
	do 21 i=1,n
	  a=glam(i,1)
	  do 19 j=1,no2
	    a=a+glam(i,j+1)*alph(j)
19	  continue
	  do 20 j=1,no2
	    a=a+glam(i,n+no2+j)*alph(no2+j)
20	  continue
	  write(10,*)a
	  xi(i)=a
21	continue
	print *, 'unit number for output?'
	read(5,99)iout
	do 100 j=2,n
	  v(1,j)=av(j)-xi(j)/gv(1,j)
	write(iout,*)v(1,j)
100	continue
	write(iout,*)
	do 102 j=3,n-1
	  v(2,j)=v(1,j)+(gv(1,j)*(v(1,j)-av(j))+
     1	  gh(1,j)*(v(1,j)-v(1,j-1))+
     2	  gh(1,j+1)*(v(1,j)-v(1,j+1)))/gv(2,j)
	write(iout,*)v(2,j)
102	continue
	write(iout,*)
	do 103 i=3,no2
	  do 104 j=1+i,n+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(iout,*)v(i,j)
104	  continue
	write(iout,*)
103	continue
	tm=dtime(tarray)
	print *, 'compute and write time  =  ',tm
	stop
	end
