; This is an example crib sheet that will load ground mag data.
; Open this file in a text editor and then use copy and paste to copy
; selected lines into an idl window. Or alternatively compile and run


; Enter time of interest: (use only a few days!)

timespan,'6-10-2',2,/days              ;  Set the time span of interest

thm_load_gmag,probe='bmls ccnv'               ;  Loads data from two sites

tplot_names                            ; Display all variable names

stop,ptrace()

tplot,'thg_mag_bmls'                   ; Plot one data variable

stop,ptrace()

tplot,'thg_mag_????'                   ; tplot accepts wildcard characters

stop,ptrace()

; The following few lines show how to get the data, manipulate
; it and create a new data variable to plot

vname = 'thg_mag_bmls'                 ; set a variable to one of those names
; Now get the data out of tplot:
get_data,vname,data=d
; Manipulate it (subtract off the average)
d.y = d.y - (replicate(1,n_elements(d.x))  # average(d.y,1,/double) )
; Return data to "TPLOT limbo" with new name
store_data,vname+'-d',data=d

tplot,/add,vname+'-d'


stop

; Change title and panel_size:
options,vname+'-d',ytitle='LOYS!cDelta B (nT)',panel_size=2.

; Plot again
tplot

stop

; change ylimits:

ylim,'*-d',-100,100,0    ; This affects all tplot variables that end in "-d"

tplot

ylim,'*-d',0,0,0         ; Set ylimits back to autoscale.

; Now try some new different tools that are associated with tplot
; Change time limits:

tlimit,'2006-10-2/12','2006-10-2/13'

stop

; set auto time limits
tlimit,0,0

stop

; Use mouse to select time range:
tlimit

stop

; use time limits defined by "timespan"
tlimit,/full        ;

stop

; Select some time points, click the left button 3 or 4 times
ctime,t


; Print time values:
print,time_string(t)

stop

; Display timebars:
timebar,t


; define the "default" tplot window to always be window 0
tplot_options,window=0
; create new window for zooming
window,1


; Use one window to zoom into another
tzoom

stop

; Select a single time value:
ctime,t,npoint=1
; extract a short (10 second) data sample centered at that time.
s = tsample(vname,t + [-5,5])
help,s
print,transpose(s)

stop


; Get some other key parameter data:

load_wi_mfi      ;

tplot,'*'                          ;plot everything!

split_vec,'thg_mag_ccnv'
options,'*[xyz]' ,/ynozero
tplot,'*[xyz]

tc = '2006 -10- 3'
tr = time_double(tc) + [-10,10]*3600.

wav_data,'thg_mag_ccnv_x',/kol  ,trange=tr   ,maxpoints=24l*3600*2
zlim,'*pow', .0001,.01,1

wshow,0
tplot,'*ccnv_x*',trange=tr


wav_data,'thg_mag_ccnv_y',/kol   ,trange=tr  ,maxpoints=24l*3600*2
wav_data,'thg_mag_ccnv_z',/kol   ,trange=tr  ,maxpoints=24l*3600*2
zlim,'*pow', .0001,.01,1

tplot, '*ccnv_[xyz]*
wshow


end