c
c *** Find the closest nodes to the observation point ***
c
      parameter(mnode=300000)
      dimension x(mnode),y(mnode),z(mnode)

c *** Observation location ***
c      xo=5.0
c      yo=5.0
c      zo=0.0
      write(*,*)'Enter Location of the OBP (km):='
      read(*,*)xo,yo,zo

c *** Open node data ***
      open(10,file='try.2.node',status='old')
        read(10,*)nnode,ntet,ninfo,nflag
        write(*,*)'Number of nodes=',nnode
        if(nnode.ge.mnode)then
          write(*,*)'nnode>mnode !!!'
          stop
        end if
        do i=1,nnode
          read(10,*)n,x(i),y(i),z(i),nf
        end do
      close(10)

c *** Find the domain lengths and the minimum node length ***
      xmin=99999.0
      xmax=0.0      
      ymin=99999.0
      ymax=0.0      
      zmin=99999.0
      zmax=0.0      
      do i=1,nnode
        if(x(i).lt.xmin)xmin=x(i)
        if(x(i).gt.xmax)xmax=x(i)
        if(y(i).lt.ymin)ymin=y(i)
        if(y(i).gt.ymax)ymax=y(i)
        if(z(i).lt.zmin)zmin=z(i)
        if(z(i).gt.zmax)zmax=z(i)
      end do
      write(*,*)'xmin, xmax=',xmin,xmax
      write(*,*)'ymin, ymax=',ymin,ymax
      write(*,*)'zmin, zmax=',zmin,zmax

c *** Find the closest node number to the OB point ***
      dlmin=xmax*ymax
      nmin=0
      do i=1,nnode
        dl=((x(i)-xo)*(x(i)-xo)+(y(i)-yo)*(y(i)-yo)
     *     +(z(i)-zo)*(z(i)-zo))
        if(dl.lt.dlmin)then
          dlmin=dl
          nmin=i
        end if
      end do
      write(*,*)
      write(*,1000)nmin,x(nmin),y(nmin),z(nmin)
 1000 format(' N-obsevation ,x,y,z=',i9,3f9.3)

      stop
      end




