This page was created by the IDL library routine mk_html_help2.

Last modified: Fri Nov 2 11:01:31 2012.


Directory Listing of Routines


Routine Descriptions

REE_SET_GSM

[Next Routine] [List of Routines]
 PRO: REE_SET_GSM, sc

 PURPOSE: LOADS STATE AD SETS UP PLOTS FOR GSM

 INPUT: 
       SC    -       REQUIRED. STRING. Spacecraft

 EXAMPLE: ree_set_gsm, 'a' 

 OUTPUT: GSM Coordinates are laoded into tplot. 

 WARNING: BE SURE TO SET TIMESPAN FIRST!

 INITIAL VERSION: REE 08-10-31
 MODIFICATION HISTORY: 
 LASP, CU
 

(See themis/spacecraft/fields/LASP/ree_set_gsm.pro)


THM_CHECK_TVAR (FUNCTION)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     THM_CHECK_TVAR (FUNCTION)
 
 PURPOSE:
     This routine check whether the given tplot variable TVAR exists in the
     memory. If not, return 0. Otherwise, then check whether it contains data
     of the current date. If yes, return 1. If not, return 0.

 ARGUMENTS:
     tvar: (INPUT, REQUIRED) The name of a tplot variable to be checked.
 
 KEYWORDS: 
     None.
 
 HISTORY:
     2009-05-10: written by Jianbao Tao, in CU/LASP.

(See themis/spacecraft/fields/LASP/thm_check_tvar.pro)


THM_EFI_CLEAN_EFP

[Previous Routine] [Next Routine] [List of Routines]
PRO: THM_EFI_CLEAN_EFP

     FOR GENERAL USE: WILL CLEAN UP EFP AND PUT INTO FAC AND GSM COORDINATES.
     DEFAULTS SET FOR TAIL. USE /SUBSOLAR FOR DAYSIDE DEFAULTS.
     MERGE CAN EXHIBIT PATHOLOGICAL BEHAVIOR IF B IS NEAR THE SPIN PLANE.
     SPIKE REMOVAL DOES NOT ALWAYS WORK.
     HINT: USE TRANGE TO ISOLATE SINGLE PARTICLE BURST AND GREATLY REDUCE RUN TIME. 
  
SETUP: MAKE SURE thX_state_spinper is available! BEST TO SET UP FOR GSM.
       MAKE SURE TIMESPAN IS SET!!!!

PURPOSE:
    FIXES AXIAL, REMOVES SPIKES, SPINTONE, SC POTENTIAL, AND OTHER EFP ERRORS.

 EXAMPLES:
     For typical use, see thm_crib_cleanefp.pro and thm_crib_cleanefi.pro which
     are typically located under TDAS_DIR/idl/themis/examples.

INPUT:

KEYWORDS (general):
    probe          NEEDED: Program does only one sc at a time!
    Ename          OPTIONAL: Valid TPLOT name for E, DEFAULT = 'thX_efp' (will fetch)
    Vname          OPTIONAL: Valid TPLOT name for E, DEFAULT = 'thX_vap' (will fetch)
    Bdslname       OPTIONAL, Valid TPLOT name for B, DEFAULT = 'thX_fgh_dsl' (will fetch)
    trange         OPTIONAL. Time range. 
                   USE TRANGE TO ISOLATE SINGLE PARTICLE BURST AND GREATLY REDUCE RUN TIME!!!! 
    subsolar       OPTIONAL. If set, defaults for subsolar region are used. DEFAULT = TAIL
    talk           OPTIONAL. Plots diagnostics. Can be fun. Slow. DEFAULT = 0

KEYWORDS (Remove_SpinTone):
    SpinRemove     If entered as 0, suppresses spintone removal. DEFAULT = 4 (Spintone removed)
                   1: Only spintone, 2: Spintone and 2nd harm. 3: Spintone and 4th harm.
                   4: Spintone, 2nd, and 4th harm.
    SpinNsmooth    Activates median smoothing. # of half periods. Must be odd. DEFAULT = 19
    SpinPoly       Activates polyfit smoothing. Can be unstable if >9. DEFAULT = 0

KEYWORDS (Remove_Potential):
    VscRemove      If entered as 0, suppresses potential removal. DEFAULT = 1 (Potential removed.)
    VscPole        Frequency to median smooth Vsc before applying to Ez. DEFAULT = 5.0 Hz
    Vpoly          Actives polyfit of Ez to Vsc.  DEFAULT = 2 (5 /Subsolar)
    Use_Electrons  (OBSOLETE) If set, Te is used to modify Vsc before removal.
                    DEFAULT = 0 (1 /SubSolar)
    TeName         (OBSOLETE) OPTIONAL: Valid TPLOT name for Te. DEFAULT =
                    'thX_peeb_avgtemp' (will fetch)

KEYWORDS (Remove_Spikes):
    SpikeRemove    If entered as 0, suppresses spike removal. DEFAULT = 1 (Spikes are removed.)
    SpikeNwin      Number of points in spike search window. DFLT = 16
    SpikeSig       Sigma of spikes. DFLT = 5           (Sometimes Sig = 6 works better)
    SpikeSigmin    Minimun of sigma. DFLT = 0.01 mV/m. (Sometimes Sigmin = 0 works better)
    SpikeNfit      Number of points in the fit window. DFLT = 16
    SpikeFit       If set, will do a Gaussian fit to Spikes. DFLT = 0

