;+ ;NAME: ; thm_ui_do_nudge ; ;PURPOSE: ; Abstracted nudge data operation ; ; ;CALLING SEQUENCE: ; thm_ui_do_nudge, ; ;INPUT: ; gui_id = widget id of the widget that called this program ; info = the info structure of the Main GUI ;OUTPUT: ; fail=fail ;HISTORY: ;$LastChangedBy: jwl $ ;$LastChangedDate: 2011-02-16 15:15:02 -0800 (Wed, 16 Feb 2011) $ ;$LastChangedRevision: 8231 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_8_00/idl/themis/thm_ui_new/utilities/thm_ui_do_nudge.pro $ ; ;--------------------------------------------------------------------------------- pro thm_ui_do_nudge,tn,nshift,shift_unit,shift_scale,use_records,isspec,loadedData,historyWin,statusbar,fail=fail,tn1=tn1 compile_opt idl2 fail = 1 tvo = loadeddata -> gettvarobject(tn) loadeddata -> getvardata, name = tn, time = t, $ data = d, limits = l, dlimits = dl, yaxis = v ; 2011-02-16 Delete temp tplot variable, bug fix QA127 del_data,tn If(ptr_valid(t) Eq 0) Then Begin statusbar->update, 'Invalid time pointer: '+tn return Endif Else Begin nshift_str = strcompress(/remove_all, string(nshift)) If(use_records) Then Begin nt = n_elements(*t) If(abs(nshift) Ge nt) Then Begin ntstr = strcompress(/remove_all, string(nt)) h = 'Shift value of '+nshift_str+' is GE the number of records:'+ntstr+'. Nudge fails' statusbar -> update, h historywin -> update, h Return Endif dt_all = (*t)[nt-1]-(*t)[0] ;offset for time arrays If(nshift Gt 0) Then Begin ; Here you have no clue about what the last record length is, so ; assume its the same as the second last record, then append the same array dtl = (*t)[nt-1]-(*t)[nt-2] t1 = [*t, (dt_all+dtl)+*t] ss_shift = lindgen(nt)+nshift ;will be the subscripts of the shifted time array t1 = t1[ss_shift] Endif Else If(nshift Lt 0) Then Begin dtl = (*t)[1]-(*t)[0] t1 = [*t-dt_all-dtl, *t] ss_shift = lindgen(nt)+nshift+nt ;will be the subscripts of the shifted time array t1 = t1[ss_shift] Endif Else Return Endif Else Begin t1 = *t+shift_scale*nshift Endelse ;Update status, history h = 'Nudging: '+tn+' by '+nshift_str+' '+shift_unit statusbar->update, h historywin->update, h tp1 = ptr_new(t1) ;Create a new variable name by appending the shift amount If((nshift Mod 1.0) Eq 0) Then Begin ext = strcompress(string(long(nshift)), /remove_all) Endif Else Begin ext = strcompress(string(nshift), /remove_all) Endelse tn1 = tn+'_'+ext+'_'+shift_unit ;Create a tplot variable If(isspec && ptr_valid(v)) Then data1 = {x:t1, y:*d, v:*v} $ Else data1 = {x:t1, y:*d} store_data, tn1, data = temporary(data1) If(ptr_valid(l)) Then store_data, tn1, limits = *l If(ptr_valid(dl)) Then Begin dlim = *dl If(isspec Eq 0) Then dlim.spec = 0 $ Else dlim.spec = 1 store_data, tn1, dlimits = temporary(dlim) Endif ;Copy variable into loaded_data object tvo_new = tvo->copy() tvo_new->setproperty, name = tn1 If(isspec Eq 0) Then tvo_new->setproperty, isspect = 0 ok = loadeddata->addtvarobject(tvo_new) ; 2011-02-16 Delete temp tplot variable, bug fix QA127 del_data,tn1 if ~ok then begin statusbar -> update, 'Trace Nudge to: '+tn1+' Failed' historywin -> update, 'Trace Nudge to: '+tn1+' Failed' return endif fail = 0 endelse end