This page was created by the IDL library routine mk_html_help2.

Last modified: Thu Aug 6 12:53:14 2020.


Directory Listing of Routines


Routine Descriptions

CTIME2[1]

[Next Routine] [List of Routines]
PROCEDURE:   ctime2
PURPOSE:
  A version of ctime.  May become obsolete.

 $LastChangedBy: jimm $
 $LastChangedDate: 2017-02-27 13:15:35 -0800 (Mon, 27 Feb 2017) $
 $LastChangedRevision: 22870 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/ctime2.pro $

CREATED BY:	David L. Mitchell  2013-07-26
FILE:  ctime2.pro

(See projects/maven/swea/ctime2.pro)


CTIME2[2]

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   ctime2,time,y,z
INPUT:  
    time: Named variable in which to return the selected time (seconds
          since 1970)
    y:    Named variable in which to return the y value
    z:    Named variable in which to return the z value
KEYWORDS:  
    PROMPT:  Optional prompt string
    NPOINTS: Max number of points to return
    PSYM:    If set to a psym number, the cooresponding psym is plotted at
             selected points
    SILENT:  Do not print data point information
    PANEL:   Set to a named variable to return an array of tplot panel numbers
             coresponding to the variables points were chosen from.
    APPEND:  If set, points are appended to the input arrays, 
             instead of overwriting the old values.
    VNAME:   Set to a named variable to return an array of tplot variable names,
             cooresponding to the variables points were chosen from.
    COLOR:   An alternative color for the crosshairs.  0<=color<=!d.n_colors-1
    SLEEP:   Sleep time (seconds) between polling the cursor for events.
             Defaults to 0.1 seconds.  Increasing SLEEP will slow ctime down,
             but will prevent ctime from monopolizing cpu time.
    INDS:    Return the indices into the data arrays for the points nearest the
             recorded times to this named variable.
    VINDS:   Return the second dimension of the v or y array.
             Thus  TIME(i) is  data.x(INDS(i))           and
                   Y(i)    is  data.y(INDS(i),VINDS(i))  and
                   V(i)    is  data.v(VINDS(i)) or data.v(INDS(i),VINDS(i))
             for get_data,VNAME(i),data=data,INDS=INDS,VINDS=VINDS             
    EXACT:   Get the time,y, and (if applicable) z values from the data
             arrays.  If on a multi-line plot, get the value from the line
             closest to the cursor along y.
    NOSHOW:  Do not show the plot window.
    DEBUG:   Avoids default error handling.  Useful for debugging.
    DAYS, HOURS, MINUTES, SECONDS: Sets time granularity.  For example
             with MINUTES=1, CTIME will find nearest minute to cursor
             position.

    BUTTON:  Returns the last button pressed.
PURPOSE:  
   Interactively uses the cursor to select a time (or times)
NOTES:	      If you use the keyword EXACT, ctime may run noticeablly slower.
	      Reduce the number of time you cross panels, especially with
	      tplots of large data sets.
SEE ALSO:  "crosshairs"

CREATED BY:	Davin Larson & Frank Marcoline
LAST MODIFICATION:     @(#)ctime.pro	1.40 99/04/22
WARNING!
  If ctime crashes, you may need to call:
  IDL> device,set_graph=3,/cursor_crosshair

(See projects/maven/swea/ctime2.pro)


CTIME_GET_EXACT_DATA2

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   ctime_get_exact_data2
PROCEDURE:     ctime_get_exact_data2
PURPOSE:       Get a data structure for ctime.  if var is a string or a strarr,
               create a structure of data structures.
               Get the new values for hx and hy, the crosshairs position.
               Also check the spec option.
               ctime need never see the actual data structures.
		All work is done with pointers to reduce data duplication
               and increase speed.
COMMON BLOCKS: CTIME_COMMON
HISTORY:       First appeared in ctime version 1.29

(See projects/maven/swea/ctime2.pro)


FIT_PAD_MAG

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   fit_pad_mag
PURPOSE:
  Determines the time offset between MAG1 data and SWEA MAG angles.  For SWEA pitch
  angle sorting, the magnetic field is averaged over the second half of the 2-sec
  measurement cycle.  However, there can be apparent differences between the MAG and
  SWEA timing if one of the decommutators has an error.  Here, I assume that the SWEA
  timing is correct (naturally) and fit for a constant MAG time offset.

USAGE:
  fit_pad_mag

INPUTS:

KEYWORDS:
       RESULT:       Timing and angular offsets.  The timing offset is robust.
                     Angular offsets are for reference only.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-02-04 13:44:34 -0800 (Wed, 04 Feb 2015) $
 $LastChangedRevision: 16867 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/fit_pad_mag.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/fit_pad_mag.pro)


MAV_PFDPU_PART_DECOMPRESS_DATA2

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mav_pfdpu_part_decompress_data2
PURPOSE:
  Decompresses ESA science packets (SWEA/SWIA/STATIC).  If the packet is already
  uncompressed, it is simply returned unchanged.

USAGE:
  decompressed_pkt = mav_pfdpu_part_decompress_data2(compressed_pkt)

INPUTS:
       compressed_pkt:  ESA science packet that is possibly compressed.

KEYWORDS:

 $LastChangedBy: jimm $
 $LastChangedDate: 2015-03-22 14:24:35 -0700 (Sun, 22 Mar 2015) $
 $LastChangedRevision: 17163 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mav_pfdpu_part_decompress_data2.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mav_pfdpu_part_decompress_data2.pro

(See projects/maven/swea/mav_pfdpu_part_decompress_data2.pro)


MVN_LPW_LOAD_DLM

[Previous Routine] [Next Routine] [List of Routines]

PROCEDURE:   mvn_lpw_load
PURPOSE:
 For a given UTC date, routine will check if the orbit data is present on the local machine. If not, it will download that data from the Berkeley server.
 Routine will then find the kernels required for that orbit on your machine. If they are not present, they will also be downloaded from the Berkeley server. 
 For now, routine grabs all SPICE kernels. 
 Directories of the data file and required SPICe kernels are saved into tplot variables so they can be accessed by other routines.
 Routine can only take one utc date, as our load routines only do one orbit at a time.
 

USAGE:
 mvn_lpw_load, '2014-02-02'
 mvn_lpw_load, filetype='GROUND'
 mvn_lpw_load, '2014-02-02', packet=['EUV','HSK'], tplot_var='all'
 
INPUTS:

(See projects/maven/swea/mvn_lpw_load_dlm.pro)


MVN_MAG_TPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_mag_tplot
PURPOSE:
  Makes fancy MAG tplot panels: amplitude on a log scale, and phi/theta
  in a single panel.  This routine is not intended for general use, but
  you're welcome to use it.  Much of this code was borrowed from Takuya
  Hara.

USAGE:
  mvn_mag_tplot
INPUTS:
       bvec:      Tplot variable name containing the magnetic field vectors.
                  Default = 'mvn_B_1sec_maven_mso'.

KEYWORDS:
       SANG:      Archmedian spiral angle at Mars.  Default = 54 deg (for
                  a nominal 400-km/s solar wind velocity).  The phi/theta
                  panel will contain horizontal lines at the angles for
                  toward and away sectors.

 $LastChangedBy: jimm $
 $LastChangedDate: 2017-02-17 11:57:50 -0800 (Fri, 17 Feb 2017) $
 $LastChangedRevision: 22820 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_mag_tplot.pro $

CREATED BY:	David L. Mitchell  2015-04-02

(See projects/maven/swea/mvn_mag_tplot.pro)


MVN_SC_RAMDIR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sc_ramdir
PURPOSE:
  Determines the spacecraft orbital velocity vector relative to
  the body-fixed rotating Mars frame (IAU_MARS).  The default is
  to rotate this vector into spacecraft coordinates.

  In the spacecraft frame, phi is the angle in the X-Y plane:
      0 --> +X axis (APP boom)
     90 --> +Y axis (+Y solar array and MAG1)
    180 --> -X axis
    270 --> -Y axis (-Y solar array and MAG2)

  and theta is the angle out of the X-Y plane:
    +90 --> +Z axis (HGA)
      0 --> X-Y plane
    -90 --> -Z axis

  In the APP frame, phi is the angle in the i-j plane:
      0 --> +i --> NGIMS boresight
    +90 --> +j --> IUVS fields of regard (general direction)

  and theta is the angle out of this plane:
    +90 --> +k --> STATIC symmetry direction

  This is the velocity vector -- the RAM flow is incident on the spacecraft
  from the opposite direction.

  The corotation velocity in the IAU_MARS frame as a function of altitude
  (h) and latitude (lat) is:

      V_corot = (240 m/s)*[1 + h/3390]*cos(lat)

  Models (LMD and MTGCM) predict that peak horizontal winds are 190-315 m/s 
  near the exobase and 155-165 m/s near the homopause.  These are comparable 
  to the corotation velocity.  The spacecraft velocity is ~4200 m/s in this 
  altitude range, so winds could result in up to a ~4-deg angular offset of 
  the actual flow from the nominal ram direction.

USAGE:
  mvn_sc_ramdir, trange

INPUTS:
       trange:   Time range for calculating the RAM direction.

KEYWORDS:
       DT:       Time resolution (sec).  Default is to use the time resolution
                 of maven_orbit_tplot (usually 10 sec).

       FRAME:    Rotate to FRAME coordinates instead of Spacecraft coord.
                 Any frame defined in the MAVEN frames kernel is allowed.

       MSO:      Calculate ram vector in the MSO frame instead of the
                 rotating IAU_MARS frame.  May be useful at high altitudes.

       APP:      Shorthand for FRAME='MAVEN_APP'.

       PANS:     Named variable to hold the tplot variables created.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-03-18 16:09:56 -0700 (Sat, 18 Mar 2017) $
 $LastChangedRevision: 22985 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sc_ramdir.pro $

CREATED BY:    David L. Mitchell  09/18/13

(See projects/maven/swea/mvn_sc_ramdir.pro)


MVN_STA_CIO_CLEAR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_clear
PURPOSE:
  Clears pointers to free the memory used by heap variable(s).
  If a filter has been defined as part of the data structure,
  it is cleared too. Pointers from the feature structure and/or the 
  plot-option structure are also cleared. Each input data is set to zero.

USAGE:
  mvn_sta_cio_clear, ptr
INPUTS:
       ptr    :    A pointer to heap variable(s) to be removed.

KEYWORDS:
     feature  :    Structure generated by get_mars_features.pro.
     p_option :    Structure generated by create_iono_p_options.pro.
     filteronly :  Only remove the filter.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-05-01 12:23:32 -0700 (Fri, 01 May 2020) $
 $LastChangedRevision: 28655 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_clear.pro $

CREATED BY:	David L. Mitchel
FILE:  mvn_sta_cio_clear.pro

(See projects/maven/swea/mvn_sta_cio_clear.pro)


MVN_STA_CIO_CONVERT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_convert
PURPOSE:
  Converts array-of-structures to structure-of-arrays.  Also performs
  several calculations and adds structure elements.

INPUTS:
     data  : A named variable to hold the data.  Reformatted data are
             returned in same variable.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-05-01 12:26:38 -0700 (Fri, 01 May 2020) $
 $LastChangedRevision: 28659 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_convert.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_convert.pro

(See projects/maven/swea/mvn_sta_cio_convert.pro)


MVN_STA_CIO_FILTER

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_filter
PURPOSE:
   A tag 'filter' is added to the input data structure.  This tag holds
   a pointer to a filter structure, which contains the filter definition
   and the indices of data that pass through the filter.  If a filter
   is already attached to the data structure then it will be overwritten
   with the new filter.

USAGE:
  mvn_sta_cio_filter, ptr, filter

INPUTS:
       ptr    :    A pointer to the CIO data structure.

       filter :    A structure containing allowed ranges for any of
                   the parameters, including time.  This structure can
                   have any combination of tags found in the CIO result
                   structure (see mvn_sta_cio_struct.pro).  Each tag
                   is given a range of values [min,max] that pass 
                   through that component of the filter.  For example:
 
                     filter = {tag1 : [min1, max1] , $
                               tag2 : [min2, max2] , $
                                 |          |
                               tagN : [minN, maxN]    }

                   If a tag is missing or set to 0, then no filter is
                   applied to that variable.  Only data that pass though
                   all the filters are used to calculate distributions.

                   The time range can be in any format accepted by
                   time_double().

KEYWORDS:
       LIST   :    Print information about the filter, return
                   its value via the 'filter' input (if present).

       SUCCESS :   Returns 1 if there were no problems.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-05-01 12:29:21 -0700 (Fri, 01 May 2020) $
 $LastChangedRevision: 28660 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_filter.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_filter.pro

(See projects/maven/swea/mvn_sta_cio_filter.pro)


MVN_STA_CIO_LOAD

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_load
PURPOSE:
  Loads all available MAVEN cold ion outflow data that were 
  processed by mvn_sta_coldion.pro.

INPUTS:
     ptr   : A named variable to hold a pointer to the data.
  species  : Which database to load?  ('h', 'o1', 'o2')

KEYWORDS:

    FROOT  : File root for save file (e.g., 'cio_ABCD_').

     TAGS  : A named variable to hold a string array of the names
             of the data structure tags.

     NPTS  : A named variable to hold the number of data points.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-11-09 11:42:13 -0800 (Fri, 09 Nov 2018) $
 $LastChangedRevision: 26099 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_load.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_load.pro

(See projects/maven/swea/mvn_sta_cio_load.pro)


MVN_STA_CIO_PLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_plot
PURPOSE:

USAGE:
  mvn_sta_cio_plot, ptr, KEYWORD=value, ...

INPUTS:
       ptr:        A pointer to the cold ion data structure, which
                   is obtained with 'mvn_sta_cio_load'.

KEYWORDS:
       OPTIONS:    Structure of options for selecting variables and binning
                   parameters.  Recognized options (tags) are:

           PVAR:       Parameter to plot.  Can be one of:

                         'den_i'  -> ion density
                         'den_e'  -> electron density
                         'temp'   -> ion temperature
                         'vbulk'  -> ion bulk velocity
                         'vratio' -> ratio of ion bulk velocity to escape velocity
                         'fbulk'  -> ion bulk flux (den_i * vbulk)
                         'vel_x'  -> ion velocity X component
                         'vel_y'  -> ion velocity Y component
                         'vel_z'  -> ion velocity Z component
                         'energy' -> ion bulk kinetic energy
                         'VB_phi' -> angle between V and B

           XVAR:       Parameter for the X variable.  Can be one of:

                         'time'  -> time               (UT/SCET)
                         'mso_x' -> MSO X              (Rm)
                         'mso_y' -> MSO Y              (Rm)
                         'mso_z' -> MSO Z              (Rm)
                         'mso_r' -> MSO R              (Rm)
                         'sza'   -> solar zenith angle (degrees)
                         'alt'   -> altitude           (km)
                         'slon'  -> subsolar longitude (degrees)
                         'slat'  -> subsolar latitude  (degrees)

           YVAR:       Parameter for the Y variable (see XVAR).  You must
                       specify at least one of XVAR and YVAR.  If only one
                       of these keywords is set, the binned PARAM is plotted
                       versus XVAR or YVAR.  If both are set, then a color
                       spectrogram of PVAR versus XVAR and YVAR is plotted.
                       YVAR cannot be 'time'.

           XBINS:      Number of bins for the X variable.  A reasonable
                       default based on XVAR is provided.

           YBINS:      Number of bins for the Y variable.  A reasonable
                       default based on YVAR is provided.

           XSPAN:      Range for binning the X variable.  A reasonable
                       default based on XVAR is provided.  This is not
                       the same as the X plot limits, which you specify
                       in the LIMITS keyword.

           YSPAN:      Range for binning the Y variable.  A reasonable
                       default based on YVAR is provided.  This is not
                       the same as the Y plot limits, which you specify
                       in the LIMITS keyword.

           STYPE:      Statistics to plot: 'mean' or 'median'.

           MTYPE:      Which moment to plot:
                         'sdev' : sdev/mean  (default)
                         'skew' : skewness
                         'kurt' : kurtosis
                         'adev' : adev/mean

           MINSAM:     Minimum number of samples per cell.  Cells that
                       contain fewer samples than this are not included
                       in the results.

           VVEC:       Overplots projections of the bulk velocity vectors in
                       the XVAR-YVAR plane.  Set this keyword to the scale
                       factor (Rm/km/s).  Only works when PVAR is set and 
                       XVAR and YVAR are any two of MSO_X, MSO_Y, and MSO_Z.
                       Using this keyword with MSO_R (cylindrical coordinates)
                       is misleading!

           VSKIP:      Bin spacing between vectors in x and y directions.
                       Default = [1,1], i.e., every bin gets a vector.

           VBAR:       Three element array specifying the length (km/s), and
                       position (XVAR, YVAR) for a velocity scale bar.

       DATA:       A named variable to hold the average, median and
                   standard deviation of PARAM versus XVAR and/or YVAR.
                   The sampling (number of points per cell) is also
                   provided.  Finally, a copy of the filter definition
                   is included.

       DST:        Save the distributions for each bin in DATA.  Then use
                   mvn_sta_cio_snap to view them.

       DOPLOT:     Plot PVAR vs. XVAR and/or YVAR.
                   Set this keyword to the IDL window number where you
                   want the plot to appear (1 to 31).  The window size
                   is set to keep Mars round.

       DOSAMP:     Plot the sampling function vs. XVAR and/or YVAR.
                   Set this keyword to the IDL window number where you
                   want the plot to appear (1 to 31).  The window size
                   is set to keep Mars round.

       DOMOM:      Plot a moment of the distribution vs. XVAR and/or YVAR.
                   Set this keyword to the IDL window number where you
                   want the plot to appear (1 to 31).  The window size
                   is set to keep Mars round.

       DOALL:      Put the parameter, sampling, and rms/mean plots on a
                   single page.  Also includes a panel of text with
                   filter settings.  Set this keyword to the IDL window
                   number where you want the plot to appear (1 to 31).

       FILTER:     Set this flag to a structure defining a filter.  See
                   mvn_sta_cio_filter for more information.  If not set,
                   then no filter is applied, even if it is present in 
                   the CIO data structure.

       LIMITS:     Structure of plotting options.  You can specify any
                   option(s) accepted by PLOT.  Reasonable defaults are
                   provided for all unspecified options.  To interpolate
                   the binned distribution function (not recommended), set
                   the tag 'no_interp' to zero.

       ZLIMITS:    Sampling plot Z limits, with 2 to 4 elements:

                           [zmin, zmax, zlog, zticks]

                   By default, the sampling plot has the same X and Y 
                   limits and plotting options as the parameter plot
                   (as controlled by LIMITS).  Reasonable defaults are
                   provided for the Z axis, but you can override them
                   with this keyword.

       RLIMITS:    RMS/Mean plot Z limits, with 2 to 4 elements:

                           [rmin, rmax, rlog, rticks]

                   By default, the rms/mean plot has the same X and Y 
                   limits and plotting options as the parameter plot
                   (as controlled by LIMITS).  Reasonable defaults are
                   provided for the Z axis, but you can override them
                   with this keyword.

       WSCALE:     Scale factor for sizing windows.  Default = 1 for a
                   an external monitor.  Use a smaller value for a laptop
                   monitor.

       PNG:        Set this keyword to the full filename (including path)
                   for outputting a png plot.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-05-01 12:25:16 -0700 (Fri, 01 May 2020) $
 $LastChangedRevision: 28657 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_plot.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_plot.pro

(See projects/maven/swea/mvn_sta_cio_plot.pro)


MVN_STA_CIO_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_restore
PURPOSE:
  Restores STATIC cold ion outflow results.
  See mvn_sta_coldion.pro for details.

USAGE:
  mvn_sta_cio_restore, trange

INPUTS:
       trange:        Restore data over this time range.  If not specified, then
                      uses the current tplot range.

KEYWORDS:
       LOADONLY:      Download but do not restore any cio data.

       RESULT_H:      CIO result structure for H+.

       RESULT_O1:     CIO result structure for O+.

       RESULT_O2:     CIO result structure for O2+.

       DOPLOT:        Make tplot variables.

       PANS:          Tplot panel names created when DOPLOT is set.

       SUCCESS:       Success flag.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-02-28 11:18:56 -0800 (Wed, 28 Feb 2018) $
 $LastChangedRevision: 24804 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_restore.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_sta_cio_restore.pro

(See projects/maven/swea/mvn_sta_cio_restore.pro)


MVN_STA_CIO_SAVE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_save
PURPOSE:
  Saves STATIC cold ion outflow results in save/restore files.
  See mvn_sta_coldion.pro for details.

USAGE:
  mvn_sta_cio_save, trange [, ndays]

INPUTS:
       trange:        Start time or time range for making save files, in any 
                      format accepted by time_double().  If only one time is 
                      specified, it is taken as the start time and NDAYS is 
                      used to get the end time.  If two or more times are 
                      specified, then the earliest and latest times are used.
                      Fractional days (hh:mm:ss) are ignored.

       ndays:         Number of dates to process.  Only used if TRANGE has
                      only one element.  Default = 1.

KEYWORDS:
       DODEN:         Calculate densities.  Default = 1 (yes).

       DOTEMP:        Calculate temperatures.  Default = 1 (yes).

       DOVEL:         Calculate temperatures.  Default = 1 (yes).

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-09-12 17:08:19 -0700 (Wed, 12 Sep 2018) $
 $LastChangedRevision: 25781 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_save.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_sta_cio_save.pro

(See projects/maven/swea/mvn_sta_cio_save.pro)


MVN_STA_CIO_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_snap
PURPOSE:
  Makes plots of statistics within individual pixels in maps created with
  mvn_sta_cio_plot.

USAGE:
  mvn_sta_cio_snap, data

INPUTS:
       data:       A data structure returned by mvn_sta_cio_plot.

KEYWORDS:
       KEEP:       Keep the last snapshot window on exit.

       RESULT:     Structure to hold the last distribution on exit.

       RANGE:      Range for binning the data.  Default = minmax(data).

       NBINS:      Number of bins.  Default = 30.

       LPOS:       Legend position [X,Y], relative coordinates.

       ALLSTAT:    Include skewness and kurtosis in legend.

       This routine also passes keywords to PLOT.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-05-01 12:25:49 -0700 (Fri, 01 May 2020) $
 $LastChangedRevision: 28658 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_snap.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_snap.pro

(See projects/maven/swea/mvn_sta_cio_snap.pro)


MVN_STA_CIO_STRUCT

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

PURPOSE:
  Creates a Cold Ion Outflow data structure.

INPUTS:
       NPTS:     Number of elements.  Default = 1.

KEYWORDS: 

CREATED BY:      D. L. Mitchell.

LAST MODIFICATION:
 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-09-09 18:05:59 -0700 (Sun, 09 Sep 2018) $
 $LastChangedRevision: 25764 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_struct.pro $

(See projects/maven/swea/mvn_sta_cio_struct.pro)


MVN_STA_CIO_TPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_tplot
PURPOSE:

USAGE:
  mvn_sta_cio_tplot

INPUTS:

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-11-24 13:40:12 -0800 (Sat, 24 Nov 2018) $
 $LastChangedRevision: 26170 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_tplot.pro $

CREATED BY:	David L. Mitchell
FILE:  mvn_sta_cio_plot.pro

(See projects/maven/swea/mvn_sta_cio_tplot.pro)


MVN_STA_CIO_UPDATE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_cio_update
PURPOSE:
  Updates STATIC cold ion outflow results in save/restore files.

USAGE:
  mvn_sta_cio_update, trange [, ndays]

INPUTS:
       trange:        Start time or time range for making save files, in any 
                      format accepted by time_double().  If only one time is 
                      specified, it is taken as the start time and NDAYS is 
                      used to get the end time.  If two or more times are 
                      specified, then the earliest and latest times are used.
                      Fractional days (hh:mm:ss) are ignored.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-02-27 18:37:52 -0800 (Tue, 27 Feb 2018) $
 $LastChangedRevision: 24801 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_cio_update.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_sta_cio_update.pro

(See projects/maven/swea/mvn_sta_cio_update.pro)