KEYWORDS (Remove_Spin_Epoch):
    EpochRemove    If set, removes all spin-epoch signals. DEFAULT = 0 (Not used.)
                   Only useful for short stretches or if plasma condtitions are constant.

KEYWORDS (Fix_Axial)
    FixAxial       If entered as 0, suppresses axial fix. DEFAULT=1 (Axial is fixed.)
    AxPoly         Forces polynomial fit of Ez-Eder of order AxPoly. DEFAULT=2 (9 /SubSolar)
    Merge          Merges Ederived with Eaxial.  DEFAULT = 0 No merging (1 /Subsolar)
                   1 - Abrupt merging. If Eder is avaliable Eder is used (0 - Fmerge). Else Ez.
                   2 - Soft merging. Bz/|B| is considered when merging.
                   WARNING: MERGE=1 OR 2 CAN EXHIBIT PATHOLOGICAL BEHAVIOR IF MAGNETIC FIELD 
                            IS NEAR THE SPIN PLANE. PLEASE DOUBLE CHECK RESULTS IF USED. 
    Fmerge         Frequency of crossover for merging Ederived with Eaxial. 
                   DEFAULT = 5.0 Hz (/Subsolar). 
    MergeRatio     Mimimum value of Bz/|B| to start merge (USED IF MERGE=2). DEFAULT = 0.05
    MinBz          Needed to avoid divide by zero in Ederive. DEFAULT = 0.01 nT
    MinRatio       Mimimum value of Bz/|B| to calculate Ederive. DEFAULT = 0.1 (0.05 /Subsolar)

KEYWORDS (B_Smooth)
    BspinPoly      Activates polyfit smoothing. Can be unstable if >9. DEFAULT = 2. -1 suppresses.
    Bsmooth        Activates B smoothing for fac rotation. DEFAULT = 11. 1 or less suppresses.
            


HISTORY:
   2009-05-05: REE. First Release.
   2009-06-04: JBT. The metadata (dlim.data_att) is modified properly.
   2009-06-04: REE/JBT. Second Release.
   2010-04-08: JBT. Fixed some bugs.

(See themis/spacecraft/fields/LASP/thm_efi_clean_efp.pro)


THM_EFI_CLEAN_EFW

[Previous Routine] [Next Routine] [List of Routines]
PRO: THM_EFI_CLEAN_EFW

           FOR GENERAL USE: WILL CLEAN UP EFW AND PUT INTO FAC.
           SPIKE REMOVAL DOES NOT ALWAYS WORK.
           HINT: USE TRANGE TO ISOLATE SINGLE PARTICLE BURST AND GREATLY REDUCE RUN TIME. 
  
SETUP: MAKE SURE thX_state_spinper is available! BEST TO SET UP FOR GSM.
       MAKE SURE TIMESPAN IS SET!!!!
PURPOSE:
    FIXES HF, REMOVES SPIKES, AND LOW FREQUENCY.

 EXAMPLES:
     For typical use, see thm_crib_cleanefw.pro and thm_crib_cleanefi.pro which
     are typically located under TDAS_DIR/idl/themis/examples.

INPUT:

KEYWORDS (general):
    probe          NEEDED: Program does only one sc at a time!
    Ename          OPTIONAL: Valid TPLOT name for E WAVE, DEFAULT = 'thX_efw' (will fetch)
    Bdslname       OPTIONAL, Valid TPLOT name for B, DEFAULT = 'thX_fgh_dsl' (will fetch)
    trange         OPTIONAL. Time range. 
                   USE TRANGE TO ISOLATE SINGLE PARTICLE BURST AND GREATLY REDUCE RUN TIME!!!! 
    talk           OPTIONAL. Plots diagnostics. Can be fun. Slow. DEFAULT = 0
    EfpName        OPTIONAL: Valid TPLOT name for EFP, DEFAULT = 'thX_efp' (will fetch)
                   EFP is used to find spike positions.
    status         OPTIONAL: A named variable to return the exiting status. If
                    exit successfully, status = 0, otherwise status = 1

KEYWORDS (Filter):
    FPole          (OBSOLETE) Pole of high-pass filter. DEFAULT = 5.0 Hz.

KEYWORDS (Remove_Spikes):
    SpikeRemove    If entered as 0, suppresses spike removal. DEFAULT = 1 (Spikes are removed.)
    SpikeNwin      Number of points in spike search window. DFLT = 16
    SpikeSig       Sigma of spikes. DFLT = 5           (Sometimes Sig = 6 works better)
    SpikeSigmin    Minimun of sigma. DFLT = 0.01 mV/m. (Sometimes Sigmin = 0 works better)
    SpikeNfit      Number of points in the fit window. DFLT = 16
    SpikeFit       If set, will do a Gaussian fit to Spikes. DFLT = 0

HISTORY:
   2009-05-06: REE. First Release.
   2009-06-04: JBT. The metadata (dlim.data_att) is modified properly.
   2009-06-17: JBT. Keyword STATUS added.
   2010-04-08: JBT. The high-pass filter is changed from an FFT filter to an
              FIR filter. Some modification is made to be compatible with
              two different sample rates 8192 Hz and 16384 Hz.

