;+ ; NAME: ; INTERPOLATE_BAD_POINTS ; ; PURPOSE: ; ; The purpose of this function is to provide ; a simple method of finding and replacing ; bad data points in a time series using ; linear interpolation. ; ; AUTHOR: ; ; Nathan Johnson ; University of Arizona ; Department of Atmospheric Sciences ; johnson AT atmo DOT arizona DOT edu ; ; CATEGORY: ; ; Data processing ; ; CALLING SEQUENCE (WITH REQUIRED INPUT PARAMETERS): ; ; new_data = INTERPOLATE_BAD_POINTS(data, -9999) ; ; ; OPTIONAL INPUT PARAMETERS: ; None. ; ; INPUT KEYWORD PARAMETERS: ; None ; ; OUTPUT KEYWORD PARAMETERS: ; None. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None known. ; ; RESTRICTIONS: ; None. ; ; EXAMPLE: ; ; new_data = INTERPOLATE_BAD_POINTS(data, -9999) ; ; This command will find the bad data points, those ; values equal to -9999, and do a linear interpolation ; to fill those values with "good" values. ; ; ; MODIFICATION HISTORY: ; ; Written by: Nathan Johnson, 16 January 2008. ;- Function INTERPOLATE_BAD_POINTS, array, bad_val new_array=array n = 0 WHILE new_array[0] eq bad_val DO BEGIN new_array = new_array[1:*] n += 1 ENDWHILE m = 0 WHILE new_array[N_ELEMENTS(new_array)-1] eq bad_val DO BEGIN new_array = new_array[0:N_ELEMENTS(new_array)-2] m += 1 ENDWHILE bad = Where(new_array eq bad_val, nbad, COMPLEMENT=good, NCOMPLEMENT=ngood) IF nbad GT 0 && ngood GT 1 THEN new_array[bad] = INTERPOL(new_array[good], good, bad) return, new_array END