MVN_STA_COLDION

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_sta_coldion
PURPOSE:
  Loads STATIC data and calculates density, temperature, and velocity of
  H+, O+, and O2+.  The data are corrected for spacecraft potential and
  spacecraft motion when transforming to the MSO frame.  Thermal electron
  density from LPW is included as a check on the total ion density
  measured by STATIC.  Topology information based on the two-stream shape
  parameter (Xu) and PAD score (Weber) is attached to each measurement.
  A variety of ephemeris and geometry information are also included.

  This routine uses STATIC code developed by J. McFadden.

  This routine uses velocity moment code developed by Y. Harada and
  T. Hara.

USAGE:
  mvn_sta_coldion

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:
    BEAM:          Use the beam version of the moment calculation.  Provides
                   the most accurate densities around periapsis.  Does not
                   work at all away from periapsis.

    POTENTIAL:     Use the composite spacecraft potential determined from
                   SWEA, STATIC, and LPW.  See mvn_scpot.pro for details.
                   This should always be set!  Default = 1.

    DENSITY:       Calculate densities for O+ and O2+.  If BEAM = 0, then 
                   H+ density is also determined.  Automatically sets 
                   POTENTIAL = 1.

    TEMPERATURE:   Calculate temperatures for O+ and O2+.  If BEAM = 0, then 
                   H+ temperature is also determined.  Automatically sets 
                   POTENTIAL = 1.

    VELOCITY:      Calculate velocities of H+, O+, and/or O2+.

                     VELOCITY = 1       --> calculate for all three species
                     VELOCITY = [0,0,1] --> calculate only for O2+

                   If you set this keyword, then you must load one of the
                   following APID's, in order of preference:

                      d1 -> 32E x  8M x 4D x 16A, burst time resolution
                      d0 -> 32E x  8M x 4D x 16A, survey time resolution
                      cf -> 16E x 16M x 4D x 16A, burst time resolution
                      ce -> 16E x 16M x 4D x 16A, survey time resolution

    FRAME:         Reference frame for velocities.  Default = 'mso'.  Try 'app'
                   to get apparent flow direction in APP frame.

    RESULT_H:      Result structure for H+.

    RESULT_O1:     Result structure for O+.

    RESULT_O2:     Result structure for O2+.

    PARNG:         Pitch angle range for 2-stream shape parameter.
                      1 : 0-30 deg  (default)
                      2 : 0-45 deg
                      3 : 0-60 deg

    TAVG:          Time averaging window size.  Improves statistics and
                   reduces run time.

    NOLOAD:        Skip the step of loading data.

    PANS:          Named variable to hold a space delimited string containing
                   the tplot variable(s) created.

    RESET:         Reinitialize the result structures.

    DOPLOT:        Make tplot variables of the results.

    SUCCESS:       Processing success flag.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-11-09 11:42:36 -0800 (Fri, 09 Nov 2018) $
 $LastChangedRevision: 26100 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_sta_coldion.pro $

CREATED BY:    David L. Mitchell

(See projects/maven/swea/mvn_sta_coldion.pro)


MVN_SWE_3DSUM

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_3dsum
PURPOSE:
  Sums multiple 3D data structures.  This is done by summing raw counts
  corrected by deadtime and then setting dtc to unity.  Also, note that 
  summed 3D's can be "blurred" by a changing magnetic field direction, 
  so summing only makes sense for short intervals.  The theta, phi, and 
  omega tags can be hopelessly confused if the MAG direction changes much.

USAGE:
  dddsum = mvn_swe_3dsum(ddd)

INPUTS:
       ddd:           An array of 3D structures to sum.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-27 14:06:18 -0700 (Tue, 27 Aug 2019) $
 $LastChangedRevision: 27682 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_3dsum.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_3dsum.pro

(See projects/maven/swea/mvn_swe_3dsum.pro)


MVN_SWE_ADDEUV

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addeuv
PURPOSE:
  Loads EUV data and creates tplot variable using EUV code.  EUV is
  measured in three bandpasses:

                   Photon      Photoelectron
    Wavelength		Energy		Energy (*)		Notes
   ----------------------------------------------------------------------
    121 nm			10.2 eV     N/A				Lyman-alpha
    17-22 nm		56-73 eV    42-59 eV (#)
    0.1-7 nm	    >177 eV     >163 eV			includes soft X-rays
   ----------------------------------------------------------------------
     * first ionization potential of CO2 is 13.77 eV
     # "Al edge" is near 60 eV

USAGE:
  mvn_swe_addeuv

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:

    PANS:          Named variable to hold an array of the tplot
                   variable(s) created.

    NOFLAG:        If set, do not flag bad data.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-01-19 14:47:21 -0800 (Fri, 19 Jan 2018) $
 $LastChangedRevision: 24551 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addeuv.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addeuv.pro)


MVN_SWE_ADDLPW

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addlpw
PURPOSE:
  Loads LPW data and creates tplot variables using LPW code.

USAGE:
  mvn_swe_addlpw

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:

    PANS:          Named variable to hold the tplot variable(s) created.

    MINCUR:        Minimum peak current in IV sweep for accepting LPW
                   density.  Default = 1e-7.  Quality filter for high-
                   altitude LPW densities suggested by Chris Fowler.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-01-19 14:47:21 -0800 (Fri, 19 Jan 2018) $
 $LastChangedRevision: 24551 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addlpw.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addlpw.pro)


MVN_SWE_ADDMAG

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addmag
PURPOSE:
  Loads MAG data from L2 or L1 save/restore files, rotates the MAG vectors to
  the SWEA frame, and stores the result in the SWEA common block for quick
  access by mvn_swe_getpad and mvn_swe_get3d.

USAGE:
  mvn_swe_addmag

INPUTS:

KEYWORDS:

    FULL:          The default priority order for loading is (highest to lowest):
                     L2_1SEC, L2_FULL, L1_1SEC, L1_FULL.

                   If set, then the priority order is: L2_FULL, L1_FULL.

    USEPADMAG:     If all else fails, then use the PAD angles as calculated 
                   onboard.  In the best case, this close to MAG L1, except the
                   angular resolution is reduced (256 azimuths, 40 elevations).
                   In the worst case, it can be off by 10's of degrees.  Use with
                   caution!  Default = 0 (never use PAD angles).  If PAD angles
                   are used, the MAG level is set to zero.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2016-05-06 10:24:30 -0700 (Fri, 06 May 2016) $
 $LastChangedRevision: 21034 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addmag.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addmag.pro)


MVN_SWE_ADDPOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:       mvn_swe_addpot

PURPOSE:         Overwrites SWEA spacecraft potentials with the
                 composite potential from mvn_scpot.

INPUTS:
      none:      All information obtained from and written to common
                 blocks and tplot variables.

KEYWORDS:

CREATED BY:      D. L. Mitchell

LAST MODIFICATION:
 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-11-30 21:23:29 -0800 (Thu, 30 Nov 2017) $
 $LastChangedRevision: 24376 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addpot.pro $

(See projects/maven/swea/mvn_swe_addpot.pro)


MVN_SWE_ADDSEP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addsep
PURPOSE:
  Loads SEP data, sums over the look directions, and stores electron and ion
  energy spectra in tplot variables.

USAGE:
  mvn_swe_addsep

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:

    PANS:          Named variable to hold an array of
                   the tplot variable(s) created.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-01-19 14:47:21 -0800 (Fri, 19 Jan 2018) $
 $LastChangedRevision: 24551 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addsep.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addsep.pro)


MVN_SWE_ADDSTA

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addsta
PURPOSE:
  Loads STATIC data and creates tplot variables using STATIC code.
  By default APID's c0, c6, and ca are loaded.  This is sufficient
  to generate energy and mass spectra.  Optionally, you can also 
  load additional APID's.

USAGE:
  mvn_swe_addsta

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:
    APID:          Additional APID's to load.  This procedure always 
                   loads c0, c6, and ca.  For example, set this keyword
                   to 'd0' (4D distributions) or 'd1' (4D distributions,
                   burst) in order to calculate velocity distributions.

    POTENTIAL:     Estimate the spacecraft potential from STATIC data.

    PANS:          Named variable to hold an array of the tplot
                   variable(s) created.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-01-19 14:47:21 -0800 (Fri, 19 Jan 2018) $
 $LastChangedRevision: 24551 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addsta.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addsta.pro)


MVN_SWE_ADDSWI

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_addswi
PURPOSE:
  Loads SWIA data and calculates moments based on coarse survey.  All calculations
  are performed with the SWIA code, which stores the results as tplot variables.

USAGE:
  mvn_swe_addswi

INPUTS:
    None:          Data are loaded based on timespan.

KEYWORDS:

    FINE:          Calculate moments with fine survey.  This provides better values
                   in the upstream solar wind.

    PANS:          Named variable to hold an array of
                   the tplot variable(s) created.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-09-12 17:09:38 -0700 (Wed, 12 Sep 2018) $
 $LastChangedRevision: 25783 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_addswi.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/mvn_swe_addswi.pro)


MVN_SWE_CALC_SHAPE_ARR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_calc_shape_arr

PURPOSE:
   Take an input spectrum and calculate the shape parameter

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:
   This procedure is called by mvn_swe_shape_pad


INPUTS:

   NPTS: Number of electron energy spectrum
   
   FIN: Input electron energy spectrum
   
   Energy: The energy array corresponding to the electron energy spectrum
   
   ERANGE: The energy range given to calculate the shape parameter
   
   HRESFLG: If set to 1, then using high energy resolution (burst) pad data
            to calculate shape parameter. Usually, hresflg=0, survey pad data is used

KEYWORDS: 
   none

OUTPUTS:
   PAR: Calculated shape parameter

 $LastChangedBy: xussui_lap $
 $LastChangedDate: 2016-06-22 17:22:28 -0700 (Wed, 22 Jun 2016) $
 $LastChangedRevision: 21352 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_calc_shape_arr.pro $

CREATED BY:    Shaosui Xu  06-22-16

(See projects/maven/swea/mvn_swe_calc_shape_arr.pro)


MVN_SWE_CALIB

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_calib
PURPOSE:
  Maintains SWEA calibration factors in a common block (mvn_swe_com).

USAGE:
  mvn_swe_calib

INPUTS:

KEYWORDS:
       TABNUM:       Table number (1-8) corresponding to predefined settings:

                       1 : Xmax = 6., Vrange = [0.75, 750.], V0scale = 1., /old_def
                           primary table for ATLO and Inner Cruise (first turnon)
                             -64 < Elev < +66 ; 7 < E < 4650
                              Chksum = 'CC'X
                              LUT = 0

                       2 : Xmax = 6., Vrange = [0.75, 375.], V0scale = 1., /old_def
                           alternate table for ATLO and Inner Cruise (never used)
                             -64 < Elev < +66 ; 7 < E < 2340
                              Chksum = '1E'X
                              LUT = 1

                       3 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0., /old_def
                           primary table for Outer Cruise
                             -59 < Elev < +61 ; 3 < E < 4630
                              Chksum = 'C0'X
                              LUT = 0
                              GSEOS svn rev 8360

                       4 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1., /old_def
                           alternate table for Outer Cruise
                             -59 < Elev < +61 ; 3 < E < 4650
                              Chksum = 'DE'X
                              LUT = 1
                              GSEOS svn rev 8361

                       5 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0.
                           primary table for Transition and Science
                             -59 < Elev < +61 ; 3 < E < 4630
                              Chksum = 'CC'X
                              LUT = 0
                              GSEOS svn rev 8481

                       6 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1.
                           alternate table for Transition and Science
                             -59 < Elev < +61 ; 3 < E < 4650
                              Chksum = '82'X
                              LUT = 1
                              GSEOS svn rev 8482

                       7 : Xmax = 5.5, Erange = [200.,200.], V0scale = 0.
                           Hires 32-Hz at 200 eV
                             -59 < Elev < +61 ; E = 200
                              Chksum = '00'X
                              LUT = 2

                       8 : Xmax = 5.5, Erange = [50.,50.], V0scale = 0.
                           Hires 32-Hz at 50 eV
                             -59 < Elev < +61 ; E = 50
                              Chksum = '00'X
                              LUT = 3

                     Passed to mvn_swe_sweep.pro.

       CHKSUM:       Specify the sweep table by its checksum.  See above.
                     This only works for table numbers > 3.  Warning: Checksums
                     for tables 7 and 8 are the same, so using checksums to 
                     specify sweep tables is now ambiguous.  See mvn_swe_getlut,
                     which resolves this ambiguity with housekeeping sweep
                     voltage readbacks and provides a more robust method of 
                     determining which LUT is in use at any time.

       SETCAL:       Structure holding calibration factors to modify.  Structure can
                     have any combination of tags, but only the following are
                     recognized (with default values):

                       {swe_Ka      : 6.17      , $   ; analyzer constant
                        swe_G       : 0.009/16. , $   ; nominal geometric factor
                        swe_Ke      : 2.8       , $   ; electron suppression constant
                        swe_dead    : 2.8e-6    , $   ; deadtime per preamp
                        swe_min_dtc : 0.25         }  ; max 4x deadtime correction

                     Any other tags are ignored.

       DEFAULT:      Reset calibration factors to the default values (see above).

       LIST:         List the current calibration constants.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-11-25 14:09:26 -0800 (Mon, 25 Nov 2019) $
 $LastChangedRevision: 28065 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_calib.pro $

CREATED BY:    David L. Mitchell  03-29-13
FILE: mvn_swe_calib.pro

(See projects/maven/swea/mvn_swe_calib.pro)


MVN_SWE_CATALOG

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_catalog
PURPOSE:
  Looks in the SWEA L2 data directories and builds a catalog of files
  organized by type, year and month.

USAGE:
  mvn_swe_catalog

INPUTS:
       None.

KEYWORDS:
       VERSION:       Look for L2 files with this version number.
                      Default is to use the current release version.

       REVISION:      Look for L2 files with this revision number.
                      Default is to look for the latest revision.

       MTIME:         Look for L2 files modified after this time.
                      Default is to look for all files regardless of
                      modification time.

       RESULT:        Named variable to hold the result structure
                      containing all valid file names organized by
                      type, year and month.

       VERBOSE:       Print out number of files of each type by
                      year and month.  This is the main point, so 
                      the default is 1 (yes).

       TOUCH:         Change the access and modification times of 
                      all files collected in RESULT to the current
                      time.  This can be used to "encourage" file
                      transfers to the SDC.  Works only in unix-like
                      environments.  Use with caution!

       TRANGE:        Search for files only within this time range.
                      Only year, month, day are used.

       PDS:           Search for files only in this PDS release
                      number or range.

       DROPBOX:       Place copies of the files into the dropbox.
                      This will force immediate delivery to the SDC.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-02-11 12:14:26 -0800 (Mon, 11 Feb 2019) $
 $LastChangedRevision: 26597 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_catalog.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mvn_swe_catalog.pro

(See projects/maven/swea/mvn_swe_catalog.pro)


MVN_SWE_CLEAR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_clear
PURPOSE:
  Clears the swe_dat common block.

     swe_hsk:  slow housekeeping
     a0:       3D survey
     a1:       3D archive
     a2:       PAD survey
     a3:       PAD archive
     a4:       ENGY survey
     a5:       ENGY archive
     a6:       fast housekeeping

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 16:00:57 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26826 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_clear.pro $

CREATED BY:	David L. Mitchell  2013-07-26
FILE:  mvn_swe_clear.pro

(See projects/maven/swea/mvn_swe_clear.pro)


MVN_SWE_COM

[Previous Routine] [Next Routine] [List of Routines]
COMMON BLOCK:   mvn_swe_com
PURPOSE:
  Stores the SWEA static memory.

     swe_hsk:  slow housekeeping
     a0:       3D survey
     a1:       3D archive
     a2:       PAD survey
     a3:       PAD archive
     a4:       ENGY survey
     a5:       ENGY archive
     a6:       fast housekeeping

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:43:23 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26815 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_com.pro $

CREATED BY:	David L. Mitchell  2013-03-18
FILE:  mvn_swe_com.pro

(See projects/maven/swea/mvn_swe_com.pro)


MVN_SWE_CONFIG

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_config
PURPOSE:
  Maintains SWEA configuration changes in a common block (mvn_swe_com).
  Sweep table updates are handled by checksums (see mvn_swe_sweep) - times
  are recorded here as documentation.

  Mission phases are as follows:

    Event       Time (UTC)             Mission Phase
    -----------------------------------------------------------------------
    Launch      2013-11-18/18:28  - 
                                   |-> Cruise
    MOI         2014-09-22/01:50  -
                                   |-> Transition (Commissioning)
    Sci Ops     2014-11-15/00:00  -
                                   |-> Primary Mission    (PDS R1 - R4)
    Ext Ops 1   2015-11-15/00:00  -
                                   |-> Extended Mission 1 (PDS R5 - R7.5)
    Ext Ops 2   2016-10-01/00:00  - 
                                   |-> Extended Mission 2 (PDS R7.5 - R16)
    Ext Ops 3   2018-10-01/00:00  -
                                   |-> Extended Mission 3 (PDS R17 - R20)
    Ext Ops 4   2019-10-01/00:00  - 
                                   |-> Extended Mission 4 (PDS R21 - R32)
    Ext Ops 5   2022-10-01/00:00  -
    -----------------------------------------------------------------------

USAGE:
  mvn_swe_config

INPUTS:

KEYWORDS:

    LIST:          List all configuration changes.

    TIMEBAR:       Overplot vertical dotted lines at the times of configuration
                   changes in a tplot window (assumed to exist).

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-17 11:20:42 -0700 (Tue, 17 Mar 2020) $
 $LastChangedRevision: 28421 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_config.pro $

CREATED BY:    David L. Mitchell  03-29-13
FILE: mvn_swe_config.pro

(See projects/maven/swea/mvn_swe_config.pro)


MVN_SWE_CONVERT_UNITS

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_convert_units
PURPOSE:
	Convert units for SPEC, PAD, and 3D data.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_convert_units, data, units, SCALE=SCALE
INPUTS: 
	Data: A 3D, PAD, or SPEC data structure for SWEA
	Units: Units to convert the structure to.  Recognized units are:
            COUNTS : raw counts, uncorrected for deadtime
            RATE   : raw count rate, uncorrected for deadtime
            CRATE  : count rate, corrected for deadtime
            FLUX   : differential number flux (1/cm^2-s-ster-eV)
            EFLUX  : differential energy flux (eV/cm^2-s-ster-eV)
            E2FLUX : energy flux per energy bin (eV/cm^2-s-ster-bin)
            DF     : distribution function (1/(cm^3-(km/s)^3))
KEYWORDS:
	SCALE: Returns the array of conversion factors used
OUTPUTS:
	Returns the same data structure in the new units

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:42:31 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26814 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_convert_units.pro $

(See projects/maven/swea/mvn_swe_convert_units.pro)


MVN_SWE_CROSSCAL

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_crosscal
PURPOSE:
  Calculates SWEA-SWIA cross calibration factor as a function of time.
  Based on polynomial fits to numerous cross calibrations between SWEA
  and SWIA in the upstream solar wind, when both instruments were 
  measuring the complete electron and ion distributions, respectively.
  Only periods of steady solar wind, when the spacecraft potential can
  be reliably estimated from SWEA data are used.

  The variation of the cross calibration factor with time after each 
  MCPHV bump is well fit with a quadratic, so I'll allow extrapolation
  into periods with no solar wind coverage.

  Assumptions:

    (1) Charge neutrality.

    (2) SWIA is measuring the entire ion distribution.  This is safe 
        in the upstream solar wind, as long as the spacecraft is Sun
        pointed, which is most of the time.  Watch out for times of
        Earth point.

    (3) The energy flux in SWEA's blind spots is the same as the 
        average energy flux over the rest of the field of view.  This
        can be very much in error for the solar wind halo distribution;
        however, most of the density is in the core distribution, which
        is not strongly directional.

USAGE:
  factor = mvn_swe_crosscal(time)

INPUTS:
       time:         A single time or an array of times in any format 
                     accepted by time_double().

KEYWORDS:
       ON:           Turn cross calibation switch on.

       OFF:          Turn cross calibration switch off.

       REFRESH:      Refresh the polynomial coefficients.

       EXTRAP:       Extrapolate past the last measured cross calibration
                     factor using a quadratic fit to all values since the 
                     last MCPHV bump. (This is the default.)  Set this 
                     keyword to zero to use the last known value instead.

       SILENT:       Don't print any warnings or messages.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-17 11:20:05 -0700 (Tue, 17 Mar 2020) $
 $LastChangedRevision: 28420 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_crosscal.pro $

CREATED BY:    David L. Mitchell  05-04-16
FILE: mvn_swe_crosscal.pro

(See projects/maven/swea/mvn_swe_crosscal.pro)


MVN_SWE_D2F_HEII

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_d2f_heii

PURPOSE:
   To calculate second derivatives of energy flux, used in routine 
   'mvn_swe_sc_negpot_twodir_burst'

INPUTS:
   faway,ftwd,energy,ee

KEYWORDS:

   ERANGE


OUTPUTS:
   d2f_away,d2f_twd

 $LastChangedBy: xussui_lap $
 $LastChangedDate: 2017-12-01 11:52:37 -0800 (Fri, 01 Dec 2017) $
 $LastChangedRevision: 24384 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_d2f_heii.pro $

CREATED BY:    Shaosui Xu  01-03-17

(See projects/maven/swea/mvn_swe_d2f_heii.pro)


MVN_SWE_EPARAM

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_eparam
PURPOSE:
  Calculates the gyrofrequency, gyroradius and adiabatic condition
  (1st adiabatic invariant) for electrons:

    Fg = (28 Hz)*B           ; gyrofrequency, [B] = nT

    Rg = (2.4 km)*sqrt(E)/B  ; gyroradius, [E] = eV, [B] = nT

    (1/B)*(dB/dx)*Rg << 1    ; adiabatic condition

  Collision frequencies (s-1) for electrons with neutrals ([Te] = K, [n] = cm-3)
  (from Ionospheres by Schunk & Nagy, Table 4.6 on pg. 99):
    N2    (2.33e-11) * n(N2)  * (1 - 1.21e-4*Te)*Te
    O2    (1.82e-10) * n(O2)  * (1 + 3.60e-2*sqrt(Te))*sqrt(Te)
    O     (8.90e-11) * n(O)   * (1 + 5.70e-4*Te)*sqrt(Te)
    He    (4.60e-10) * n(He)  * sqrt(Te)
    H     (4.50e-09) * n(H)   * (1 - 1.35e-4*Te)*sqrt(Te)
    CO    (2.34e-11) * n(CO)  * (Te + 165)
    CO2   (3.68e-08) * n(CO2) * (1 + 4.1e-11*abs(4500 - Te)^2.93)

USAGE:
  mvn_swe_eparam

INPUTS:
   None:      Mag data are obtained from tplot variable.  Spacecraft ephemeris
              is obtained from common block.

KEYWORDS:
   MINALT:    Below this altitude, electrons are assumed to be non-adiabatic
              because of collisions with atmospheric species.

   ENERGY:    Electron energies (eV) for which to calculate parameters.
              Default = [1000.,100.,10.]


 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-11-04 17:36:55 -0800 (Wed, 04 Nov 2015) $
 $LastChangedRevision: 19246 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_eparam.pro $

CREATED BY:    David L. Mitchell  09/18/15

(See projects/maven/swea/mvn_swe_eparam.pro)


MVN_SWE_ESUPPRESS

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_esuppress
PURPOSE:
  Calculates the SWEA electron suppression constant (Ke).  The correction is
  based on monthly calibration sequences, during which the sweep table
  alternates between table 5 (V0 disabled) and table 6 (V0 enabled) several
  times.

  Empirically, the energy dependence of the suppression behaves as if there
  is a slightly different work function near the entrance aperture (top cap 
  and entrance to concentric hemispheres) compared with the hemispheres closer 
  to the MCP.  This is modeled as two ESA's in series that have different 
  analyzer constants.  The functional form of the correction factor is then an 
  exponential:

      correction factor = exp(-(Ke/E_in)^2.)

  where E_in is the energy of the electron interior to the toroidal grids.
  When Ke = 0, the correction factor is unity.  Otherwise, there is a steep 
  drop in sensitivity for E_in <~ Ke.

  This is the same functional form as observed for STATIC ion suppression.
  For STATIC, there is a clear time dependence over the mission and a 
  directionality (mainly in RAM) that points to the influence of atomic O
  on internal STATIC surfaces, which are coated with CuO (commonly known by
  the trade name "Ebonol C").  The hypothesis is that atomic oxygen is 
  altering the work function of CuO near the aperture.

  However, SWEA internal surfaces are coated with Cu2S instead of CuO, and 
  there is no clear variation of the electron suppression with time.  This
  suggests that exposure to atomic O does not affect SWEA significantly, and
  consequently that the suppression has been present since launch.

