      subroutine subtecw(n,az,bz,xav,yav,zav,tecw)
	  dimension xi(20),yi(20),zi(20),wi(20) ! input from main program
	  common /BL1/xi,yi,zi,wi
C
      xav=0.
	yav=0.
	zav=0.
	sw=0.
      DO k=1,n
	sw=sw+wi(k)
	xav=xav+xi(k)*wi(k)
	yav=yav+yi(k)*wi(k)
	zav=zav+zi(k)*wi(k)
	ENDDO
      xav=xav/sw
	yav=yav/sw
	zav=zav/sw
C
      ca=0.
	cab=0.
	cb=0.
	c1=0.
	c2=0.
	DO k=1,n
	dx=xi(k)-xav
	dy=yi(k)-yav
	dz=zi(k)-zav
	ca=ca+dx**2*wi(k)
      cab=cab+dx*dy*wi(k)
	c1=c1+dx*dz*wi(k)
	cb=cb+dy**2*wi(k)
	c2=c2+dy*dz*wi(k)
	ENDDO
C
      bz=(c1*cab-c2*ca)/(cab**2-ca*cb)
	az=(c1-bz*cab)/ca
	tecw=zav-az*xav-bz*yav
	RETURN
	END