(See themis/spacecraft/fields/LASP/thm_efi_clean_efw.pro)


THM_EFI_DERIVE_EZ

[Previous Routine] [Next Routine] [List of Routines]
 PRO: THM_EFI_DERIVE_EZ, Edsl, Bdsl, new_name=new_name
                   

 PURPOSE: DERIVES EZ ASSUMING EdotB = 0

 INPUT: 
       Edsl -       REQUIRED. STRING Efield data name (tplot).
       Bdsl -       REQUIRED. STRING Bfield data (tplot)

 CALLING: thm_efi_derive_Ez, Edsl, Bdsl 

 OUTPUT: Tplot 


 INITIAL VERSION: REE 08-11-04
 MODIFICATION HISTORY: 
 LASP, CU
 

(See themis/spacecraft/fields/LASP/thm_efi_derive_ez.pro)


THM_EFI_EXB

[Previous Routine] [Next Routine] [List of Routines]
 PRO: THM_EFI_ExB, Ename, Bname, Sname=Sname, Vname=Vname, $
                   EdotB=EdotB, Btot=Btot

 PURPOSE: Calculate Poynting Flux and Flow Velocity

 INPUT: 
       Eanme -       REQUIRED. STRING Efield data name (tplot).
       Bname -       REQUIRED. STRING Bfield data (tplot)
       Sname -       OPTIONAL. Poynting Flux name (tplot)
       Vname -       OPTIONAL. Velocity Flow name (tplot)

 CALLING: thm_efi_exb, Ename, Bname, Sname 

 OUTPUT: Poynting Flux is Calculated 


 INITIAL VERSION: REE 08-10-31
 LASP, CU
 MODIFICATION HISTORY: 
       2010-02-21: Added a check of the coordinate systems of Ename and Bname.
                   -JBT, CU/LASP.
 

(See themis/spacecraft/fields/LASP/thm_efi_exb.pro)


THM_EFI_FIX_FREQ_AND_PHASE

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: THM_EFI_FIX_FREQ_AND_PAHSE, E, freq=freq, ghf=ghf, dt=dt, axial=axial

 PURPOSE: A routine which integrates data to fix the gain and remove the
          phase shift due to resistive to capacitive crossover of the  
          THEMIS preamps. ONLY USEFUL FOR BURST DATA.

 INPUT: 
       data -        REQUIRED. Data to be fixed. DEFAULT = SPIN PLANE

 KEYWORDS: 
       axial -       OPTIONAL. Changes freq and gh to AXIAL default values.
       freq -        OPTIONAL. Crossover frequency in HZ. DEFAULT = SPIN PLANE
                     Careful! Derived from Rsheath(Csheath+Cin)
       ghf -         OPTIONAL. Gain at high frequency. DEFAULT = SPIN PLANE
                     Csheath/(Csheath+Cin)
       dt -          OPTIONAL. Time between samples (s). DEFAULT = 1/8192

 CALLING: Esp = thm_efi_fix_freq_and_phase(Esp) or 
          Eax = thm_efi_fix_freq_and_phase(Ex, /ax)

 OUTPUT: Data is integrated to remove gain/phase error from preamp RC 
         crossover.

 NOTE ON DEFAULTS: Spin Plane: The front-end network, R=100k, C = 10pF is  
    ignored. Instead, I fudge Csh = 14 pF  and Cin = 11.5 pF to realize a close 
    approximation of measured gain/phase (see Bonnell et al. paper).
    Axial: Same system. I use Csh = 4 pf, Cin = 13 pF to approximate. 
    One could improve the calculation with 2 poles, but the location of Cin
    (before or after the input network) would need to be questioned.
    Rsh is assumed to be 20 MOhm
        
 BEHAVIOR: 
    (1) USE /AX for AXIAL SIGNALS!!!
    (2) DATA AT BEGINNING OF AN ARRAY MAY NOT BE CORRECTED. 
    Use large arrays if possible. The program relaxes by one
    e-fold every 3 ms. 
    (3) Electric field is improved for all plasma conditions. However, 
    PHASE/GAIN CORRECTION MAY NOT BE ENOUGH FOR ALL PLASMA CONDITIONS.
    (4) PROBES MUST BE IN SUNLIGHT!
    (5) ONLY USEFUL FOR BURST DATA!
    (6) BE SURE TO SET DT = 1/16384 FOR AC BURST!!!

 INITIAL VERSION: REE 08-08-26
 MODIFICATION HISTORY: 
 LASP, CU
 

(See themis/spacecraft/fields/LASP/thm_efi_fix_freq_and_phase.pro)


THM_EFI_FIX_HF