USAGE:
  Ke = mvn_swe_esuppress(time)

INPUTS:
       time:         A single time or an array of times in any format 
                     accepted by time_double().

KEYWORDS:
       ON:           Enable suppression correction.

       OFF:          Disable suppression correction.

       SET:          Set the suppression constant to any fixed value > 0.
                     (This also enables the suppression correction.)  This 
                     value remains persistent until you override it with a
                     different value or disable it altogether with SET = 0.
                     Note that SET = 0 reverts to the nominal suppression
                     constant; it does not disable the correction.

                     This is useful for fine tuning the correction, 
                     especially outside of the calibrated time range
                     (2015-03-01 to 2016-09-01).

       SILENT:       Don't print any warnings or messages.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-10-02 16:44:57 -0700 (Mon, 02 Oct 2017) $
 $LastChangedRevision: 24086 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_esuppress.pro $

CREATED BY:    David L. Mitchell  2016-09-13
FILE: mvn_swe_esuppress.pro

(See projects/maven/swea/mvn_swe_esuppress.pro)


MVN_SWE_ETSPEC

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	MVN_SWE_ETSPEC

PURPOSE:
	Makes tplot variables with respect to the MAVEN SWEA
       Energy-time spectrogram(s). 

CALLING SEQUENCE: 
       mvn_swe_etspec, ['2014-11-17/08:04:19', '2014-11-17/12:40:31'], $
                      units='eflux', data_type='3d', $
                      angle='pa', /default

INPUTS: 
   none - 3D, PAD, or SPEC  data are obtained from SWEA common block.
   If you set the time interval, then a tplot variable is created
   between you specified time intervals.  
   (Noted that it might take more than 10 minutes to resample pitch
   angle distributions if you use PAD data for 1 day, depending on
   your machine spec and data amount.)

KEYWORDS:
   TRANGE:    Instead of an input variable, you can alternatively specify
              the time interval when you want to create a tplot variable.

   DATA_TYPE: Chooses the data product type ('3d', 'pad', or 'spec')
              Default is 'spec'.

   ERANGE:    Specifies energy range over which you want to plot .
              Default is the whole enegy range.

   UNITS:     Sets the unit to prefer to use. Default = 'crate'.

   ANGLE:     Selects the angular spectrum. Now 'pa' is only available.
              'pa' means it can plot the pitch-angle-sorted, energy-time
              spectrogram. In near future, 'phi'(= azimuth anode),
              'theta'(= deflection angle) will be available.
   
   PHI:       Limits the azimuth anode (or looking direction) as
              2-elements array [min, max], in degrees.

   THETA:     Limits the deflection angle (or lookgin direction) as
              2-elements array [min, max], in degrees.

   PITCH:     Limits the pitch angle as 2-elements array [min, max],
              in dgrees. If it is used, 'mvn_swe_pad_resample' is
              automatically executed.

   SUFFIX:    Sets a tplot suffix to apply when generating outputs.

   MASK:      Masks the expected angular bins whose field of view is
              blocked by the spacecraft body and solar
              paddles. Automatically identifying the mission phases
              (cruise or science mapping).

   STOW:      (Obsolete). Mask the angular bins whose field of view
              is blocked before the boom deploy. 

   ARCHIVE:   Uses the archive data, instead of the survey data.

   WINDOW:    Set the window number to show the snapshot. Default = 0.

   ABINS:     Specify which anode bins to 
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,16)

   DBINS:     Specify which deflection bins to
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,6)

   MBINS:     Specify which angular (both anode and deflection) bins
              to include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1, 96)

   SC_POT:    Account for the spacecraft potential correction.
              (Not completely activated yet)

   VERBOSE:   Controls how often the processing information is shown
              onto the terminal.

   Default:   If you use this keyword, the following tplot variables
              are automatically created:
              If you also use the keyword as angle='pa',
                 - quasi-parallel (0-30 deg),
                 - quasi-perpendicular (75-105 deg),
                 - quasi-antiparallel (150-180 deg),
              Above 3 directional pitch-angle-sorted energy-time spectrograms
              are created.
              If you do NOT use 'angle' keyword, 
                 - sunward      (+ MSO_X)
                 - anti-sunward (- MSO_X)
                 - duskward     (+ MSO_Y)
                 - dawnward     (- MSO_Y)
                 - northward    (+ MSO_Z)
                 - southward    (- MSO_Z)
              Above 6 directional enegry-time spectrograms
              are created if SPICE/Kernels are available.

  FRAME:      Sets the coordinate system to define the direction. 
              In the present version, the coordinate system(s)
              derived from the SPICE/Kernels are available, 
              e.g., 'MAVEN_MSO', 'IAU_MARS', 'MAVEN_SWEA' or so on.

CREATED BY:      Takuya Hara on 2014-11-22. 

 $LastChangedBy: hara $
 $LastChangedDate: 2015-08-12 20:41:21 -0700 (Wed, 12 Aug 2015) $
 $LastChangedRevision: 18478 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_etspec.pro $

MODIFICATION LOG:
(YYYY-MM-DD)
 2014-11-22: Starts to prepare this routine.
 

(See projects/maven/swea/mvn_swe_etspec.pro)


MVN_SWE_FLATFIELD

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_flatfield
PURPOSE:
  Maintains the angular sensitivity calibration and provides a means to
  enable and disable the correction.  See mvn_swe_fovcal for details.
  You can choose only one action: ON, OFF, or SET.  If you don't specify
  an action, no change is made, and the routine only reports its current
  state.

  Calibrations are performed in the solar wind, using the strahl as a
  calibration beam.  As the magnetic field direction changes, different
  parts of the FOV are "illuminated".  Electron 3D distributions are 
  corrected for spacecraft potential and transformed to the plasma rest
  frame (using SWIA data), where the gyrotropy condition applies.
  Correction factors are then determined for each of the 96 angular bins
  that symmetrizes the angular distribution with respect to the magnetic
  field direction.  To date, the solar wind calibration periods are:

      1 : 2014-10-27 to 2015-03-14
      2 : 2015-06-10 to 2015-10-15
      3 : 2015-12-13 to 2016-04-05
      4 : 2016-05-29 to 2016-10-06
      5 : 2016-11-28 to 2017-03-15
      6 : 2017-06-13 to 2017-08-22
      7 : 2017-12-10 to 2018-04-25
      8 : 2018-06-23 to 2018-11-13 (break at MCP bump)
      9 : 2018-11-13 to 2019-03-25
     10 : 2019-05-08 to 2019-08-14
     11 : 2019-10-23 to 2019-12-23
     12 : 2020-03-03 to ...

  Solar wind periods 1 and 3 yield calibrations that are very similar.
  These are combined into a single FOV calibration.  Solar wind period
  2 occurred when the SWEA MCP bias was not optimized.  The lower MCP
  gain results in a measurably different FOV sensitivity.

  Once set, a configuration is persistent within the current IDL session 
  until changed with this routine.

USAGE:
  ff = mvn_swe_flatfield(time)

INPUTS:
       time:         Specify the time (in any format accepted by time_double)
                     for calculating the flatfield correction.

KEYWORDS:
       NOMINAL:      Enable the nominal correction.

       SET:          Set the flatfield to this 96-element array.

       OFF:          Disable the correction.

       SILENT:       Don't print any warnings or messages.

       INIT:         Reinitialize the flatfield common block.

       TEST:         Returns calibration used.  For testing.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-21 14:50:59 -0700 (Sat, 21 Mar 2020) $
 $LastChangedRevision: 28450 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_flatfield.pro $

CREATED BY:    David L. Mitchell  2016-09-28
FILE: mvn_swe_flatfield.pro

(See projects/maven/swea/mvn_swe_flatfield.pro)


MVN_SWE_FOVCAL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_fovcal
PURPOSE:
  Given 3D electron distributions, the magnetic field direction, the 
  solar wind velocity, and the spacecraft potential, this routine 
  estimates the relative sensitivities of the SWEA 3D angular bins.
  The technique takes advantage of the fact that the electron 
  distribution should be very nearly gyrotropic in the plasma rest 
  frame.

  Assumptions: (1) The measured magnetic field vector is accurate, and
                   apparent deviations from gyrotropy are caused entirely
                   by uncompensated variations in sensitivity around the
                   field of view.

               (2) A polynomial fit to the measured distribution is a
                   reasonable approximation to the "true" distribution.
                   Corollary: There are no sharp features in the pitch
                   angle distribution.

  Errors caused by (1) can be minimized by comparing the magnetic field
  vector to the symmetry direction of the electron angular distribution.
  Only times when these two directions agree to within a fraction of a 
  ~20-deg-wide angular bin are used.  Exceptions can be made when the
  magnetic field vector is in or near one of SWEA's blind spots, in which
  case the symmetry direction is ill defined.  See swe_3d_strahl_dir.

  Errors caused by (2) can be minimized by visually inspecting the fits
  before adding the calibration to the database.  There are, occasionally,
  sharp features in the pitch angle distribution, and these should be
  avoided.

  Since the calibration is based on numerous pitch angle distributions, 
  each with its own polynomial fit, the assumption is that any remaining
  errors introduced by (1) and (2) will be averaged out.

USAGE:
  mvn_swe_fovcal, result=result

INPUTS:

KEYWORDS:
       UNITS:     Units.

       MINCNTS:   Minimum number of raw counts for calculating the result.
                  Used to ensure reasonable statistics. Default = 30.

       ORDER:     A one- or two-element integer array specifying the 
                  polynomial orders for each half of the pitch angle
                  distribution.  Default = [4,4].

       MIDPA:     Pitch angle at which to divide the spectrum for fitting
                  each polynomial.  Default = 90 deg.

       OLAP:      Pitch angle width for overlapping MIDPA for polynomial 
                  fits.  Produces more reasonable fits by constraining the
                  polynomial to continue going through data points beyond
                  MIDPA.  Default = 10 deg.

       ENERGY:    Energy at which to perform the calibration.  Default is
                  125 eV.

       SYMDIR:    Use the 3D symmetry direction instead of the magnetic
                  field vector.  Use with caution, since this routine is
                  symmetrizes the distribution based on this direction.

       SCP:       Set the spacecraft potential to this value.

       CALNUM:    Set the nominal calibration to this solar wind period.
                  Default = 1.

       RESULT:    A structure containing the time and a 96-element array
                  containing the relative geometric factors for the 3D
                  bins.

CREATED BY:	David L. Mitchell  2016-08-03

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-26 16:50:29 -0700 (Mon, 26 Aug 2019) $
 $LastChangedRevision: 27657 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_fovcal.pro $

(See projects/maven/swea/mvn_swe_fovcal.pro)


MVN_SWE_FOVPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_fovplot
PURPOSE:
  Plots the results of a FOV calibration obtained with mvn_swe_fovcal.

USAGE:
  mvn_swe_fovplot, dat, result=result

INPUTS:
       dat1:      A FOV calibration structure obtained with mvn_swe_fovcal.

       dat2:      A FOV calibration structure obtained with mvn_swe_fovcal.
                  If present, create the ratio dat2/dat and propagate errors.

KEYWORDS:
       BAD:       A set of solid angle bins to ignore when calculating the
                  azimuth and elevation responses.  Bins blocked by the 
                  spacecraft are automatically ignored.

       DATE:      Date string associated with calibration ('MMM YYYY').

       CRANGE:    Color scale range.  Default = [0.5,1.5].

       YRANGE:    RGF range for data point plot.  Default = [0,1.4].

       MAP:       Mapping projection.  Can be one of:
                     'mol' = Mollweide
                     'cyl' = Cylindrical
                     'ort' = Orthographic
                     'ait' = Aitoff (default)
                     'lam' = Lambert
                     'gno' = Gnomic
                     'mer' = Mercator

       LON:       Center longitude for 3D map.  Default = 180.

       LAT:       Center latitude for 3D map.  Default = 0.

       RESULT:    Structure containing the azimuth and elevation responses
                  with uncertainties.

       CAT:       Print the results.

       PSNAME:    File name for postscript output.

CREATED BY:	David L. Mitchell  2016-08-03

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-26 16:48:53 -0700 (Mon, 26 Aug 2019) $
 $LastChangedRevision: 27655 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_fovplot.pro $

(See projects/maven/swea/mvn_swe_fovplot.pro)


MVN_SWE_GET3D

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_get3d
PURPOSE:
  Returns a SWEA 3D data structure constructed from L0 data or extracted
  from L2 data.  This routine automatically determines which data are loaded.
  Optionally sums the data over a time range, propagating uncertainties.

USAGE:
  ddd = mvn_swe_get3d(time)

INPUTS:
       time:          An array of times for extracting one or more 3D data structure(s)
                      from survey data (APID A0).  Can be in any format accepted by
                      time_double.

KEYWORDS:
       ARCHIVE:       Get 3D data from archive instead (APID A1).

       BURST:         Synonym for ARCHIVE.

       ALL:           Get all 3D spectra bounded by the earliest and latest times in
                      the input time array.  If no time array is specified, then get
                      all available spectra from the currently loaded data.

       SUM:           If set, then sum all 3D's selected.

       UNITS:         Convert data to these units.  (See mvn_swe_convert_units)

       SHIFTPOT:      Correct for spacecraft potential.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:45:14 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26818 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_get3d.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_get3d.pro

(See projects/maven/swea/mvn_swe_get3d.pro)


MVN_SWE_GETBITS

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_getbits
PURPOSE:
  Extracts a sub-word defined by a range of bits from an input word.

USAGE:
  subword = mvn_swe_getbits(word, bitrange)

INPUTS:
       word:          A 16-bit (2-byte) word.  Can also be an array of words.
                      Can also be a byte or an array of bytes.

       bitrange:      A one- or two-element array specifying the desired bit or 
                      range of bits: [MSB [, LSB]], where MSB and LSB are integers 
                      between 0 and 15.  If MSB and LSB are the same, or if only 
                      one bit is specified, then just that one bit is returned.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 12:38:38 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16103 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_getbits.pro $

CREATED BY:    David L. Mitchell  08-29-11
FILE: mvn_swe_getbits.pro
VERSION:   1.0
LAST MODIFICATION:   08/29/11

(See projects/maven/swea/mvn_swe_getbits.pro)


MVN_SWE_GETLUT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_getlut
PURPOSE:
  Determines the sweep lookup table used for each 2-sec measurement
  cycle.  This information is stored in the SPEC, PAD, and 3D data
  structures.  The vast majority of the time a single sweep table is
  used, in which case this routine is trivial.  The exceptions are
  power on, monthly calibrations (until late 2019) and high time
  resolution campaigns.  The latter two use rapid mode toggling, so
  that high cadence housekeeping is needed to keep track of the mode
  changes.  Even then, there are occasional mismatches between the 
  sweep table reported in housekeeping and the one actually used for 
  measurements.  Three methods are provided (via keyword) to identify 
  and correct these mismatches.  None is perfect, but at least one of
  them, depending on the circumstances, has been able to identify all
  table changes correctly ... so far.

USAGE:
  mvn_swe_getlut

INPUTS:
       None.

KEYWORDS:
       TPLOT:    Make a tplot variable.

       DT_LUT:   Time offset between housekeeping SSCTL values and
                 science data.  Units: sec.  Default = 0D.

       VOLT:     Use analyzer voltage to identify tables 7 and 8.

       FLUX:     Use constant flux to identify tables 7 and 8.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:22:18 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28837 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_getlut.pro $

(See projects/maven/swea/mvn_swe_getlut.pro)


MVN_SWE_GETPAD

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_getpad
PURPOSE:
  Returns a SWEA PAD data structure constructed from L0 data or extracted
  from L2 data.  This routine automatically determines which data are loaded.
  Optionally sums the data over a time range, propagating uncertainties.

USAGE:
  pad = mvn_swe_getpad(time)

INPUTS:
       time:          An array of times for extracting one or more PAD data structure(s)
                      from survey data (APID A2).  Can be in any format accepted by
                      time_double.

KEYWORDS:
       ARCHIVE:       Get PAD data from archive instead (APID A3).

       BURST:         Synonym for ARCHIVE.

       ALL:           Get all PAD spectra bounded by the earliest and latest times in
                      the input time array.  If no time array is specified, then get
                      all PAD spectra from the currently loaded data.

       SUM:           If set, then sum all PAD's selected.

       UNITS:         Convert data to these units.  (See mvn_swe_convert_units)
                      Default = 'eflux'.

       SHIFTPOT:      Correct for spacecraft potential.

       HIRES:         Returns 0 for normal resolution (2-sec) data; returns 1 for
                      high resolution (0.03-sec) data.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:46:16 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26819 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_getpad.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_getpad.pro

(See projects/maven/swea/mvn_swe_getpad.pro)


MVN_SWE_GETSPEC

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_getspec
PURPOSE:
  Returns a SWEA SPEC data structure constructed from L0 data or extracted
  from L2 data.  This routine automatically determines which data are loaded.
  Optionally sums the data over a time range, propagating uncertainties.

USAGE:
  spec = mvn_swe_getspec(time)

INPUTS:
       time:          An array of times for extracting one or more SPEC data structure(s).
                      Can be in any format accepted by time_double.  If more than one time
                      is specified, then all spectra between the earliest and latest times
                      in the array is returned.

KEYWORDS:
       ARCHIVE:       Get SPEC data from archive instead (APID A5).

       BURST:         Synonym for ARCHIVE.

       SUM:           If set, then sum all spectra selected.

       UNITS:         Convert data to these units.  Default = 'EFLUX'.

       SHIFTPOT:      Correct for spacecraft potential (must call mvn_scpot first).

       YRANGE:        Returns the data range, excluding zero counts.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-08-31 11:31:33 -0700 (Thu, 31 Aug 2017) $
 $LastChangedRevision: 23867 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_getspec.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_getspec.pro

(See projects/maven/swea/mvn_swe_getspec.pro)


MVN_SWE_HSKPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_hskplot
PURPOSE:
  Plots time series summary plots of SWEA housekeeping data over arbitrarily
  long time spans.  The result is stored in TPLOT variables.

USAGE:
  mvn_swe_hskplot, trange=trange, orbit=orbit, hsk=hsk

INPUTS:

KEYWORDS:

       TRANGE:       Time range over which load data.  Must have at least two
                     elements, in any format accepted by time_double().  If
                     not specified, then load data using the current timespan.

       ORBIT:        Load data by orbit number (overrides TRANGE and TIMESPAN
                     methods).

       HSK:          Restore housekeeping from this IDL save/restore file.
                     (Full path and name required.)

       RESET:        Sets common block HSK to zero.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-10-21 10:15:04 -0700 (Mon, 21 Oct 2019) $
 $LastChangedRevision: 27902 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_hskplot.pro $

CREATED BY:    David L. Mitchell  2017-04-06

(See projects/maven/swea/mvn_swe_hskplot.pro)


MVN_SWE_INIT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_init
PURPOSE:
  Initializes SWEA common block (mvn_swe_com).


USAGE:
  mvn_swe_init

INPUTS:

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-10-02 16:45:21 -0700 (Mon, 02 Oct 2017) $
 $LastChangedRevision: 24087 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_init.pro $

CREATED BY:    David L. Mitchell  02-01-15
FILE: mvn_swe_init.pro

(See projects/maven/swea/mvn_swe_init.pro)


MVN_SWE_KP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_kp
PURPOSE:
	Calculates SWEA key parameters.  The result is stored in tplot variables,
   and as a save file.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_kp
INPUTS:
   None:      Uses data currently loaded into the SWEA common block.

