;+ ;NAME: ;thm_ui_load_data_fn ;PURPOSE: ;A widget interface to load CDF data for whatever instrument ;CALLING SEQUENCE: ;varnames = thm_ui_load_data_fn(st_time, En_time, dtype, station, $ ; id_string,data_ss) ;INPUT: ;st_time, en_time = start and end times in seconds from ; 1-jan-1970 0:00 ;dtype, the type of data, a string, of form 'thg_gmag', for example ;station, the ground station of the gmag data ;probe = the probe_is string, or 'thg' for ground data ;data_level = 'L0','L1', or 'l2' ;OUTPUT: ;varnames = an array of tplot variable names, to pass into tplot ;data_ss = the subscripts of the new data in the tplot data_quants structure ; The tplot common is loaded, or appended ;HISTORY: ; 22-sep-2006, jmm, jimm@ssl.berkeley.edu ; 23-oct-2006, jmm, changed to call cdf2tplot ; 30-oct-2006, jmm, changed again, to call load_thg_mag, also added ; dtype and station as inputs ; 13-nov-2006, jmm, changed the argument list, now the output is a ; data id string, added a check for start time > end ; time ; 08-dec-2006, krb, changed load_thg_mag to thm_load_gmag ; 13-dec-2006, jmm, Added call to cdf2tplot for data for which there ; is no load program... ; 14-dec-2006, jmm, returns an array of variable names and ; subscripts, which should be easier to read.. ; 15-dec-2006, jmm, Added calls to thm_load_fgm, fit, sst, efi, ; ask,probe can be an array ; 16-jan-2007, jmm, Add all of the thm_load routines ; 5-feb-2007, jmm, update calls to load routines ; ;$LastChangedBy: kenb-mac $ ;$LastChangedDate: 2007-01-26 15:52:34 -0800 (Fri, 26 Jan 2007) $ ;$LastChangedRevision: 241 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/trunk/idl/themis/common/thm_ui_load_data_fn.pro $ ; ;- Function thm_ui_load_data_fn, st_time, en_time, $ dtype0, station0, astation0, $ probe0, data_ss, $ history_ext, _extra = _extra @tplot_com otp = -1 data_ss = -1 ;database thm_init ;this should work dtype = strlowcase(strcompress(dtype0, /remove_all)) ndtype = n_elements(dtype) instr = strarr(ndtype) & iname = instr For j = 0, ndtype-1 Do Begin ppp = strsplit(dtype[j], '/', /extract) instr[j] = ppp[0] If(n_elements(ppp) Gt 1) Then iname[j] = ppp[1] Endfor station = strlowcase(strtrim(station0, 2)) astation = strlowcase(strtrim(astation0, 2)) probe = strlowcase(strtrim(probe0, 2)) ;Get the info for the data that has been loaded If(is_struct(data_quants)) Then Begin tx0 = time_string(data_quants.trange) didx0 = data_quants.name+':'+tx0[0, *]+' To '+tx0[1, *] Endif Else didx0 = -1 If(en_time Le st_time) Then Begin message, /info, 'End time is less than Start time?' message, /info, 'No data Loaded' Return, otp Endif ;GMAG gmag_ss = where(instr Eq 'gmag') If(gmag_ss[0] Ne -1) Then Begin thm_load_gmag, site = station, trange = [st_time, en_time] history_ext = 'thm_load_gmag, site = station, trange = [start_time, end_time]' Endif ;ASI asi_ss = where(instr Eq 'asi') If(asi_ss[0] Ne -1) Then Begin datatype = iname[asi_ss] history_ext1 = thm_ui_multichoice_history('datatype =', datatype) thm_load_asi, site = astation, trange = [st_time, en_time], datatype = datatype history_ext1 = [history_ext1, 'thm_load_asi, astation, trange = [st_time, en_time], datatype = datatype'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;ASK ask_ss = where(instr Eq 'ask') If(ask_ss[0] Ne -1) Then Begin thm_load_ask, trange = [st_time, en_time] history_ext1 = 'thm_load_ask, trange = [start_time, end_time]' If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;EFI efi_ss = where(instr Eq 'efi') If(efi_ss[0] Ne -1) Then Begin datatype = iname[efi_ss] thm_load_efi, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_efi, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;FBK fbk_ss = where(instr Eq 'fbk') If(fbk_ss[0] Ne -1) Then Begin datatype = iname[fbk_ss] thm_load_fbk, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_fbk, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;FFT fft_ss = where(instr Eq 'fft') If(fft_ss[0] Ne -1) Then Begin datatype = iname[fft_ss] thm_load_fft, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_fft, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;FGM fgm_ss = where(instr Eq 'fgm') If(fgm_ss[0] Ne -1) Then Begin datatype = iname[fgm_ss] thm_load_fgm, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_fgm, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;FIT fit_ss = where(instr Eq 'fit') If(fit_ss[0] Ne -1) Then Begin datatype = iname[fit_ss] thm_load_fit, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_fit, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;SCM scm_ss = where(instr Eq 'scm') If(scm_ss[0] Ne -1) Then Begin datatype = iname[scm_ss] thm_load_scm, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_scm, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;MOM mom_ss = where(instr Eq 'mom') If(mom_ss[0] Ne -1) Then Begin datatype = iname[mom_ss] thm_load_mom, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_mom, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;SST sst_ss = where(instr Eq 'sst') If(sst_ss[0] Ne -1) Then Begin datatype = iname[sst_ss] thm_load_sst, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_sst, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;STATE state_ss = where(instr Eq 'state') If(state_ss[0] Ne -1) Then Begin datatype = iname[state_ss] thm_load_state, probe = probe, datatype = datatype, /get_support_data, trange = [st_time, en_time] history_ext1 = [thm_ui_multichoice_history('datatype =', datatype), $ 'thm_load_state, probe = probe, datatype = datatype, /get_support_data, trange = [start_time, end_time]'] If(is_string(history_ext)) Then Begin history_ext = [temporary(history_ext), temporary(history_ext1)] Endif Else history_ext = temporary(history_ext1) Endif ;What are the new structure elements? If(is_struct(data_quants)) Then Begin ndq = n_elements(data_quants) If(data_ss[0] Eq -1) Then data_ss = 1+lindgen(n_elements(data_quants)-1) $ Else Begin If(is_string(didx0)) Then Begin tx = time_string(data_quants.trange) didx = data_quants.name+':'+tx[0, *]+' To '+tx[1, *] new_flag = bytarr(ndq) For j = 0, ndq-1 Do Begin fff = where(didx0 Eq didx[j], nfff) If(nfff Eq 0) Then new_flag[j] = 1 Endfor data_ss = where(new_flag Eq 1) Endif Else data_ss = 1+lindgen(n_elements(data_quants)-1) Endelse ;Here restrict to the input time range ; thm_ui_only_trange, st_time, en_time, data_ss ;Here get the tplot variable names tplotvars = tnames() otp = tplotvars[data_ss-1] Endif Else Begin message, /info, 'No valid_data_structure' data_ss = -1 otp = -1 Endelse Return, otp End