[Previous Routine] [Next Routine] [List of Routines]
 PRO: THM_EFI_FIX_HF, dname, freq=freq, ghf=ghf, dt=dt

 PURPOSE: A routine which calls THM_EFI_FIX_FREQ_AND_PHASE to fix the gain and remove the
          phase shift due to resistive to capacitive crossover of the  
          THEMIS preamps. ONLY USEFUL FOR BURST DATA.

 INPUT: 
       danme -       REQUIRED. tplot data to be fixed. 

 KEYWORDS: 
       freq -        OPTIONAL. Crossover frequency in HZ. DEFAULT = SPIN PLANE
                     Careful! Derived from Rsheath(Csheath+Cin)
       ghf -         OPTIONAL. Gain at high frequency. DEFAULT = SPIN PLANE
                     Csheath/(Csheath+Cin)
       dt -          OPTIONAL. Time between samples (s). DEFAULT = 1/8192

 CALLING: Esp = thm_efi_fix_freq_and_phase(Esp) or 
          Eax = thm_efi_fix_freq_and_phase(Ex, /ax)

 OUTPUT: Data is integrated to remove gain/phase error from preamp RC 
         crossover.


 INITIAL VERSION: REE 08-08-26
 MODIFICATION HISTORY: 
 LASP, CU
 

(See themis/spacecraft/fields/LASP/thm_efi_fix_hf.pro)


THM_EFI_GET_POTENTIAL

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION: THM_EFI_GET_POTENTIAL, Vname

           NOT FOR GENERAL USE. CALLED BY THM_EFI...
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

PURPOSE:
    Remove SC potential from axial signal.

INPUT:
    Vname           TPLOT name of voltages.

KEYWORDS:

HISTORY:
   2009-03-30: REE. 

(See themis/spacecraft/fields/LASP/thm_efi_get_potential.pro)


THM_EFI_REMOVE_SPINTONE

[Previous Routine] [Next Routine] [List of Routines]
 PROCEEDURE: THM_EFI_REMOVE_SPINTONE, name, trange, new_name=new_name, per=per

 PURPOSE: GETS RID OF SPIN TONE AND OFFSET ON MEDIUM SIZE STRETCHES

 INPUT: 

 KEYWORDS: 
    name -         TPLOT NAME

 OUTPUT: TPLOT STORE

 INITIAL VERSION: REE 99-03-25 (ff_remove_spintone)
 Space Scienes Lab, UCBerkeley
 MODIFICATION HISTORY: 
 08-10-31 Modified for THEMIS by REE
 University of Colorado

(See themis/spacecraft/fields/LASP/thm_efi_remove_spintone.pro)


THM_EFI_SIN_FIT

[Previous Routine] [Next Routine] [List of Routines]
 PROCEEDURE: THM_EFI_SIN_FIT, e, t, es=es, ec=ec, per=per 

 Called by THM_EFI_REMOVE_OFFSET_AND_SPIN, name, ask=ask 

 PURPOSE: DOES A QUICK SIN AND COS FIT

 INPUT: 
    E -         REQUIRED (Electric Field)
    T -         REQUIRED

 WARNING: USE SHORT SEGMENTS


 OUTPUT: 

    AMP  -         AMPLITUDE
    PHS  -         PHASE
    Per  -         PERIOD (Sypply and save a lot of time!)

 INITIAL VERSION: REE 08-10-31
 University of Colorado
 MODIFICATION HISTORY: 

(See themis/spacecraft/fields/LASP/thm_efi_sin_fit.pro)


THM_JBT_GET_BTRANGE (FUNCTION)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     THM_JBT_GET_BTRANGE (FUNCTION)

 PURPOSE:
     This routine is to find the starting time and ending time of each
     continuous section of a give tplot variable which essentially is specified
     by a tplot name such as 'tha_efp'.
     If the routine exit unsuccessfully, it will return -1. Otherwise, it will
     return a 2D array as [2,number_of_total_bursts] which stores the
     the starting time and the ending time of each continuous section.

 CALLING SEQUENCE:
     thm_jbt_get_btrange, tvar, nbursts=nbursts, tind=tind

 ARGUMENTS: 
    tvar: (INPUT, REQUIRED). The name of a tplot variable.

 KEYWORDS:
    nbursts: (OUTPUT, OPTIONAL) A named variable to return the number of
           sections.
    tind: (OUTPUT, OPTIONAL) A named variable to return a 2D array of the index of
          starting and ending time points with structure [[starting],[ending]]
 
 EXAMPLES:
     tvar = 'tha_efp'
     btrange = thm_jbt_get_btrange(tvar, nb = nb, tind = tind)

HISTORY:
    2009-05-04, written by Jianbao Tao, in CU/LASP.
    2010-04-08: Updated the help information. JBT, CU/LASP.

(See themis/spacecraft/fields/LASP/thm_jbt_get_btrange.pro)


THM_LSP_CHECKARG_TVAR (PROCEDURE)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     THM_LSP_CHECKARG_TVAR (PROCEDURE)

 PURPOSE:
     A utility to check whether the given argument is a valid tplot variable. A
     tplot variable is specified by a tplot name such as 'tha_efp'

 CALLING SEQUENCE:
     thm_lsp_checkarg_tvar, tvar, error, errmsg

 ARGUMENTS:
     tvar: (INPUT, REQUIRED) The argument to be checked. It must be a scalar or
           1-element array.
     error: (OUTPUT, REQUIRED) The error code returned to the caller. If tvar
           is a valid tplot variable, error=0. If not, error = 1. 
     errmsg: (OUTPUT, REQUIRED) The error message returned to the caller. If
           error = 0, errmsg=''. Otherwise a string containing error info is
           returned.

 KEYWORDS:
     None.

 EXAMPLES:
     thm_lsp_checkarg_tvar, tvar, error, errmsg
     if error ne 0 then print, errmsg

 HISTORY:
     2010-03-06: Created by JBT, CU/LASP.