KEYWORDS:
   PANS:      Named variable to return tplot variables created.

   MOM:       Calculate density using a moment.  This is the default and
              only option for now.

   DDD:       Calculate density from 3D distributions (allows bin
              masking).  Default is to use SPEC data.  This option fits
              a Maxwell-Boltzmann distribution to the core and performs
              a moment calculation for the halo.  This provides corrections
              for both spacecraft potential and scattered photoelectrons.
              (Currently disabled.)

   ABINS:     Anode bin mask - 16-element byte array (0 = off, 1 = on)
              Default = replicate(1B, 16).

   DBINS:     Deflector bin mask - 6-element byte array (0 = off, 1 = on)
              Default = replicate(1B, 6).

   OBINS:     Solid angle bin mask - 96-element byte array (0 = off, 1 = on)
              Default = reform(ABINS # DBINS, 96).

   MASK_SC:   Mask PA bins that are blocked by the spacecraft.  This is in
              addition to any masking specified by ABINS, DBINS, and OBINS.
              Default = 1 (yes).

   L2ONLY:    Only process data using L2 MAG data.

   OUTPUT_PATH: An output_path for testing, the save file will be put into 
                OUTPUT_PATH/yyyy/mm/.  Directories are created as needed.
                Default = root_data_dir() + 'maven/data/sci/swe/kp'.

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-27 16:58:12 -0700 (Tue, 27 Aug 2019) $
 $LastChangedRevision: 27686 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_kp.pro $

(See projects/maven/swea/mvn_swe_kp.pro)


MVN_SWE_LOAD_HSK

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_load_hsk
PURPOSE:
  Reads in MAVEN Level 0 telemetry files (PFDPU packets wrapped in 
  spacecraft packets).  SWEA normal housekeeping (APID 28) is decomuted
  and stored in a common block (mvn_swe_com).

USAGE:
  mvn_swe_load_hsk, trange

INPUTS:
       trange:        Load SWEA packets from L0 data spanning this time range.
                      (Reads multiple L0 files, if necessary.  Use MAXBYTES to
                      protect against brobdingnagian loads.)
                      OPTIONAL - recommended method is to run timespan before
                      calling this routine.

KEYWORDS:
       FILENAME:      Full path and file name for loading data.  Can be multiple
                      files.  Takes precedence over trange, ORBIT, and LATEST.

       ORBIT:         Load SWEA data by orbit number or range of orbit numbers 
                      (trange and LATEST are ignored).  Orbits are numbered using 
                      the NAIF convention, where the orbit number increments at 
                      periapsis.  Data are loaded from the apoapsis preceding the
                      first orbit (periapsis) number to the apoapsis following the
                      last orbit number.

       LATEST:        Ignore trange (if present), and load all data within the
                      LATEST days where data exist.  (Routine checks the database
                      to find latest L0 file.)

       CDRIFT:        Correct for spacecraft clock drift using SPICE.
                      Default = 1 (yes).

       MAXBYTES:      Maximum number of bytes to process.  Default is all data
                      within specified time range.

       BADPKT:        An array of structures providing details of bad packets.

       STATUS:        Report statistics of data actually loaded.

       SUMPLOT:       Create a summary plot of the loaded data.

       LOADONLY:      Download data but do not process.

       SPICEINIT:     Force a re-initialization of SPICE.  Use with caution!

       NOSPICE:       Do not initialize SPICE.

       NODUPE:        Filter out identical packets.  Default = 1 (yes).

       SURVEY:        If no merged file(s) exist over requested time range, then 
                      look for survey-only files.  This is slow, because the
                      survey files are all located in a single directory.

       REALTIME:      Use realtime file naming convention: YYYYMMDD_HHMMSS_*_l0.dat

       VERBOSE:       Level of diagnostic message suppression.  Default = 0.  Set
                      to a higher number to see more diagnostic messages.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-11-18 14:25:54 -0800 (Mon, 18 Nov 2019) $
 $LastChangedRevision: 28030 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_load_hsk.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_swe_load_hsk.pro

(See projects/maven/swea/mvn_swe_load_hsk.pro)


MVN_SWE_LOAD_L0

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_load_l0
PURPOSE:
  Reads in MAVEN Level 0 telemetry files (PFDPU packets wrapped in 
  spacecraft packets).  SWEA packets are identified, decompressed if
  necessary, and decomuted.  SWEA housekeeping and data are stored in 
  a common block (mvn_swe_com).

  The packets can be any combination of:

    Housekeeping:      normal rate  (APID 28)
                       fast rate    (APID A6)

    3D Distributions:  survey mode  (APID A0)
                       archive mode (APID A1)

    PAD Distributions: survey mode  (APID A2)
                       archive mode (APID A3)

    ENGY Spectra:      survey mode  (APID A4)
                       archive mode (APID A5)

  Sampling and averaging of 3D, PAD, and ENGY data are controlled by group
  and cycle parameters.  The group parameter (G = 0,1,2) sets the summing of
  adjacent energy bins.  The cycle parameter (N = 0,1,2,3,4,5) sets sampling 
  of 2-second measurement cycles.  Data products are sampled every 2^N cycles.

  3D distributions are stored in 1, 2 or 4 packets, depending on the group 
  parameter.  Multiple packets must be stitched together (see swe_plot_dpu).

  PAD packets have one of 3 possible lengths, depending on the group parameter.
  The PAD data array is sized to accomodate the largest packet (G = 0).  When
  energies are summed, only 1/2 or 1/4 of this data array is used.

  ENGY spectra always have 64 energy channels (G = 0).

USAGE:
  mvn_swe_load_l0, trange

INPUTS:
       trange:        Load SWEA packets from L0 data spanning this time range.
                      (Reads multiple L0 files, if necessary.  Use MAXBYTES to
                      protect against brobdingnagian loads.)
                      OPTIONAL - recommended method is to run timespan before
                      calling this routine.

KEYWORDS:
       FILENAME:      Full path and file name for loading data.  Can be multiple
                      files.  Takes precedence over trange, ORBIT, and LATEST.

       ORBIT:         Load SWEA data by orbit number or range of orbit numbers 
                      (trange and LATEST are ignored).  Orbits are numbered using 
                      the NAIF convention, where the orbit number increments at 
                      periapsis.  Data are loaded from the apoapsis preceding the
                      first orbit (periapsis) number to the apoapsis following the
                      last orbit number.

       LATEST:        Ignore trange (if present), and load all data within the
                      LATEST days where data exist.  (Routine checks the database
                      to find latest L0 file.)

       CDRIFT:        Correct for spacecraft clock drift using SPICE.
                      Default = 1 (yes).

       MAXBYTES:      Maximum number of bytes to process.  Default is all data
                      within specified time range.

       BADPKT:        An array of structures providing details of bad packets.

       STATUS:        Report statistics of data actually loaded.

       SUMPLOT:       Create a summary plot of the loaded data.

       LOADONLY:      Download data but do not process.

       SPICEINIT:     Force a re-initialization of SPICE.  Use with caution!

       NOSPICE:       Do not initialize SPICE.

       NODUPE:        Filter out identical packets.  Default = 1 (yes).

       SURVEY:        If no merged file(s) exist over requested time range, then 
                      look for survey-only files.  This is slow, because the
                      survey files are all located in a single directory.

       REALTIME:      Use realtime file naming convention: YYYYMMDD_HHMMSS_*_l0.dat

       VERBOSE:       Level of diagnostic message suppression.  Default = 0.  Set
                      to a higher number to see more diagnostic messages.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-11-11 12:06:40 -0800 (Mon, 11 Nov 2019) $
 $LastChangedRevision: 28001 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_load_l0.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mvn_swe_load_l0.pro

(See projects/maven/swea/mvn_swe_load_l0.pro)


MVN_SWE_LOAD_L2

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_load_l2
PURPOSE:
  Reads in MAVEN Level 2 telemetry files (CDF format).  Data are stored in 
  a common block (mvn_swe_com).

  SWEA data structures are:

    3D Distributions:  mvn_swe_3d

    PAD Distributions: mvn_swe_pad

    ENGY Spectra:      mvn_swe_engy

USAGE:
  mvn_swe_load_l2, trange

INPUTS:
       trange:        Load SWEA packets from L2 data spanning this time range.
                      (Reads multiple L2 files, if necessary.)  This input is 
                      not needed if you first call timespan.

KEYWORDS:
       FILENAME:      Full path and file name for loading data.  Can be multiple
                      files.  Takes precedence over trange, ORBIT, and LATEST.

       ORBIT:         Load SWEA data by orbit number or range of orbit numbers 
                      (trange and LATEST are ignored).  Orbits are numbered using 
                      the NAIF convention, where the orbit number increments at 
                      periapsis.  Data are loaded from the apoapsis preceding the
                      first orbit (periapsis) number to the apoapsis following the
                      last orbit number.

       LATEST:        Ignore trange (if present), and load all data within the
                      LATEST days leading up to the current date.

       SPEC:          Load SPEC data.

       PAD:           Load PAD data.

       DDD:           Load 3D data.

       ALL:           Load SPEC, PAD, and 3D data.

       BURST:         Load burst data.  (Default is to load survey data.)

       ARCHIVE:       Synonym for BURST.  (For backward compatibility.)

       STATUS:        Report statistics of data actually loaded.

       SUMPLOT:       Create a summary plot of the loaded data.

       LOADONLY:      Download data but do not process.

       NOERASE:       Do not clear the common block before loading.  This
                      allows multiple calls to load subsets of the data.

       SPICEINIT:     Force an initialization of SPICE.  Use with caution!
                      Best practice is to initialize SPICE before calling
                      this routine (or any other data loader).

       NOSPICE:       Do not initialize SPICE.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-08-14 11:10:46 -0700 (Mon, 14 Aug 2017) $
 $LastChangedRevision: 23783 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_load_l2.pro $

CREATED BY:    David L. Mitchell  02-02-15
FILE: mvn_swe_load_l2.pro

(See projects/maven/swea/mvn_swe_load_l2.pro)


MVN_SWE_LOWE_MASK

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_lowe_mask
PURPOSE:
  Masks data affected by the sporadic low energy suppression anomaly.  The affected spectra
  are stored in a database.  This routine checks data times against that database and masks
  affected spectra with NaN's below 28 eV.  Works for all SWEA data types.  Also works for
  TPLOT variables of the form:

      {x:[time], y:[time,energy], v:[energy]}

  or

      {x:[time], y:[time]}.

  First anomalous spectrum: 2018-12-08/05:27:44
  Last anomalous spectrum: 2019-11-30/23:55:42
  Total number of anomalous spectra: 54530

USAGE:
  mvn_swe_lowe_mask, data

INPUTS:
         data:       SWEA data structure (SPEC, PAD, or 3D).
                     Can also be a TPLOT variable.  In this case, tagname 'v', if present,
                     is interpreted as energy.

KEYWORDS:
         BADVAL:     Value to mask anomalous data with.  Default = NaN.

         STATUS:     Return the current coverage and return.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-17 11:25:17 -0700 (Tue, 17 Mar 2020) $
 $LastChangedRevision: 28425 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_lowe_mask.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_swe_lowe_mask.pro

(See projects/maven/swea/mvn_swe_lowe_mask.pro)


MVN_SWE_LPW_SCPOT

[Previous Routine] [Next Routine] [List of Routines]
 PROCEDURE:
       mvn_swe_lpw_scpot
 PURPOSE:

       !!! This routine could take a very long time to generate the data !!!
       !!! To load pre-generated data quickly, use 'mvn_swe_lpw_scpot_restore' !!!

       Empirically derives spacecraft potentials using SWEA/STA and LPW.
       Inflection points in LPW I-V curves are tuned to positive and negative
       spacecraft potentials estimated from SWEA/STA energy spectra
       (mvn_swe_sc_pot, mvn_swe_sc_negpot, mvn_sta_scpot_load).

       Does not work in shadow.

       For more information, see 
       http://research.ssl.berkeley.edu/~haraday/tools/mvn_swe_lpw_scpot.pdf

 CALLING SEQUENCE:
       timespan,'16-01-01',14   ;- make sure to set a long time range
       mvn_swe_lpw_scpot
 OUTPUT TPLOT VARIABLES:
       mvn_swe_lpw_scpot :     best-estimate scpot data
                               (currently "mvn_swe_lpw_scpot_pol")
       mvn_swe_lpw_scpot_lin : spacecraft potentials derived from
                               linear fitting of Vswe v. -Vinfl
       mvn_swe_lpw_scpot_pol : spacecraft potentials derived from
                               2nd-order polynomial fitting of Vswe v. -Vinfl
       mvn_swe_lpw_scpot_pow : (obsolete)
 KEYWORDS:
       trange: time range
       norbwin: odd number of orbits used for Vswe-Vinfl fitting (Def. 37)
       minndata: minimum number of data points for Vswe-Vinfl fitting
                 (Def. 1e4)
       maxgap: maximum time gap allowed for interpolation (Def. 257)
       plot: if set, plot the time series and fitting
       noload: if set, use pre-existing input tplot variables:
               'swe_pos', 'mvn_lpw_swp1_IV'
       vrinfl: voltage range for searching the inflection point
               (Def. [-15,18])
       ntsmo: time smooth width (Def. 3)
 NOTES:
       1) The data quality are not good before 2015-01-24.
       2) The peak fitting algorithm sometimes breaks down
          when multiple peaks are present in dI/dV curves.
          Check the quality flag: mvn_lpw_swp1_IV_vinfl_qflag
                                  1 = good, 0 = bad
          As a rule of thumb, the quality is generally good if flag > 0.8
          You may need caution if 0.5 < flag < 0.8 (check the consistency with SWEA spectra)
       3) Short time scale variations will be smoothed out by default.
          Setting ntsmo=1 will improve the time resolution
          at the expense of better statistics.
       4) Potential values between 0 and +3 V are interpolated
          - they cannot be verified by SWEA measurements
 CREATED BY:
       Yuki Harada on 2016-02-29
       Major update on 2017-07-24 - incl. negative pot

 $LastChangedBy: haraday $
 $LastChangedDate: 2019-11-25 19:45:00 -0800 (Mon, 25 Nov 2019) $
 $LastChangedRevision: 28067 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_lpw_scpot.pro $

(See projects/maven/swea/mvn_swe_lpw_scpot.pro)


MVN_SWE_LPW_SCPOT_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_lpw_scpot_restore
PURPOSE:
  Reads in scpot data precalculated by mvn_swe_lpw_scpot
  and stored in a tplot save/restore file. 

       For more information, see
       http://research.ssl.berkeley.edu/~haraday/tools/mvn_swe_lpw_scpot.pdf

USAGE:
  timespan,'2016-01-01',2
  mvn_swe_lpw_scpot_restore

 NOTES:
       1) The data quality are not good before 2015-01-24.
       2) The peak fitting algorithm sometimes breaks down
          when multiple peaks are present in dI/dV curves.
          Check the quality flag: mvn_lpw_swp1_IV_vinfl_qflag
                                  1 = good, 0 = bad
          As a rule of thumb, the data quality is generally good if flag > 0.8
          You may need caution if 0.5 < flag < 0.8 (check the consistency with SWEA spectra)
       3) Short time scale variations will be smoothed out by default
       4) Potential values between 0 and +3 V are interpolated
          - they cannot be verified by SWEA measurements

INPUTS:
       trange:        Restore data over this time range.  If not specified, then
                      uses the current tplot range or timerange() will be called

KEYWORDS:
       ORBIT:         Restore pad data by orbit number.

       LOADONLY:      Download but do not restore any pad data.

 $LastChangedBy: haraday $
 $LastChangedDate: 2017-07-28 07:16:06 -0700 (Fri, 28 Jul 2017) $
 $LastChangedRevision: 23717 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_lpw_scpot_restore.pro $

CREATED BY:    Yuki Harada  03-24-16
FILE: mvn_swe_lpw_scpot_restore.pro

(See projects/maven/swea/mvn_swe_lpw_scpot_restore.pro)


MVN_SWE_LPW_SCPOT_SAVE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_lpw_scpot_save
PURPOSE:

USAGE:
  mvn_swe_lpw_scpot_save, start_day=start_day, ndays=ndays

INPUTS:
       None

KEYWORDS:
       start_day:     Save data over this time range.  If not specified, then
                      timerange() will be called

       ndays:         Number of dates to process.
                      Default = 7

NOTES:
       mvn_swe_lpw_scpot uses a long span of data.
       For efficient processing, this save routine first loads the entire data,
       and then split and save them into one-day files.

 $LastChangedBy: haraday $
 $LastChangedDate: 2017-09-07 09:29:15 -0700 (Thu, 07 Sep 2017) $
 $LastChangedRevision: 23903 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_lpw_scpot_save.pro $

CREATED BY:    Yuki Harada  03-04-16
FILE: mvn_swe_lpw_scpot_save.pro

(See projects/maven/swea/mvn_swe_lpw_scpot_save.pro)


MVN_SWE_MAGDIR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_magdir
PURPOSE:
  Converts magnetic field azimuth and elevation bytes from PAD packets
  (A2 and A3) into azimuth and elevation in radians.

USAGE:
  mvn_swe_magdir, iBaz, jBel, Baz, Bel

INPUTS:
       time:     Packet time.  Used to correct for MICD error when needed.

       iBaz:     Azimuth byte in PAD packet.

       jBel:     Elevation byte in PAD packet.

OUTPUTS:
       Baz:      Magnetic field azimuth in radians.  SWEA coordinates.

       Bel:      Magnetic field azimuth in radians.  SWEA coordinates.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:21:18 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28836 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_magdir.pro $

CREATED BY:    David L. Mitchell  09/18/13

(See projects/maven/swea/mvn_swe_magdir.pro)


