pro filtzero,a,b,n ;Created 4/9/98 by C See ;This program filters out the common zero elements of arrays a & b ;and returns the resulting array size as n. ;a and b must be the unidimensional and have the same size. ;if all elements are zero, the programs returns n=0 and the arrays, ; a & b are untouched. sa=size(a) sb=size(b) dima=sa(sa(0)) dimb=sb(sb(0)) if dima ne dimb then begin print,'filtzero called with disparent arrays' goto, exit endif ;pack all the data into the top of the arrays... i=0 ;i steps through array's n=dima ;n holds the size of the final array again: while i lt n do begin if a(i) eq 0. and b(i) eq 0. then begin if dima eq 1 then goto,shorten_array ;one element, zero array set if i eq dima-1 then begin ;last set are 0,0 n=n-1 goto,shorten_array endif a(i:dima-1)=[a(i+1:dima-1),0] & b(i:dima-1)=[b(i+1:dima-1),0] ;moves data up one set n=n-1 goto,again endif i=i+1 endwhile shorten_array: ;shorten_array to the size of the valid data... if n eq 0 then goto,exit ;if all elements are zero a1=fltarr(n) b1=fltarr(n) a1=a(0:n-1) b1=b(0:n-1) a=fltarr(n) b=fltarr(n) a=a1 & b=b1 exit: return end