(See themis/spacecraft/fields/LASP/thm_lsp_checkarg_tvar.pro)


THM_LSP_DERIVE_EZ

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: THM_EFI_DERIVE_EZ, E, B, minBz=minBz, minRat=minRat, ratio=ratio
                   

 PURPOSE: DERIVES EZ ASSUMING EdotB = 0

 INPUT: 
       E -       REQUIRED. Data structure in DSL
       B -       REQUIRED. Data structure in DSL

 KEYWORDS: 
       minBz -       OPTIONAL. Keeps from divide by zero. DEFAULT = 0.01 nT
       minRat -      OPTIONAL. Minimum value of Bz/|B|.  DEFAULT = 0.1
       ratio -       OUTPUT. = Bz/|B|

 CALLING: thm_efi_derive_Ez, Edsl, Bdsl 

 OUTPUT: Tplot 


 INITIAL VERSION: REE 08-11-04
 MODIFICATION HISTORY: 
 REE 09_05_01
 LASP, CU
 

(See themis/spacecraft/fields/LASP/thm_lsp_derive_ez.pro)


THM_LSP_EZFILTER (PROCEDURE)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     THM_LSP_EZFILTER (PROCEDURE)

 PURPOSE:
     Simply wrap up the process of filtering a tplot varialbe with a filter
     from digital_filter.

 CALLING SEQUENCE:
     thm_lsp_ezfilter, tvar, filter, newname=newname

 ARGUMENTS:
     tvar: (INPUT, REQUIRED) The name of a field tplot variable.
     filter: (INPUT, REQUIRED) A filter generated by the routine
           DIGITAL_FILTER.

 KEYWORDS:
     newname: (INPUT, OPTIONAL) A name for storing the filtered data into a new
           tplot variable.

 EXAMPLES:
     See THM_CRIB_LSP_GET_SPEC which is typically located under
     TDAS_DIR/idl/themis/examples.

 HISTORY:
     2010-03-06: Created by JBT, CU/LASP.

(See themis/spacecraft/fields/LASP/thm_lsp_ezfilter.pro)


THM_LSP_FILTER

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:  THM_LSP_FILTER, x, dt, flow, fhigh, db=db
			
		       
PURPOSE:   Filters the data COMP*.
 
INPUT:   
	x         - NEEDED. Just the data. Not a structure or name.
	dt        - NEEDED. Time between points.
       freq      - NEEDED. Pole of filter. If band_pass: [f1,f2] f1<f2
                 - If low-pass: [0,f]. If high-pass [f,0]
 
 KEYWORDS: 
       db        - OPTIONAL. If convol option is taken, default = 120. 


CREATED BY:	REE, 97-03-17 - modified 97-10-03 REE added buf_dt
FILE:  fa_fields_filter.pro
VERSION:  0.0
LAST MODIFICATION:  
REE 08-11-02, rewrite for THEMIS - no call external so much slower.
REE 09-04-30, made it a simple function.
REE 09-05-05, Added Gaussian option. Changed passband to match digital_fliter

(See themis/spacecraft/fields/LASP/thm_lsp_filter.pro)


THM_LSP_FILTER_FFT

[Previous Routine] [Next Routine] [List of Routines]
HEAD:
    function thm_lsp_filter_fft, datain, dt, flow, fhigh
                        
PURPOSE:
    This routine filters the input data with the band [flow, fhigh]. The data to
    be filtered must be continuously sammpled with the given sample rate. If
    the routine exit unsuccessfully, -1 will be retured.

ARGUMENTS
    datain: NEEDED. The data to be filtered. It must be a 1-D array.
    dt: NEEDED. The sample period of DATAIN.
    flow: NEEDED. The lower bound of the filter, in units of Hz.
    fhigh: NEEDED. The upper bound of the filter, in units of Hz.

HISTORY:
    2009-05-03: Writen by Jianbao Tao, in LASP/CU.
    2009-05-17: Fixed the edge effect due to sectioning original data.
                Jianbao Tao, in CU/LASP

(See themis/spacecraft/fields/LASP/thm_lsp_filter_fft.pro)


THM_LSP_FILTER_HIGHPASS (FUNCTION)

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
     THM_LSP_FILTER_HIGHPASS (FUNCTION)
                        
 PURPOSE:
     CAUTION: THIS ROUTINE ONLY WORKS FOR DATA SAMPLED AT EITHER 8192 HZ OR
              16384 HZ.
     In general, this routine works as a high-pass filter on the input data.
     The data to be filtered must be a continuously sampled 1D array. The basic
     process of this routine is the following. First, the input data will be
     low-pass filtered with two Finite Impulse Response filters and 2:1
     decimations. The details of this procedure is described in the paper
        Cully, Space Sci Rev, 2008, V141, 343-355.
     Second, the output from the first step is extracted from the input data to
     generate the final output. This whole process is equivalent to a high-pass
     filter. 
     If the routine exit unsuccessfully, -1 will be retured.

 CALLING SEQUENCE:
     output = thm_lsp_filter_highpass(datain, dt, [keywords])

 ARGUMENTS:
     datain: (INPUT, REQUIRED) The data to be filtered. It must be a 1D array.
     dt: (INPUT, REQUIRED) The sample interval of DATAIN in seconds; 
           1/dt = sample_rate.

 KEYWORDS:
     freqlow: (OUTPUT, OPTIONAL) The approximate lower bound of the frequency
              range of the output of the routine.