MVN_SWE_MAKECDF_3D

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
   MVN_SWE_MAKECDF_3D
 SYNTAX:
	MVN_SWEA_MAKECDF_3D, DATA, FILE = FILE, VERSION = VERSION
 PURPOSE:
	Routine to produce CDF file from SWEA 3D data structures
 INPUTS:
   DATA: Structure with which to populate the CDF file
         (nominally created by mvn_swe_get3d.pro)
 OUTPUT:
   CDF file
 KEYWORDS:
   FILE: full file name of the output file - only used for testing
         if not specified (usually won't be), the program creates the appropriate filename
   VERSION: integer; software version
          - read from common block (SWE_CFG) defined in mvn_swe_calib.pro
          - keyword no longer needed (but kept for compatibility)
 HISTORY:
   Created by Matt Fillingim (with code stolen from JH and RL)
   Added directory keyword, and deletion of old files, jmm, 2014-11-14
   Read version number from common block; MOF: 2015-01-30
   ISTP compliance scrub; DLM: 2016-04-08
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-15 16:31:45 -0700 (Fri, 15 Mar 2019) $
   $LastChangedRevision: 26829 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_makecdf_3d.pro $

(See projects/maven/swea/mvn_swe_makecdf_3d.pro)


MVN_SWE_MAKECDF_PAD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   MVN_SWE_MAKECDF_PAD
 SYNTAX:
   MVN_SWEA_MAKECDF_PAD, DATA, FILE = FILE, VERSION = VERSION
 PURPOSE:
   Routine to produce CDF file from SWEA pad data structures
 INPUT:
   DATA: Structure with which to populate the CDF file
         (nominally created by mvn_swe_getpad.pro)
 OUTPUT:
   CDF file
 KEYWORDS:
   FILE: full file name of the output file - only used for testing
         if not specified (usually won't be), the program creates the appropriate filename
   VERSION: integer; software version
          - read from common block (SWE_CFG) defined in mvn_swe_calib.pro
          - keyword no longer needed (but kept for compatibility)
   L2_ONLY: only create cdf if L2 MAG data are available.
 HISTORY: 
   Created by Matt Fillingim (with code stolen from JH and RL)
   Added directory keyword, jmm, 2104-11-14
   Read version number from common block; MOF: 2015-01-30
   ISTP compliance scrub; DLM: 2016-04-08
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-15 16:31:37 -0700 (Fri, 15 Mar 2019) $
   $LastChangedRevision: 26828 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_makecdf_pad.pro $

(See projects/maven/swea/mvn_swe_makecdf_pad.pro)


MVN_SWE_MAKECDF_SPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   MVN_SWE_MAKECDF_SPEC
 SYNTAX:
   MVN_SWE_MAKECDF_SPEC, DATA, FILE = FILE, VERSION = VERSION
 PURPOSE:
   Routine to produce CDF file from SWEA spec data structures
 INPUT:
   DATA: Structure with which to populate the CDF file
         (nominally created by mvn_swe_getspec.pro)
 OUTPUT:
   CDF file
 KEYWORDS:
   FILE: full name of the output file - only used for testing
         if not specified (usually won't be), the program creates the appropriate filename
   VERSION: integer; software version
          - read from common block (SWE_CFG) defined in mvn_swe_calib.pro
          - keyword no longer need (but kept for compatibility)
 HISTORY:
   created by Matt Fillingim (with code stolen from JH and RL)
   Added directory keyword, and deletion of old files, jmm, 2014-11-14
   Read version number from common block; MOF: 2015-01-30
   ISTP compliance scrub; DLM: 2016-04-08
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-15 16:31:31 -0700 (Fri, 15 Mar 2019) $
   $LastChangedRevision: 26827 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_makecdf_spec.pro $

(See projects/maven/swea/mvn_swe_makecdf_spec.pro)


MVN_SWE_MAKEFPAD

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_makefpad
PURPOSE:
  Constructs Hires PAD data structures from raw data.

USAGE:
  mvn_swe_makefpad

INPUTS:

KEYWORDS:

       UNITS:    Convert data to these units.  Default = 'eflux'.

       TPLOT:    Make tplot variables.

       MERGE:    If TPLOT is set, then create normal-resolution
                 PAD spectrograms at the same energies and merge
                 with the high-resolution data.  Set this keyword
                 to the desired time range, or just set it to 1 
                 and the routine will choose a reasonable time 
                 range that encompasses all the hires data.

       PANS:     Returns names of any tplot variables.

       PFILE:    Name of an IDL save file containing the hires PAD
                 data structures: swe_fpad, swe_fpad_arc.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:22:53 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28838 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_makefpad.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_makespec.pro

(See projects/maven/swea/mvn_swe_makefpad.pro)


MVN_SWE_MAKESPEC

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_makespec
PURPOSE:
  Constructs ENGY data structure from raw data.

USAGE:
  mvn_swe_makespec

INPUTS:

KEYWORDS:

       SUM:      Force sum mode for A4 and A5.  Not needed for EM or for FM post ATLO.
                 Default = get mode from packet.

       UNITS:    Convert data to these units.  Default = 'eflux'.

       TPLOT:    Make a energy-time spectrogram and store in tplot.

       SFLG:     If TPLOT is set, then this controls whether the panel
                 is a color spectrogram or stacked line plots.
                 Default = 1 (color spectrogram).

       PAN:      Returns the name of the tplot variable.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:22:53 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28838 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_makespec.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_makespec.pro

(See projects/maven/swea/mvn_swe_makespec.pro)


MVN_SWE_MCPCAL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_mcpcal
PURPOSE:
  Analyzes in-flight MCP calibration data to estimate the optimal
  MCP bias value.  Returns the best value in decimal and hex.


USAGE:
  mvn_swe_mcpcal, trange

INPUTS:
     trange:          Time range bracketing calibration sequence.

KEYWORDS:

     SCP:             Spacecraft potential (volts).  Assumes same potential
                      across calibration sequence.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-08-15 17:53:12 -0700 (Tue, 15 Aug 2017) $
 $LastChangedRevision: 23798 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_mcpcal.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_swe_mcpcal.pro

(See projects/maven/swea/mvn_swe_mcpcal.pro)


MVN_SWE_N1D

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_n1d
PURPOSE:
	Determines density from 1D energy spectra.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_n1d
INPUTS: 
KEYWORDS:
   PANS:     Named variable to return tplot panels created.

   DDD:      Calculate density from 3D distributions (allows bin
             masking).  Typically lower cadence and coarser energy
             resolution.

   ABINS:    Anode bin mask -> 16 elements (0 = off, 1 = on)
             Default = replicate(1,16)

   DBINS:    Deflector bin mask -> 6 elements (0 = off, 1 = on)
             Default = replicate(1,6)

   OBINS:    3D solid angle bin mask -> 96 elements (0 = off, 1 = on)
             Default = reform(ABINS # DBINS)

   MASK_SC:  Mask the spacecraft blockage.  This is in addition to any
             masking defined by the ABINS, DBINS, and OBINS.
             Default = 1 (yes).  Set this to 0 to disable and use the
             above 3 keywords only.

   MINDEN:   Smallest reliable density (cm-3).  Default = 0.08

   ERANGE:   Restrict calculation to this energy range.

   BACKGROUND: Set the background to this value.  Units = EFLUX.  Default is
               to use the value in the data structure.

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-17 11:24:31 -0700 (Tue, 17 Mar 2020) $
 $LastChangedRevision: 28424 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_n1d.pro $

(See projects/maven/swea/mvn_swe_n1d.pro)


MVN_SWE_N3D

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_n3d
PURPOSE:
	Determines density from a 3D distribution.  Adapted from McFadden's n_3d.pro.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_n3d
INPUTS: 
KEYWORDS:

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-08-04 12:16:07 -0700 (Fri, 04 Aug 2017) $
 $LastChangedRevision: 23758 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_n3d.pro $

(See projects/maven/swea/mvn_swe_n3d.pro)


MVN_SWE_PADLUT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_padlut
PURPOSE:
  Calculates the pitch angle sorting look up table.

USAGE:
  mvn_swe_padlut, lut=lut

INPUTS:

KEYWORDS:

       DLAT:        Latitude range of each elevation bin (deg).  This depends
                    on the sweep table.

                        Default at launch is 22.5 deg.
                        Actual value is closer to 20 deg.

       LUT:         Named variable to hold the LUT.

       DOPLOT:      Plot the result.

       PRINTAB:     Print the result.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-03-25 11:27:57 -0700 (Tue, 25 Mar 2014) $
 $LastChangedRevision: 14671 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_padlut.pro $

CREATED BY:    David L. Mitchell  03-17-14
FILE: mvn_swe_padlut.pro

(See projects/maven/swea/mvn_swe_padlut.pro)


MVN_SWE_PADMAP

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_padmap
PURPOSE:
  Calculates the pitch angle map for a PAD.

USAGE:
  pam = mvn_swe_padmap(pkt)

INPUTS:
       pkt  :         A raw PAD packet (APID A2 or A3).

KEYWORDS:
       MAGF :         Magnetic field direction in SWEA coordinates.  Overrides
                      the nominal direction contained in the A2 or A3 packet.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-05-25 17:12:25 -0700 (Mon, 25 May 2015) $
 $LastChangedRevision: 17705 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_padmap.pro $

CREATED BY:    David L. Mitchell  03-18-14
FILE: mvn_swe_padmap.pro

(See projects/maven/swea/mvn_swe_padmap.pro)


MVN_SWE_PADMAP_32HZ

[Previous Routine] [Next Routine] [List of Routines]

FUNCTION:        MVN_SWE_PADMAP_32HZ

PURPOSE:         Maps pitch angle over the SWEA field of view with high time
                 resolution, taking into account magnetic field variations 
                 during the 2-second SWEA measurement cycle.  Separate pitch
                 angle maps are calculated for each of the 64 SWEA energy
                 steps using 32-Hz MAG data.  The results are appended as new
                 tags to the PAD data structure.

                 BEWARE!  This routine requires accurate relative timing
                 between MAG and SWEA.  This is not guaranteed when using 
                 preliminary data that do not have accurate corrections
                 for spacecraft clock drift.  If you get a warning message
                 about using MAG quicklook data, then you are on thin ice!
                 You might still be OK if you can verify that the MAG and 
                 SWEA data were processed with the same SCLK kernel.

                 ALSO!  Since the purpose of this routine is to accurately
                 map pitch angles when the magnetic field varies on time
                 scales that are shorter than the 2-second SWEA measurement
                 cycle, you should ask yourself whether the electrons are
                 magnetized at all.  How good is the adiabatic approximation?
                 See mvn_swe_eparam.pro for more information.

INPUTS:          PAD data structure obtained from 'mvn_swe_getpad'.

KEYWORDS:

   FBDATA:       Tplot variable name of full resolution magnetic
                 field data.  Default = 'mvn_B_full'.

   STATUS:       Returns the calculation result
                 (Success: 1 / Failure: 0).

   MAGLEV:       Returns the MAG data level.  See warning above.
                   0 -> on-board determination or unknown
                   1 -> gains and zeroes only (quicklook)
                   2 -> fully calibrated

   L2ONLY:       Insist on using MAG L2 data.

CREATED BY:      Takuya Hara on 2015-07-20.

LAST MODIFICATION:
 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:41:01 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26811 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_padmap_32hz.pro $

(See projects/maven/swea/mvn_swe_padmap_32hz.pro)


MVN_SWE_PADMAP_3D

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_padmap_3d

PURPOSE:
	Map pitch angle for PAD or 3D distributions.  In either case, you must first
   call mvn_swe_addmag to load MAG L1 or L2 data, rotate to SWEA coordinates, and
   sample at the SWEA data times.

CALLING SEQUENCE: 
	mvn_swe_padmap_3d, data

INPUTS: 
       data:     An array of PAD or 3D structures.  For PAD structures, the
                 appropriate tags are updated.  For 3D structures, the results 
                 are added as new tags.

KEYWORDS:

CREATED BY:      D.L. Mitchell on 2014-09-24.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-08-04 17:15:05 -0700 (Tue, 04 Aug 2015) $
 $LastChangedRevision: 18398 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_padmap_3d.pro $

(See projects/maven/swea/mvn_swe_padmap_3d.pro)


MVN_SWE_PADSUM

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_padsum
PURPOSE:
  Sums multiple PAD data structures.  This is done by summing raw counts
  corrected by deadtime and then setting dtc to unity.  Also, note that 
  summed PAD's can be "blurred" by a changing magnetic field direction, 
  so summing only makes sense for short intervals.  The theta, phi, and 
  omega tags can be hopelessly confused if the MAG direction changes much.

USAGE:
  padsum = mvn_swe_padsum(pad)

INPUTS:
       pad:           An array of PAD structures to sum.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-27 14:06:18 -0700 (Tue, 27 Aug 2019) $
 $LastChangedRevision: 27682 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_padsum.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_padsum.pro

(See projects/maven/swea/mvn_swe_padsum.pro)


MVN_SWE_PAD_LC_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_pad_lc_restore
PURPOSE:
  Reads in save files mvn_swe_padscore
                                      
USAGE: 
  mvn_swe_pad_lc_restore, trange

INPUTS: 
       trange:        Restore data over this time range.  If not
                      specified, then uses the current tplot range 
                      or timerange() will be called                         
 
KEYWORDS: 
       ORBIT:         Restore mvn_swe_padscore data by orbit number.

       RESULT:       Hold the full structure of PAD score and
                      other parameters

       storeTPLOT:         Create tplot varibles
                                                                                                         
 $LastChangedBy: tweber $  
 $LastChangedDate: 2019-10-24 09:07:47 -0700 (Thu, 24 Oct 2019) $  
 $LastChangedRevision: 27928 $ 
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_pad_lc_restore.pro $     
 
CREATED BY:    Tristan Weber
FILE: mvn_swe_pad_lc_restore

(See projects/maven/swea/mvn_swe_pad_lc_restore.pro)


MVN_SWE_PAD_RESAMPLE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	MVN_SWE_PAD_RESAMPLE

PURPOSE:
	Resamples the pitch angle distribution from SWEA PAD or 3D data,
   averaging the signals from bins that overlap in pitch angle space.
   Typically (and by default), pitch angle is oversampled by a factor
   of 16 to accurately treat partial overlap.

   PAD or 3D data are obtained from SWEA common block.  If you set the
   time interval, then the snapshot of the pitch angle distribution at
   the specified time is plotted.

   The result is stored in a tplot variable and can also be returned
   via keyword.

CALLING SEQUENCE: 
	mvn_swe_pad_resample, nbins=128., erange=[100., 150.]

INPUTS: 
   trange:    Optional: Time range for resampling.  Default is to resample
              all data (PAD or 3D, survey or burst, depending on keywords).
              This routine might take more than 10 minutes to process PAD 
              survey data for one day, depending on your machine specs.

KEYWORDS:
   SILENT:    Minimize to show the processing information in the terminal.

   MASK:      Mask angular bins that are blocked by the spacecraft.
              Automatically determines whether or not the SWEA boom is
              deployed.  Default = 1 (yes).

   NO_MASK:   If set, do not mask angular bins blocked by the spacecraft.
              Equivalent to MASK = 0.

   STOW:      (Obsolete). Mask the angular bins whose field of view
              is blocked before the boom deploy. --> This is now done
              automatically.

   DDD:       Use 3D data to resample pitch angle distribution.

   PAD:       Use PAD data to resample pitch angle distribution.
              It is the default setting.

   NBINS:     Specify resampling binning numbers. Default = 128.

   ABINS:     Specify which anode bins to 
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,16)

   DBINS:     Specify which deflection bins to
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,6)

   MBINS:     Specify which solid angle bins to
              include in the analysis: 0 = no, 1 = yes.
              Default = ABINS # DBINS

   ARCHIVE:   Use archive (burst) data, instead of survey data.

   PANS:      Named varible to hold the tplot panels created.

   WINDOW:    Set the window number to show the snapshot. Default = 0.

   RESULT:    Return the resampled pitch angle distribution data.

   UNITS:     Set the units. Default = 'EFLUX'.

   ERANGE:    Energy range over which to plot the pitch angle distribution.
              For tplot case, default = 280 eV, based on the L0 tplot setting.

   NORMAL:    If set, then normalize the pitch angle distribution to have an
              average value of unity at each energy.

   SNAP:      Plot a snapshot.  Default = 0 (no).

   TPLOT:     Make a tplot variable.  Default = 1 (yes).

   MAP3D:     Take into account the pitch angle width even for 3D
              data. This keyword only works 3D data. The mapping
              method is based on 'mvn_swe_padmap'.

   SWIA:      Resample PAD in the plasma rest frame, where electron
              angular distributions are typically gyrotropic. Plasma bulk
              velocity is taken from SWIA Course data.  This keyword only
              works after loading (restoring) SWIA data.  

   HIRES:     Calculate a separate pitch angle map for each energy step 
              within a sweep using 32-Hz MAG data.
              See mvn_swe_padmap_32hz for caveats and details.

   SC_POT:    Correct for the spacecraft potential.
              (Not completely activated yet)
  
   SYMDIR:    Instead of the observed magnetic field vector, use the
              symmetry direction of the (strahl) electron distribution.
              The symmetry direction is calculated via 'swe_3d_strahl_dir'.

   INTERPOLATE: When you try to resample the pitch angle distribtion
                in the plasma rest frame, it calculates non-zero
                value to have the data evaluated (interpolated) at
                the original energy steps. This keyword is associated
                with 'convert_vframe'.

   CUT:       Plot the pitch-angle-sorted 1d spectra for each energy step.
              It is an optional plot.

   SPEC:      Plot the pitch-angle-selected 1d energy spectra. 
              In the default settings, 5 pitch angle bands are selected.
                 - quasi-parallel (0-30 deg),
                 - quasi-perpendicular (75-105 deg),
                 - quasi-antiparallel (150-180 deg),
                 - 2 obliquenesses (30-75, 105-150 deg).
              It is also an optional plot.

   PSTYLE:    It means "plot style". This keyword allows
              specification which plots you want to show.
              Each option is described as follows:
              - 1: Plots the snapshot(, equivalent to the "snap" keyword.)
              - 2: Generates the tplot variable(, equivalent to the "tplot" keyword.)
              - 4: Plots the pitch-angle-sorted 1d spectra(, equivalent to the "cut" keyword.)
              - 8: Plots the pitch-angle-selected 1d energy spectra(, equivalent to the "spec" keyword.)
              Note that this keyword is set bitwise, so multiple
              effects can be achieved by adding values together. For
              example, to plot the snapshot (value 1) and to generate
              the tplot variable (value 2), set the PSTYLE keyword to
              1+2, or 3. This basic idea is same as that
              [x][y][z]style keyword included in default PLOT options.

CREATED BY:      Takuya Hara on 2014-09-24.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:44:29 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26817 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_pad_resample.pro $

(See projects/maven/swea/mvn_swe_pad_resample.pro)


MVN_SWE_PAD_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_pad_restore
PURPOSE:
  Reads in resampled pad data (100-150 eV) precalculated by mvn_swe_pad_resample
  and stored in a tplot save/restore file.  Command line used to create the tplot
  variables was:

    mvn_swe_pad_resample, nbins=128, erange=[100.,150.], /norm, /mask

  Can also be used to restore resampled 2D energy-pitch angle data.  In this case,
  use the FULL and PAD keywords.  Note that 2D pad data consume up to 375 MB/date, 
  so use these keywords with caution.

USAGE:
  mvn_swe_pad_restore, trange

INPUTS:
       trange:        Restore data over this time range.  If not specified, then
                      uses the current tplot range.

KEYWORDS:
       ORBIT:         Restore pad data by orbit number.

       LOADONLY:      Download but do not restore any pad data.

       UNNORM:        Unnormalize the color code.  (Only applies to single-energy
                      100-150-eV pad data.  Full 2D pad data are not normalized
                      in the first place.)

       FULL:          Restore the resampled 2D energy-pitch angle data, instead
                      of just the 100-150-eV range.  Must be used with keyword PAD.

       PAD:           Named variable to hold the restored 2D energy-pitch angle
                      data.  Must be used with keyword FULL.

       L2ONLY:        Insist that MAG L2 data were used for resampling.

 $LastChangedBy: rlillis3 $
 $LastChangedDate: 2018-04-28 18:30:05 -0700 (Sat, 28 Apr 2018) $
 $LastChangedRevision: 25142 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_pad_restore.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mvn_swe_pad_restore.pro

(See projects/maven/swea/mvn_swe_pad_restore.pro)


MVN_SWE_PAD_SAVE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_pad_save
PURPOSE:
  Calculates resampled pad data (100-150 eV) using mvn_swe_pad_resample and
  saves in a tplot save/restore file.  Command line used to create the tplot
  variables is:

    mvn_swe_pad_resample, nbins=128, erange=[100.,150.], /norm, /mask

USAGE:
  mvn_swe_pad_save, start_day, interval, ndays

INPUTS:
       None:          Default is to process data currently loaded into memory.

KEYWORDS:
       start_day:     Restore data over this time range.  If not specified, then
                      use the currently loaded data.

       interval:      If start_day is defined and ndays > 1, then this is the number 
                      of days to skip before loading the next date.  (Only useful
                      for poor-man's parallel processing.)  Default = 1

       ndays:         Number of dates to process, each separated by interval.
                      Default = 1

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-06-07 13:35:34 -0700 (Sun, 07 Jun 2015) $
 $LastChangedRevision: 17820 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_pad_save.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mvn_swe_pad_save.pro

(See projects/maven/swea/mvn_swe_pad_save.pro)


MVN_SWE_POT_CONVE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_pot_conve

PURPOSE:
   correct for potential and then convert to SWEA original resolution

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:
   

INPUTS:
   
   INEN: The energy array corresponding to the input energy spectrum
   
   INSPEC: Input electron energy spectrum
   
   
   POT: Specify the potential to be corrected

KEYWORDS:

   none

OUTPUTS:

   OUTEN: The energy array corresponding to the input energy spectrum, 
          currently set to be SWEA energy resolution
         
   OUTSPEC: The converted energy spectrum

 $LastChangedBy: xussui_lap $
 $LastChangedDate: 2016-06-22 17:23:44 -0700 (Wed, 22 Jun 2016) $
 $LastChangedRevision: 21353 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_pot_conve.pro $

CREATED BY:    Shaosui Xu  06-22-16

(See projects/maven/swea/mvn_swe_pot_conve.pro)


MVN_SWE_QL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_ql
PURPOSE:
  Creates SWEA TPLOT variables for QuickLook plots.

USAGE:
  mvn_swe_ql

INPUTS:

KEYWORDS:

       NAMES:        TPLOT variables names created.
                     Returns 0 if no variables are created.

       PAD_E:        Energy for plotting PAD's.  Default = 280 eV.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 14:15:03 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16106 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_ql.pro $

CREATED BY:    David L. Mitchell  04-30-13
FILE: mvn_swe_ql.pro
VERSION:   1.0

(See projects/maven/swea/mvn_swe_ql.pro)


MVN_SWE_READCDF_3D

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
   MVN_SWE_READCDF_3D
 SYNTAX:
   MVN_SWE_READCDF_3D, INFILE, STRUCTURE
 PURPOSE:
   Routine to read CDF file from mvn_swe_makecdf_3d.pro
 INPUTS:
   INFILE: CDF file name to read
           (nominally created by mvn_swe_makecdf_3d.pro)
 OUTPUT:
   STRUCTURE: IDL data structure
 KEYWORDS:
   OUTFILE: Output file name
 HISTORY:
   Created by Matt Fillingim
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-20 13:57:40 -0700 (Wed, 20 Mar 2019) $
   $LastChangedRevision: 26864 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_readcdf_3d.pro $

(See projects/maven/swea/mvn_swe_readcdf_3d.pro)


MVN_SWE_READCDF_PAD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   MVN_SWE_READCDF_PAD
 SYNTAX:
   MVN_SWE_READCDF_PAD, INFILE, STRUCTURE
 PURPOSE:
   Routine to read CDF file from mvn_swe_makecdf_pad.pro
 INPUTS:
   INFILE: CDF file name to read
           (nominally created by mvn_swe_makecdf_pad.pro)
 OUTPUT:
   STRUCTURE: IDL data structure
 KEYWORDS:
   OUTFILE: Output file name
 HISTORY:
   Created by Matt Fillingim
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-20 13:57:40 -0700 (Wed, 20 Mar 2019) $
   $LastChangedRevision: 26864 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_readcdf_pad.pro $

(See projects/maven/swea/mvn_swe_readcdf_pad.pro)


MVN_SWE_READCDF_SPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
   MVN_SWE_READCDF_SPEC
 SYNTAX:
	MVN_SWE_READCDF_SPEC, INFILE, STRUCTURE
 PURPOSE:
	Routine to read CDF file from mvn_swe_makecdf_spec.pro
 INPUTS:
   INFILE: CDF file name to read
           (nominally created by mvn_swe_makecdf_spec.pro)
 OUTPUT:
   STRUCTURE: IDL data structure
 KEYWORDS:
   OUTFILE: Output file name
 HISTORY:
   Created by Matt Fillingim
 VERSION:
   $LastChangedBy: dmitchell $
   $LastChangedDate: 2019-03-20 13:57:40 -0700 (Wed, 20 Mar 2019) $
   $LastChangedRevision: 26864 $
   $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_readcdf_spec.pro $

(See projects/maven/swea/mvn_swe_readcdf_spec.pro)


MVN_SWE_READ_HSK

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_read_hsk
PURPOSE:
  Reads in MAVEN Level 0 telemetry files (PFDPU packets wrapped in 
  spacecraft packets).  SWEA normal housekeeping packets (APID 28)
  are identified and decomuted.  Data are stored in a common block
  (mvn_swe_com).

USAGE:
  mvn_swe_read_hsk, filename

INPUTS:
       filename:      The full filename (including path) of a binary file containing 
                      zero or more SWEA APID's.  This file can contain compressed
                      packets.

KEYWORDS:
       TRANGE:        Only keep packets within this time range.

       CDRIFT:        Correct for spacecraft clock drift using SPICE.
                      Default = 0 (no).

       MAXBYTES:      Maximum number of bytes to process.  Default is entire file.

       BADPKT:        An array of structures providing details of bad packets.

       APPEND:        Append data to any previously loaded data.

       VERBOSE:       If set, then print diagnostic information to stdout.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-04-08 16:59:23 -0700 (Mon, 08 Apr 2019) $
 $LastChangedRevision: 26965 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_read_hsk.pro $

CREATED BY:    David L. Mitchell
FILE: mvn_swe_read_hsk.pro

(See projects/maven/swea/mvn_swe_read_hsk.pro)


MVN_SWE_READ_L0

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_read_l0
PURPOSE:
  Reads in MAVEN Level 0 telemetry files (PFDPU packets wrapped in 
  spacecraft packets).  SWEA packets are identified, decompressed if
  necessary, and decomuted.  SWEA housekeeping and data are stored in 
  a common block (mvn_swe_com).

  The packets can be any combination of:

    Housekeeping:      normal rate  (APID 28)
                       fast rate    (APID A6)
                       pfp analog   (APID 23)

    3D Distributions:  survey mode  (APID A0)
                       archive mode (APID A1)

    PAD Distributions: survey mode  (APID A2)
                       archive mode (APID A3)

    ENGY Spectra:      survey mode  (APID A4)
                       archive mode (APID A5)

  Sampling and averaging of 3D, PAD, and ENGY data are controlled by group
  and cycle parameters.  The group parameter (G = 0,1,2) sets the summing of
  adjacent energy bins.  The cycle parameter (N = 0,1,2,3,4,5) sets sampling 
  of 2-second measurement cycles.  Data products are sampled every 2^N cycles.

  3D distributions are stored in 1, 2 or 4 packets, depending on the group 
  parameter.  Multiple packets must be stitched together (see swe_3d_stitch).

  PAD packets have one of 3 possible lengths, depending on the group parameter.
  The PAD data array is sized to accomodate the largest packet (G = 0).  When
  energies are summed, only 1/2 or 1/4 of this data array is used.

  ENGY spectra always have 64 energy channels (G = 0).

USAGE:
  mvn_swe_read_l0, filename

INPUTS:
       filename:      The full filename (including path) of a binary file containing 
                      zero or more SWEA APID's.  This file can contain compressed
                      packets.

KEYWORDS:
       TRANGE:        Only keep packets within this time range.

       CDRIFT:        Correct for spacecraft clock drift using SPICE.
                      Default = 0 (no).

       MAXBYTES:      Maximum number of bytes to process.  Default is entire file.

       BADPKT:        An array of structures providing details of bad packets.

       APPEND:        Append data to any previously loaded data.

       VERBOSE:       If set, then print diagnostic information to stdout.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-04-08 16:57:57 -0700 (Mon, 08 Apr 2019) $
 $LastChangedRevision: 26964 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_read_l0.pro $

CREATED BY:    David L. Mitchell  04-25-13
FILE: mvn_swe_read_l0.pro

(See projects/maven/swea/mvn_swe_read_l0.pro)


MVN_SWE_REGID_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_regid_restore
PURPOSE:
  Reads in save files mvn_swia_regid

USAGE:
  mvn_swe_regid_restore, trange

INPUTS:
       trange:        Restore data over this time range.  If not
                      specified, then uses the current tplot range
                      or timerange() will be called

KEYWORDS:
       ORBIT:         Restore mvn_swia_regid data by orbit number.

       RESULTS:       Hold the full structure of region id

       TPLOT:         Create tplot varible for region id "reg_id"
       
 $LastChangedBy: xussui $
 $LastChangedDate: 2018-07-18 12:28:53 -0700 (Wed, 18 Jul 2018) $
 $LastChangedRevision: 25488 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_regid_restore.pro $

CREATED BY:    Shaosui Xu  11-17-17
FILE: mvn_swe_regid_restore

(See projects/maven/swea/mvn_swe_regid_restore.pro)


MVN_SWE_SCIPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_sciplot
PURPOSE:
	Creates a science-oriented summary plot for SWEA and MAG and optionally other 
   instruments.

   Warning: This routine can consume a large amount of memory:

     SWEA + MAG : 0.6 GB/day
     SEP        : 0.2 GB/day
     SWIA       : 0.2 GB/day
     STATIC     : 3.5 GB/day
     LPW        : 0.001 GB/day
     EUV        : 0.004 GB/day
     -------------------------
      total     : 4.5 GB/day

   You'll also need memory for performing calculations on large arrays, so you
   can create a plot with all data types spanning ~1 day per 8 GB of memory.

AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_sciplot
INPUTS:
   None:      Uses data currently loaded into the SWEA common block.

KEYWORDS:
   SUN:       Create a panel for the Sun direction in spacecraft coordinates.

   RAM:       Create a panel for the RAM direction in spacecraft coordinates.

   NADIR:     Create a panel for the Nadir direction in spacecraft coordinates.

   DATUM:     Reference surface for calculating altitude.  Can be one of
              "sphere", "ellipsoid", "areoid", or "surface".  Passed to 
              maven_orbit_tplot.  Default = 'ellipsoid'.
              See mvn_altitude.pro for details.

   SEP:       Include two panels for SEP data: one for ions, one for electrons.

   SWIA:      Include panels for SWIA ion density and bulk velocity (coarse
              survey ground moments).

   STATIC:    Include two panels for STATIC data: one mass spectrum, one energy
              spectrum.

   APID:      Additional STATIC APID's to load.  (Hint: D0, D1 might be useful.)

   LPW:       Include panel for electron density from LPW data.

              Note: if two or more of O2+, O+, and electron densities are present
              they are combined into a single panel.

   EUV:       Include a panel for EUV data.

   SC_POT:    Include a panel for spacecraft potential.

   EPH:       Named variable to hold ephemeris data.

   LOADONLY:  Create tplot variables, but don't plot.

   PANS:      Array of tplot variables created.

   PADSMO:    Smooth the resampled PAD data in time with this smoothing interval,
              in seconds.

   SHAPE:     Include a panel for the electron shape parameter.

   MAGFULL:   If set, then try to load full resolution (32 Hz) MAG data.
              Default is to load 1-sec data.

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:36:16 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26805 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sciplot.pro $

(See projects/maven/swea/mvn_swe_sciplot.pro)


MVN_SWE_SC_NEGPOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_sc_negpot

PURPOSE:
   Estimates the negative spacecraft potential within the ionosphere
   from SWEA energy spectra.  The basic idea is to use the second 
   derivative of the spectrum to find the shift of the He II features
   at 23 and 27 eV (mainly the 23 eV feature), from which then the 
   negative potential can be calculated.  No attempt is made to 
   estimate the potential when the spacecraft is in darkness or above
   1000 km altitude.

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:
   This procedure requires tplot variables "mvn_swe_shape_par, swe_a4, alt,
   sza, d2f".  If any of these variables does not exist, then this procedure
   attempts to create them using the appropriate procedures.
   
INPUTS:
   none

KEYWORDS:
	POTENTIAL: Returns spacecraft potentials in a structure.

   FILL:      Do not fill in the common block.  Default = 0 (no).

   RESET:     Initialize the spacecraft potential, discarding all previous 
              estimates, and start fresh.

OUTPUTS:
   None - Result is stored in the common block variables swe_sc_pot and 
          mvn_swe_engy, and as the TPLOT variable 'neg_pot'.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-10-02 16:46:41 -0700 (Mon, 02 Oct 2017) $
 $LastChangedRevision: 24089 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sc_negpot.pro $

(See projects/maven/swea/mvn_swe_sc_negpot.pro)


MVN_SWE_SC_NEGPOT_TWODIR_BURST

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_sc_negpot_twodir_burst

PURPOSE:
   Estimates potentials from the shift of He II features 
   for both anti-parallel and parallel directions with 
   SWEA PAD data. Right now it only works for burst data. 

INPUTS:
   none

KEYWORDS:
	POTENTIAL: Returns spacecraft potentials in a structure.

   SHADOW:    If keyword set, all the estimations outside of shadow
              at altitudes > 800 km are set to NANs

   SWIDTH:    Field-aligned angle to calculate spectra for both
              directions. The default value is 45 degrees. 

   FILL:      Fill in the common block.  Default = 0 (no).

   RESET:     Initialize the spacecraft potential, discarding all previous 
              estimates, and start fresh.

   SCPOT:     If keyword set, it provides s/c potential estimates. 
              The default is set to be 1.

OUTPUTS:
   None - Potential results are stored as a TPLOT variable 'negpot_pad'. 
          Four additional TPLOT variables are created for diagnostics. 

 $LastChangedBy: xussui $
 $LastChangedDate: 2018-06-26 14:36:25 -0700 (Tue, 26 Jun 2018) $
 $LastChangedRevision: 25398 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sc_negpot_twodir_burst.pro $

CREATED BY:    Shaosui Xu  01-03-2017

(See projects/maven/swea/mvn_swe_sc_negpot_twodir_burst.pro)


MVN_SWE_SC_POSPOT

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

PURPOSE:
	Estimates the spacecraft potential from SWEA energy spectra.  The basic
   idea is to look for a break in the energy spectrum (sharp change in flux
   level and slope).  Works for one or more spectra.
 
AUTHOR: 
	David L. Mitchell

CALLING SEQUENCE: 
	scpot = mvn_swe_sc_pospot(engy, eflux)

INPUTS: 
   engy:      Energy array with dimensions of [n_e] or [n_e, n_t].

   eflux:     Energy flux, with dimensions of [n_e, n_t].

KEYWORDS:

OUTPUTS:
   scpot:     An array of n_t spacecraft potentials.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-07-31 15:24:02 -0700 (Mon, 31 Jul 2017) $
 $LastChangedRevision: 23737 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sc_pospot.pro $

(See projects/maven/swea/mvn_swe_sc_pospot.pro)


MVN_SWE_SC_POT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_sc_pot

PURPOSE:
	Estimates the spacecraft potential from SWEA energy spectra.  The basic
   idea is to look for a break in the energy spectrum (sharp change in flux
   level and slope).  No attempt is made to estimate the potential when the
   spacecraft is in darkness (expect negative potential) or below 250 km
   altitude (expect small or negative potential).

 
AUTHOR: 
	David L. Mitchell

CALLING SEQUENCE: 
	mvn_swe_sc_pot, potential=dat

INPUTS: 
   none - energy spectra are obtained from SWEA common block.

KEYWORDS:
	POTENTIAL: Returns spacecraft potentials in a structure.

   ERANGE:    Energy range over which to search for the potential.
              Default = [3.,30.]

   THRESH:    Threshold for the minimum slope: d(logF)/d(logE). 
              Default = 0.05

              A smaller value includes more data and extends the range 
              over which you can estimate the potential, but at the 
              expense of making more errors.

   MINFLUX:   Minimum peak energy flux.  Default = 1e6.

   DEMAX:     The largest allowable energy width of the spacecraft 
              potential feature.  This excludes features not related
              to the spacecraft potential at higher energies (often 
              observed downstream of the shock).  Default = 6 eV.

   DDD:       Use 3D data to calculate potential.  Allows bin masking,
              but lower cadence and typically lower energy resolution.

   ABINS:     When using 3D spectra, specify which anode bins to 
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,16)

   DBINS:     When using 3D spectra, specify which deflection bins to
              include in the analysis: 0 = no, 1 = yes.
              Default = replicate(1,6)

   OBINS:     When using 3D spectra, specify which solid angle bins to
              include in the analysis: 0 = no, 1 = yes.
              Default = reform(ABINS#DBINS,96).  Takes precedence over
              ABINS and OBINS.

   MASK_SC:   Mask the spacecraft blockage.  This is in addition to any
              masking specified by the above three keywords.
              Default = 1 (yes).

   ANGCORR:   Angular distribution correction based on interpolated 3d data
              to emphasize the returning photoelectrons and improve 
              the edge detection (added by Yuki Harada).

   PANS:      Named varible to hold the tplot panels created.

   BADVAL:    If the algorithm cannot estimate the potential, then set it
              to this value.  Units = volts.  Default = NaN.

   FILL:      Do not fill in the common block.  Default = 0 (no).

   RESET:     Initialize the spacecraft potential, discarding all previous 
              estimates, and start fresh.

OUTPUTS:
   None - Result is stored in SPEC data structure, returned via POTENTIAL
          keyword, and stored as a TPLOT variable.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-09-17 16:58:25 -0700 (Tue, 17 Sep 2019) $
 $LastChangedRevision: 27777 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sc_pot.pro $

(See projects/maven/swea/mvn_swe_sc_pot.pro)


MVN_SWE_SHAPE_DAILYSAVE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_shape_dailysave
PURPOSE:

USAGE:
  mvn_swe_shape_dailysave,start_day=start_day,end_day=end_day,ndays=ndays, saveflux=saveflux

INPUTS:
       None

KEYWORDS:
       start_day:     Save data over this time range.  If not
                      specified, then timerange() will be called

       end_day:       The end day of intented time range

       ndays:         Number of dates to process. Will be overwritten
                      if start_day & end_day are given. If both
                      end_day and ndays are not specified, ndays=7

       saveflux:      If set to 1, will save eflux for 3 PA ranges to
                      a provided directory. 
 $LastChangedBy: xussui $
 $LastChangedDate: 2018-05-23 13:49:27 -0700 (Wed, 23 May 2018) $
 $LastChangedRevision: 25250 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_dailysave.pro $

CREATED BY:    Shaosui Xu, 08/01/2017
FILE: mvn_swe_shape_dailysave.pro

(See projects/maven/swea/mvn_swe_shape_dailysave.pro)


MVN_SWE_SHAPE_PAR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	mvn_swe_shape_par
PURPOSE:
	Calculates SWEA energy shape parameter and stores it as a TPLOT variable.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	mvn_swe_shape_par
INPUTS: 

KEYWORDS:
   PANS:      Named variable to return tplot variable created.

   VAR:       Get SPEC data from tplot instead of SWEA common block.
              In this case, you are responsible for making sure the
              data are in units of EFLUX.  Any other units will give
              bogus results.
              (Set this keyword to the variable name or index.)

   KEEP_NAN:  If set, then include results for all input spectra, using
              NaN for invalid results.  Otherwise, only valid results
              are returned.

   ERANGE:    If set, then calculate the shape parameter over this 
              energy range.  Default is 0-100 eV.

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2015-11-02 14:14:58 -0800 (Mon, 02 Nov 2015) $
 $LastChangedRevision: 19214 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_par.pro $

(See projects/maven/swea/mvn_swe_shape_par.pro)


MVN_SWE_SHAPE_PAR_PAD

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_shape_par_pad

PURPOSE:
   
   Calculate pitch angle resolved shape parameters for loaded SWEA PAD data
   and create tplot variable "Shape_PAD"

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:

   Assume SWEA l0 data loaded
   
   If desire to correct for spacecraft potential, first run "mvn_swe_sc_pot"

INPUTS:

   none

KEYWORDS:

   BURST: If set to 1, then use burst data to calculate the shape parameter, 
          however, not tested yet
          
   SPEC: A pitch angle in degrees given to average. 
         PA [0,SPEC] & [(180-SPEC),180] for two directions.
         The default value is 30
         
   ERANGE: Shape parameter calculated based on the spectrum within this energy
           range. The default values are [20,80] eV

   MAG_GEO: A MAG structure that contains magnetic elevation angle. If not given,
            The program will load MAG data in GEO coordinates.

   POT: If set to 1, this program will correct the spacecraft potential for 
        the electron energy spectrum.
   
OUTPUTS:

   Tplot variable "Shape_PAD": store shape parameters for two directions, as well
       as the shape parameter for trapped population, spacecraft potentials, 
       min/max pitch angle range to check if the PA coverage is enough
   
   Tplot variable "EFlux_ratio": store the flux ratio for two directions

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-01-09 16:43:10 -0800 (Mon, 09 Jan 2017) $
 $LastChangedRevision: 22549 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_par_pad.pro $

CREATED BY:    Shaosui Xu  06-22-16

(See projects/maven/swea/mvn_swe_shape_par_pad.pro)


MVN_SWE_SHAPE_PAR_PAD_L2

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   mvn_swe_shape_par_pad_l2

PURPOSE:

   Calculate pitch angle resolved shape parameters for loaded SWEA L2
   PAD survey data and create tplot variable "Shape_PAD"

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:

   If desire to correct for spacecraft potential, first run "mvn_swe_sc_pot"

INPUTS:

   none

KEYWORDS:

   BURST:    If set to 1, then use burst data to calculate the shape parameter,
             however, not tested yet

   SPEC:     A pitch angle in degrees given to average.
             PA [0,SPEC] & [(180-SPEC),180] for two directions.
             The default value is 30

   ERANGE:  Shape parameter calculated based on the spectrum within this energy
            range. The default values are [20,80] eV

   MIN_PAD_EFLUX: Minimum energy flux level.

   MAG_GEO: A MAG structure that contains magnetic elevation angle. If not given,
            The program will load MAG data in GEO coordinates.

   POT:     If set to 1, this program will correct the spacecraft potential for
            the electron energy spectrum.

   NSMO:    Number of spectra to average over before calculating shape parameter.
            Default = 1 (no smoothing).

   TSMO:    Boxcar smooth the PADs with this width (in seconds) before calculating
            the shape parameter.  This method is slower but handles data gaps and 
            changes in instrument mode.  Takes precedence over NSMO.

OUTPUTS:

   Tplot variable "Shape_PAD": store shape parameters for two directions, as well
       as the shape parameter for trapped population, spacecraft potentials,
       min/max pitch angle range to check if the PA coverage is enough

   Tplot variable "EFlux_ratio": store the flux ratio for two directions

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-11-30 21:19:45 -0800 (Thu, 30 Nov 2017) $
 $LastChangedRevision: 24373 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_par_pad_l2.pro $

CREATED BY:    Shaosui Xu  12-08-16

(See projects/maven/swea/mvn_swe_shape_par_pad_l2.pro)


MVN_SWE_SHAPE_PAR_PAD_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_shape_par_pad_restore
PURPOSE:
  Reads in tplot save/restore files swe_shape_par_pad 
  Command line used to create the tplot

USAGE:
  mvn_swe_shape_par_pad_restore, trange

INPUTS:
       trange:        Restore data over this time range.  If not specified, then
                      uses the current tplot range or timerange() will be called

KEYWORDS:
       ORBIT:         Restore pad data by orbit number.

       LOADONLY:      Download but do not restore any pad data.

 $LastChangedBy: xussui_lap $
 $LastChangedDate: 2016-10-11 14:11:51 -0700 (Tue, 11 Oct 2016) $
 $LastChangedRevision: 22085 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_par_pad_restore.pro $

CREATED BY:    Shaosui Xu  10-11-16
FILE: mvn_swe_shape_par_pad_restore.pro

(See projects/maven/swea/mvn_swe_shape_par_pad_restore.pro)


MVN_SWE_SHAPE_RESTORE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_shape_restore
PURPOSE:
  Reads in save files swe_shape_par_pad

USAGE:
  mvn_swe_shape_restore, trange

INPUTS:
       trange:        Restore data over this time range.  If not specified, then
                      uses the current tplot range or timerange() will be called

KEYWORDS:
       ORBIT:         Restore shape_par_pad data by orbit number.

       RESULTS:       Hold the full structure of shape parameters and other parameters

       TPLOT:         Create tplot varible for two-stream shape parameter, being
                      stored as tplot variable "Shape_PAD" and "rat_a2t"

       PARNG:         Shape parameter calculated based on 30, 45, and 60 deg, 
                      corresponding to PARNG=1,2,3. Default is PA=45
       
 $LastChangedBy: cfowler2 $
 $LastChangedDate: 2018-03-21 10:59:12 -0700 (Wed, 21 Mar 2018) $
 $LastChangedRevision: 24923 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_shape_restore.pro $

CREATED BY:    Shaosui Xu  06-23-17
FILE: mvn_swe_shape_restore

(See projects/maven/swea/mvn_swe_shape_restore.pro)


MVN_SWE_SLICE2D_SNAP

[Previous Routine] [Next Routine] [List of Routines]

PROCEDURE:       MVN_SWE_SLICE2D_SNAP

PURPOSE:         Plots 2D slice for the times and data type selected by cursor.
                 Hold down the left mouse button and slide for a movie effect. 
                 
INPUTS:          None.
                 But the specified time (or [tmin, tmax]) is set, it
                 automatically show the snapshot. In this case, the
                 cursor does not appear in a tplot window.

CAUTION:         *** !!! ***
                 The velocity estimated from the SWEA electron 3D data
                 via 'v_3d' is not likely reliable. 
                 Highly recommended to use the bulk velocity
                 estimated from the other data (e.g., SWIA ion data). 
                 *** !!! ***

KEYWORDS:        All the keywords included in 'slice2d' are acceptable. 

   ARCHIVE:      Returns archive distribution instead of survey.

     BURST:      Synonym for "ARCHIVE".
   
    WINDOW:      Specifies window number to plot.
                 A new window to show is generated as default.
   
     BLINE:      Shows magnetic field direction by a black solid line.

       MSO:      Rotates into the MSO coordinates (no effect on 'BV',
                 'BE', and 'perp' cuts). 

     ABINS:      Specifies which azimuth anode bins to
                 include in the analysis: 0 = no, 1 = yes.
                 Default = replicate(1, 16)

     DBINS:      Specifies which deflection bins to
                 include in the analysis: 0 = no, 1 = yes.
                 Default = replicate(1, 6).

     OBINS:      Specifies which angular bins to inclue in the
                 analysis: 0 = no, 1 = yes. Default = replicate(1, 96).

   MASK_SC:      Mask solid angle bins that are blocked by the spacecraft.
                 Default = 1

   KEEPWIN:      If set, then don't close the snapshot window on exit.

       SUM:      If set, use cursor to specify time ranges for averaging.

USAGE EXAMPLES:
         1.      ; Normal case
                 ; Uses archive data, and shows the B field direction.
                 ; Draws the X-Y plane slice in the SWEA coordinates.
   
                 mvn_swe_slice2d_snap, /arc, /bline, rot='xy'

         2.      ; Specified time case
                 ; Selects the time to show.

                 ctime, t ; Clicks once or twice on the tplot window.

                 ; Draws the electron velocity distribution
                 ; function in the plane perpendicular to the B field.   

                 mvn_swe_slice2d_snap, t, rot='perp' 

         3.      ; Advanced case
                 ; Uses 'ctime' procedure with "routine" keyword.

                 ctime, routine='mvn_swe_slice2d_snap'

CREATED BY:      Takuya Hara on 2015-07-13.

LAST MODIFICATION:
 $LastChangedBy: hara $
 $LastChangedDate: 2015-07-17 14:34:02 -0700 (Fri, 17 Jul 2015) $
 $LastChangedRevision: 18173 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_slice2d_snap.pro $

(See projects/maven/swea/mvn_swe_slice2d_snap.pro)


MVN_SWE_SPECPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_specplot
PURPOSE:
  Plots time series summary plots of SWEA SPEC data over arbitrarily long
  time spans.  The result is stored in a single TPLOT variable.

USAGE:
  mvn_swe_specplot, trange=trange, orbit=orbit

INPUTS:

KEYWORDS:

       TRANGE:       Time range over which load data.  Must have at least two
                     elements, in any format accepted by time_double().  If
                     not specified, then load data using the current timespan.

       ORBIT:        Load data by orbit number (overrides TRANGE and TIMESPAN
                     methods).

       UNITS:        Units for plotting energy spectra.  Default = 'eflux'.

       ENERGY:       Energy for line plot.

       ERATIO:       Two energies for calculating a flux ratio.

       TAVG:         Time averaging when using ENERGY or ERATIO keywords.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-08-14 11:18:45 -0700 (Mon, 14 Aug 2017) $
 $LastChangedRevision: 23786 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_specplot.pro $

CREATED BY:    David L. Mitchell  2015-05-06

(See projects/maven/swea/mvn_swe_specplot.pro)


MVN_SWE_SPECSUM

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_specsum
PURPOSE:
  Sums multiple SPEC data structures.  This is done by summing raw counts
  corrected by deadtime and then setting dtc to unity.

USAGE:
  specsum = mvn_swe_specsum(spec)

INPUTS:
       spec:           An array of SPEC structures to sum.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-27 14:06:18 -0700 (Tue, 27 Aug 2019) $
 $LastChangedRevision: 27682 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_specsum.pro $

CREATED BY:    David L. Mitchell  03-29-14
FILE: mvn_swe_specsum.pro

(See projects/maven/swea/mvn_swe_specsum.pro)


MVN_SWE_SPICE_INIT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_spice_init
PURPOSE:
  Initializes SPICE.

USAGE:
  mvn_swe_spice_init

INPUTS:

KEYWORDS:

    TRANGE:        Time range for MAVEN spacecraft spk and ck kernels.

    LIST:          After loading, list the kernels in use.

    FORCE:         If set, then clear all kernels and reload them based on TRANGE
                   or the current value of trange_full.  Otherwise, ask the user
                   for permission to clear and reload.

    SCLK_VER:      Force the SCLK kernel version to be this.  Sometimes needed for
                   accurate relative timing between MAG and SWEA.  If set, then
                   FORCE is also set.

    STATUS:        Don't load anything; just give status.

    INFO:          Returns an array of structures providing detailed information
                   about each kernel, including coverage in time.

    VERBOSE:       Control level of messages.  (0 = suppress most messages)
                   Default is current value of swe_verbose.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-04-18 05:43:01 -0700 (Thu, 18 Apr 2019) $
 $LastChangedRevision: 27042 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_spice_init.pro $

CREATED BY:    David L. Mitchell  09/18/13

(See projects/maven/swea/mvn_swe_spice_init.pro)


MVN_SWE_STAT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_stat
PURPOSE:
  Reports the status of SWEA data loaded into the common block.

USAGE:
  mvn_swe_stat

INPUTS:

KEYWORDS:

    NPKT:          Returns the number of packets of each type.

    FULL:          If set, then display version information about IDL
                   and the SPICE and CDF dynamic load modules.

    SILENT:        Shhhh.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:46:42 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26820 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_stat.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/mvn_swe_stat.pro)


MVN_SWE_STRUCT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_struct
PURPOSE:
  Defines data structures for 3D, PAD, and ENGY products.  These work for both survey
  and archive.

  All times are for the center of the sample.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:43:46 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26816 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_struct.pro $

CREATED BY:	David L. Mitchell  2013-07-26
FILE:  mvn_swe_struct.pro

(See projects/maven/swea/mvn_swe_struct.pro)


MVN_SWE_SUMPLOT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_sumplot
PURPOSE:
  Plots information generated by MAVEN SWEA APID's.

  See 'mvn_swe_load_l0.pro' for details.

USAGE:
  mvn_swe_sumplot

INPUTS:

KEYWORDS:

       EPH:          Load the MAVEN ephemeris and include a panel showing altitude, 
                     color coded by nominal plasma regime.

       ORB:          Include the orbit number along the horizontal axis.

       SPICE:        Create a panel showing spice coverage.

       VNORM:        Subtract nominal values from all housekeeping voltages and plot all
                     voltage differences in a single panel.  Default = 1 (yes).

       CMDCNT:       Plot the SWEA command counter.

       SFLG:         Plot Energy Spectra and PAD's as spectrograms.  Default = 1 (yes).

       PAD_E:        PAD energy to plot.  Default = 280 eV.

       PAD_SMO:      Number of PAD energy bins to smooth over.

       A4_SUM:       Force sum mode for A4 and A5.  Not needed for EM or for FM post ATLO.

       EUNITS:       Units for plotting energy spectra (A4 and A5).  Default = 'crate'.

       TFIRST:       Earliest time to plot.  (Used for realtime plotting loop.)

       TITLE:        Title of TPLOT window.

       TSPAN:        Maximum number of hours to plot.  Default = plot all data.

       APID:         APID's to plot.  Housekeeping (APID 28) is always plotted.  3D
                     distributions (A0 and A1) are never plotted.  (Use swe_3d_snap to
                     display A0 and A1.)  This keyword controls plotting of A2-A5.
                     Default: ['A2','A4'].

       HSK:          String array indicating additional housekeeping panels to plot
                     (e.g., HSK = ['MCPHV'] during HV ramps).  Default = [''].

       FHSK:         Create tplot variables for fast housekeeping.  Default = 0 (no).

       FSHIFT:       Shift fast housekeeping packets to the start time of the first.

       FNORM:        Normalize the fast housekeeping channels to the nominal value.

       LUT:          Plot the active LUT.

       SIFCTL:       Plot SIF control register bits.

       TIMING:       Plot packet timing.  Useful to identify instrument mode and
                     dropped packets.  Default = 0 (no).

       LOADONLY:     Load tplot variables but do not plot.

       PNG:          Create a PNG image and place it in the default location.

       BURST:        Plot a color bar showing PAD burst coverage.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-03-17 11:23:59 -0700 (Tue, 17 Mar 2020) $
 $LastChangedRevision: 28423 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sumplot.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/mvn_swe_sumplot.pro)


MVN_SWE_SUNDIR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_sundir
PURPOSE:
  Calculates the direction of the Sun in SWEA coordinates.
  Optionally, calculates the direction of the Sun in additional 
  frames specified by keyword.  The results are stored in TPLOT 
  variables.

  Spacecraft frame:
    X --> APP boom axis
    Y --> +Y solar array axis
    Z --> HGA axis

  SWEA frame:
    X --> boundary between Anodes 15 and 0
    Y --> boundary between Anodes 3 and 4
    Z --> instrument symmetry axis
          (points "down" from top cap to pedestal)

  When boom is deployed, Z_sc = Z_swea

  If [X,Y,Z] is a unit vector, then
    phi   = atan(Y,X)
    theta = asin(Z)

  Some important angles:

    theta (deg)   : significance
  ---------------------------------------------------------------
    90 to 87      : entire sensor in shadow of pedestal
    < 87          : toroidal grids illuminated
    < 77          : upper deflector illuminated
    < 37          : top cap (periphery) illuminated
    17 to   0     : scalloped part of top cap illuminated
     0 to -10     : photons enter gap between hemispheres
  ---------------------------------------------------------------

  Negative values of theta are very unlikely in practice, since it
  means that the solar panels are facing away from the Sun.  The
  grids and upper deflector often become illuminated during comm
  passes and fly-Y.  The maximum angular separation between Earth
  and the Sun as seen from Mars is 47.5 deg.

  Toroidal grid support ribs are located every 45 degrees.  Each
  rib is 7-deg wide at theta = 0, with centers at:

    phi = 0, 45, 90, 135, 180, 225, 270, 315 degrees

USAGE:
  mvn_swe_sundir, trange

INPUTS:
       trange:   Time range for calculating the Sun direction.

KEYWORDS:
       DT:       Time resolution (sec).  Default = 1, which is plenty
                 fast to resolve spacecraft rotations.

       PANS:     Named variable to hold the tplot variables created.

       FRAME:    Also calculate the Sun direction in one or more 
                 frames specified by this keyword.  Default = 'MAVEN_SWEA'

       LIST:     List the key angles (as described above) and exit.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-03-01 14:50:37 -0800 (Wed, 01 Mar 2017) $
 $LastChangedRevision: 22886 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sundir.pro $

CREATED BY:    David L. Mitchell  09/18/13

(See projects/maven/swea/mvn_swe_sundir.pro)


MVN_SWE_SWEEP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_sweep
PURPOSE:
  Generates a SWEA sweep table exactly as done in flight software (same digital 
  commands, same checksum).  This table is combined with calibration data to 
  determine energy sweep and deflection angle.

  Eight pre-defined tables are provided via keyword TABNUM.  Tables 1-4 are 
  obsolete.  Tables 5 and 6 correspond to tables as loaded into flight software
  during commissioning in October 2014.  Table 8 will be loaded into flight 
  software as part of an EEPROM update in late August 2018.  Table 7 will be 
  loaded via CDI commands, since there is no contiguous block of PFDPU memory 
  large enough to hold the table.

KEYWORDS:
       RESULT:       Named variable to hold result structure: analyzer, deflector,
                     and V0 sweeps, energy/angle sweeps, energy resolution (dE/E)
                     and geometric factor vs. energy.

       TPLOT:        Create tplot variables.

       DOPLOT:       Plot Va, Vd, V0, E, dE/E, X, TH, and GFW for one 2-sec sweep.

       TSTART:       Arbitrary start time for DOPLOT.

       PROP:         Print the table properties: checksum, energy and angle ranges.

       TABNUM:       Table number corresponding to predefined settings.  Currently,
                     there are eight tables defined:

                       1 : Xmax = 6., Vrange = [0.75, 750.], V0scale = 1., /old_def
                           primary table for ATLO and Inner Cruise (first turnon)
                             -64 < Elev < +66 ; 7 < E < 4650
                              Chksum = 'CC'X

                       2 : Xmax = 6., Vrange = [0.75, 375.], V0scale = 1., /old_def
                           alternate table for ATLO and Inner Cruise (never used)
                             -64 < Elev < +66 ; 7 < E < 2340
                              Chksum = '1E'X

                       3 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0., /old_def
                           primary table for Outer Cruise
                             -59 < Elev < +61 ; 3 < E < 4630
                              Chksum = 'C0'X
                              GSEOS svn rev 8360

                       4 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1., /old_def
                           alternate table for Outer Cruise
                             -59 < Elev < +61 ; 3 < E < 4650
                              Chksum = 'DE'X
                              GSEOS svn rev 8361

                       5 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0.
                           primary table for Transition and Science
                             -59 < Elev < +61 ; 3 < E < 4630
                              Chksum = 'CC'X
                              GSEOS svn rev 8481
                              LUT = 0

                       6 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1.
                           alternate table for Transition and Science
                             -59 < Elev < +61 ; 3 < E < 4650
                              Chksum = '82'X
                              GSEOS svn rev 8482
                              LUT = 1

                       7 : Xmax = 5.5, Erange = [200.,200.], V0scale = 0.
                           Hires 32-Hz at 200 eV
                             -59 < Elev < +61 ; E = 200
                              Chksum = '00'X
                              LUT = 2

                       8 : Xmax = 5.5, Erange = [50.,50.], V0scale = 0.
                           Hires 32-Hz at 50 eV
                             -59 < Elev < +61 ; E = 50
                              Chksum = '00'X
                              LUT = 3

                     Otherwise, use the following keywords to define the sweep.

       CHKSUM:       Use checksum to determine which table to use.  Only works
                     for table numbers >= 3.

       Xmax:         Maximum ratio of deflector voltage to analyzer voltage.
                     (Controls maximum deflection angle.)  Default = 6.

       V0scale:      Scale factor for V0 (a number from 0 to 1).
                         |V0| = E/2 < (25*V0scale) Volts
                     Default = 1.

       Vrange:       Voltage range of sweep (commanded).  Default = [0.75, 750.].

       Erange:       Energy range of sweep (commanded).  Takes precendence over Vrange.
                     This keyword allows one to set the energy range, correcting for
                     V0, if necessary.  No default.

       old_def:      Use the old method for sweeping the deflectors.  This is valid
                     for ground tests, early cruise checkout (Dec 6-7, 2013), and
                     outer cruise.

       DUMPFILE:     Saves an ascii hex dump to this named file, for comparison with
                     PFDPU EEPROM dump.

       CMDFILE:      Saves an ascii command file for upload to the PFDPU.

       MEMADDR:      PFDPU memory address to begin loading table.  Only used if
                     FORMAT < 2.

       SWEBUF:       SWEA SLUT buffer to load table to (0-7).  Only used if FORMAT = 2.

       FORMAT:       Output sweep table in specified format:
                        0 = old PFDPU format (bytes)
                        1 = new PFDPU format (4-byte words)
                        2 = SWEA native format (2-byte words)

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-02-09 16:39:20 -0800 (Sat, 09 Feb 2019) $
 $LastChangedRevision: 26583 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_sweep.pro $

CREATED BY:	David L. Mitchell  2014-01-03
FILE:  mvn_swe_sweep.pro

(See projects/maven/swea/mvn_swe_sweep.pro)


MVN_SWE_SWI_CAL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_swi_cal
PURPOSE:
  Compares ion density from SWIA and electron density from SWEA for the purpose 
  of cross calibration.  Beware of situations where SWEA and/or SWIA are not
  measuring important parts of the distribution.  Furthermore, SWEA data must be
  corrected for spacecraft potential (see mvn_scpot), and photoelectron 
  contamination must be removed for any hope of a decent cross calibration.  For
  some distributions, secondary electrons can also bias the SWEA density estimate.

USAGE:
  mvn_swe_swi_cal

INPUTS:
   None.  Uses the current value of TRANGE_FULL to define the time range
   for analysis.  Calls timespan, if necessary, to set this value.

KEYWORDS:
   COARSE:    Select SWIA 'coarse' data for analysis.  Provides density estimates
              in the sheath.  Not recommended for cross calibration.

   FINE:      Select SWIA 'fine' data for analysis.  This is the default.

   ALPHA:     Calculate both proton and alpha densities using SWIA code.
              Requires 'fine' data, so this forces FINE to be set.

   DDD:       Use SWEA 3D data for computing density.  Allows for bin
              masking.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2018-02-18 12:25:42 -0800 (Sun, 18 Feb 2018) $
 $LastChangedRevision: 24735 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_swi_cal.pro $

CREATED BY:    David L. Mitchell

(See projects/maven/swea/mvn_swe_swi_cal.pro)


MVN_SWE_TABNUM

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_tabnum
PURPOSE:
  Given a checksum, determines the corresponding table number.  Only returns
  table numbers >= 3.

  Eight tables are defined.  Tables 1-4 are obsolete.  Tables 5 and 6 
  correspond to tables as loaded into flight software during commissioning 
  in October 2014.  Table 8 will be loaded into flight software as part of 
  an EEPROM update in late August 2018.  Table 7 will be loaded via CDI 
  commands, since there is no contiguous block of PFDPU memory large enough 
  to hold the table.

  Tables 7 and 8 both have a checksum of zero.  Use energy to resolve.

        1 : Xmax = 6., Vrange = [0.75, 750.], V0scale = 1., /old_def
            primary table for ATLO and Inner Cruise (first turnon)
              -64 < Elev < +66 ; 7 < E < 4650
               Chksum = 'CC'X

        2 : Xmax = 6., Vrange = [0.75, 375.], V0scale = 1., /old_def
            alternate table for ATLO and Inner Cruise (never used)
              -64 < Elev < +66 ; 7 < E < 2340
               Chksum = '1E'X

        3 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0., /old_def
            primary table for Outer Cruise
              -59 < Elev < +61 ; 3 < E < 4630
               Chksum = 'C0'X
               GSEOS svn rev 8360

        4 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1., /old_def
            alternate table for Outer Cruise
              -59 < Elev < +61 ; 3 < E < 4650
               Chksum = 'DE'X
               GSEOS svn rev 8361

        5 : Xmax = 5.5, Vrange = [3./Ka, 750.], V0scale = 0.
            primary table for Transition and Science
              -59 < Elev < +61 ; 3 < E < 4630
               Chksum = 'CC'X
               GSEOS svn rev 8481
            loaded into SWEA LUT 0 (via FSW)

        6 : Xmax = 5.5, Vrange = [2./Ka, 750.], V0scale = 1.
            alternate table for Transition and Science
              -59 < Elev < +61 ; 3 < E < 4650
               Chksum = '82'X
               GSEOS svn rev 8482
            loaded into SWEA LUT 1 (via FSW)

        7 : Xmax = 5.5, Erange = [200.,200.], V0scale = 0.
            Hires 32-Hz at 200 eV
              -59 < Elev < +61 ; E = 200
               Chksum = '00'X
            loaded into SWEA LUT 2 (via CDI)

        8 : Xmax = 5.5, Erange = [50.,50.], V0scale = 0.
            Hires 32-Hz at 50 eV
              -59 < Elev < +61 ; E = 50
               Chksum = '00'X
            loaded into SWEA LUT 3 (via FSW)

USAGE:
  tabnum = mvn_swe_tabnum(i)

INPUTS:
       i:            The checksum or table number.

KEYWORDS:
       INVERSE:      Given a table number, return its checksum.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:38:10 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26808 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_tabnum.pro $

CREATED BY:	David L. Mitchell  2014-01-03
FILE:  mvn_swe_tabnum.pro

(See projects/maven/swea/mvn_swe_tabnum.pro)


MVN_SWE_VALIDLUT

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   mvn_swe_validlut
PURPOSE:
  Checks for valid sweep lookup tables (LUTs).  The valid
  tables are: 3, 5 and 6.  Table 3 is primary during cruise,
  and was superceded by table 5 during transition on Oct. 6,
  2014.  Table 6 is very similar to 5, except that it enables
  V0.

  The high resolution tables (7 and 8) do not comform to the
  PDS archive specification and will need to be handled
  separately.

USAGE:
  valid = mvn_swe_validlut(lut)

INPUTS:
   lut:       Sweep table number.

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 16:32:12 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26830 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_validlut.pro $

CREATED BY:    David L. Mitchell  02-01-15
FILE: mvn_swe_validlut.pro

(See projects/maven/swea/mvn_swe_validlut.pro)


MVN_SWE_VERBOSE

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   mvn_swe_verbose
PURPOSE:
  Sets the SWEA verbosity level.

USAGE:
  mvn_swe_verbose, level

INPUTS:

    level:         Verbosity level (0 = suppress most messages).

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2017-10-02 16:48:57 -0700 (Mon, 02 Oct 2017) $
 $LastChangedRevision: 24094 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/mvn_swe_verbose.pro $

CREATED BY:    David L. Mitchell

(See projects/maven/swea/mvn_swe_verbose.pro)


NIBBLE

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   nibble
PURPOSE:
  Converts a byte into an 8-element byte array where the elements are
  the individual bits (0 or 1).  LSB is stored in element 0 and MSB is
  in element 7.  Note: if this function is fed an integer or a long,
  then it processes only the least significant byte without crashing.
  No error checking for maximum speed.
USAGE:
  bits = nibble(byte)
INPUTS:
       byte : A byte scalar.
KEYWORDS:
CREATED BY:	David L. Mitchell  01-15-98
FILE:  nibble.pro
VERSION:  1.2
LAST MODIFICATION:  01-31-98

(See projects/maven/swea/nibble.pro)


NIBBLE_LONG

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   nibble_long
PURPOSE:
  Converts an unsigned long into a 32-element byte array where the 
  elements are the individual bits (0 or 1).  LSB is stored in 
  element 0 and MSB is in element 32.  No error checking for maximum 
  speed.
USAGE:
  bits = nibble_long(lword)
INPUTS:
       lword : A unsigned long scalar.
KEYWORDS:
CREATED BY:	David L. Mitchell  02-06-11
FILE:  nibble_long.pro
VERSION:  1.0
LAST MODIFICATION:  06-02-11

(See projects/maven/swea/nibble_long.pro)


NIBBLE_WORD

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   nibble_word
PURPOSE:
  Converts an unsigned int into a 16-element byte array where the 
  elements are the individual bits (0 or 1).  LSB is stored in 
  element 0 and MSB is in element 15.  Note: if this function is 
  fed a long, then it processes only the least significant word 
  without crashing.  No error checking for maximum speed.
USAGE:
  bits = nibble_word(word)
INPUTS:
       word : A unsigned integer scalar.
KEYWORDS:
CREATED BY:	David L. Mitchell  01-15-98
FILE:  nibble.pro
VERSION:  1.2
LAST MODIFICATION:  01-31-98

(See projects/maven/swea/nibble_word.pro)


ROTATE_MAG_TO_SWE

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   rotate_mag_to_swe
PURPOSE:
  Rotates input vectors from MAG instrument coordinates to
  SWEA FSW coordinates.

USAGE:
  v_out = rotate_mag_to_swe(v_in)

INPUTS:
       v_in:     Input vectors with dimensions of N x 3.  The result
                 will have the same dimensions.

KEYWORDS:

       MAGU:     Identifies the MAG sensor unit: 1 or 2.  Default is 1.
                 (MAG1 is used for on-board pitch angle mapping.)

       STOW:     Calculate the transformation for a stowed SWEA boom.
                 Default assumes a deployed boom.

       PAYLOAD:  Input vectors are in payload coordinates.

       INVERSE:  Reverse the rotation: swe to mag coordinates.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 14:15:03 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16106 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/rotate_mag_to_swe.pro $

CREATED BY:    David L. Mitchell  09/18/13

(See projects/maven/swea/rotate_mag_to_swe.pro)


SIGFIG

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   sigfig
PURPOSE:
  Simple function for rounding off.

USAGE:
  y = sigfig(x,n)

INPUTS:
       x:      The value to be rounded.  Can be an array.

       n:      Number of significant figures (>= 1).

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-03-31 18:06:44 -0700 (Mon, 31 Mar 2014) $
 $LastChangedRevision: 14725 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/sigfig.pro $

CREATED BY:    David L. Mitchell  A Long Time Ago

(See projects/maven/swea/sigfig.pro)


SWE_3D_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_3d_snap
PURPOSE:
  Plots 3D snapshots in a separate window for times selected with the cursor in
  a tplot window.  Hold down the left mouse button and slide for a movie effect.
  This version uses plot3d and spec3d on packaged 3D data.

USAGE:
  swe_3d_snap

INPUTS:

KEYWORDS:
       EBINS:         Energy bins to plot (passed to plot3d).  Default = 16 evenly
                      spaced bins.

       CENTER:        Longitude and latitude of the center [lon, lat].

       MAP:           Mapping projection.  See plot3d_options for details.

       ZLOG:          If set, use a log color scale.

       ZRANGE:        Range for color bar.

       SPEC:          Plot energy spectra using spec3d.

       POT:           Plot the spacecraft potential on the SPEC plots.

       UNITS:         Units for the spec3d.

       ENERGY:        One or more energies to plot.  Overrides EBINS.

       PADMAG:        If set, use the MAG angles in the PAD data to show the 
                      magnetic field direction.

       DDD:           Named variable to hold a 3D structure at the last time
                      selected.  If this is a 3D structure, then plot a snapshot
                      of this instead of using the tplot window to select a time.

       SUM:           If set, use cursor to specify time ranges for averaging.

       TSMO:          Smoothing interval, in seconds.  Default is no smoothing.

       SMO:           Set smoothing in energy and angle.  Since there are only six
                      theta bins, smoothing in that dimension is not recommended.

                        smo = [n_energy, n_phi, n_theta]  ; default = [1,1,1]

                      This routine takes into account the 360-0 degree wrap when 
                      smoothing.

       SYMDIR:        Calculate and overplot the symmetry direction of the 
                      electron distribution.

       SYMENERGY:     Energy at which to calculate the symmetry direction.  Should
                      be > 100 eV.  Using the SMO keyword also helps.

       POWER:         Weighting function is proportional to eflux^power.  Higher
                      powers emphasize the peak of the distribution; lower powers
                      give more weight to surrounding cells.  Default = 2.

       SYMDIAG:       Plot symmetry weighting function in separate window.

       SUNDIR:        Plot the direction of the Sun in SWEA coordinates.

       LABEL:         If set, label the 3D angle bins.

       LABSIZE:       Character size for the labels.  Default = 1.

       WSCALE:        Window size scale factor.

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ARCHIVE:       If set, show snapshots of archive data.

       BURST:         Synonym for ARCHIVE.

       MASK_SC:       Mask solid angle bins that are blocked by the spacecraft.

       PLOT_SC:       Draw an outline of the spacecraft as seen from SWEA on 
                      the 3D plot.

       PLOT_FOV:      Replace the data with a "chess board" pattern to show the
                      field of view.  FOV masking, if any, will be shown.

       TRANGE:        Plot snapshot for this time range.  Can be in any
                      format accepted by time_double.  (This disables the
                      interactive time range selection.)

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:20:00 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28834 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_3d_snap.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/swe_3d_snap.pro)


