module OW_pickint

implicit none

contains

subroutine owpickint(nh,nhh,pick1,sh,coorz2)

integer,pointer,dimension(:,:)				:: pick1
real,pointer,dimension(:)					:: z,x,weight,sh
real, allocatable,dimension(:,:)				:: coorz1,coorz2
integer							:: nhorz
integer							:: i,m,n,j,minm,maxm,k,stat,ns,ms,nh,nhh(999)
integer,allocatable						:: minx(:),maxx(:)

    n=0; m=1
    do i=1,nh
       n=n+nhh(i)
       allocate(z(n-m+1));z=float(pick1(m:n,2))
       allocate(x(n-m+1));x=float(pick1(m:n,4))
       allocate(weight(n-m+1)); weight=1.
       call lint_init (.true.,float(pick1(m,4)),1.,sog%xm%n,x,weight)
       stat = lint_lop (.true.,.false., coorz1(i,:), z)
!       call lint1_init (float(pick1(m,4)),1.,x)
!       call solver_reg( m=coorz1(i,:), d=z, Fop=lint1_lop, Aop=igrad1_lop, &
!			stepper=cgstep, nAop=sog%xm%n, niter=20,eps=0.1)
       coorz1(i,int(x(n-m+1)):sog%xm%n)=9999.
       m=m+nhh(i)
       deallocate(z,x,weight)
    end do

    allocate(coorz2(sog%sh%n,sog%xm%n))
    allocate(weight(j)); weight=1.
    call lint1_init (1.,1.,sh)
    do i=1,sog%xm%n
       call solver_reg( m=coorz2(:,i), d=coorz1(:,i), Fop=lint1_lop, Aop=igrad1_lop, &
			stepper=cgstep, nAop=sog%sh%n, niter=20,eps=0.1)
       coorz2(1:int(sh(1)-1),i)=9999.
       coorz2(int(sh(j)+1):sog%sh%n,i)=9999.
    end do
    deallocate(weight)

 end if	