HISTORY:
    2009-05-03: Created by Jianbao Tao, CU/LASP.
    2009-05-17: Fixed the edge effect due to sectioning original data.
                Jianbao Tao, CU/LASP
    2010-01-22: Fixed the issue of dealing with a too-short input array.
                Jianbao Tao, CU/LASP

(See themis/spacecraft/fields/LASP/thm_lsp_filter_highpass.pro)


THM_LSP_FILTER_STRUC

[Previous Routine] [Next Routine] [List of Routines]
HEAD:
    function thm_lsp_filter_struc, data, dt, f_low, f_high
                        
PURPOSE:
    This routine filters the data with the band [f_low, f_high]. The data to be
    filtered must be continuously sammpled with the given sample rate. If the
    routine exit unsuccessfully, -1 will be
    retured.

ARGUMENTS
    data:        NEEDED. The data to be filtered. It must be a structure from a
                 tplot variable.
    dt:          NEEDED. The sample period of DATA.
    f_low:       NEEDED. The lower bound of the filter, in units of Hz.
    f_high:      NEEDED. The upper bound of the filter, in units of Hz.

HISTORY:
    2009-05-03: writen by Jianbao Tao, in LASP/CU.

(See themis/spacecraft/fields/LASP/thm_lsp_filter_struc.pro)


THM_LSP_FIND_BURST

[Previous Routine] [Next Routine] [List of Routines]
PRO: THM_LSP_FIND_BURST

           NOT FOR GENERAL USE. 

PURPOSE:
    Isolate an indivitual burst for analysis. 

INPUT:
    Data          -NEEDED. A data structure
    tfind         -OPTIONAL. Time of interest.

KEYWORD:

HISTORY:
   2009-05-30: REE. Broke out to run with wave burst.

(See themis/spacecraft/fields/LASP/thm_lsp_find_burst.pro)


THM_LSP_FIND_SPIKES

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION: THM_LSP_FIND_SPIKES

           NOT FOR GENERAL USE. CALLED BY THM_EFI_REMOVE_SPIKES
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

PURPOSE:
    Remove the non-physical spiky signals in the efw data.

INPUT:
    t             -NEEDED. Time array
    xx            -NEEDED. EFP data, DO NOT GIVE EFW DATA. Won't work.
    per           -NEEDED. Spin period.

KEYWORD:
    nwin          -OPTIONAL. Number of points in spike search window. DFLT = 16
    spikesig      -OPTIONAL. Sigma of spikes. DFLT = 5
    sigmin        -OPTIONAL. Minimun of sigma. DFLT = 0 mV/m.

OUTPUT:
    tpks          RETURN VALUE. Time of peaks (mod spin per) + t0
    Amp           Estimated amplitude of spikes. Helps remove_spikes.

HISTORY:
   2009-05-30: REE. Broke out to run with wave burst.

(See themis/spacecraft/fields/LASP/thm_lsp_find_spikes.pro)


THM_LSP_GET_SPEC (PROCEDURE)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     THM_LSP_GET_SPEC (PROCEDURE)

 PURPOSE:
     Get the power spectrum density (PSD) of a given tplot variable. 

 CALLING SEQUENCE:
     thm_lsp_get_spec, tvar, units = units, prefix = prefix, fftlen = fftlen, $
        yrange = yrange

 ARGUMENTS:
     tvar: (INPUT, REQUIRED) The name of a tplot variable to calculate the
           PSD from.

 KEYWORDS:
     units: (INPUT, OPTIONAL) A string of the units of the data in the tvar. By
           default, it is obtained from dlim.data_att.units, or 'unknown' if
           dlim.data_att.units is not available.
     prefix: (INPUT, OPTIONAL) The prefix for tplot variables that contain the
           resulting PSD. By default, prefix = tvar.
     fftlen: (INPUT, OPTIONAL) The number of data points to FFT. By default, 
           fftlen = 512.
     yrange: (INPUT, OPTIONAL) The yrange for the spectra. By default, yrange =
           [1, Nyquist] in units of Hz.

 EXAMPLES:
     See thm_crib_lsp_get_spec.pro which is typically located under
     TDAS_DIR/idl/themis/examples.

 HISTORY:
     2010-03-07: Created by JBT, CU/LASP.

(See themis/spacecraft/fields/LASP/thm_lsp_get_spec.pro)


THM_LSP_NOTCH_SPIKES

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION: THM_LSP_NOTCH_SPIKES

           NOT FOR GENERAL USE. 
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

PURPOSE:
    Remove the non-physical spiky signals in the efw data.

INPUT:
    t             -NEEDED. Time array
    x             -NEEDED. Data
    per           -NEEDED. Spin period.
    tpks          -NEEDED. Phase of spikes.