SWE_3D_STITCH

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_3d_stitch
PURPOSE:
  Constructs 3D spectrograms from A0 packets.  Depending on the group parameter,
  1, 2, or 4 A0 packets are needed to make one 3D.

USAGE:
  swe_3d_stitch

INPUTS:

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2016-04-25 20:07:01 -0700 (Mon, 25 Apr 2016) $
 $LastChangedRevision: 20924 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_3d_stitch.pro $

CREATED BY:    David L. Mitchell  07-24-12
FILE: swe_3d_stitch.pro

(See projects/maven/swea/swe_3d_stitch.pro)


SWE_3D_STRAHL_DIR

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE: 
	swe_3d_strahl_dir
PURPOSE:
	Determines the direction in SWEA coordinates of the strahl.
AUTHOR: 
	David L. Mitchell
CALLING SEQUENCE: 
	swe_3d_strahl_dir
INPUTS: 
KEYWORDS:
       SMO:           Set smoothing in energy and angle.  Since there are only six
                      theta bins, smoothing in that dimension is not recommended.

                        smo = [n_energy, n_phi, n_theta]  ; default = [5,3,1]

       ENERGY:        Energy at which to calculate the symmetry direction.  Should
                      be > 100 eV.  Using the SMO keyword also helps.
                      Default = 130.

       POWER:         Weighting function is proportional to eflux^power.  Higher
                      powers emphasize the peak of the distribution; lower powers
                      give more weight to surrounding cells.  Default = 2.

       PANS:          Named variable to hold TPLOT variable names created.

       RESULT:        Named variable to hold the result.

       ARCHIVE:       Use archive data instead of survey data.

