;+ ;NAME: ; thm_ui_cotrans_new ; ;PURPOSE: ; A performs the coordinate transformations ; ;CALLING SEQUENCE: ; thm_ui_cotrans_new, value,info ; ;INPUT: ; value: a string storing the destination coordinate system ; active: the set of variables to be transformed ; loadedData: the loadedData object ; sobj: the status bar object to which messages should be sent ; silent(optional): set this keyword to suppress popup messages.(Used during replay) ; ; ;OUTPUT: ; none ; ; SIDE EFFECT: New active variable for each prior active stored in loaded data ; and transformed into the new coordinate system with suffix added/changed ; ;HISTORY: ;$LastChangedBy: jwl $ ;$LastChangedDate: 2009-06-11 14:54:28 -0700 (Thu, 11 Jun 2009) $ ;$LastChangedRevision: 6149 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_5_1/idl/themis/thm_ui_new/panels/thm_ui_cotrans_new.pro $ ; ;--------------------------------------------------------------------------------- pro thm_ui_cotrans_new,value,active,loadedData,sobj,silent=silent compile_opt idl2,hidden all = loadedData->getAll(/parent) ; no children traces will hold support data so we don't bother either validcoords = ['dsl','ssl','spg','gsm','gse','gei','sm','geo'] if ~keyword_set(active) then begin ;info.statusBar->update,'No active data is transformable' sobj->update,'No active data is transformable' return endif else begin for i = 0,n_elements(active)-1 do begin tn_before = tnames('*') var = loadedData->getTvarObject(active[i]) var->GetProperty,name=name,coordSys=coordSys,observatory=probe,mission=mission origname=name if strlowcase(mission) ne 'themis' then begin ; result=error_message('No coordinate transformation support for non-THEMIS missions',$ ; title ='Error in Cotrans: ', /noname ) ; sobj->update, 'No coordinate transformation support for non-THEMIS missions' probe='xxx' ; set a dummy probe so non-THEMIS data can be converted ; continue ;skip the rest of the loop endif if strlowcase(coordSys) eq 'n/a' then begin if ~keyword_set(silent) then begin result=error_message('Sorry. '+name+ ' does not have its coordinate system defined. Cannot perform transformation.', $ title ='Error in Cotrans: ', /noname, /center,traceback=0) endif sobj->update, 'Sorry. '+name+ ' does not have its coordinate system defined. Cannot perform transformation.' thm_ui_cleanup_tplot,tn_before,del_vars=to_delete if to_delete[0] ne '' then begin store_data,to_delete,/delete endif continue ;skip the rest of the loop endif if strlowcase(probe) eq 'tha' then probe = 'a' if strlowcase(probe) eq 'thb' then probe = 'b' if strlowcase(probe) eq 'thc' then probe = 'c' if strlowcase(probe) eq 'thd' then probe = 'd' if strlowcase(probe) eq 'the' then probe = 'e' if strlowcase(probe) eq 'xxx' then probe = 'x' ; dummy probe for non-THEMIS data ok_probe = where(['a', 'b', 'c', 'd', 'e', 'x'] Eq probe) if ok_probe[0] eq -1 then begin if ~keyword_set(silent) then begin result=error_message('Sorry. No coordinate transformation support for ground-based data: '+probe,$ title ='Error in Cotrans: ', /noname, /center,traceback=0) endif sobj->update, 'Sorry. No coordinate transformation support for ground-based data: '+probe thm_ui_cleanup_tplot,tn_before,del_vars=to_delete if to_delete[0] ne '' then begin store_data,to_delete,/delete endif continue ;skip the rest of the loop endif if strlowcase(coordSys) eq 'spg' || strlowcase(coordSys) eq 'dsl' || strlowcase(coordSys) eq 'ssl' || $ strlowcase(value) eq 'spg' || strlowcase(value) eq 'dsl' || strlowcase(value) eq 'ssl' then begin if probe eq 'x' then begin ; make sure non-THEMIS data isn't converted to spg, dsl, or ssl coords if ~keyword_set(silent) then begin result=error_message('Sorry. '+name+ ' is not THEMIS data. Can not convert to SPG, DSL, or SSL coordinates.',$ title ='Error in Cotrans: ', /noname, /center,traceback=0) endif sobj->update, 'Sorry. '+name+ ' is not THEMIS data. Can not convert to SPG, DSL, or SSL coordinates.' thm_ui_cotrans_new_cleanup,tn_before continue ;skip the rest of the loop endif spinras = 'th'+probe+'_state_spinras' spindec = 'th'+probe+'_state_spindec' if (~tnames(spinras) && ~in_set(spinras,all)) || $ (~tnames(spindec) && ~in_set(spindec,all)) then begin if ~keyword_set(silent) then begin result=dialog_message(String('State data not loaded for probe: ' + probe + string(10B) + "This data is required to perform the requested transformation." + string(10B) + "Would you like to load it?"),/Question,/CENTER) endif else begin result = 'Yes' endelse sobj->Update, String('State data not loaded for probe: ' + probe + string(10B)) if strlowcase(result) eq 'no' then begin thm_ui_cleanup_tplot,tn_before,del_vars=to_delete if to_delete[0] ne '' then begin store_data,to_delete,/delete endif continue endif else begin thm_load_state,probe=probe,/get_support_data if ~in_set(spindec,all) || ~in_set(spinras,all) then begin if ~loadedData->add(spinras) && ~keyword_set(silent) then begin ok = error_message('error adding data',traceback=0,/center,title='Error in Cotrans New') endif if ~loadedData->add(spindec) && ~keyword_set(silent) then begin ok = error_message('error adding data',traceback=0,/center,title='Error in Cotrans New') endif endif endelse endif ;if the state data is stored in gui memory, then offload it into tplot variables ;for the duration of this operation if (~tnames(spinras) && in_set(spinras,all)) then begin tmp = loadedData->getTvarData(spinras) endif if (~tnames(spindec) && in_set(spindec,all)) then begin tmp = loadedData->getTvarData(spindec) endif endif out_suffix = '_'+strlowcase(value) in_suffix = '' ;info.statusBar->update,'Coordinate Transforming: ' + name sobj->update,String('Coordinate Transforming: ' + name) for j = 0,n_elements(validCoords)-1 do begin if (pos = stregex(name,'_'+validCoords[j]+'$',/fold_case)) ne -1 then begin in_suffix = '_'+ validCoords[j] name = strmid(name,0,pos) break endif endfor catch,err if err ne 0 then begin catch,/cancel if ~keyword_set(silent) then begin ok = error_message('caught cotrans error',/traceback,/center,title='Error in Cotrans New') endif thm_ui_cotrans_new_cleanup,tn_before return endif else begin thm_cotrans,name,in_suffix=in_suffix,out_suffix=out_suffix,out_vars=out_var,probe=probe,in_coord=coordSys,out_coord=value endelse catch,/cancel if ~keyword_set(out_var) then begin ;info.statusbar->update,'Data not transformed: '+name sobj->update,String('Data not transformed: '+name) thm_ui_cotrans_new_cleanup,tn_before continue endif else begin ;info.statusbar->update,'Successfully transformed variable to: ' + out_var[0] sobj->update,String('Successfully transformed variable to: ' + out_var[0]) endelse out = var->copy() out->setProperty,coordSys = value,name=out_var if ~loadedData->addTvarObject(out) && ~keyword_set(silent) then begin ok = error_message('error adding data',traceback=0,/center,title='Error in Cotrans New') endif ;delete the left over variables from normal memory(they'll still be stored as traces within loaded data) ; store_data,spinras,/delete ; store_data,spindec,/delete loadedData->clearActive,origname loadedData->setActive,out_var thm_ui_cleanup_tplot,tn_before,del_vars=to_delete if to_delete[0] ne '' then begin store_data,to_delete,/delete endif endfor endelse end