KEYWORD:
    nfit          -OPTIONAL. Number of points in the fit window. DFLT = 16 (256 for wave)
    fit           -OPTIONAL. If set, will perform a Gauss fit.
    Amp           -OPTIONAL. Estimated amplitudes. Same number of elements as tpks. 
    Diagnose      -OPTIONAL. Plots fits and notchs. 
    Talk          -OPTIONAL. Indicates number of fits and notchs. 

HISTORY:
   2009-05-30: REE. Broke out to run with wave burst.

(See themis/spacecraft/fields/LASP/thm_lsp_notch_spikes.pro)


THM_LSP_REMOVE_SPIKES

[Previous Routine] [Next Routine] [List of Routines]
PRO: THM_LSP_REMOVE_SPIKES

           NOT FOR GENERAL USE. 
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

PURPOSE:
    Remove the non-physical spiky signals in the efw data.

INPUT:
    t             -NEEDED. Time array
    Ex, Ey, Ez    -NEEDED. Data. Leave blank or set to zero to skip.
    per           -NEEDED. Spin period.
    Efp           -NEEDED for wave burst. Not needed for particle burst.

KEYWORD:
    nwin          -OPTIONAL. Number of points in spike search window. DFLT = 16
    spikesig      -OPTIONAL. Sigma of spikes. DFLT = 5
    sigmin        -OPTIONAL. Minimun of sigma. DFLT = 0 mV/m.
    nfit          -OPTIONAL. Number of points in the fit window. DFLT = 16
    fit           -OPTIONAL. If set, will fit spikes to Gaussian. DFLT = 0

HISTORY:
   2009-05-12: REE. Complete rewrite for wave burst.

(See themis/spacecraft/fields/LASP/thm_lsp_remove_spikes.pro)


THM_LSP_REMOVE_SPINTONE

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: THM_LSP_REMOVE_SPINTONE, t, x, per, SpinPoly=SpinPoly, $
                                    nsmooth=nsmooth, talk=talk

           NOT FOR GENERAL USE. CALLED BY THM_EFI...
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

 PURPOSE: GETS RID OF SPIN TONE AND OFFSET ON MEDIUM SIZE STRETCHES

 INPUT: 
    t             -NEEDED. Time array.
    x             -NEEDED. Data array.
    per           -NEEDED. Spin period. NOTE: input per/2 for 2nd harmonic, etc.
 
 KEYWORDS: 
                  -DEFAULT ACTION. If neither nsmooth or SpinPoly are set, sin  
                                   and cos fits over entire period are used.
    nsmooth       -OPTIONAL. If set, it takes precedence. It uses qfit 
                             and "median smooth" sin and cos over
                             nsmooth points.
    SpinPoly      -OPTIONAL. If set (and nsmooth not set), it uses qfit         
                             and polyfits sin and cos over nsmooth points.          
    
    talk          -OPTIONAL. Plots diagnostics.          

 OUTPUT: TPLOT STORE

 INITIAL VERSION: REE 99-03-25 (ff_remove_spintone)
 Space Scienes Lab, UCBerkeley
 MODIFICATION HISTORY: 
 08-10-31 Modified for THEMIS by REE
 University of Colorado

(See themis/spacecraft/fields/LASP/thm_lsp_remove_spintone.pro)


THM_LSP_REMOVE_SPIN_EPOCH

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION: THM_LSP_REMOVE_SPIN_EPOCH, t, x, per, talk=talk

           NOT FOR GENERAL USE. CALLED BY THM_EFI_REMOVE_SPIKES
           ONLY FOR ISOLATED PARTICLE OR WAVE BURSTS
           NOT FOR ENTIRE ORBIT.

PURPOSE:
    Remove the non-physical spiky signals in the efw data.

INPUT:
    t             -NEEDED. Time array
    x             -NEEDED. Data
    per           -NEEDED. Spin period.

KEYWORDS:
    talk          -OPTIONAL. Provides diagnostic plots.

HISTORY:
   2008-11-08: Created by Jianbao Tao at LASP@CU-Boulder.
   2008-11-10: The head comment was added.
   2009-03-30: REE. Rewrite to test epoch analysis.

(See themis/spacecraft/fields/LASP/thm_lsp_remove_spin_epoch.pro)


