;******************************************** ; This program finds the mode of an array ; using the histogram method. ; INPUT: ; missing=missing value in array ; binsize=size of the bins to bin the array ; var_array=array of the variables ; OUTPUT: ; var_mode=the mode of the array ;******************************************** pro hist_mode,missing,binsize,var_array,var_mode ; Find the good data in the array result=where(var_array gt missing,count) ; Find the mode if there is any good data if count gt 0 then begin minval=min(var_array[result]) maxval=max(var_array[result]) hist=histogram(var_array,binsize=binsize,min=minval,max=maxval) bins=minval+(findgen(n_elements(hist)))*binsize hist_max=max(hist,ind) var_mode=bins[ind] endif return end