;+
; CRIB SHEET EXAMPLE
; PURPOSE:
;   A sample crib sheet that demonstrates the "TPLOT" package functionality.
; 
;   In the following text all comment lines are preceeded by a ;  (semi-colon)
;   All other lines are commands.
;
;   This gives only a partial listing of the options that are available.
;-


; Load some data that are already loaded and saved in the _example_data.tplot file
tplot_restore, f='_example_data.tplot'


;list the currently available data (just produced by loading _example_data.tplot)
tplot_names


;Plot the quantities:
tplot, ['STA_PLA_ENSPEC_COUNTS_H_ALPHA','STA_PLA_ENSPEC_COUNTS_H+PEAK','STA_PLA_ENSPEC_COUNTS_HE++PEAK']

;or alternatively:
tplot, [1,3,5]



;Some examples of changing plotting options:

;Limits:


ylim, 1, 1, 1e1, 0      ; set linear y-limits from 1.0 to 1e1 for 'STA_PLA_ENSPEC_COUNTS_H_ALPHA' 
tplot

ylim, 1, 0.1, 1e2, 1    ; reset to logarithmic and change the range to 0.1-1e2
tplot

zlim, 1, 0, 0, 1        ; autoscaling logarithmic
tplot

zlim, 1, 0, 0, 0        ; autoscaling linear
tplot

zlim, 1, 0.1, 1e3, 1    ; back to logarithmic
tplot

;Time limits

tlimit,1,3                           ;time limit from 01:00 UT to 03:00 UT

tlimit,/full                         ;full range

tlimit                               ; use cursor to select the time range

tlimit,0,0                           ;back to auto ranging.


; Spectrograms

options, 1, 'y_no_interp',1   ; prevent y-axis interpolation
tplot

options, 1, 'y_no_interp',0   ; allow y-axis interpolation
tplot

options, 1,'ystyle',1     ; force exact yaxis limits
tplot

options, 1, 'spec',0       ; change to multi-line plot:
tplot

options, 1, 'spec',1       ; back to spectragram
tplot



; Overplotting a line plot (in this case the S-Channel) over a spectra plot
tplot_panel, v=1, o=2

or alternatively:

tplot_panel, v='STA_PLA_ENSPEC_COUNTS_H_ALPHA', o='STA_PLA_ENSPEC_COUNTS_H_ALPHA_s_chan'


;Multiline plots:

tplot, 7

tplot,/nocolor     ; Turn off auto coloring on multi-line plots (for hardcopy)

options, 7, 'labflag',-1    ; set evenly spaced labels
tplot

options, 7, 'labflag',0     ; No labels
tplot

options, 7, 'labflag',1     ; Reverse order
tplot

options, 7, 'labflag',2     ; Auto spacing
tplot


;Setting global options:   (these will affect the entire plot)

tplot_options,'title','My very own plot'
tplot


tplot_options,'region',[0.,.5,1.,1.]   ; use top half of screen only
tplot

tplot_options,'region'                 ; remove region keyword (full screen)
tplot

tplot_options,'xmargin' ,[15,10]         ; change default xmargin
tplot

tplot_options,'ymargin' ,[6,3]          ; change default ymargin
tplot

tplot_options,'charsize',.5             ; change default character size
tplot


;Miscellaneous:

tplot,mix=[4,1,2]   ;Mix the panel order,  plot the 4th, then 1st, then 2nd

tplot,/pick         ;Use the cursor to pick panels

options, 1, 'panel_size',1.   ;make the spectrogram panel normal size
tplot

time_stamp,/off     ;Turn of the time_stamp
tplot

time_stamp,/on      ;Turn it on again
tplot



;Example of getting to the data and creating new data:

;Suppose one wishs to view the spectral data with the steep slope factored
;out.  The following example shows how this might be done:

tplot,'STA_PLA_ENSPEC_COUNTS_H_ALPHA'               ;display the data

get_data, 1, data=dat  ,alim=lim                    ; get the data, and limits
help,dat,lim,/st                                        
flux = dat.y                                        ; create flux variable
avg  = total(flux,1,/nan) / total(finite(flux),1)   ; average over dimension 1
n = dimen1(flux)                                    ; determine 1st dimension
avg  = replicate(1.,n) # avg
help,flux,avg,n                                     ; help
flux = flux / avg                                   ; divide by average
dat.y = flux                                        ; replace old data
lim.ztitle= 'New Data'                              ; change the title

store_data,'ndat',data=dat  ,dlim=lim               ; store the data for TPLOT

tplot_names                                         ; Verify it is really there

tplot,'ndat',/add                                   ; 