THM_QFIT

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: THM_QFIT,  data, phs, phsf=phsf, es=es, ec=ec, zero=zero,
                  do_sigma=do_sigma, sigma=sigma,
                  period=period, slide=slide, n_fitpts=n_fitpts, 
                  out=out, max_err=max_err, bad_pts=bad_pts                 
       
 PURPOSE: User unfriendly fit routine. 
          NOTE: REQUIRES CONTINUOUS BUFFERS!
          NOT FOR GENERAL USE. 

 INPUT: 
       data -        REQUIRED. A DATA ARRAY -  NOT A STRUCTURE!
                     RECOMMEND: dat_in does not have NANS. One nan
                                may destroy entire period.
       phs -         REQUIRED. An array of phases.
                     IMPORTANT! All phases must be valid! No NANs!

 KEYWORDS: 
       period   -    INPUT. Fit period. DEFAULT = 4pi
       slide    -    NO LONGER AN OPTION!
                     NOTE: Slide will be forced to be pi/2.
       n_fitpts -    INPUT. Number of points per fit. DEFAULT = 64.
       do_sigma -    OPTION. /do_sigma fills sigma.
       out      -    OPTION. /out fills bad_pts.
                     NOTE: FOR OUTLYER REJECTION, SEE BELOW!
       max_err  -    INPUT. Maximum allowable error of bad_pts. DEFAULT=25 nT

 OUTPUT: 
       phsf    -     OUTPUT. Phase of fit -> Time of fit.
       es      -     OUTPUT. Sin phase of fit.
       ec      -     OUTPUT. Cos phase of fit.
       zero    -     OUTPUT. Zero level of fit.
       sigma   -     OUTPUT. Deviation in nT. Only filled if /do_sigma
       bad_pts -     OUTPUT. Deviation in nT. Only filled if /out

 CALLING: 
       SEE ff_magdc for an example. MUST USE fa_fields_bufs, and 
       ff_zero_crossing first.

 OUT-LYING POINTS REJECTION: 
       The program must be iterated. For example, below shows one interation:

       ff_qfit,data,phs,phsf=phsf,es=es,ec=ec,zero=zero,/out, bad_pts=bad_pts
       data(bad_pts) = !values.f_nan
       index = where(finite(data), n_index)
       IF n_index GT 0 then BEGIN
           data = data(index)
           phs  = phs(index)
           ff_qfit,data,phs,phsf=phsf,es=es,ec=ec,zero=zero
       ENDIF ELSE print, "Big trouble! No valid points."

 INITIAL VERSION: REE 97-10-05
 Space Sciences Lab, UCBerkeley
 MODIFICATION HISTORY: 
 

(See themis/spacecraft/fields/LASP/thm_qfit.pro)


TRANGE_CLIP (PROCEDURE)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     TRANGE_CLIP (PROCEDURE)

 PURPOSE:
     Utility to trim the time range of a tplot variable and remove
     excess data.
 
 CALLING SEQUENCE:
     trange_clip,name, t1, t2, newname=newname, data_in=data_in,$
               remove_match=remove_match, BadClip=BadClip

 ARGUMENTS:
     name: (INPUT, REQUIRED) Either tplot variable name
                or data structure (if data_in keyword specified)
     t1: (INPUT, REQUIRED) Start time (double, time since 1970)
     t2: (INPUT, REQUIRED) Stop time (double, time since 1970)

 KEYWORDS:
     data_in: (INPUT, OPTIONAL) Set to specify that the input is a data
           structure, not a tplot name.
     remove_match: (INPUT, OPTIONAL) Removes data between t1 and t2
                     (default is keep only data between t1 and t2)
     BadClip: (OUTPUT, OPTIONAL) A named variable of the status of the clip. If
           the clip is valid, BadClip = 0, otherwise 1.
     newname: (INPUT, OPTIONAL) A new name for storing the clip into a tplot
           variable if the name is also a tplot variable name. 

 Outputs:
    Modifies the specified tplot name or data structure.

 Examples:
     tvar = 'thd_fgh_dsl'
     newname = tvar + '_clip'
     trange_clip, tvar, t1, t2, newname = newname

 MODS:
    REE. 09-05-11. Changed to work with CLEAN EFP. Added BadClip=BadClip

(See themis/spacecraft/fields/LASP/trange_clip.pro)


VH (PROCEDURE)

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
     VH (PROCEDURE)

 PURPOSE:
     To make a shortcut to the IDL procedure DOC_LIBRARY

 CALLING SEQUENCE:
     vh, pro_name

 ARUGMENTS:
     pro_name: (INPUT, REQUIRED) The name of an IDL routine.

 KEYWORDS:
     None.

 EXAMPLES:
     vh, 'trange_clip'

 HISTORY:
     2008-05-23: Created by JBT, CU/LASP.
     2010-04-07: Modified to be ready for public use. JBT, CU/LASP.

(See themis/spacecraft/fields/LASP/vh.pro)


[2]

[Previous Routine] [List of Routines]
 NAME:

       FFT_CONVOLUTION

 PURPOSE:

		Computes the convolution of two or many 1D to 3D arrays by using the FFT.

 DESCRIPTION:

		This function computes in one time the convolution of an array with
		one or more convolution kernels, e.g. F*K1*K2*...Kn.
		1 dimensional to 3 dimensional arrays are supported.

 CATEGORY:

       Mathematics.

 CALLING SEQUENCE:

		Result = FFT_CONVOLUTION(array, kernel, /DOUBLE)

 INPUTS:

		Array: 1-D to 3-D array to be convolved.

		Kernel: 1-D to 3-D array to be used as convolution kernel.
				Kernel Must have the SAME SIZE as Array.
				For multiple convolutions Kernel must have the dimension of Array + 1 and
				must have one convolution kernel for each element of the Last dimension:
				e.g.: for F(x,y)*K1(x,y)*K2(x,y) where F is of LX*LY size the kernel is
				an array of [LX, LY, 2] in size.
				The Kernel is always centered on the Array points to make convolution.

 KEYWORD PARAMETERS:

		DOUBLE: if set uses the double precision for the FFT.

 MODIFICATION HISTORY:

       Feb 2004 - 	Gianluca Li Causi & Massimo De Luca, INAF - Rome Astronomical Observatory
					licausi@mporzio.astro.it
					http://www.mporzio.astro.it/~licausi/

(See themis/spacecraft/fields/LASP/fft_convolution.pro)