OUTPUTS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2016-10-18 15:24:35 -0700 (Tue, 18 Oct 2016) $
 $LastChangedRevision: 22134 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_3d_strahl_dir.pro $

(See projects/maven/swea/swe_3d_strahl_dir.pro)


SWE_3D_TIMING

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_3d_timing
PURPOSE:
  Disassembles A0 packets and sorts data in time sequence.

USAGE:
  swe_3d_timing

INPUTS:

KEYWORDS:
       TRANGE:       Time range for processing, in any format
                     accepted by time_double().

       ANODE:        Anode number to process.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 14:15:03 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16106 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_3d_timing.pro $

CREATED BY:    David L. Mitchell  06-25-13
FILE: swe_3d_timing.pro

(See projects/maven/swea/swe_3d_timing.pro)


SWE_A0_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_a0_snap
PURPOSE:
  Plots 3D snapshots in a separate window for times selected with the cursor in
  a tplot window.  Hold down the left mouse button and slide for a movie effect.

  If housekeeping data exist (almost always the case), then they are displayed 
  as text in a small separate window.

USAGE:
  swe_3d_snap

INPUTS:

KEYWORDS:
       LAYOUT:        A named variable to specify window layouts.

                        0 --> Default.  No fixed window positions.
                        1 --> Macbook Air with Dell 1920x1200 external screen.
                        2 --> HP Z220 with twin Dell 1920x1200 screens.
                        3 --> Dell 2009W 1680x1050 with Macbook Air

                      This puts up snapshot windows in convenient, non-overlapping
                      locations, depending on display hardware.

       MODEL:         Plot a model of the 3D data product with the test pulser on in a
                      separate window.  (An analytic approximation to the test pulser
                      signal is used.  See 'swe_testpulser_model.pro' for details.)

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ZRANGE:        Sets color scale range.  Default = [1,3000].

       ZLOG:          Sets log color scaling.  Default = 1.

       ARCHIVE:       If set, show snapshots of archive data (A1).

CREATED BY:    David L. Mitchell  07-24-12
FILE: swe_a0_snap.pro
VERSION:   1.0
LAST MODIFICATION:   07/24/12

(See projects/maven/swea/swe_a0_snap.pro)


SWE_A2_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_a2_snap
PURPOSE:
  Plots PAD snapshots in a separate window for times selected with the cursor in
  a tplot window.  Hold down the left mouse button and slide for a movie effect.

  If housekeeping data exist (almost always the case), then they are displayed 
  as text in a small separate window.

USAGE:
  swe_a2_snap

INPUTS:

KEYWORDS:
       LAYOUT:        A named variable to specify window layouts.

                        0 --> Default.  No fixed window positions.
                        1 --> Macbook Air with Dell 1920x1200 external screen.
                        2 --> HP Z220 with twin Dell 1920x1200 screens.

                      This puts up snapshot windows in convenient, non-overlapping
                      locations, depending on display hardware.

       MODEL:         Plot a model of the PAD data product with the test pulser on in
                      a separate window.  (An analytic approximation to the test pulser
                      signal is used.  See 'swe_testpulser_model.pro' for details.)

       DDD:           Calculate a pseudo-PAD data product from the nearest 3D spectrum,
                      and plot in a separate window.  Better when A0 and A2 have the same
                      energy grouping and time sampling.  Best when A0 and A2 are at max
                      rate with no energy grouping.  There is always the limitation that
                      3D spectra average adjacent anode bins at the highest upward and
                      downward deflections (80 solid angle bins instead of 96), whereas 
                      PAD spectra do not.

       ENORM:         Normalize PAD at each energy step.

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ZRANGE:        Sets color scale range.  Default = [1,3000].

       ZLOG:          Sets log color scaling.  Default = 1.

       ARCHIVE:       If set, show shapshots of archive data (A3).  Pseudo-PAD data is 
                      calculated from 3D archive data (A1).

CREATED BY:    David L. Mitchell  07-24-12
FILE: swe_a2_snap.pro
VERSION:   1.0
LAST MODIFICATION:   07/24/12

(See projects/maven/swea/swe_a2_snap.pro)


SWE_CAL_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_cal_snap
PURPOSE:
  Plots snapshots of calibration data in a separate window for times selected 
  with the cursor in a tplot window.  Hold down the left mouse button and slide
  for a movie effect.

  Calibration data can be extracted from 3D, PAD, or SPEC data.

USAGE:
  swe_cal_snap

INPUTS:

KEYWORDS:
       DDD:           Get calibration from 3D data.

       PAD:           Get calibration from PAD data.

       SPEC:          Get calibration from SPEC data.

       UNITS:         Data units.

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ARCHIVE:       If set, show snapshots of archive data.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-08-26 16:49:26 -0700 (Mon, 26 Aug 2019) $
 $LastChangedRevision: 27656 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_cal_snap.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/swe_cal_snap.pro)


SWE_ENGY_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_engy_snap
PURPOSE:
  Plots omnidirectional energy spectrum snapshots in a separate window for times 
  selected with the cursor in a tplot window.  Hold down the left mouse button 
  and slide for a movie effect.

USAGE:
  swe_engy_snap

INPUTS:

KEYWORDS:
       UNITS:         Plot the data in these units.  See mvn_swe_convert_units.
                      Default = 'eflux'.

       TIMES:         Make a plot for these times.  (Placeholder only.)

       TPLOT:         Get energy spectra from tplot variable instead of SWEA
                      common block.

       FIXY:          Use a fixed y-axis range.  Default = 1 (yes).

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ARCHIVE:       If set, show shapshots of archive data (A5).

       BURST:         Synonym for ARCHIVE.

       SPEC:          Named variable to hold the energy spectrum at the last time
                      selected.

       SUM:           If set, use cursor to specify time ranges for averaging.

       TSMO:          Smoothing interval, in seconds.  Default is no smoothing.

       ERROR_BARS:    If set, plot energy spectra with error bars.  Does not work 
                      when the TPLOT option (see above) is set, because statistical
                      uncertainties are not stored in the tplot variable.

       POT:           Overplot an estimate of the spacecraft potential.  Must run
                      mvn_scpot first.

       SCP:           Temporarily override any other estimates of the spacecraft 
                      potential and force it to be this value.

       SHIFTPOT:      Correct for the spacecraft potential.  Spectra are shifted from
                      the spacecraft frame to the plasma frame.

       DEMAX:         Maximum width of spacecraft potential signature.

       PEPEAKS:       Overplot the nominal energies of the photoelectron energy peaks
                      at 23 and 27 eV.

       CUII:          Overplot ionization potential of Cu (hemispheres and top cap are
                      coated with Cu2S).  This is the threshold for electron impact
                      ionization and secondary electron contamination inside the 
                      instrument.

       PEREF:         Overplot photoelectron reference spectra

       BCK:           Plot background level (Potassium-40 decay and penetrating
                      particles only).

       MAGDIR:        Print magnetic field geometry (azim, elev, clock) on the plot.

       PDIAG:         Plot potential estimator in a separate window.

       PXLIM:         X limits (Volts) for diagnostic plot.

       PYLIM:         Y limits (Volts) for diagnostic plot.

       MB:            Perform a Maxwell-Boltzmann fit to determine density and 
                      temperature.  Uses a moment calculation to determine the
                      halo density, which is defined as the high energy residual
                      after subtracting the best-fit Maxwell-Boltzmann.

       KAP:           Instead of the halo moment calculation, fit the halo with
                      a kappa function to estimate halo density.

       MOM:           Instead of fitting the core with a Maxwell-Boltzmann, use
                      a moment calculation for all energies above the spacecraft
                      potential.

       ERANGE:        Energy range for computing the moment.  Only effective when
                      keyword MOM is set.

       FLEV:          Calculate the signal level at this energy, using interpolation
                      as needed.

       SCAT:          Plot the scattered photoelectron population, which is defined
                      as the low-energy residual after subtracting the best-fit
                      Maxwell-Boltzmann.

       SEC:           Calculate secondary electron spectrum using McFadden's
                      semi-empirical approach.

       SSCALE:        Scale factor for secondary electron spectrum.  Default = 5.
                      This scales the secondary electron production efficiency.
                      A better value might be ~0.5.  This can be estimated by comparing
                      with SWIA densities.  Look for consistent density ratio.  Also,
                      shape of energy spectrum.

       DDD:           Create an energy spectrum from the nearest 3D spectrum and
                      plot for comparison.

       ABINS:         Anode bin mask (16 elements: 0=off, 1=on).  Default = all on.

       DBINS:         Deflector bin mask (6 elements: 0=off, 1=on).  Default = all on.

       OBINS:         3D solid angle bin mask (96 elements: 0=off, 1=on).
                      Default = reform(ABINS # DBINS).

       MASK_SC:       Mask solid angle bins that view the spacecraft.  Default = yes.
                      This masking is in addition to OBINS.

       NOERASE:       Overplot all spectra after the first.

       VOFFSET:       Vertical offset when overplotting spectra.

       RAINBOW:       With NOERASE, overplot spectra using up to 6 different colors.

       RCOLORS:       Instead of the default rainbow colors, use these instead.
                      Any number of colors is allowed.  The routine cycles through 
                      the colors as needed, if there are many spectra to plot.

       POPEN:         Set this to the name of a postscript file for output.

       WSCALE:        Window size scale factor.

       CSCALE:        Character size scale factor.

       XRANGE:        Override the default horizontal axis range with this.

       YRANGE:        Override the default vertical axis range with this.

       TRANGE:        Plot snapshot for this time range.  Can be in any
                      format accepted by time_double.  (This disables the
                      interactive time range selection.)

       TWOT:          Compare energy of peak energy flux and temperature of 
                      Maxwell-Boltzmann fit. (Nominally, E_peak = 2*T)

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 12:21:06 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28842 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_engy_snap.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/swe_engy_snap.pro)


SWE_ENGY_TIMING

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_engy_timing
PURPOSE:
  Disassembles A4 packets and sorts data in time sequence.

USAGE:
  swe_engy_timing

INPUTS:

KEYWORDS:
       CAL:           Use calibrated data (mvn_swe_engy).

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:20:36 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28835 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_engy_timing.pro $

CREATED BY:    David L. Mitchell  06-25-13
FILE: swe_engy_timing.pro

(See projects/maven/swea/swe_engy_timing.pro)


SWE_GETMAG_QL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_getmag_ql
PURPOSE:
  Loads MAG data from one of two sources:

      (1) MAG quicklook sts files provided by the MAG team.  These are converted
          into IDL save files -- this routine restores the save files.  These
          data include corrections for nominal offsets.  MAG1 data only.  Typically
          available one day after the L0 data arrive.

      (2) Davin's decommutator.  These are loaded directly from the L0 data.
          These data do not have offset corrections.  Both MAG1 and MAG2 data are
          provided.

  Once loaded, the data are smoothed to the 2-sec SWEA resolution.

  OBSOLETE: Use mvn_swe_addmag instead.

USAGE:
  swe_getmag_ql

INPUTS:
       trange:        Time range for loading data.

KEYWORDS:
       FILENAME:      Full path and file name containing L0 MAG data.
                      Can be an array of file names.  Loading MAG data
                      from multiple files can take a long time.

       TOFF:          Time offset for MAG data.  This accounts for any
                      differences in MAG vs. SWEA timing.  Ideally, this
                      should be zero, once both decommutators are correct.
                      Use fit_pad_mag to empirically determine the offset.

       STS:           Read in MAG STS files generated by the MAG team.
                      Default is to use Davin's decommutator.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-12-11 16:20:52 -0800 (Thu, 11 Dec 2014) $
 $LastChangedRevision: 16465 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_getmag_ql.pro $

CREATED BY:    David L. Mitchell  03/18/14

(See projects/maven/swea/swe_getmag_ql.pro)


SWE_HSK_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_hsk_snap
PURPOSE:
  Plots housekeeping snapshots for times selected with the cursor in a tplot
  window.

USAGE:
  swe_hsk_snap, hsk=hsk

INPUTS:

KEYWORDS:

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 14:15:03 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16106 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_hsk_snap.pro $

CREATED BY:    David L. Mitchell  07-25-12

(See projects/maven/swea/swe_hsk_snap.pro)


SWE_MAXBOL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_maxbol
PURPOSE:
  Maxwell-Boltzmann distribution for fitting SWEA electron energy spectra.
  The reference frame is at the instrument aperture, after the electrons
  have been accelerated by the spacecraft potential.

  Correction for spacecraft potential, but no correction for bulk flow.

  Units are energy flux [eV/cm2-sec-ster-eV].

USAGE:
    eflux = swe_maxbol(E, par=p)

INPUTS:

    E:             Measured energy [eV].

KEYWORDS:

    PARAM:         Parameter structure.

                   p = {n    :    1.0d  , $   ; core density [cm-3]
                        T    :   10.0d  , $   ; core temperature [eV]
                        k_n  :    0.0d  , $   ; halo density [cm-3]
                        k_vh : 4000.0d  , $
                        k_k  :    5.0d  , $
                        pot  :    0.0d     }  ; spacecraft potential [V]

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-09-22 09:25:06 -0700 (Mon, 22 Sep 2014) $
 $LastChangedRevision: 15831 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_maxbol.pro $

CREATED BY:    David L. Mitchell  03-29-13
FILE: swe_maxbol.pro

(See projects/maven/swea/swe_maxbol.pro)


SWE_N_3D

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:	swe_n_3d(dat,EBINS=ebins,ABINS=abins,DBINS=dbins)
INPUT:	
	dat:	structure,	2d data structure filled mvn_swe_get3d
KEYWORDS
	EBINS:	bytarr(na),	optional, energy bins array for integration
					0,1=exclude,include, na = dat.nenergy
	ABINS:	bytarr(16),	optional, anode bins array for integration
					0,1=exclude,include
	DBINS:	bytarr(6),	optional, deflector bins array for integration
					0,1=exclude,include

   OBINS:  bytarr(96), optional, solid angle bins for integration
                   0,1=exclude,include
PURPOSE:
	Returns the density, n, 1/cm^3

CREATED BY:
	J.McFadden	95-7-27	
LAST MODIFICATION:
	96-7-6		J.McFadden	added more keywords
   14-7-6      D.Mitchell  redefined keywords, 
                           added correction for spacecraft potential

(See projects/maven/swea/swe_n_3d.pro)


SWE_PAD32HZ_UNPACK

[Previous Routine] [Next Routine] [List of Routines]
FUNCTION:   swe_pad32hz_unpack
PURPOSE:
  Expands a high time resolution PAD structure into 64 single-energy
  PAD structures, with appropriate timing, magnetic field data, and
  pitch angle mapping.

USAGE:
  pad32hz = swe_pad32hz_unpack(pad)

INPUTS:
       pad:          Array of 64-energy PAD structures with sweep
                     tables > 6.  (Tables <= 6 are ignored.)

OUTPUT:
       pad32Hz:      Array of single-energy PAD structures with
                     high time resolution.

KEYWORDS:
       none

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2019-03-15 12:34:08 -0700 (Fri, 15 Mar 2019) $
 $LastChangedRevision: 26802 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_pad32hz_unpack.pro $

CREATED BY:	David L. Mitchell  2019-03-01

(See projects/maven/swea/swe_pad32hz_unpack.pro)


SWE_PAD_SNAP

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_pad_snap
PURPOSE:
  Plots PAD snapshots in a separate window for times selected with the cursor in
  a tplot window.  Hold down the left mouse button and slide for a movie effect.
  A PAD snapshot is an pitch angle X energy spectrogram at the selected time.
  Optionally, keyword ENERGY can be used to plot a PAD in histogram mode for a 
  single energy.

USAGE:
  swe_pad_snap

INPUTS:

KEYWORDS:
       ENERGY:        Energy (eV) to use for the histogram plot.

       UNITS:         Plot PAD data in these units.

       PAD:           Named variable to hold a PAD structure at the last time
                      selected.

       DDD:           If set, compare with the nearest 3D spectrum.

       CENTER:        Specify the center azimuth for 3D plots.  Only works when DDD
                      is set.

       SUM:           If set, use cursor to specify time ranges for averaging.

       TSMO:          Smoothing interval, in seconds.  Default is no smoothing.

       SMO:           Number of energy bins to smooth over.

       NORM:          At each energy step, normalize the distribution to the mean.

       POT:           Overplot an estimate of the spacecraft potential.  Must run
                      mvn_scpot first.  Default = 1 (yes).

       SCP:           Temporarily override any other estimates of the spacecraft
                      potential and force it to be this value.

       SHIFTPOT:      Correct for the spacecraft potential.  If the data are in
                      instrument units (COUNTS, RATE, CRATE), then the energy
                      scale is shifted by the amount of the potential, but the 
                      signal level remains unchanged.  If the data are in physical
                      units (FLUX, EFLUX, DF), then the signal level is also
                      adjusted to ensure conservation of phase space density.

       LABEL:         Label the anode and deflection bin numbers (label=1) or the
                      solid angle bin numbers (label=2).

       KEEPWINS:      If set, then don't close the snapshot window(s) on exit.

       ARCHIVE:       If set, show snapshots of archive data.

       BURST:         Synonym for ARCHIVE.

       DIR:           If set, show some useful information with
                      respect to the observed vector magnetic field
                      in the MSO and LGEO(local geographic coordinate). 

       ABINS:         Anode bin mask -> 16 elements (0 = off, 1 = on)
                      Default = replicate(1,16)

       DBINS:         Deflector bin mask -> 6 elements (0 = off, 1 = on)
                      Default = replicate(1,6)

       OBINS:         3D solid angle bin mask -> 96 elements (0 = off, 1 = on)
                      Default = reform(ABINS # DBINS)

       MASK_SC:       Mask the spacecraft blockage.  This is in addition to any
                      masking defined by the ABINS, DBINS, and OBINS.
                      Default = 1 (yes).  Set this to 0 to disable and use the
                      above 3 keywords only.

       SPEC:          Plot energy spectra for parallel, anti-parallel, and
                      90-degree pitch angle populations.  The value of this 
                      keyword is the pitch angle width (deg) that is used
                      to separate the populations:

                        parallel      : 0 to SPEC degrees
                        middle        : SPEC to (180 - SPEC) degrees
                        anti-parallel : (180 - SPEC) to 180 degrees

                      Pitch angle bins must be entirely contained within
                      one of these ranges to be included.

                      Any value of SPEC < 30 deg is taken to be 30 deg.

        NOMID:        When using keyword SPEC, do not plot the energy spectrum
                      for the middle range of pitch angles.  Plot only the 
                      spectra for parallel and anti-parallel populations.

        PLOTLIMS:     Plot dashed lines at the limits of the pitch angle
                      coverage.

        PEP:          Plot vertical dashed lines at the nominal photoelectron
                      energy peaks at 23 and 27 eV (due to ionization of CO2
                      and O by 304-Angstrom He-II line).

        RESAMPLE:     Two independent pitch angle distributions are measured 
                      for each PAD data structure.  This keyword averages them
                      together and plots the result.

        UNCERTAINTY:  If set, show the relative uncertainty of the resampled PAD.

        ERROR_BARS:   Plot energy spectra with error bars.  Default = 1 (yes).

        MINCOUNTS:    Minumum number of counts for plotting.  Default = 10.

        MAXRERR:      Maximum relative error in resampled PADs.  Default = 10
                      (i.e., disabled).  Set this to some lower value (~1) to
                      filter out data with large relative errors.

        HIRES:        Use 32-Hz MAG data to map pitch angle with high time 
                      resolution within a 2-second SWEA measurement cycle.  A
                      separate pitch angle map is determined for each of the
                      64 energy steps.  You must first load 32-Hz MAG data for 
                      this keyword to be effective.  Please read warnings in 
                      mvn_swe_padmap_32Hz.pro.

        FBDATA:       Tplot variable name that contains the 32-Hz MAG data.
                      Default = 'mvn_B_full'.

        WINDOW:       Window number for the first snapshot window.  Additional 
                      snapshot windows are in numerical sequence.  If not set,
                      then all snapshot window numbers are generated automatically.

        ADIABATIC:    Calculate and display the adiabatic condition:

                        (1/B)*(dB/dx)*Rg << 1

                      which is the fractional change in the magnetic field over
                      one gyroradius.  Only works when HIRES is set.

        POPEN:        Set this to the name of a postscript file for output.
        
        INDSPEC:      To plot out the energy spectrum for each PA bins
        
        TWOPOT:       Set to a two-element array to allow shifting different
                      potentials on parallel and anti-parallel directions.
                        -> Assumes data are in EFLUX units.
                        -> Assumes SHIFTPOT is not set.

        XRANGE:       Override default horizontal axis range with this.

        YRANGE:       Override default vertical axis range with this.

        ZRANGE:       Override default color scale range with this.

        TRANGE:       Plot snapshot for this time range.  Can be in any
                      format accepted by time_double.  (This disables the
                      interactive time range selection.)

        WSCALE:       Scale all window sizes by this factor.  Default = 1.

        CSCALE:       Scale all characters by this factor.  Default = 1.

        NOTE:         Insert a text label.  Keep it short.
        
 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 12:21:06 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28842 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_pad_snap.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/swe_pad_snap.pro)


SWE_PAD_TIMING

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_pad_timing
PURPOSE:
  Disassembles A2 packets and sorts data in time sequence.

USAGE:
  swe_pad_timing

INPUTS:

KEYWORDS:
       TRANGE:       Time range for processing, in any format
                     accepted by time_double().

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-10-31 14:15:03 -0700 (Fri, 31 Oct 2014) $
 $LastChangedRevision: 16106 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_pad_timing.pro $

CREATED BY:    David L. Mitchell  06-25-13
FILE: swe_pad_timing.pro

(See projects/maven/swea/swe_pad_timing.pro)


SWE_PLOT_FHSK

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_plot_fhsk
PURPOSE:
  Makes tplot variables for SWEA fast housekeeping data (A6).

USAGE:
  swe_plot_fhsk

INPUTS:
       None:  All information is obtained from the common block.

KEYWORDS:
       PANS:          Returns the tplot variables created.

       TSPAN:         Include only fast housekeeping packets within this
                      time span.  This is different from the next keyword!

       TRANGE:        Returns a 2xN array of time ranges for the N 
                      tplot variables created.  This makes it easy to
                      zoom in to view each channel.  For example:

                        tplot, pans[i], trange=trange[*,i]

       TSHIFT:        If set, then for each housekeeping channel, shift
                      data from multiple sweeps to start at the time
                      of the first sweep.  This makes it easy to compare
                      multiple channels synchronized to the sweep.  In
                      this case, TRANGE will have just two elements.

       VNORM:         If set, normalize voltage housekeeping data to the
                      nominal value for each channel.  Temperatures and
                      voltages that do not have a nominal value are left
                      unchanged.

       AVG:           If set, average multiple sweeps for each channel.
                      Automatically sets TSHIFT.

       MODEL:         When any of the fast housekeeping channels are one
                      of the analyzer voltages (ANALV, DEF1V, DEF2V, V0V),
                      overlay the expected voltages.

       RESULT:        Named variable to hold structure of results.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-07-01 11:22:53 -0700 (Wed, 01 Jul 2020) $
 $LastChangedRevision: 28838 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_plot_fhsk.pro $

CREATED BY:    David L. Mitchell  2017-01-15

(See projects/maven/swea/swe_plot_fhsk.pro)


SWE_SHAPE_PAR_PAD_L2_3PA

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:
   swe_shape_par_pad_l2_3pa

PURPOSE:

   Calculate pitch angle resolved shape parameters for loaded SWEA L2
   PAD survey data for three PA ranges and create tplot variable "Shape_PAD"

AUTHOR:
   Shaosui Xu

CALLING SEQUENCE:

   If desire to correct for spacecraft potential, first run "mvn_swe_sc_pot"

INPUTS:

   none

KEYWORDS:

   BURST:    If set to 1, then use burst data to calculate the shape parameter,
             however, not tested yet

   SPEC:     A pitch angle in degrees given to average.
             PA [0,SPEC] & [(180-SPEC),180] for two directions.
             The default value is 30

   ERANGE:  Shape parameter calculated based on the spectrum within this energy
            range. The default values are [20,80] eV

   MIN_PAD_EFLUX: Minimum energy flux level.

   MAG_GEO: A MAG structure that contains magnetic elevation angle. If not given,
            The program will load MAG data in GEO coordinates.

   POT:     If set to 1, this program will correct the spacecraft potential for
            the electron energy spectrum.

   NSMO:    Number of spectra to average over before calculating shape parameter.
            Default = 1 (no smoothing).

   TSMO:    Boxcar smooth the PADs with this width (in seconds) before calculating
            the shape parameter.  This method is slower but handles data gaps and 
            changes in instrument mode.  Takes precedence over NSMO.

OUTPUTS:

   Tplot variable "Shape_PAD": store shape parameters for two directions, as well
       as the shape parameter for trapped population, spacecraft potentials,
       min/max pitch angle range to check if the PA coverage is enough

   Tplot variable "EFlux_ratio": store the flux ratio for two directions

 $LastChangedBy: xussui $
 $LastChangedDate: 2018-01-17 10:24:48 -0800 (Wed, 17 Jan 2018) $
 $LastChangedRevision: 24532 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_shape_par_pad_l2_3pa.pro $

CREATED BY:    Shaosui Xu  12-09-17

(See projects/maven/swea/swe_shape_par_pad_l2_3pa.pro)


SWE_SNAP_COMMON

[Previous Routine] [Next Routine] [List of Routines]
COMMON BLOCK:   swe_snap_common
PURPOSE:
  Common block for swe_snap_layout.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-08-03 16:50:48 -0700 (Mon, 03 Aug 2020) $
 $LastChangedRevision: 28981 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_snap_common.pro $

CREATED BY:    David L. Mitchell

(See projects/maven/swea/swe_snap_common.pro)


SWE_SNAP_LAYOUT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_snap_layout
PURPOSE:
  Puts snapshot windows in convenient, non-overlapping locations, 
  depending on display hardware.  These layouts are only recognized
  by the SWEA snapshot routines.  This routine has no effect unless
  a non-zero layout is specified, and you can only do that by calling
  this routine.  It is perfectly safe to simply ignore the existence 
  of this routine.  It is admittedly only useful to the author.

  See putwin.pro for details on how the configuration structures are
  used to create and place windows.

USAGE:
  swe_snap_layout, layout

INPUTS:
       layout:        Integer specifying the layout:

                        0 --> Default.  No fixed window positions.
                        1 --> Macbook 1440x900 (below) with Dell 5120x1440 (above)
                        2 --> Macbook 1440x900 (below) with twin Dell 2560x1440 (left, right)
                        3 --> Macbook 1440x900 (below) with Dell 2560x1440 (above)

KEYWORDS:

       HOME:          Equivalent to LAYOUT=3.

       WORK:          Equivalent to LAYOUT=2.

       WORK2:         Equivalent to LAYOUT=1.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-08-03 16:50:17 -0700 (Mon, 03 Aug 2020) $
 $LastChangedRevision: 28980 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_snap_layout.pro $

CREATED BY:    David L. Mitchell  07-24-12

(See projects/maven/swea/swe_snap_layout.pro)


SWE_TESTPULSER_MODEL

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   swe_testpulser_model
PURPOSE:
  Creates SWEA Test Pulser Model and generates test pulser signatures
  in the three main data products (APID's A0, A2, A4).  The model is
  an analytic approximation to the measured test pulser signal.

USAGE:
  swe_testpulser_model

INPUTS:

KEYWORDS:

       GROUP:        Group parameter (g) that controls energy bin
                     averaging for A0 and A2 products.  Does not
                     affect A4.

                     g = 0,1,2 corresponds to averaging 1, 2, or 4 
                     adjacent energy channels.

       PAM:          Pitch angle map structure specifying the anode and deflector
                     bins comprising the PAD.  0 < andx < 15 ; 0 < dndx < 5.

                       pam = {andx:intarr(16), dndx:intarr(16)}

       RESULT:       Structure to hold A0, A2, and A4 test pulser
                     models.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2014-04-07 20:05:19 -0700 (Mon, 07 Apr 2014) $
 $LastChangedRevision: 14775 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/swe_testpulser_model.pro $

CREATED BY:    David L. Mitchell  05-28-13
FILE: swe_testpulser_model.pro
VERSION:   1.0

(See projects/maven/swea/swe_testpulser_model.pro)


TIMEFIT

[Previous Routine] [Next Routine] [List of Routines]
PROCEDURE:   timefit
PURPOSE:
  Given an input time array or tplot variable name, sets the tplot time window to span
  the range of times in the array or tplot variable.

USAGE:
  timefit, time, var=var

INPUTS:
       time:      If this is a scalar string or integer, it's interpreted as
                  a tplot variable name or number, from which the time is
                  extracted.  If this is an array, it's interpreted as an
                  array of times, in any format accepted by time_double().

                  If all the times are identical and if keyword PAD
                  is not set, then a one hour interval centered on
                  that time is set.

KEYWORDS:

       VAR:       Tplot variable name/number.  OBSOLETE, but retained for 
                  backward compatibility.  If VAR is set, then time input
                  is ignored.

       PAD:       Amount of time to pad on either end of the time
                  span.  Default units are seconds.

       MIN:       PAD units are minutes.

       HOUR:      PAD units are hours.

       DAY:       PAD units are days.

 $LastChangedBy: dmitchell $
 $LastChangedDate: 2020-08-03 16:49:25 -0700 (Mon, 03 Aug 2020) $
 $LastChangedRevision: 28979 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/timefit.pro $

CREATED BY:	David L. Mitchell  07-06-14

(See projects/maven/swea/timefit.pro)


TOPOMTRX

[Previous Routine] [List of Routines]
PROCEDURE:   topomtrx

PURPOSE: This routine provides topology matrix or a table of topology 
         for 6 given dimensions, defined by shape parameters, voids,
         and PAD info, which are:
                  0 - upward shape: 0: phe, 1: swe, 2:nan
                  1 - downward shape: 0: phe, 1: swe, 2:nan
                  2 - void: 0: yes, 1: no, 2:nan 
                  3 - upward PAD: 0: not loss cone, 1: loss cone, 2:nan 
                  4 - downward PAD: 0: not loss cone, 1: loss cone, 2:nan 
                  5 - day/night: currently not used
         8 topology results are provided:
                  0 Unknown
                  1 Dayside Closed
                  2 Day-Night Closed
                  3 Night Closed -- Trapped/two-sided loss cone
                  4 Night CLosed -- Void
                  5 Day Open
                  6 Night Open
                  7 Draped

USAGE:
  result = topomtrx()

INPUTS:
       None

KEYWORDS:
       None
                      
 $LastChangedBy: xussui $
 $LastChangedDate: 2018-11-29 15:53:18 -0800 (Thu, 29 Nov 2018) $
 $LastChangedRevision: 26186 $
 $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/tags/spedas_4_0/projects/maven/swea/topomtrx.pro $

CREATED BY:    Shaosui Xu, 11/03/2017
FILE: topomtrx.pro

(See projects/maven/swea/topomtrx.pro)