pro subsample, A, B, suba, subb, delta,COUNT = count,KS = ks ;+ ; NAME: ; subsample ; PURPOSE: ; Routine to get the sub sample of A and B ; these two subsaples are supposed to follow the same distribution ; ; CALLING SEQUENCE: ; subsample, A, B, suba, subb, count = count, KS = ks ; ; INPUTS: ; A,B - two samples, its better to set A have less elements than B ; delta - the allowed difference between a and b ; ; OUTPUTS: ; suba - subscripts of elements in sample A with a match ; in sample B ; subb - subscripts of elements in sample B with a match ; in sample a. ; OPTIONAL KEYWORD OUTPUT: ; COUNT - number of the elements of the sub sample ; KS - KS test results between SA and SB where SA=a[suba] and SB=b[subb] ; ; HISTORY: ; Shiyin Shen Jan. 2015 ; ;- ;------------------------------------------------------------------------- NA=N_elements(A) NB=N_elements(B) Bflag=intarr(NB) Is=0 for i=0L,NA-1 do begin diff=abs(B-A[i]) sel=where(diff lt delta and Bflag eq 0,Nsel) if Nsel gt 0 then begin mdiff=min(diff[sel],mloc) if IS eq 0 then begin suba=i subb=sel[mloc] endif else begin suba=[suba,i] subb=[subb,sel[mloc]] endelse Bflag[sel[mloc]]=1 Is=Is+1 endif endfor count=Is if(Is gt 0) then begin Kstwo,A[suba],B[subb],D,prob ks=prob if prob lt 0.5 then begin print,'Caution KS test of two subsample with prob',prob endif endif end