;+ ;NAME: ; thm_gui ;PURPOSE: ; Widget program for THEMIS data Analysis, to get the infomation in ; the widget ; use widget_control, widget_id, uval = state ; state = {wmaster:master, $ ;master widget id ; sttime_display:sttime_display, $ ;start_time display id ; entime_display:entime_display, $ ;end_time display id ; datalist:datalist, $ ;datalist id ; plottypelist:plottypelist, $ ;plot type list id ; dtyplist:dtyplist, $ ;data type list id ; stationlist:stationlist, $ ;station list id ; lvllist:lvllist, $ ;data level list id ; sclist:sclist, $ ;probe list id ; plot_type:'X', $ ;plot_type ; st_time:tt0, $ ;start_time, double ; en_time:tt1, $ ;end_time ; data:ptr_new(), $ ;a pointer to the data_quants array in the tplot common ; tplot_vars:ptr_new(), $ ;points to the tplot_vars structure ; plot_configs:ptr_new(), $ ;points to the plot_configs structure ; current_config:ptr_new(), $;points to the current_config ; data_id:ptr_new(), $ ;a pointer to an array of strings, 1 for each loaded dataset ; history:ptr_new(init_history), $ ;a string array with the analysis history ; dtypstring:'mag', $ ;the most recently loaded datatype ; lvl:'l2', $ ;level 0, 1 or 2 ; sc:'thg', $ ;probe_id, 'thg' is ground magnetometer ; station:'all'} ;CALLING SEQUENCE: ; thm_gui ;HISTORY: ; sep-2006, jmm, jimm@ssl.berkeley.edu ; 13-dec-2006, jmm, changed format of times in history strings, added ; clear_history button ; 14-dec-2006, jmm, added delete_data button ; 8 - 16-jan 2007, all sorts of changes, to describe the different ; data types. Input is now restricted to thm_load pograms ; 8-feb-2007, jmm,, changed the name ;$LastChangedBy$ ;$LastChangedDate$ ;$LastChangedRevision$ ;$URL$ ; ;- @tplot_com ;this is available from the main level Pro thm_gui_event, event common thm_gui_private, plot_types, data_types, $ stations, astations, sc_arr, arr_user, $ valid_dlist, valid_ilist @tplot_com ;Put a catch here to insure that the state remains defined err_xxx = 0 catch, err_xxx If(err_xxx Ne 0) Then Begin catch, /cancel message, /info, 'FYI:' help, /last_message, output = err_msg For j = 0, n_elements(err_msg)-1 Do print, err_msg[j] If(is_struct(state)) Then Begin widget_control, event.top, set_uval = state, /no_copy Endif Return Endif ; what happened? widget_control, event.id, get_uval = uval Case uval Of 'EXIT': Begin widget_control, event.top, get_uval = state, /no_copy If(is_struct(state)) Then Begin If(state.tplot_wid Gt 0) Then $ If(widget_valid(state.tplot_wid)) Then widget_control, state.tplot_wid, /destroy Endif widget_control, event.top, /destroy End 'HELP': thm_ui_help 'USERLIST':Begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.userlist, /list_select) npindex = n_elements(pindex) For j = 0, npindex-1 Do Begin test_str = arr_user[pindex[j]] call_procedure, test_str Endfor thm_ui_update_history, arr_user[pindex], state widget_control, event.top, set_uval = state, /no_copy End 'DATALIST':Begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.datalist, /list_select) pindex = pindex+1 tv_names = tnames() newnames = tv_names[pindex-1] If(ptr_valid(state.active_vnames)) Then ptr_free, state.active_vnames state.active_vnames = ptr_new(newnames) history_ext = thm_ui_multichoice_history(' varnames = ', newnames) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy ; thm_ui_update_data_display, event.top End 'LOAD': Begin widget_control, event.top, get_uval = state, /no_copy widget_control, state.sttime_display, $ ;reset displayed times set_val = time_string(state.st_time) widget_control, state.entime_display, $ set_val = time_string(state.en_time) If(ptr_valid(state.dtyp)) Then dtype = *state.dtyp $ Else message, 'Choose a data type' If(ptr_valid(state.station)) Then station = *state.station $ Else station = 'all' If(ptr_valid(state.astation)) Then astation = *state.astation $ Else astation = 'all' If(ptr_valid(state.sc)) Then probe = *state.sc $ Else probe = ['A', 'B', 'C', 'D', 'E'] tv_names = thm_ui_load_data_fn(state.st_time, state.en_time, $ dtype, station, astation, $ probe, data_ss, history_ext) If(data_ss[0] Ne -1) Then Begin dss = thm_ui_set_active_dset(tv_names, state) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top Endif Else Begin message, /info, 'Data input is not a valid structure, no loading' widget_control, event.top, set_uval = state, /no_copy Endelse End 'CALEFI': Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_cal_data, state, 'EFI' widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top End 'CALFBK': Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_cal_data, state, 'FBK' widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top End 'CALFGM': Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_cal_data, state, 'FGM' widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top End 'CALFIT': Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_cal_data, state, 'FIT' widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top End 'CALMOM': Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_cal_data, state, 'MOM' widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top End 'PTYPE':Begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.plottypelist, /list_select) state.plot_type = plot_types[pindex] ;in common, this can't not work message, /info, 'Plot_type set to; '+plot_types[pindex] history_ext = 'plot_type = '''+plot_types[pindex]+'''' thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'DTYP': begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.dtyplist, /list_select) If(ptr_valid(state.dtyp)) Then ptr_free, state.dtyp state.dtyp = ptr_new(data_types[pindex]) np = n_elements(pindex) history_ext = thm_ui_multichoice_history('dtype = ', data_types[pindex]) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'SC': begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.sclist, /list_select) sc = sc_arr[pindex] all_chosen = where(sc Eq 'ALL', nall) If(nall Gt 0) Then sc = sc_arr[1:*] If(ptr_valid(state.sc)) Then ptr_free, state.sc state.sc = ptr_new(sc) history_ext = thm_ui_multichoice_history('probe = ', sc) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'STATION': begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.stationlist, /list_select) stp = stations[pindex] all_chosen = where(stp Eq 'ALL', nall) If(nall Gt 0) Then stp = 'ALL' If(ptr_valid(state.station)) Then ptr_free, state.station state.station = ptr_new(stp) history_ext = thm_ui_multichoice_history('gmag_station = ', stp) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'ASI_STATION': begin widget_control, event.top, get_uval = state, /no_copy pindex = widget_info(state.astationlist, /list_select) stp = astations[pindex] all_chosen = where(stp Eq 'ALL', nall) If(nall Gt 0) Then stp = 'ALL' If(ptr_valid(state.astation)) Then ptr_free, state.astation state.astation = ptr_new(stp) history_ext = thm_ui_multichoice_history('asi_station = ', stp) thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'PLOT': Begin message, /info, 'Not currently Fully Implemented' widget_control, event.top, get_uval = state, /no_copy thm_ui_plot_data, state, history_ext thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy End 'HIST':Begin widget_control, event.top, get_uval = state, /no_copy thm_ui_history, state widget_control, event.top, set_uval = state, /no_copy End 'CLEAR_HIST':Begin widget_control, event.top, get_uval = state, /no_copy If(ptr_valid(state.history)) Then Begin ptr_free, state.history state.history = ptr_new('NONE') Endif widget_control, event.top, set_uval = state, /no_copy End 'SHOWACTIVE':Begin thm_ui_update_data_display, event.top, /add_a End 'STTIME':Begin t0 = thm_ui_tselect_fn() If(is_struct(t0)) Then Begin t1 = time_double(temporary(t0)) t0 = time_string(t1) widget_control, event.top, get_uval = state, /no_copy state.st_time = t1 ;Set the value in the text widget too display_id = state.sttime_display widget_control, display_id, set_val = t0 ;set a history value string history_ext = 'start_time = '''+time_string(t1)+'''' thm_ui_update_history, history_ext, state ;set the value in the master widget widget_control, event.top, set_uval = state, /no_copy Endif Else Begin message, /info, 'Bad time selection, No action taken' Endelse End 'ENTIME':Begin t0 = thm_ui_tselect_fn() If(is_struct(t0)) Then Begin t1 = time_double(temporary(t0)) t0 = time_string(t1) widget_control, event.top, get_uval = state, /no_copy state.en_time = t1 display_id = state.entime_display widget_control, display_id, set_val = t0 history_ext = 'end_time = '''+time_string(t1)+'''' thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy Endif Else Begin message, /info, 'Bad time selection, No action taken' Endelse End 'STTIME_DISPLAY':Begin widget_control, event.id, get_val = temp_string t0 = time_string(temp_string) If(event.type Le 2) Then Begin If(is_string(t0)) Then Begin t1 = time_double(t0) widget_control, event.top, get_uval = state, /no_copy state.st_time = t1 history_ext = 'start_time = '''+time_string(t1)+'''' thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy Endif Else Begin message, /info, 'No action taken' Endelse Endif End 'ENTIME_DISPLAY':Begin widget_control, event.id, get_val = temp_string t0 = time_string(temp_string) If(event.type Le 2) Then Begin If(is_string(t0)) Then Begin t1 = time_double(t0) widget_control, event.top, get_uval = state state.en_time = t1 history_ext = 'end_time = '''+time_string(t1)+'''' thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy Endif Else Begin message, /info, 'Bad time selection, No action taken' Endelse Endif End 'CALL_TPLOT':Begin thm_ui_update_data_display, event.top, /add_a ;Only call a new one if there is no valid one up widget_control, event.top, get_uval = state, /no_copy If(widget_valid(state.tplot_wid)) Then Begin widget_control, state.tplot_wid, /show widget_control, event.top, set_uval = state, /no_copy Endif Else Begin widget_control, event.top, set_uval = state, /no_copy thm_ui_call_tplot, event.top, tplot_wid widget_control, event.top, get_uval = state, /no_copy state.tplot_wid = tplot_wid widget_control, event.top, set_uval = state, /no_copy Endelse End 'DELETE':Begin ;deletes the active datasets widget_control, event.top, get_uval = state, /no_copy If(ptr_valid(state.active_vnames)) Then Begin vnames = *state.active_vnames vnames0 = vnames store_data, vnames0, /delete thm_ui_set_state_ptrs, state ;you need to reset the active dataset If(ptr_valid(state.data)) Then Begin nnn = n_elements(*state.data) If(nnn Gt 1) Then Begin tv_names = tnames() dss = thm_ui_set_active_dset(tv_names[0], state) Endif Else Begin ;no data left If(ptr_valid(state.active_vnames)) Then $ ptr_free, state.active_vnames Endelse Endif Else Begin ;no data left If(ptr_valid(state.active_vnames)) Then ptr_free, state.active_vnames Endelse ;history is hard... vnames = ''''+vnames+'''' npindex = n_elements(vnames) If(npindex Eq 1) Then history_ext = ' del_varnames = '+vnames[0] $ Else Begin history_ext = 'del_varnames = ['+vnames[0] For j = 1, npindex-1 Do $ history_ext = history_ext+','+vnames[j] history_ext = history_ext+']' Endelse history_ext = [history_ext, 'store_data, /delete, del_varnames'] thm_ui_update_history, history_ext, state widget_control, event.top, set_uval = state, /no_copy thm_ui_update_data_display, event.top Endif Else message, /info, 'No datasets chosen to delete' End Endcase Return End Pro thm_gui, test_dbase_dir = test_dbase_dir common thm_gui_private, plot_types, data_types, $ stations, astations, sc_arr, arr_user, $ valid_dlist, valid_ilist @tplot_com ;for testing ;Call the new thm_init program thm_init If(keyword_set(test_dbase_dir)) Then Begin ;add a slash if necessary to avoid issues in thm_load_gmag, etc.... tdd = strcompress(/remove_all, test_dbase_dir) sl = strlen(tdd) sl1 = strmid(tdd, sl-1, 1) If(sl1 Ne '/' And sl1 Ne '\') Then Begin os_family = strupcase(!version.os_family) If(os_family Eq 'WINDOWS') Then tdd = tdd+'\' Else tdd = tdd+'/' Endif setenv, 'THEMIS_DATA_DIR='+tdd !themis.local_data_dir = getenv('THEMIS_DATA_DIR') remote_host_dir = 'http://sprg.ssl.berkeley.edu/data/themis/' setenv, 'THEMIS_REMOTE_HOST_DIR'+'='+remote_host_dir !themis.remote_data_dir = getenv('THEMIS_REMOTE_HOST_DIR') Endif ;get data types, probe and stations valid_dlist = thm_ui_valid_dtype(valid_ilist) ;gmag stations thm_load_gmag, /valid_names, site = gmag_stations stations = ['all', gmag_stations] stations = strupcase(strcompress(/remove_all, stations)) ;asi stations thm_load_asi, /valid_names, site = asi_stations astations = ['all', asi_stations] astations = strupcase(strcompress(/remove_all, astations)) ;the other data types nsc_ss = n_elements(valid_dlist) data_types = strarr(nsc_ss) For j = 0, nsc_ss-1 Do Begin If(valid_ilist[j] Eq valid_dlist[j]) Then Begin data_types[j] = valid_dlist[j] Endif Else data_types[j] = valid_ilist[j]+'/'+valid_dlist[j] Endfor data_types = strupcase(data_types) sc_arr = ['ALL', 'A', 'B', 'C', 'D', 'E'] ;build master widget master = widget_base(/row, title = 'THEMIS data analysis', $ /tlb_frame_attr, /align_top) print, 'Master widget id', master ;build controls widget controls = widget_base(master, /col, /align_left) ;data widget data_control = widget_base(master, /col, /align_left) ;another data widget data_control1 = widget_base(master, /col, /align_left) ;button widget buttons = widget_base(master, /col, /align_left) ;plot type list plottype = widget_base(data_control, /col, /align_left, frame = 5) plottype_label = widget_label(plottype, value = 'Plot Type') plot_types = ['SCREEN', 'PNG'] plottypelist = widget_list(plottype, value = plot_types, $ ysize = n_elements(plot_types), $ xsize = 10, uval = 'PTYPE') ;probe list scid = widget_base(data_control, /col, /align_left, frame = 5) flabel = widget_label(scid, value = 'Probe') sclist = widget_list(scid, value = sc_arr, xsiz = 10, $ ysiz = n_elements(sc_arr), uval = 'SC', $ /multiple) ; GMAG station list stationid = widget_base(data_control, /col, /align_left, frame = 5) flabel = widget_label(stationid, value = 'GMAG Site') stationlist = widget_list(stationid, value = stations, xsiz = 10, $ ysiz = 8, uval = 'STATION', $ /multiple) ; ASI station list astationid = widget_base(data_control, /col, /align_left, frame = 5) flabel = widget_label(astationid, value = 'ASI Site') astationlist = widget_list(astationid, value = astations, xsiz = 10, $ ysiz = 8, uval = 'ASI_STATION', $ /multiple) ;datatype list dtypid = widget_base(data_control1, /col, /align_left, frame = 5) flabel = widget_label(dtypid, value = 'Data Type') dtyplist = widget_list(dtypid, value = data_types, xsiz = 10, $ ysiz = n_elements(data_types), uval = 'DTYP', $ /multiple) ; load button loadbutbase = widget_base(buttons, /col, frame = 5) loadbut = widget_button(loadbutbase, val = ' Load Data', uval = 'LOAD', $ /align_left) ; call tplot button tplotbut = widget_button(loadbutbase, val = ' Process Data/Tplot ', $ uval = 'CALL_TPLOT', /align_left) ; delete button deletebut = widget_button(loadbutbase, val = ' Delete ', uval = 'DELETE', $ /align_left) ; show active dset button showactivebut = widget_button(loadbutbase, val = ' Show Active Dset ', $ uval = 'SHOWACTIVE', /align_left) ; history button historybase = widget_base(buttons, /col, frame = 5) histbut = widget_button(historybase, val = ' History ', uval = 'HIST', $ /align_left) ; clear history button clearbut = widget_button(historybase, val = ' Clear History ', $ uval = 'CLEAR_HIST', /align_left) ; calibrate buttons calbutbase = widget_base(buttons, /col, frame = 5) calbut1 = widget_button(calbutbase, val = ' Calibrate EFI', uval = 'CALEFI', $ /align_left) calbut2 = widget_button(calbutbase, val = ' Calibrate FBK', uval = 'CALFBK', $ /align_left) calbut3 = widget_button(calbutbase, val = ' Calibrate FGM', uval = 'CALFGM', $ /align_left) calbut4 = widget_button(calbutbase, val = ' Calibrate FIT', uval = 'CALFIT', $ /align_left) calbut5 = widget_button(calbutbase, val = ' Calibrate MOM', uval = 'CALMOM', $ /align_left) ; summary plot buttons summarybase = widget_base(buttons, /col, frame = 5) plotbut = widget_button(summarybase, val = ' GMAG Summary Plot ', uval = 'PLOT', $ /align_left) ; exit button exitbase = widget_base(buttons, /col, frame = 5) helpbut = widget_button(exitbase, val = ' Help ', uval = 'HELP', $ /align_left) exitbut = widget_button(exitbase, val = ' Exit ', uval = 'EXIT', $ /align_left) ;time selection widget timebase = widget_base(controls, /row, /align_left, frame = 5) timeselbase = widget_base(timebase, /column, /align_left, frame = 5) ; sttime button sttime_button = widget_base(timeselbase, /col, /align_left) sttimebut = widget_button(sttime_button, val = ' Choose Start time ', $ uval = 'STTIME', /align_left) ; entime button entime_button = widget_base(timeselbase, /col, /align_left) entimebut = widget_button(entime_button, val = ' Choose End time ', $ uval = 'ENTIME', /align_left) ;time display widget timedisplaybase = widget_base(timebase, /column, /align_left, frame = 5) ; sttime text sttime_display = widget_text(timedisplaybase, /edit, $ uval = 'STTIME_DISPLAY', $ val = '2006-11-30/00:00:00', $ xsize = 30, /all_events) ; entime button entime_display = widget_text(timedisplaybase, /edit, $ uval = 'ENTIME_DISPLAY', $ val = '2006-12-01/00:00:00', $ xsize = 30, /all_events) tt0 = time_double('2006-11-30/00:00:00') tt1 = time_double('2006-12-01/00:00:00') ; The dataset_display widget dataset_display = widget_base(controls, /col, /align_left) datadisp = widget_base(dataset_display, /col, /align_left) datadisplabel = widget_label(datadisp, value = 'Loaded Data') datalist = widget_list(datadisp, value = 'No Data loaded', $ uval = 'DATALIST', xsiz = 60, ysiz = 20, frame = 5, $ /multiple) ; User defined procedures If(is_string(getenv('THEMIS_USER_PROC_FILE'))) Then Begin user_file = getenv('THEMIS_USER_PROC_FILE') arr_user = rd_tfile(user_file) Endif Else arr_user = 'None' user_display = widget_base(controls, /col, /align_left) userdisp = widget_base(user_display, /col, /align_left) userdisplabel = widget_label(userdisp, value = 'User Defined Procedures') userlist = widget_list(userdisp, value = arr_user, $ uval = 'USERLIST', xsiz = 60, ysiz = 10, frame = 5, $ /multiple) ;init the history with defaults init_history = ['plot_type = ''SCREEN''', $ 'dtype = ''GMAG''', $ 'probe = ''A''', $ 'gmag_station = ''ALL''', $ 'start_time = '''+time_string(tt0)+'''', $ 'end_time = '''+time_string(tt1)+''''] state = {wmaster:master, $ ;master widget id sttime_display:sttime_display, $ ;start_time display id entime_display:entime_display, $ ;end_time display id datalist:datalist, $ ;datalist id userlist:userlist, $ ;userlist id plottypelist:plottypelist, $ ;plot type list id dtyplist:dtyplist, $ ;data type list id stationlist:stationlist, $ ; GMAG station list id astationlist:astationlist, $ ;ASI station list id sclist:sclist, $ ;probe list id plot_type:'SCREEN', $ ;plot_type st_time:tt0, $ ;start_time, double en_time:tt1, $ ;end_time data:ptr_new(), $ ;a pointer to the data_quants array in the tplot common tplot_vars:ptr_new(), $ ;points to the tplot_vars structure plot_configs:ptr_new(), $ ;points to the plot_configs structure current_config:ptr_new(), $;points to the current_config data_id:ptr_new(), $ ;a pointer to an array of strings, 1 for each loaded dataset active_vnames:ptr_new(), $ ;the tplot variable names that are active history:ptr_new(init_history), $ ;a string array with the analysis history dtyp:ptr_new('GMAG'), $ ;the most recently loaded datatype sc:ptr_new('A'), $ ;probe_id, 'thg' is ground magnetometer station:ptr_new('ALL'), $ astation:ptr_new('ALL'), $ tplot_wid:0l} ;the widget id of the eventual tplot widget widget_control, master, set_uval = state, /no_copy widget_control, master, /realize xmanager, 'thm_gui', master, /no_block Return End