;+ ;NAME: ; thm_ui_tplot_gui_load_tvars ; ;PURPOSE: ; Verifies input tplot variables for tplot_gui. This is actually the trickiest part of the whole process ; ;CALLING SEQUENCE: ; thm_ui_tplot_gui_validate_tvars,in_names,out_names=out_names ; ;INPUT: ; in_names: Input names supplied by user. ; ;Keywords: ;(Input): ; no_verify: value of the no_verify keyword supplied by user(optionally) ;(Output): ; out_names: csvector containing lists of validated names for plots ; all_names: All the non-pseudo variables that will be used for verification ; limits: csvector containing variable specific settings, somewhat collated in the case of pseudo variables, ; dlimits: csvector containing defaultish variable specific settings, somewhat collated in the case of pseudo variables ; ; ;SEE ALSO: ; ssl_general/misc/csvector.pro ; (Used to generate linked list, so that temporary tplot variables aren't needed) ; ; 06/06/2011: lphilpott, added option for user to rename variable before loading if a variable with that name already exists. ; 11/04/2011: lphilpott, moved thm_ui_tplot_gui_load_tvars_with_new_name to thm_ui_load_tvars_with_new_name - now it is also used by thm_ui_manage_data. ; Stopped it from looping when you click 'X' in the rename prompt dialogue. ; ;$LastChangedBy: lphilpott $ ;$LastChangedDate: 2012-02-17 10:31:23 -0800 (Fri, 17 Feb 2012) $ ;$LastChangedRevision: 9774 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_8_00/idl/themis/thm_ui_new/utilities/thm_ui_tplot_gui_funcs/thm_ui_tplot_gui_load_tvars.pro $ ;-------------------------------------------------------------------------------- ; Helper procedure to load a variable with a new user specified name to avoid conflict with an existing variable ; 'name' should be a valid tplot variable name that is already in use ; 'newname' is the name to load the variable under instead ; fail = 0 if variable is successfully loaded under new name ;pro thm_ui_tplot_gui_load_tvars_with_new_name, name, newname=newname, fail=fail ; ; compile_opt idl2, hidden ; fail = 1 ; guiNames = !thm_gui_new.loadedData->GetAll(/Parent) ; tempint = 0 ; tempname = name+'_temp_'+strtrim(systime(/julian),1)+'_'+strtrim(tempint,1) ; while in_set(tempname, guiNames) do begin ; tempint ++ ; tempname = name +'_temp_'+strtrim(systime(/julian),1)+'_'+strtrim(tempint,1) ; endwhile ; ; Rename existing variable with temp name ; !thm_gui_new.loadedData->SetDataInfo,name,newname=tempname,fail=fail ; if fail then return ; ; Load new variable ; if ~!thm_gui_new.loadedData->add(name) then begin ; dprint,"Problem adding: " + varsToRename[i] + " to GUI" ; endif ; ; Rename new variable with user specified name ; !thm_gui_new.loadedData->SetDataInfo,name,newname=newname,fail=fail ; if fail then return ; ; Rename original variable with its original name ; !thm_gui_new.loadedData->SetDataInfo,tempname, newname=name, fail=fail ; ;end ;NB: this routine is very similar to thm_ui_manage_data_import (in thm_ui_manage_data). If you ; need to fix a bug here you may need to fix it there too. pro thm_ui_tplot_gui_load_tvars,in_names,no_verify=no_verify,out_names=out_names,all_names=all_names compile_opt idl2 ;just in case undefine,out_names undefine,all_names undefine,limits undefine,dlimits ; make sure indexes are converted array of tplot variable names varnames = tnames(in_names,nd,/all) if nd eq 0 then begin return endif if keyword_set(no_verify) then begin clobber = 'yestoall' endif else begin clobber = '' endelse ; add tplot variables to loadedData object for i=0L,nd-1 do begin ; get pre-existing gui variable names guiNames = !thm_gui_new.loadedData->GetAll(/Parent) if size(guiNames, /type) ne 7 then guiNames='' ; check if pseudovariable get_data, varnames[i], data=d, dlimits=pseudo_dl, limits=pseudo_l if ~keyword_set(d) then begin ok = error_message('The variable '+varnames[i]+' does not appear to contain any data. Variable not loaded.', $ /center, title='Error in Load TVars') continue endif dSize = size(d, /type) if dSize eq 7 then begin ;load tplot pseudovariable ;extract_tags, pseudo_dl, pseudo_l subNames = tnames(d, sub_nd, ind=sub_ind, /all) undefine,valid_sub for j=0L,sub_nd-1 do begin ; load each component of pseudovariable ;make sure dlimits from pseudovar are inherited by component variables get_data, subNames[j], dlimits=sub_dl, limits=sub_l,data=d extract_tags, sub_dl, pseudo_dl extract_tags, sub_l, pseudo_l dSizeSub = size(d, /type) if dSizeSub eq 7 then begin ok = error_message('It looks like you attempted to load a pseudovariable containing a pseudovariable. Unfortunately that case is not handled by this procedure.', $ /center, title='Error in Load TVars') continue endif subvarexists = in_set(subNames[j], guiNames) if subvarexists then begin if (clobber ne 'yestoall' AND clobber ne 'notoall') then begin prompttext = 'The variable ' + strupcase(subNames[j]) + ' already exists in the GUI. Do you want to ' + $ 'overwrite it with the new variable?'+thm_ui_newline()+' '+thm_ui_newline()+$ 'Click "No" to load the variable ' + strupcase(subNames[j]) + ' under a new name.' + thm_ui_newline()+$ 'Click "Cancel" to stop the load and continue with the existing '+ strupcase(subNames[j]) +'.' clobber = thm_ui_prompt_widget(!thm_gui_new.guiId,obj_new(),!thm_gui_new.historyWin,promptText=promptText,$ /no,/yes,/allno,/allyes,/cancel, title='LOAD DATA: Variable already exists.', defaultvalue='cancel') ; loop so that hitting the widget kill button doesn't close the window ;while clobber eq '' do clobber = thm_ui_prompt_widget(!thm_gui_new.guiId,obj_new(),!thm_gui_new.historyWin,$ ; promptText=promptText,/no,/yes,/allno,/allyes,/cancel,$ ; title='LOAD DATA: Variable already exists.', defaultvalue='') endif if clobber eq 'yes' OR clobber eq 'yestoall' then begin h = 'TPLOT_GUI: ' + strupcase(subNames[j]) + ' will be overwritten.' !thm_gui_new.historyWin->Update, h ;tmp=!thm_gui_new.loadedData->Remove(newname) I'm not sure what this line was for. endif if (clobber eq 'notoall') then begin subVarsToRename = array_concat(subNames[j], subVarsToRename) endif else if (clobber eq 'no') then begin thm_ui_rename_variable,!thm_gui_new.guiId, subNames[j], !thm_gui_new.loadedData, $ !thm_gui_new.windowStorage, !thm_gui_new.historywin, $ success=success,newnames=newname if ~success then begin dprint,'Data rename and load canceled.' !THM_GUI_NEW.historyWin->update,'Data rename and load canceled.' continue endif else begin thm_ui_load_tvars_with_new_name, subNames[j], newname=newname, fail=fail if fail then begin ok = error_message('Error renaming variable ' + subNames[j], $ /center, title='Error in Load TVars',traceback=0) continue endif subNames[j]=newname endelse endif else if (clobber eq 'cancel') then begin h = 'LOAD DATA: ' + strupcase(subNames[j]) + $ ' not loaded to prevent overwrite of existing data.' !thm_gui_new.historyWin->Update, h endif else if ~!thm_gui_new.loadedData->addData(subNames[j],d,limit=sub_l,dlimit=sub_dl) then begin dprint,"Problem adding: " + subNames[j] + " to GUI" continue endif endif else if ~!thm_gui_new.loadedData->addData(subNames[j],d,limit=sub_l,dlimit=sub_dl) then begin dprint,"Problem adding: " + subNames[j] + " to GUI" continue endif if (clobber ne 'notoall') && (clobber ne 'cancel') then begin valid_sub = array_concat(subNames[j],valid_sub) endif endfor ; Handle renaming of any pseudo var components. if n_elements(subVarsToRename) ne 0 then begin thm_ui_rename_variable,!thm_gui_new.guiId, subVarsToRename, !thm_gui_new.loadedData, $ !thm_gui_new.windowStorage, !thm_gui_new.historywin, $ success=success,newnames=newsubnames if ~success then begin dprint,'Data rename and load canceled.' !THM_GUI_NEW.historyWin->update,'Data rename and load canceled.' endif else begin for i=0L,n_elements(subVarsToRename)-1 do begin get_data, subVarsToRename[i], dlimits=sub_dl, limits=sub_l,data=d extract_tags, sub_dl, pseudo_dl extract_tags, sub_l, pseudo_l thm_ui_load_tvars_with_new_name, subVarsToRename[i], newname=newsubnames[i], fail=fail if fail then begin ok = error_message('Error renaming variable ' + subVarsToRename[i], $ /center, title='Error in Load TVars',traceback=0) continue endif else if ~!thm_gui_new.loadedData->addData(newsubnames[i],d,limit=sub_l,dlimit=sub_dl) then begin; Not sure if this is necessary, but for consistency with other cases above it is included. dprint,"Problem adding: " + newsubnames[i] + "data to GUI" continue endif subVarsToRename[i]=newsubnames[i] valid_sub = array_concat(subVarsToRename[i],valid_sub) endfor endelse endif if n_elements(valid_sub) gt 0 then begin all_names = array_concat(valid_sub,all_names) out_names = csvector(valid_sub,out_names) endif endif else begin ; load standard tplot variable varexists = in_set(varnames[i], guiNames) if varexists then begin if (clobber ne 'yestoall' AND clobber ne 'notoall') then begin prompttext = 'The variable ' + strupcase(varnames[i]) + ' already exists in the GUI. Do you want to ' + $ 'overwrite it with the new variable?'+thm_ui_newline()+' '+thm_ui_newline()+$ 'Click "No" to load the variable ' + strupcase(varnames[i]) + ' under a new name.' + thm_ui_newline()+$ 'Click "Cancel" to stop the load and continue with the existing '+ strupcase(varnames[i]) +'.' clobber = thm_ui_prompt_widget(!thm_gui_new.guiId,obj_new(),!thm_gui_new.historyWin,promptText=promptText,$ /no,/yes,/allno,/allyes,/cancel, title='LOAD DATA: Variable already exists.', defaultvalue='cancel') ; while clobber eq '' do clobber = thm_ui_prompt_widget(!thm_gui_new.guiId,obj_new(),!thm_gui_new.historyWin,promptText=promptText,$ ; /no,/yes,/allno,/allyes,/cancel, title='LOAD DATA: Variable already exists.', defaultvalue='') endif if clobber eq 'yes' OR clobber eq 'yestoall' then begin h = 'TPLOT_GUI: ' + strupcase(varnames[i]) + ' will be overwritten.' !thm_gui_new.historyWin->Update, h endif if (clobber eq 'notoall') then begin varsToRename = array_concat(varnames[i], varsToRename) endif else if (clobber eq 'no') then begin thm_ui_rename_variable,!thm_gui_new.guiId, varnames[i], !thm_gui_new.loadedData, $ !thm_gui_new.windowStorage, !thm_gui_new.historywin, $ success=success,newnames=newname if ~success then begin dprint,'Data rename and load canceled.' !THM_GUI_NEW.historyWin->update,'Data rename and load canceled.' continue endif else begin thm_ui_load_tvars_with_new_name, varnames[i], newname=newname, fail=fail if fail then begin ok = error_message('Error renaming variable ' + varnames[i], $ /center, title='Error in Load TVars', traceback=0) continue endif varnames[i]=newname endelse endif else if (clobber eq 'cancel') then begin h = 'LOAD DATA: ' + strupcase(varnames[i]) + $ ' not loaded to prevent overwrite of existing data.' !thm_gui_new.historyWin->Update, h endif else if ~!thm_gui_new.loadedData->add(varnames[i]) then begin; adds the data for yes and yestoall dprint,"Problem adding: " + varnames[i] + " to GUI" continue endif ; if variable does not already exist: endif else if ~!thm_gui_new.loadedData->add(varnames[i]) then begin dprint,"Problem adding: " + varnames[i] + " to GUI" continue endif if (clobber ne 'notoall') && (clobber ne 'cancel') then begin all_names = array_concat(varnames[i],all_names) out_names = csvector(varnames[i],out_names) endif endelse endfor if n_elements(varsToRename) ne 0 then begin thm_ui_rename_variable,!thm_gui_new.guiId, varsToRename, !thm_gui_new.loadedData, $ !thm_gui_new.windowStorage, !thm_gui_new.historywin, $ success=success,newnames=newnames if ~success then begin dprint,'Data rename and load canceled.' !THM_GUI_NEW.historyWin->update,'Data rename and load canceled.' endif else begin for i=0L,n_elements(varsToRename)-1 do begin thm_ui_load_tvars_with_new_name, varsToRename[i], newname=newnames[i], fail=fail if fail then begin ok = error_message('Error renaming variable ' + varsToRename[i], $ /center, title='Error in Load TVars', traceback=0) continue endif varsToRename[i]=newnames[i] all_names = array_concat(varsToRename[i],all_names) out_names = csvector(varsToRename[i],out_names) endfor endelse endif end