#  <triplets.H Suspect.x [mdz=infinity  mdr=infinity] > quads.H
#	mdz is the maximum z jump to define a spike.
#	mdr is the maximum r jump to define a new track.
#	Append a fourth column to matrix with measure of suspicion.
#	w(i)  = 0  means data point is without suspicion.
#       w(i) += 1  means data point abuts a spike.
#       w(i) += 2  means data point is a spike.
#	w(i) += 4  means data point is at a boundary in (x,y) plane.
#                   Caution, most edges are also counted as spikes
#%
integer n1,n2, n3, three, nd
from history:	integer n1:nd, n2:three, n3=1
if( three != 3 ) call erexit( 'three!=3 ')
allocate:	real xyz(nd,3), xyzw(nd,4), dr( nd), dz(nd), w(nd)

subroutine doit( xyz,  nd,  xyzw,       dr,     dz,     w)
integer i,   id,       nd
real             xyz(nd,3), xyzw(nd,4), dr(nd), dz(nd), w(nd)
real mdr, mdz, rand01, edges, spikes
integer iseed
iseed = 19982		# my sort program is too slow when many equal values.
call sreed( 'in', xyz , 4*3*nd)
do id= 2, nd {
	dr(id) = sqrt( (xyz(id,1)-xyz(id-1,1))**2 +
	  	       (xyz(id,2)-xyz(id-1,2))**2   )
#	dz(id) = abs(   xyz(id,3)-xyz(id-1,3)  ) * (1+.00001*rand01(iseed)) +rand01(iseed)* 1.e-10
	dz(id) = abs(   xyz(id,3)-xyz(id-1,3)  ) * (1+.00001*.4) +.35* 1.e-10

	}
call snap('dr.H', nd,1, dr)
call snap('dz.H', nd,1, dz)
from par:	real    mdr=mdr, mdz=mdz
do id= 1, nd
	w(id) = 0.
w(1)  = 4.;		edges = 0.
w(nd) = 4.;		spikes = 0.
do id= 2, nd {  #  do id=2, nd-1   #  my edits  -jesse
	if( dz(id) > mdz)  { w(id) +=  1.;  w(id-1) +=  1.;  spikes += 1}
	if( dr(id) > mdr)  { w(id) +=  4.;  w(id-1) +=  4.;   edges += 1}
#	if( dz(id) > mdz)  { w(id+1)+=1. ;w(id) +=  1.;  w(id-1) +=  1.;  spikes += 1}# my edits  -jesse
#	if( dr(id) > mdr)  { w(id+1)+=4. ;w(id) +=  4.;  w(id-1) +=  4.;   edges += 1}


	}
do id= 1, nd {
	xyzw(id,1) = xyz(id,1)
	xyzw(id,2) = xyz(id,2)
	xyzw(id,3) = xyz(id,3)
	xyzw(id,4) = w  (  id)
	}

call putch( 'n1','i', nd)
call putch( 'n2','i', 4)
call putch( 'edges' ,'r', edges)
call putch( 'spikes','r', spikes)
call hclose()
call srite('out', xyzw, 4*4*nd)
return; end
