pro fill_missing_data, time_offset, interval, interval_comp, vars_array, data_struct, missing_data_flag ;************************************************************************* ;* Description: ;* This procedure examines missing data from passed data arrays ;* and dertermines if space should be added based on the acceptable ;* intervals assigned. ;* ;* Input: ;* time_offset, interval, interval_comp, vars_array, data_struct, missing_data_flag ;* ;* Output: ;* time_offset, data_struct, missing_data_flag ;* ;* History: ;* Created for the purpose of adding missing shot data to prevent ;* images from distorting across time axis, by Chris Galli. ;* ;* Notes: ;* 1. Parameter time_offset must exist in $MAIN$. ;* 2. Parameter vars_array contains a 2d array of string values where: ;* a. 1st dimension is name of data array variable ;* b. 2nd dimension is the size of any existing 2nd dimensions- ;* use 0 if the data array is only 1d. ;* ;************************************************************************* ; ; Create a new time_offset array to compare with original ; time_offset2 = time_offset[1:n_elements(time_offset)-1] dummy = time_offset[n_elements(time_offset)-1] time_offset2 = [time_offset2, dummy] ; Break apart vars_array for easier use num_vars = n_elements(vars_array[*,0]) vars = vars_array[*,0] vars2d = vars_array[*,1] ; Set new arrays to the old for concat later new_time_offset = time_offset for i = 0, num_vars-1 do begin ok = execute('new_' + vars[i] + '=data_struct.' + vars[i]) endfor ; Find the delta of time offset subscripts (t2-t1) delta_time = time_offset2 - time_offset result = where(delta_time gt interval_comp, count) ; print, 'Number of data gaps: ', count ; ; Loop through all data gaps and insert missing data values ; if count gt 0 then begin missing_data_flag = 1.0 ; we have missing data to report total_missing_shots = 0.0 ; Set values for missing data ; for i = 0, num_vars-1 do begin if vars2d[i] gt 0 then begin ok = execute('missing_data_' + vars[i] + $ '=make_array(/float, ' + string(vars2d[i]) + ', value=-8888)' ) endif else begin ok = execute('missing_data_' + vars[i] + '= -8888') endelse endfor ; Loop through and create each section of missing data ; for i = 0, count-1 do begin sub=result[i] ;print, 'how big is the gap?: ',delta_time[sub] missing_shots = fix(delta_time[sub] / interval) ;print, 'missing shots are: ', missing_shots missing_shot_time = lonarr(missing_shots) missing_time_offset = lonarr(missing_shots) for j = 0,num_vars-1 do begin if vars2d[j] gt 0 then begin ok = execute('missing_' + vars[j] + '= fltarr(missing_shots, ' + string(vars2d[j]) + ' )' ) endif else begin ok = execute('missing_' + vars[j] + '= fltarr(missing_shots)' ) endelse endfor for j = 1, missing_shots do begin missing_shot_time[j-1] = time_offset[sub] + (interval * j) for k = 0,num_vars-1 do begin if vars2d[k] gt 0 then begin ok = execute('missing_' + vars[k] + '[j-1, *] = missing_data_' + vars[k] ) endif else begin ok = execute('missing_' + vars[k] + '[j-1] = missing_data_' + vars[k] ) endelse endfor endfor ; Add missing shots into the new array at the right place new_time_offset = [ new_time_offset[0:sub+total_missing_shots], $ missing_shot_time, $ new_time_offset[sub+total_missing_shots+1:n_elements(time_offset)+total_missing_shots-1] ] for j = 0, num_vars-1 do begin ok = execute('new_' + vars[j] + $ ' = [ new_' + vars[j] + '[0:sub+total_missing_shots,*], ' + $ 'missing_' + vars[j] + ', new_' + vars[j] + $ '[sub+total_missing_shots+1:n_elements(time_offset)+total_missing_shots-1, * ] ]' ) endfor ; For example, backscatter looks like: ; new_backscatter = [ new_backscatter[0:sub+total_missing_shots,*], $ ; missing_backscatter, $ ; new_backscatter[sub+total_missing_shots+1:n_elements(time_offset)+total_missing_shots-1, * ] ] total_missing_shots = total_missing_shots + missing_shots endfor ; ; Set new arrays ; ; Reset old data_struct data_struct = create_struct('name','new_arrays') ; Create new data_struct array time_offset = new_time_offset for j = 0, num_vars-1 do begin ok = execute('data_struct = create_struct(vars[j], new_' $ + vars[j] + ', data_struct)' ) endfor endif end