	function funx(itest)
	dimension xa(100),ya(100),y2(100)
	common/cfff/nnodi,hcf(100),xt(100),abb(100),abbin(50)
	common/spettro/al(100),asp(100,200),at(200)
	common/pinco/xxa(100,100),yya(100,100),nt(100)
	common/line1/line,kkt
c	write(*,*)'x',x,al(line),line
	funx=0.
	xx=0
	in=0
	nnnn=kkt
c	write(*,*)line,j, asp(line,1),asp(line,kkt),kkt
c
c	cerca il massimo della g(t)
c

	amax=1.e30
	do it =1,kkt
	if(asp(line,it).lt.amax)amax=asp(line,it)
	end do
	if(itest.ne.0)pppp=amax+itest
	if(itest.eq.0)pppp=100
	do 11 j=1,kkt
	xa(j)=0
	ya(j)=0.
	prova=asp(line,j)
	if(prova.gt.pppp)then
	nnnn=nnnn-1
	in=in+1
	go to 11
	end if
	xa(j-in)=at(j)
	ya(j-in)= -asp(line,j)
11	continue

	nt(line)=nnnn

	do j=1,nnnn
	xxa(j,line)=xa(j)
	yya(j,line)=ya(j)
	end do
c	write(*,*)nnnn
c	write(*,*)(xa(i),i=1,nnnn)
c	write(*,*)(ya(i),i=1,nnnn)
c	write(95,*)nnnn
c	write(95,*)(xa(i),i=1,nnnn)
c	write(95,*)(ya(i),i=1,nnnn)



	funx=xx
	return
	end

