pro medfil,arr,width,narr,mean,badval ;Modified 1/4/98 by BWBerger to change the initialization of narr from ;all zeros to all -999. This repairs a likely situation where the zeros ;can't be weeded out later if they exist where a badval is (if narr is ;all zeros, zeros remain where the indexes are not equal to g). ; applies a median filter of width WIDTH to an array ARR, then ; computes the mean MEAN, while avoid bad data denoted by BADVAL ; also returns median filtered array, NARR. g=where(arr ne badval,n) narr=fltarr(n_elements(arr))-999. ; the number of good data values must be greater than the width of ; the filter in order to proceed. if (n gt width) then begin narr(g)=median(arr(g),width) mean=total(narr(g))/n endif else begin mean=badval endelse return end