The routines described in this help file are accessible by adding the
following directories in your IDL !PATH system variable:

  /home/sylvain/idl/lib.v6/color     color map handling
  /home/sylvain/idl/lib.v6/math      math functions
  /home/sylvain/idl/lib.v6/misc      misceleanous
  /home/sylvain/idl/lib.v6/plot      plotting stuff
  /home/sylvain/idl/lib.v6/widgets   widget stuff
  /home/sylvain/idl/lib.v6/io        io stuff (byte order indep)
  /home/sylvain/idl/lib.v6/jobctl    job control
  /home/sylvain/idl/lib.v6/obsolete  backward compatible functions & routines

i.e.:

IDL> libDir  = '/home/sylvain/idl/lib.v6/'
IDL> !PATH = libDir+'io:'       + $
             libDir+'color:'    + $
             libDir+'math:'     + $
             libDir+'misc:'     + $
             libDir+'plot:'     + $
             libDir+'widgets:'  + $
             libDir+'jobct:'    + $
             libDir+'obsolete:' + !PATH

Note that the documentation for some routines is quite terse.

 
*** io ***
 
 cvtByteOrder    - equiv to swap_endian
 OPENR_          - openr, /SWAP_IF_LITTLE_ENDIAN
 OPENU_          - openu, /SWAP_IF_LITTLE_ENDIAN
 OPENW_          - openw, /SWAP_IF_LITTLE_ENDIAN
 SGK_PICKFILE    - return a picked file 
 
*** color ***
 
 NOBPTT          -  do NOT bypass translation table
 PC8             - Set device, pseudo_color = 8
 PICKCOLOR       - help pick a color, using HSV model (best w/ 24 bit disp)
 PLCT            - Load a `plotting' color map (16 predefined colors)
 SGKLCT          - Load a color table, using SGK's format
 SGKLCT          - Load a color table, using SGK's format
 TC24            - Set device, true_color = 24
 UDC             - use decomposed color model for  24 bit dispays
 XSGKLCT         - GUI interface to SGKLCT
 XSGKLCT         - GUI to SGKLCT
 
*** math ***
 
 CMP_AVG         - computes average of argument
 CMP_CC          - compute cross-correlation
 CMP_COVAR       - compute covariance from Hessian matrix (use num. der.)
 CMP_COVAR_A     - compute covariance from Hessian matrix (analytical)
 CMP_RMS         - computes root-mean-squares of argument
 CMP_WAVG        - computes weighted average of arguments
 DLSQ_FIT        - perform non linear least-square fit
 FCC             - compute cross-correlation using FFT
 LZ              - Lorentzian((x-x0)/w)
 FCN             - c(0)*lz(x, c(1), c(2)) + c(3)
 DLZ             - 1st derivative wrt kth param of lz()
 DFCN            - 1st derivative wrt kth param of fcn()
 D2FCN           - 2nd derivative wrt kth & kkth param of fcn()
 FRSTDER         - computes the 1st derivative
 FSMOOTH         - frequency smoothing, over `n' pixels
 FSMOOTH2D       - 2d frequency smoothing, over `n' pixels
 GEN_POLY        - Generalized Polynomial Computation
 getFWHM         - computes FWHM of y(x)
 GETMAX          - compute the maximum, using parabolic fit
 INTERP_1D       - 1D linear interpolation
 INTERP_2D       - 2D bi-cubic interpolation
 LGFIT           - Fit a Legendre polynomial expansion
 LGPOLY          - evaluate Legendre polynomial expansion
 LINFIT          - perform a linear fit
 LSQ             - perform a Least-Squares fit
 POLY2D          - estimate a 2D polynomial
 POLY_SOLVE      - solve for x the polynomial expansion Sum_i Pi(x) = y
 POLYFIT         - perform a polynomial fit, include x-sigma rejection
 POLYFIT2D       - perform a 2D polynomial fit, include x-sigma rejection
 POLYX           -  evaluates extended polynomial
 QEQROOTS        - solve quadratic equation  a x^2 + b x + c
 SANMBA          - simulated annealing amoeba minimization
 SCNDER          - computes second derivative
 SVDINVERT       - invert matrix using single value decomposition 
 TZ_INTEGRATE    - trapeze rule integration
 TZ_INTEGRATE2D  - 2D trapeze rule integration
 XBIN            - bin a data set xybin = xbin(x,y,n)
 XSMOOTH         - smoothing up to the edges
 ZBIN2D          - bin a data set zbin = zbin2d(x,y,z,nx,ny)
 
*** misc ***
 
 @ADD-ALL-ASTRON-LIBS - add ALL pro/* for astron lib
 addal           - add ASTRON lib to the path
 ADDSLASH        - add a slash (/) to end of a string, unless ...
 CTRL            - return control char
 cvt_d2HMS       - return 'HH:MM:SS.SS' string of a value
 cvt_HMS2D       - return double value of a 'HH:MM:SS' string
 cvt_jd2t        - return 'YYYY.MM.DD_HH:MM:SS_UT' string for JD
 cvt_s2hms       - return 'HH:MM:SS.SSS' or '+D:HH:MM' string for s
 cvt_s2t         - return 'YYYY.MM.DD_HH:MM:SS' string for seconds
 cvt_T2JD        - convert 'YYYY.MM.DD_HH:MM:SS' string to JD
 DEG2RAD           - convert degree to radians
 EPLAPSED        - measured elapsed time since last call to ELAPSED
 FILEEXIST       - check if a file exists
 FLIP            - flip an array
 FTOA            - return string(f), using fixed formating rule
 GETVAL          - extract the value of a string in the form 'key: value'
 IMAg            - return imaginary part of value
 ISAPEAK         - return list of peaks
 ISDOUBLE        - return 1 if argument is of type DOUBLE
 ISLONG          - return 1 if argument is of type LONG
 ISSTRING        - return 1 if argument is of type STRING
 ISSTRUC         - return 1 if argument is of type STRUCTURE
 ITOA            - return  strcat(string(round(i), format='(i0)'), sep)
 NEEDSWAP        - check OS byte order
 NLAST           - n_elements()-1
 NLINES          - return the no of lines in a file
 @NO-WARNINGS    - turn off all warnings
 OLH             - wrapper to widget_olh
 PAUSE           - pause until a CR is pressed
 PCURSOR         - print the current value of the cursor
 PLOT_CLOCK      - plot the time as a clock
 PTELL           - print a number to tell progress of a computation
 RAD2DEG           - convert radians to degrees
 RAMP            - return a ramp of N values for a given range
 RCALL           - return & close,/all
 READ_RDB        - read a RDB table, ie tab separated
 READ_STRUCT     - read a struct array from a flat ASCII table
 READ_TABLE      - read a flat ASCII table
 REAL            - return real part of value
 REWIND, lu      - point_lun, lu, 0
 RHIST           - [cumul] histogram w/ range
 STRCAP          - capitalize arg
 STRCAT          - catenate string array in one string w/ given separator
 STRSEP          - calls strsplit(string, separator, /extract)
 WRITE_MGIFS     - hacked version of write_gif, w/ LOOP keyword
 WRITE_RDB       - write a RDB table, ie tab separated
 WRITE_STRUCT    - write a struct array as a flat ASCII table
 
*** plot ***
 
 AUTO_RANGE      - return a padded plotting range
 bMenu           - button selection menu
 BWIN            - wrapper around window to open a big window
 COLBAR          - Add a color bar to a plot
 DEMO_MODE       - Returns true if IDL is in Demo Mode.
 EB_PLOT         - overplot error-bars
 @EPS-PRINT      - print the postscript plot
 @EPS-PRINT-C    - print the postscript plot
 @EPS-PRINT-C    - print the postscript plot
 EPSCLOSE        - call ps_close for EPS files (noprint, noid)
 EPSOPEN         - call ps_open for EPS files
 FSDSP           - Scaled display of a 2D array in a FITS file
 GET_CPOS        - get the cursor postion
 GV              - run cmd=ghostview on plot file
 HHASH           - plot hashes in the given yRange
 hist_oplot      - oplot histogram using polyfill
 HLINE           - overplot an horizontal line
 IDENTIFY        - identify points on a plot
 LABEL           - LaTeX alike string parser for labeling
 MAKE_LEGEND     - put a legend on a plot
 MAKE_USERSYM    - create the user symbol of given name
 PLOT3D          - 3d point plot
 plot_vs_date    - wrapper to plot, t, y, to labe x-axis as time/date spec
 @PS-PRINT-C     - print the postscript plot
 @PS-PRINT-CP    - print the postscript plot: color & portrait
 @PS-PRINT-GV    - print the postscript plot
 @PS-PRINT-P     - print the postscript plot, portrait mode
 @PS-PRINT-Q     - queue the postscript plot to be printed
 @PS-PRINT       - print the postscript plot
 PS_CLOSE        - Close the PostScript plotting device opened with PS_Open
 PS_OPEN         - Set the plotting device to be PostScript
 PS_OPTS         - Set options for plotting device if set to be PostScript
 PUT_ID          - Put an ID (time stamp, user, & hostname) on a plot
 RELSCALE        - Relative scaling, convert relative unit to data unit
 RXYOUTS         - "Relative" version of xyouts
 SDSP            - Scaled display of a 2D array (ie image)
 SDSPOS          - position equiv to sdsp, when using !p.multi
 setRelPos       - set relpos parameters for getrelpos()
 SHOW3D          - displays volumetric data using cuts
 SHOW_FONT       - Show all the characters in a given font
 SPOSITION       - Return dev. pos. for proper scaling of plots on images
 SQUARE_PLOT     - Restrict the plotting area to a relative square position
 STV             - Performs a "scaled" TV, see SWINDOW
 STVSCL          - Performs a "scaled" TVSCL, see SWINDOW
 SWINDOW         - Open a "scaled" window, w/ proper scaling whether X or PS
 SXYOUTS         - "scaled" version of XYOUTS, see SWINDOW
 VEC2D           - Plot 2D vector
 VEC3D           - Make a 3d vector plot
 VECOL2D         - Plot 2D vector, using color coding
 VHASH           - plot hashes in the given xRange
 VLINE           - overplot a vertical line
 XBOPLOT         - over-plot binned values
 XFONTSEL        - Select an X font
 XGetScreenSize  - return the screen(s) size (using xdpyinfo)
 XPLOT_IO        - Log plot x vs y, works when y is not always positive
 XYLABEL         - wrapper to xyouts, x, y, label(string), but add /rel
 ZOOM            - Zoom an array by factor(s) n1, [n2]
 ZOOMTO          - Zoom an array to be N1 x N2
 
*** widgets ***
 
 getIDsFromCheckList - get widget IDs from checkList (see topMBW)
 PlayAnyMovie    - Play movie from list of any images.
 PlayPPMMovie    - Play movie from list of PPM images.
 PlayPPMMovie    - Play movie from list of PPM images.
 setIDsFromCheckList - (re)set check marks from checkList (see topMBW)
 SHOWPERCENT     - Creates a widget to indicate fraction completed
 TOPMBW          - Creates a top level base widget w/ menu bar
 XBLINK          - blink two images
 XWDEL           - wdel for xwin
 XWIN            - widget wrapper around window to open a big window
 XWSET           - wset for xwin

; add-all-astron-libs
;
;   @add-all-astron-libs: add ALL pro/* for astron lib

; add ASTRON lib to the path

;  dir = addSlash(dir, notAfter = notAfter)
;
;  add a '/' to the end of dir, unless dir == '', or there is already one
;  notAfter: if given, won't add a '/' if last char is char in notAfter
;
; <- Last updated: Thu Mar  9 19:49:35 2006 -> SGK

; xrange = auto_range(x)
;
; compute the plotting range for x, adding some extra padding factor
;
; Input Keyword:
;
;   factor = additional padding factor,                             def. 0.05
;   ylog   = set when estimating limits for /ylog plot
;
; returns [x1,x2], where : 
;
;   x1 = min(x) - pad
;   x2 = max(x) + pad
;
; where pad = f*(max(x)-min(x)) 
; or    pad = f*(min(x)) if min = max
;
; <- Last updated: Mon Nov 22 15:58:05 2010 -> SGK

; iChoice = bMenu(menu)
;
; draws a set of boxes and wait for button to be pressed for a selection
; returns the menu array index selected
;
; Input:
;
;   menu - a string array
;
; Input keywords:
;
;   nRow      no of rows to use                                (def.: 1)
;   xFactor   x-scaling factor, positive or negative           (def.: 1)
;   yFactor   y-                                               (def.: 1)
;   wno       window no to use, set to  -1 to use current window
;   xSize     window xSize (unless wno = -1)                   (def.: 900)
;   ySize            ySize                                     (def.: 300*nRow)
;   noErase   flag, if set do not erase current plot
;   cSize     character size                                   (def.: 1.5)
;
; Ouput keyword:
;
;   button - which button was pressed (!mouse.button)
;
; <- Last updated: Thu Oct  4 18:21:51 2001 -> SGK

; bwin, [wno]: 
;
; wrapper around window to open a 1100x920 (or 900x850) 'big' window.
;  depending on display screen size.
;
; additional input keywords:
;
;  fScr      - fraction of screen to cover (def: .85)
;  wide      - set width only  for a 'wide' window
;  tall      - set height only for a 'tall' window
;  landscape - set size to 1000 x  750 (11"x8.5" - 1"x1" @ 10pxl/inch)
;  portrait  - set size to  750 x 1000 
;  square    - set size to 
;  pc8       - call pc8 (set visual to 8bit pseudocolor)
;  udc       - call UDC (use decomposed color model)
;  plct      - call plct (set color map to 16 basic color), imply pc8
;  csz       - set !p.charsize = csz
;  _EXTRA    - passed to window
;
; <- Last updated: Thu Nov 14 11:00:47 2013 -> SGK

; Name:
;             Cmp_Avg
;
; Purpose:
;           computes average of argument: Cmp_Avg(x) = total(x)/n_elements(x) 
;
; Calling Sequence:
;          avg = Cmp_Avg(x)
;
; Keywords:
;
;   nrej: if set, will perform an RMS rejection NREJ times
;   xrej: rejection factor, default 3.0
;   rms:  return the RMS of the pts included
;   mRMS: computes the RMS of the mean (extra sqrt(cnt))
;   idx:  indices of pts included
;   cnt:  no of points included
;
;   includes only finite() values when nRej set

; cc = cmp_cc(s1, s2)
;   compute cross-correlation of {s1-,s2-} using FFT
;   shift result by n/2, and return abs(CC)
; BTW:
;   nc = n_elements(cc)
;   xc = (findgen(nc)-nc/2)/ovsf
;
; Optional Input:
;
;  ovsf:  oversampling factor
;  noabs: if set, return the float(CC) not the abs(CC)
;
; @(#)cmp_cc.pro	1.2 96/07/03 16:38:05 SGK

; covar = cmp_covar(p, nfree)
;
; compute the covariance using the Hessian matrix, and a numerical estimate of
; the 2nd derivative of the merit function FMERIT(p)
;
; keywords:
;   var: return variance
;   eps: relative change to use to compute derivatives (scalar or array)
;        select it carefully!
;   best_eps: if set, will try to guess the best 'eps'
;             from the given starting eps
;   hmat: return the Hessian matrix
;   debug: if set, will print stuff, and stop inside routine
;
; uses numerical derivatives
;
; if NFREE == 0 indicates maximum likelyhood
;    NFREE = n_elements(c) otherwise
;
; <- Last updated: Wed Sep  9 11:59:34 1998 -> SGK
;                  

; covar = cmp_covar_a(x, y, c, nfree)
;
; compute the covariance using the Hessian matrix, and analytical expressions
; of the derivatives, for the DLSQ problem y = fcn(x, c)
;
; keywords:
;   weigths: weigths associated to (x,y) == 1/sigma
;            (as for obsolete cmp_covar_aw)
;   var: return variance
;   hmat: return the Hessian matrix
;   no2d: don't include 2nd deriv terms
;   debug: if set, will print stuff, and stop inside routine
;
; calls dfcn(x, c, k) and d2fcn(x, c, k, kk), for 1st and 2nd derivatives
;
; if NFREE == 0 indicates maximum likelyhood, use
; NFREE = n_elements(c) otherwise
;
; <- Last updated: Fri Dec  4 16:51:48 1998 -> SGK
;                  

; Name:
;             Cmp_Rms
;
; Purpose:
;           computes root-mean-squares of argument:
;             Cmp_Rms(x) = sqrt( total(x^2)/n_elements(x) )
;
; Calling Sequence:
;          rms = Cmp_RMS(x)
;
; Keyword:
; 
;   ZERO_AVERAGED - if set, returns the rms of the argument minus its average;
;     and its average in the variable equated to the keyword AVERAGE
;     i.e.: Cmp_Rms(x) = sqrt(total((x-Cmp_Avg(x))^2)/n_elements(x))
;
;   STD_DEV - if set, normalizes by n_elements(x)-1, not n_elements(x)

; Name:
;             Cmp_WAvg
;
; Purpose:
;           computes weighted average of arguments:
;   Cmp_WAvg(x) = total(x*w)/total(w)
;
; Calling Sequence:
;          avg = Cmp_Avg(x, w)
;
; Keywords:
;
;   nrej: if set, will perform an RMS rejection NREJ times
;   xrej: rejection factor, default 3.0
;   rms:  return the RMS of the pts included
;   mRMS: computes the RMS of the mean (extra sqrt(cnt))
;   idx:  indices of pts included
;   cnt:  no of points included

; colbar, xp, yp, range, $
;   nwidth = nwidth, $
;   nheight = nheight, 
;   horizonthal = horizonthal,
;   title = title
;
; add a colbar on a plot at position [xp, yp], with given range
;
; def.: vertical with nwidth = 16, nheight = 128
;

; c = ctrl('M')
;
;   return ctlr-M
;
; <- Last updated: Fri Jan 21 17:42:38 2000   -> SGK

; identical to swap_endian

;  str = cvt_d2HMS(value)
;
;  convert a decimal value to HH:MM:SS.SS
;
; input keywords:
;
;   second - input is in seconds
;   signed - output must be signed
;   nsd = nsd - no of decimal places for seconds - def :0.
;   space  - flag, if set, use spaces as separator, not ':'
;

; gmNo   = cvt_gm('1995.05.24')
; string = cvt_gm(1)
;
; convert to/from gong month number, 
; 36d long, #1 is 1995.05.24: middle or +17, unless /start

;  s = cvt_HMS2D('HH:MM:SS')
;
;  convert a HH:MM:SS or MM:SS string to its numerical value [in seconds]
;
; input keywords:
;
;  second - flag, if set return value inseconds
;  space  - flag, if set, use spaces as separator, not ':'
; 

;  d = cvt_jd2t(JD)
;
;  convert a julian date to YYYY.MM.DD_HH:MM:SS_UT
;
; input:
;
;   JD: julian date
;
; input keywords:
;
;   MDI   - JD is MDI mission number (JD-2448988.5D0 or 1993.01.01_00:00:00)
;   MJD   - JD is modified JD number (JD-2450000.5D0 or 1995.10.10_00:00:00)
;   DSS   - seconds returned as SS.S for dss = 1, SS.SS for dss=2, etc...
;   no_UT - don't add _UT
;   compact - return YYYYMMDD_HHMMSS
;   ymd     - return YYYYMMDD
;
; <- Last updated: Sat Dec  7 12:18:45 2013 -> SGK

; dayNo  = cvt_mdi('2001.02.04')
; string = cvt_mdi(2956)

; yr  = cvt_mdi2yr(2956)
; yr  = cvt_mdi2yr('2001.02.04')

;  str = cvt_s2tms(s)
;
;  convert seconds to HH:MM:SS.SSS or +D:HH:MM
;
; input:
;
;   s: seconds
;
; <- Last updated: Wed Dec  3 10:30:20 2014 -> SGK

;  str = cvt_s2t(s)
;
;  convert seconds since 1970-01-01 00:00:00 UTC to date YYYY.MM.DD_HH:MM:SS[_UT]
;
; input keywords:
;
;  UT           - return UT
;  TZ = x       - time zone offset, in hours
;  DST          - daylight saving time
;  timeRef = str  - s is elapsed sec since that time
;
; <- Last updated: Wed Dec  3 10:41:48 2014 -> SGK

;  s = cvt_t2jd('YYYY.MM.DD_HH:MM:SS')
;
;  convert a YYYY.MM.DD_HH:MM:SS to its numerical value [JD]
;
;     msep = '_'
;     dsep = '/'
;     tsep = ':'
;
;    /iraf' for yyyy-mm-ddThh:mm:ss 
;
;     msep = 'T'
;     dsep = '-'
;     tsep = ':'
;
; input keywords:
;
;   MDI  - JD is MDI mission number (JD-2448988.5D0 or 1993.01.01_00:00:00) 
;   MJD  - JD is modified JD number (JD-2450000.5D0 or 1995.10.10_00:00:00)
;   COMPACT - input is 'YYYYMMDD_HHMMSS' or  'YYYYMMDD'
;
; <- Last updated: Fri Dec 13 10:04:27 2013 -> SGK

; NAME:
;	CWX_ANIMATE
;
; PURPOSE:
;	This widget displays an animated sequence of images using
;	X-windows Pixmaps. This is a compound widget, based on the
;	XINTERANIMATE procedure, with the following advantages:
;		- It can be included in other applications.
;		- Multiple copies can be run simultaneously.
;
;	The speed and direction of the display can be adjusted using
;	the widget interface.
;
; CATEGORY:
;	Image display, compound widgets.
;
; CALLING SEQUENCE:
;	To initially create:
;		widget = CWX_ANIMATE(PARENT, SIZEX, SIZEY, NFRAMES)
;
;	To reinitialize when another animation is loaded:
;		CWX_ANIMATE_INIT, ANIMATEBASE, SIZEX, SIZEY, NFRAMES
;
;	To load a single image:
;		CWX_ANIMATE_LOAD, WIDGET, IMAGE = IMAGE, FRAME = FRAME_INDEX
;
;	To load a single image that is already displayed in an existing window:
;
;		CWX_ANIMATE_LOAD, WIDGET, FRAME = FRAME_INDEX, $
;			WINDOW = [WINDOW_NUMBER [, X0, Y0, SX, SY]]
;
;	(This technique is much faster than reading back from the window.)
;
;	To display the animation after all the images have been loaded:
;
;		CWX_ANIMATE, WIDGET [, RATE]
;
;	To get a copy of the vector of Pixmaps being used by the widget.
;	If this routine is called, the widget does not destroy the pixmaps
;	when it is destroyed. The user can then provide them to a later
;	call to CWX_ANIMATE to re-use them while skipping the Pixmap creation
;	and rendering step:
;
;		CWX_ANIMATE_GETP, widget, PIXMAPS
;
; INPUTS:
;   CWX_ANIMATE:
;		PARENT:	 The ID of the parent widget.
;		SIZEX:	 The width of the displayed image.
;		SIZEY:	 The height of the displayed image.
;		NFRAMES: The number of frames in the animation sequence.
;
;   CWX_ANIMATE_INIT:
;		ANIMATEBASE: The ID of the base animation widget.
;		SIZEX:	 The width of the displayed image.
;		SIZEY:	 The height of the displayed image.
;		NFRAMES: The number of frames in the animation sequence.
;
;  	CWX_ANIMATE_LOAD:
;		WIDGET:	 The ID of the widget (as created with CWX_ANIMATE)
;			 into which the image should be loaded.
;
;   CWX_ANIMATE_RUN:
;		WIDGET:	 The ID of the widget (as created with CWX_ANIMATE)
;			 into which the image should be loaded.
;		RATE:	 A value between 0 and 100 that represents the
;			 speed of the animation as a percentage of the
;			 maximum display rate. The fastest animation has
;			 a value of 100 and the slowest  has a value of 0.
;			 The default animation rate is 100.
;       STOP:    If this keyword is set, the animation is stopped.
;       NFRAMES: Specifies the number of frames to animate, must
;                        <= the number specified in CWX_ANIMATE().
;
; KEYWORD PARAMETERS:
;   	CWX_ANIMATE:
;		PIXMAPS: This keyword provides the new widget with a vector
;			 of pre-existing pixmap (off screen window) IDs.
;			 This vector is usually obtained from a call to
;			 CWX_ANIMATE_GETP applied to a previous animation
;			 widget.
;		UVALUE:  A user supplied value to be stored in the widget's
;			 user value field.
;               UNAME:   A user supplied string name to be stored in the
;                        widget's user name field.
;               NO_KILL: If NOT set, an "End Animation" button is added to the
;			 animation base.  If set the button is not added.
;		OPEN_FUNC: A user supplied string that specifies a callback
;			 function name. When a value is specified for this
;			 keyword, an "Open..." pushbutton is added to the
;			 window.  When the "Open..." pushbutton is clicked
;			 the OPEN_FUNC function is called to load new
;			 animation data.
;		INFO_FILE: A filename containing text to be displayed by
;                        XDISPLAYFILE when user selects the help button.
;
;   	CWX_ANIMATE_INIT:
;		PIXMAPS: This keyword provides the new widget with a vector
;			 of pre-existing pixmap (off screen window) IDs.
;			 This vector is usually obtained from a call to
;			 CWX_ANIMATE_GETP applied to a previous animation
;			 widget.
;
;   	CWX_ANIMATE_LOAD:
;		CYCLE:   If set, cycle. Normally, frames are displayed
;			 going either forward or backwards. If CYCLE is
;			 set, reverse direction after the last frame in
;			 either direction is displayed.
;		FRAME: 	 The frame number to be loaded. This is a value
;			 between 0 and NFRAMES. If not supplied, frame 0
;		  	 is loaded.
;		IMAGE:   The image to be loaded.
;		ORDER:   Set this keyword to display images from the top
;			 down instead of the default bottom up. This keyword
;			 is only used when loading images with the IMAGE
;			 keyword.
;		TRACK:   If set, the frame slider tracks the current frame.
;			 Default is not to track.
;		WINDOW:  When this keyword is specified, an image is copied
;			 from an existing window to the animation pixmap.
;			 When using X windows, this technique is much faster
;			 than reading from the display and then loading with
;			 the IMAGE keyword.
;
;			 The value of this parameter is either an IDL window
;			 number (in which case the entire window is copied),
;			 or a vector containing the window index and the
;			 rectangular bounds of the area to be copied. For
;			 example:
;			 WINDOW = [Window_Number, X0, Y0, Sx, Sy]
;
;      		XOFFSET: The horizontal offset, in pixels from the left of
;			 the frame, of the image in the destination window.
;
;      		YOFFSET: The vertical offset, in pixels from the bottom of
;			 the frame, of the image in the destination window.
;
; OUTPUTS:
;	No explicit outputs.
;
; SIDE EFFECTS:
;	If the widget is realized before calls to CWX_ANIMATE_LOAD, the frames
;	are displayed as they are loaded. This provides the user with an
;	indication of how things are progressing.
;
;	When the widget is destroyed, it destroys the pixmaps used in the
;	animation, unless they were previously obtained via CWX_ANIMATE_GETP
;       and the KILL_ANYWAY keyword was not set.
;
;	The only event returned by this widget indicates that the user
;	has pressed the DONE button. The parent application should use
;	this as a signal to kill the animation widget via WIDGET_CONTROL.
;
; RESTRICTIONS:
;	If more than one animation widget is running at a time, they
;	will fight for resources and run slower.
;
; PROCEDURE:
;	When initialized, this procedure creates pixmaps containing the
;	frames of the animation sequence. Once the images are loaded,
;	they are displayed by copying the images from the pixmap or buffer
;	to the visible draw widget.
;
; EXAMPLE:
;	Assume the following event handler procedure exists:
;		PRO EHANDLER, EV
;		  WIDGET_CONTROL, /DESTROY, EV.TOP
;		end
;
;	Enter the following commands to open the file ABNORM.DAT (a series
;	of images of a human heart) and load the images it contains into
;	an array H:
;
;		OPENR, 1, FILEPATH('abnorm.dat', SUBDIR = 'images')
;		H = BYTARR(64, 64, 16)
;		READU, 1, H
;		CLOSE, 1
;		H = REBIN(H, 128, 128, 16)
;
;	Create an instance of the animation widget at load the frames:
;
;		base = widget_base()
;		animate = CWX_ANIMATE(base, 128, 128, 16)
;		WIDGET_CONTROL, /REALIZE, base
;		for i=0,15 do CWX_ANIMATE_LOAD, animate, FRAME=i, IMAGE=H[*,*,I]
;
;	Start the animation:
;
;		CWX_ANIMATE_RUN, animate
;		XMANAGER, "CWX_ANIMATE Demo", base, EVENT_HANDLER = "EHANDLER"
;
;	Pressing the DONE button kills the application.
;
; MODIFICATION HISTORY:
;	AB, June 1992		Heavily based on the XINTERANIMATE procedure.
;	SR, September 1992	Fixed a problem when a paused animation's
;				frame selection was moved and the resulting
;				frame change ended up in another animation.
;	SR, November  1992	Fixed a problem when a single paused animation
;				would fail when the frame selection slider
;				event tried to set do a bad drawing window.
;	DMS/AB, March, 1993	Got rid of state caching. Got rid of
;				XMANAGER background tasks in favor of new
;				"WIDGET_CONTROL,timer=" feature.
;	ACY, October 1993	Set RETAIN=2 for draw widget to prevent
;				clipping by an overlapping window when
;				loading frames.
;   DMS, Dec, 1993   Added STOP and NFRAMES keywords to CWX_ANIMATE_RUN.
;                    Added KILL_ANYWAY keyword to CWX_ANIMATE_GETP.
;   WSO, Jan, 1995   Added OPEN_FUNC keyword and updated UI.
;   ACY, Jan, 1997   Added INFO_FILE keyword to allow user-supplied
;                    files for help text
;   JLP, Jan, 2000   Allow TrueColor images as input to CWX_ANIMATE_LOAD.

;  deg2rad(radians)

; NAME:
;	DEMO_MODE
;
; PURPOSE:
;	Returns true if IDL is in Demo Mode.
;
; CALLING SEQUENCE:
;	Result = DEMO_MODE()
;
; OUTPUTS:
;	Returns 1 if IDL is in Demo Mode and 0 otherwise.
;
; SIDE EFFECTS:
;	Does a FLUSH, -1.
;
; PROCEDURE:
;	Do a FLUSH, -1 and trap the error message.
;
; MODIFICATION HISTORY:
;	Written by SMR, Research Systems, Inc.	Feb. 1991
;	KDB Oct,1993: The error string had an extra ' ' in it and 
;		      the function would always return 0. 

; Name:
;           dlsq_fit
; Purpose:
;           perform non linear least-square fit to
;               Y = FCN(X, C)
;
; Calling Sequence:
;          niter = dlsq_fit(x, y, c, eps, niterx)
; Keywords:
;          silent:     if set, perform fit silently
;          debug:      if set, print the 'A' and 'B' matrices
; Inputs:
;          c():        first guess of fitting coefs
;          eps():      relative accuracy required for each coef
;          niterx:     max no of iterations
;          weights:    weights associated to (x,y) == 1/sigma
;          useNumDer:  flag, if set, uses numerical derivative
;                      (instead of DFCN)
;          delta():    array of relative changes to compute numerical
;                      derivatives (default: eps/2.)
;
; Output:
;          niter:      no if iteration required to achieve required accuracy
;                      (negative if error 
;                       or did not converge in niterx iterations)
;          c:          fitting coefs
;
;          dc:           keyword w/ values of delta-c at last iteration
;          hasConverged: keyword w/ index of coefs that have converged
;
; Notes:
;          uses the function FCN(x,c) to fit, 
;          and DFCN(x,c,k) as derivative of FCN vs c(k)
;
;          adjust only c( where eps gt 0 ) until abs(d-c/c) < eps, 
;                                          and # iter <= niterx

; Name:
;
;   EB_PLOT
;
; Purpose:
;
;   overplot error-bars (in y-direction by default)
;
; Calling sequence:
;
;   EB_PLOT, X, Y, S
;
; Inputs:
;
;   X: vector of absices
;   Y: vector of ordinates
;   S: error-bar size (y-s to y+s, or x-s to x+s if XAXIS is set)
;
; Input Keyword:
;
;   XAXIS: if set, specify abcisses style error bars (x-axis)
;   SERIF: add serifs
;   LENGTH: relative length of the serifs, default : 0.005
;   POSITIVE: draw only postive (y+s, or x+s) error bars
;   NEGATIVE: draw only negative (y-s, or x-s) error bars
;             
; Support all oplot keywords, as well
;
; Example:
;
;   plot, x, y, psym=4
;   eb_plot, x, y, s, color = 2
;
; <- Last updated: Tue Mar  6 19:49:36 2018 -> SGK

; elapsed, eTime, /reset, /split, /silent, string = str
;
;   measure and display elapsed time since last call to elapsed
;         
; <- Last updated: Wed Dec 20 15:10:09 2017 -> SGK

; eps-print-c
;
;   @eps-print-c: print the postscript plot to eps file, /color
;
;  execute:
;     epsOpen, /color, epsW, epsH, epsFN
;     !p.charsize = epsCSZ
;     .g
;     epsClose, gv = gv
;
;  def 9x6.5 in /tmp/plot

; eps-print
;
;   @eps-print: print the postscript plot to eps file
;
;  execute:
;     epsOpen, epsW, epsH, epsFN
;     !p.charsize = epsCSZ
;     .g
;     epsClose, gv = gv
;
;  def 9x6.5 in /tmp/plot

; eps-print-c
;
;   @eps-print-c: print the postscript plot to eps file, /color
;
;  execute:
;     epsOpen, /color, epsW, epsH, epsFN
;     !p.charsize = epsCSZ
;     .g
;     epsClose, gv = gv
;
;  def 9x6.5 in /tmp/plot

;  epsClose, silent = silent,gv=gv
;
;     ps_close, /noprint, /noid

;  epsOpen, xSize, ySize, fn, color = color
;
;     ps_open, /portrait, /font, /encapsulated, color = color, 
;        size = [xSize, ySize], file = fn+'.eps', /cmyk
;     [!p.charsize = csz]

; Name:
;           fcc
;Purpose:
;           compute cross-correlation using FFT
;           cc = fft((fft( (x1 - avg1),-1) * conj(fft( (x2 - avg2) ,-1))), 1)
;
; Calling Sequence:
;          cc = fcc(x1, x2[, nfft=n])
; Keywords:
;          nfft = n       use a n-long (zero padded) FFT
;          shift          if set, shifts the output by ncc/2
; Output:
;          [un]shifted cross-correlation

; functions:
;
;   lz(x,x0,w) = Lorentzian((x-x0)/w)
;   fcn(x,c)   = c(0)*lz(x, c(1), c(2)) + c(3)
;  and
;   dlz(x, x0, w, k): 1st derivative wrt kth param of lz()
;   dfcn(x, c, k):    1st derivative wrt kth param of fcn()
;   d2fcn(x, c, k, kk):   2nd derivative wrt kth & kkth param of fcn()
;
;  fcn() and dfcn() are used by dlsq_fit
;  lz() and dlz() are used by fcn() and dfcn()

;  iStatus = fileExist(fn)
;
;  return 1 if the file exists.

;  flip, array
;
; flip an array, ie:
;
;   n = n_elements(array(*,0))
;   for i= 0, n/2 do array(i,*) <-> array(n-i,*)

; yp = frstder(x, y, [/nozero])
;
; computes the 1st derivative of y(x) wrt x using 1st differences:
;
;    yp(i) = y(i)-y(i-1)/(x(i)-x(i-1))
;
; keywords:
;
;  nozero: set yp(0) = yp(1)
;
; Jul 19 1994 / SGK

;
; fsdsp, fileName, $
;    dir = dir, img = img, hdr = hdr, sign = sign, _extra = _extra
;
; scaled display of a 2D array in a fist file
;
; perform:
;   readfits(dir+fn, hdr)
;   sdsp, sign*img, _extra = _extra
;
; look at readfits and sdsp

; FSMOOTH: frequency smoothing, over `n' pixels; i.e., perform the smoothing
;          by attenuating high frequency in the Fourier space. 
;
;   z = fsmooth(y, n, xdn = xdn, wiener = wiener)
;
; Keywords:
;
;  xdn: relative width of the cosine bell, default: 0.05
;  wiener: apply a `Wiener' filter,  default: not set
;

; FSMOOTH: frequency smoothing, over `n' pixels; i.e., perform the smoothing
;          by attenuating high frequency in the Fourier space. 
;
;   z = fsmooth(y, n, xdn = xdn, wiener = wiener)
;
; Keywords:
;
;  xdn: relative width of the cosine bell, default: 0.05
;  wiener: apply a `Wiener' filter,  default: not set
;

;   str = ftoa(f, nDigit = [0,0], /noplussign)
;
; return string that represent float f (scalar only):
;
;   ftoa(!pi, nDigit = [1,3]) -> '+3.142'
;

;
; Name:
;           Gen_Poly
; Purpose:
;           Generalized Polynomial Computation
;            y(*) =  Sum c(i).p(*, i)
;                   i = 0,#(c)-1
;
; Calling Sequence:
;          y = Gen_Poly(c, p)
;
; Example:
;   Computes Legendre polynomials to 5th order, for x = -1.,(0.1),1., then
;   value for y = Sum_i c_i P_i(x)
;
;     x = findgen(21)/10.-1.
;     p =fltarr(21, 6)
;     p(*,0) = 1.0
;     p(*,1) = x
;     for i = 2, 5 do $ ; Legendre polynomials recursion relation 
;       p(*,i) = ((2*i-1)*x*p(*, i-1) - (i-1)*p(*, i-2))/i      
;
;     c = [0.1, 420., 0.1, 20.0, 0.1, -5.0]
;     y = gen_poly(c, p)
;     plot, x, y
;
; See Also: LGPOLY LSQ

; fwhm = getFWHM(x,y)
;
; computes FWHM of y(x)
;

; ids = getIDsFromCheckList(name, cnt, value = value)
;
; returns widget IDs from checkList for given name
; like, name = 'options.colors'

; val = getMax(xx, cc, npts)
;
;   compute max of CC(i), as a function of XX(i) using parabolic fit on NPTS
;   points. 
;
; Optional Inputs:
;
;  xr: x-range to look for the max
;  yx: value of polyn fit at xMax
;
; optional output
;   ierr: error flag

;
;  v = getVal(strarr, key, type = type)
;
;    extract the value of a string in the form 'key: value' in the given string array
;
;  type - 'int', 'long', 'float', 'double' or 'string' to overwrite sValType(string)
;
; <- Last updated: Wed Jun 22 16:38:14 2016 -> SGK

; get the cursor postion
;
; c = get_cpos()
;
; input keywords:
;
;   oplot     flag, if set overplot it
;   noPrint   do not print the values
;   psym      psym value to use to overplot, def: 4
;                                                 
;   also pass any extra params to OPLOT (like symsize, color, ..)

;   GV [, fn], cmd=cmd, noprint=noprint, debug=debug
;
;     execute cmd fn, where:
;
;         fn  = file_name of last ps_open   (def.)
;         cmd = ghostview                   (def.)
;
;     don't ask if print when noprint is set

; hHash, yRange, xRange = x, nHash = nHash, _EXTRA = extra
;
; hash the region defined by yRange[0] to yRange[1]
;
; ie:
;
;   plot, findgen(10)
;   hHash, [4, 6], nHash = 12
;
; <- Last updated: Tue Jul  2 16:36:02 2002 -> SGK

;   hist_oplot, r, h, _EXTRA = extra
;
;   over plot histogram using polyfill, typical use:
;
;   plot, r, h, psym = 10
;   hist_oplot, r, h , /line_fill, orientation = 45
;
;   produce a histogram w/ line fill at 45 deg

;  hline, yval, linestyle = linestyle, ls0 = ls0
;
; overplot an horizontal line at yval (yval can be an array)
;
; Support all OPLOT keywords

; index = identify(x, y, [/markit], [psym=], /loop)
;
; identify points on a plot, ie the closest value in x[], y[] selecte with the
; cursor; return the index/indices of the identified point(s)
;
; input keywords:
;
; markit = flag, of set will mark the identified point
; loop   = flag, if set loop until click outside plot boundary
; psym   = value of psym for marking identified points
;
; support all oplot keywords, like color, etc...
;
; example:
;
; plot, x, y, /psym
; idx = identify(x, y, /loop, /mark, color=2, symsize=2)
;

; r = imag(v)
;
;   return iimaginary part of v
;
; <- Last updated: Tue May 15 14:41:18 2012 -> SGK

; yy = interp_1d(x, y, xx)
;
;   reinterpolate Y[i] = f(X[i]) defined on non-uniform grid x 
;             to YY[j] = f(XX[j])  def'd on non-uniform grid xx
;
; uses a simple linear interpolation.
;
; Keywords: 
;   noSort = noSort   flag, if set won't sort x,y
;   extrapolate:      flag, if set allow the routine to extrapolate
;   zeroExtrapolate:  flag, if set return 0 where routine need to extrapolate
;   onError:          flag, if set turn on `on_error, 2' statement
;                    
; <- Last updated: Wed Sep 11 09:39:08 2013 -> SGK

; zz = interp_2d(x, y, z, xx, yy)
;
; reinterpolate Z[i,j]  defined on a regular grid X[i], Y[j]
;           to  ZZ[ii,jj], given the regular grid XX[ii], YY[jj]
;
; using a bi-cubic interpolator.
;
; Keyword:
;
;  double: if set, use double precision
;
; <- Last updated: Fri Aug 28 12:02:15 1998   -> SGK
;                  

; idx = isAPeak(y)
;
; return list of indices for which Y[] is a peak
;
; Keyword:
;
;   sort   sort index array by y(idx)

; flag = isDouble(arg)

; flag = isLong(arg)

; flag = isString(arg)

; flag = isStruc(arg)

;   str = itoa(i)
;
; convert integer `i' to a string
;
; Input Keyword:
;
; nDigit: number of digits to use
;         def: format='(i0)', 
;         become '(iN.N)' where N = nDigit when nDigit > 0
;         ie, itoa(3, nDigit=5) --> '00003'
;         if nDigit < 0: specify the minimum N:
;             itoa(  3, nDigit=-2) --> '03'
;             itoa(123, nDigit=-2) --> '123'
;
; sign:   put a sign ('+' or '-') in front (btw 0 -> '+0')
;
; sep:    separator, if i is an array (def: '' if sign=1, ' ' otherwise)
;
; actual conversion is:
;
;   str =  strcat(string(round(i), format = format), sep)

; newString = label(string)
;
; convert LaTeX like formatted string to IDL equivalent
;
; Input Keywords:
;
;  math:  if set, turn on math mode when starting to process the string
;        
;  useIE: if set, uses !E/!I instead of !U/!D for super/subscripts 
;         (44% instead of 62%) 
;        
;  pFont: if set, uses hardware fonts instead of Hershey fonts
;         otherwise look at the value of !p.font to decide which type of font
;         will be used
;
;  rFont: font number for non math mode text, def.: 6 for Hershey, 3 otherwise
;  mFont: font number for math mode,          def.: 8 for Hershey, 14 otherwise
;  sFont: font number for symbols,            def.: 9
;
; <- Last updated: Tue Jan 22 12:13:30 2008 -> SGK

;   c = lgfit(x, y, m)
;
; fit a m-coefficients Legendre polynomial expansion to {X,Y}, with
;   optional x-Sigma rejection
;
; Input Keyword
;
;   sy      1-sigma uncertainties on y
;   nRej    no of rejection passes,                             def. 0 (none)
;   xRej    x-sigma rejection factor,                           def. 3.0
;   regular flag, if set uses regular polynomial instead of legendre
;   plot    flag, if set plot the data and the fit
;   xtitle  xtitle for the plot
;   ytitle  ytitle for the plot
;   title   subtitle for the plot
;
; Output Keyword
;
;   rms    RMS of residuals to the fit
;   cnt    no of points included in the fit
;   idi    index list of value included in the fit
;   idx    index list of value excluded in the fit
;   sc     1-sigma uncertainty on the fitted coefs
;   px     evaluated polynomials P_i(x_j)
;   extra  values for [r, rr, s, ss], see LSQ
;          
;   see also LGPOLY, LSQ, GEN_POLY
;
; <- Last updated: Fri Dec 18 15:24:30 1998 -> SGK
;

; Name:
;           lgpoly
; Purpose:
;           Legendre Polynomial Computation:
;
;            y(*) =  Sum c[i].Pk(x[*])
;                   k = 0,#(c)-1
;
; Calling Sequence:
;          y = lgpoly(x, c)
;
; Uses Legendre polynomials recursion relation and gen_poly(c, px)
;
; Output Keyword:
;
;   px: return values of Lengendre polynomials, ie Pk(x[*])
;
; Example:
;   y = lgpoly(x, c)
; or
;   y = lgpoly(x, c, px = px)
;   z = gen_poly(d, px) equiv to z = lgpoly(x, d) for same x, but diff coefs!
;
; <- Last updated: Fri Aug 28 12:10:14 1998   -> SGK
;

; Name:
;           linfit
; Purpose:
;           perform simple linear fit to 
;
;               Y = A * X + B  [or Y = A * X]
;
; Calling Sequence:
;
;          result = linfit(xarray, yarray)
;
; Input Keywords:
;
;   noDC      flag, if set fit only Y = A * X (fit must go thru [0,0])
;   nRej      no of rejection passes,                             def. 0 (none)
;   xRej      x-sigma rejection factor,                           def. 3.0
;   print     flag, if set print the fitting coefs
;   plot      flag, if set plot
;   xtitle    xtitle for the plot
;   ytitle    ytitle for the plot
;   title     subtitle for the plot
;   noerase   /noerase set to plot
;
; Output:
;          result = [slope, intercept, regression]
;
; Output Keywords:
;
;   rms      RMS of residuals to the fit
;   cnt      no of points included in the fit
;   idi      list of included indices
;   idx      list of excluded indices
;
; <- Last updated: Fri Aug 28 12:36:38 1998 -> SGK
;

;     lsq, y, sy, x, m, a, sa, r, rr, s, ss, $
;        nonerror = nonerror,  scaleSA = scaleSA
;
;     least square solution to:
;
;     y(k) +/- sy(k) = Sum a(i).x(k,i),     for k=1,n
;                      i=1,m
;
;     m< don't use that point
;     r is the average residual, rr its stdev,
;     s is the stdev of the prob, ss=std(s).
;
; keyword:
;
;  nonerror: if set disable the 'on_error, 2'
;  scaleSA: how to svcale SA
;          if <0 sa = sqrt(cinv[i,i])
;          if =0 sa = sqrt(cinv[i,i]) * sqrt(s)
;          if >0 sa = sqrt(cinv[i,i]) * (sqrt(s) > scaleSA)
;
;     Ref : Linnik, Y. V., Method of Least Squares and Principle of the Theory
;     of Observation, Pergamon Press, Mc Millan Co., 1961, ch. 6, pp 135-187.
;
; <- Last updated: Wed Mar  7 13:20:57 2018 -> SGK
;

; make_legend, symbols, text
;
; put a legend on a plot, parse text with LABEL()
;
; input keywords:
;
;   lines   =  list of line style
;   location=  1, 2, 3 or 4 for lower left/right, upper right/left resp.
;                                                          def: 1 (lower left)
;   colors  = list of colors
;   spaceFctr = extra y-space factor
;   noLabel =  flag, if set do not parse the text with LABEL()
;   charsize=  character size, def. 1
;
; Support all keywords common to XYOUTS and OPLOT
; 
; Example:
;  make_legend, [4, 2], ['\alpha-\Omega\ model', 'observations'], color = 1
;
; <- Last updated: Tue Nov 13 13:55:51 2001 -> SGK

; make_usersym, name, _extra = _extra
;
; create the user symbol of given name, currently defined:
;
;  circle:          radius = radius, npoints = npoints
;  tiangle/square:  size = size
;
; <- Last updated: Mon Dec  4 14:20:09 2017 -> SGK

;  flag = needSwap()
;
;  return 1 if arch is DEC byte-order
;

;
; nlast(v) = n_elements(v)-1
;

;
;  n = nLines(file)
;
;  return the no of lines in file
;
; <- Last updated: Wed Apr 26 11:09:06 2000 -> SGK

; turn off all warnings
; @no-warnings

; Name: NOBPTT
;       
; Purpose:
;
;  set device to NOT bypass the translation table
;
;  ie: device, bypass_translation = 0
;      this need to be called AFTER the first window is opened ;(
;
; Calling Sequence:
;
;       NOBPTT
;

; olh: wrapper to widget_olh

;  openr_ --> openr, /SWAP_IF_LITTLE_ENDIAN

;  openu_ --> openr, /SWAP_IF_LITTLE_ENDIAN

;  openw_ --> openr, /SWAP_IF_LITTLE_ENDIAN

; pause, prompt = prompt, force = force, noID = noID, pmulti = pmulti
; 
; pause until CR is pressed, unless !d.name == 'PS'
; in which case put_id is called
;
; Keyword:
;
;   prompt   prompt to print, def. 'CR>  '
;   force    force the pause, even if !d.name == 'PS'
;   noID     disable put_id
;   pmulti   pause only if !p.multi[0] EQ 0
;   noErase  do not erase when !p.multi[0] EQ 0 and pmulti is set

; pc8 ==> device, pseudo_color = 8

; pCursor, x, y, device = device, normal = normal, oplot = oplot
;
;  print the current value of the cursor, 
;  until any button is pressed in the current plotting window
;
; Sep  9 1999 SGK/Nov 22 2002 IDL 5.4 complient

; help pick a color, using HSV model (best w/ 24 bit disp)
;
;   pickColor
;
; keywords:
;   nPxl        - size of picker image (def=512)
;   gamma       - gamma equal (def=1.25)
;   hMin, hMax  - limit the Hue range
;   sMIn, sMax  - limit the Saturation range
;   vMin, vMax  - limit the Value range
;   noBlock     - flag to run in non-blocking mode
;   useFrac     - display RGB components as fractional values between 0 and 1
;   dummyWindow - flag to display a dummy window (IDL bug workaround) 
;

; playAnyMovie, fSpec, bDir = bDir, $
;                  rate = rate, title = title
;
; call sz=dspImg(fn, wno) to load & display the image

; playPPMmovie, fSpec, nt, offset = offset, bDir = bDir, $
;                  sideBySide = sideBySide, rate = rate, $
;                  title = title, fmt = fmt, no_block = no_block, $
;                  no_order = no_order, zoom = zoomFctr

; playPPMmovie, fSpec, nt, offset = offset, bDir = bDir, $
;                  sideBySide = sideBySide, rate = rate, $
;                  title = title, fmt = fmt, no_block = no_block, $
;                  no_order = no_order, zoom = zoomFctr

; Name:
;
;        PLCT
; Purpose: 
;
;       Load a `plotting' color map:
;         red, green, blue, yellow, magenta, indigo, etc...
;       up to 14 colors.
;
; Calling Sequence:
;
;       PLCT
;
; Keywords:
;       n =  - no of colors [3-14], 
;           default 14, min 3, max 14.
;       offset =  - offset at which to load the colmap,
;           default 1, min 1.
;       invertBW = flag, of set invert black and white levels
;
; Side Effects:
;       Modify the color map, using TVLCT.
;
; Example:
;
;  IDL> plct
;  IDL> plot, findgen(3), thick=4, yr=[0, 6]
;  IDL> for i = 1, 14 do oplot,findgen(3) + i/4., color = i, thick = 4
;
; Modification History:
;       Jul  7 1995 Written by SGK, CfA.
;       Jun 29 1998 modified to create a full color map, and deal w/ b/w
;       levels, SGK
;       May 13 2000 no action if TEK window system
;       May 26 2002 call UDC if !D.N_COLORS NE !D.TABLE_SIZE

; PLOT3D, Z, X, Y
;
; makes a 3d point plot using a dummy
;    SURFACE, /SAVE 
; followed by a 
;    PLOTS, /T3D
;
; if [xyz]ranges are not set, uses SGK's AUTO_RANGE()
;
; The following keywords are supported:
;   AX, AZ, XSTYLE, YSTYLE, ZSTYLE, XRANGE, YRANGE, ZRANGE, 
;   XTITLE, YTITLE, ZTITLE, TITLE, SUBTITLE,
;   PSYM, SYMSIZE, CHARSIZE

; plot_clock, hr
;
; plot a clock showing the time, hr is decimal hours
;

;
;    plot_vs_date, t, y, mdi = mdi, mjd = mjd, [dateFormat = dFmt | /addsecs]
;
; <- Last updated: Sat Mar 18 08:05:31 2017 -> SGK
;

;
; Name:
;         v =  poly2d(x, y, c, [ni, nj], legendre = legendre)
;
; Purpose:
;         estimate a 2D polynomial:
;
; y = Sum      Sum     x^i y^j c[i,j]
;     i=0,ni-1 j=0,nj-1
;
; keyword:
;
;   legendre uses legendre polynomials Pi(x) instead of x^i
;
; <- Last updated: Mon Feb 28 15:23:39 2011 -> SGK
;

; Name:
;           c = polyfit(x, y, m)
; Purpose:
;           perform a polynomial fit to 
;                          
;               y = Sum a P (x )   for i=0,m and j=0,N-1 w/ n >> m
;                j   i   i i  j
;
; by default P_i(x) = x^ii   where ii = i-xZero
;
; Input Keywords:
;
;   sy        specify uncertainties for y, 
;             if sy(i) <= 0.0 this point is NOT used in the fit
;   Legendre  use legendre polynomials
;   xZero     offset to exponent                                  def. 0 (none)
;   noDC      flag, if set does not include dc term (fit must go thru [0,0])
;   usePX     flag, if set uses the values passed in px= for P_i(x_j)
;   nRej      no of rejection passes,                             def. 0 (none)
;   xRej      x-sigma rejection factor,                           def. 3.0
;   print     flag, if set print the fitting coefs
;   plot      flag, if set plot
;   pResid    flag, if set plot plot residuals (sets plot)
;   psym      psym for oplot                                      def. 1
;   sSA       see LSQ scaleSA (0, <0 or >0)
;   chiFit    rms of reduced residuals (used by scaleSA)
;   noLabel   flag, if set don't label values of coefs on plot
;   cz        character size for labels,                          def: 1.
;   xtitle    xtitle for the plot
;   ytitle    ytitle for the plot
;   title     subtitle for the plot
;   noerase   /noerase set to plot
;   nonerror  flag, if set disable the 'on_error, 2'
;
; Output:
;          polynonial coefficients
;
; Output Keywords:
;
;   rms      RMS of plotResiduals to the fit
;   cnt      no of points included in the fit
;   idi      list of included indices
;   idx      list of excluded indices
;   px       values of P_i(x_j) (for gen_poly)
;   sc       uncertainties on coefs
;   extra    [r, rr, s, ss] as defined by LSQ, ie:
;     r is the average residual, rr its stdev,
;     s is the stdev of the prob, ss = std(s).
;
; <- Last updated: Thu Mar  8 08:17:03 2018 -> SGK
;

; Name:
;           c = polyfit2D(x, y, z, n1, n2)
; Purpose:
;           perform a 2D polynomial fit to 
;                          
;               z = Sum  a    P (x ) P (y )   for i=0,m1 j=0,m2, k=0,N-1
;                k  i,j   i,j  i  k   j  k
;
; by default P_i(x) = x^i P_j(y)= y^j
;
; Input Keywords:
;
;   nRej      no of rejection passes,                             def. 0 (none)
;   xRej      x-sigma rejection factor,                           def. 3.0
;   szVals    sigma(z)
;
; Output:
;          polynonial coefficients
;
; Output Keywords:
;
;   rms      RMS of residuals to the fit
;   cnt      no of points included in the fit
;   idi      list of included indices
;   idx      list of excluded indices
;   px       values of P_i(x_j) (for gen_poly)
;
; <- Last updated: Mon May 18 11:22:03 2015 -> SGK
;

;  y = polyx(x, a)
;
; extended polynomial evaluator:
;
;                  i-xZero 
;     y = Sum a  x
;          i   i 
;
; Input Keywords:
;
;   xZero     offset to exponent                                  def. 0 (none)
;
; <- Last updated: Mon Mar 15 15:06:37 1999 -> SGK
;

;   nIter = poly_solve(y, c, x)
;
; solve y = Sum Ci.Pi(x) for x, given y
;            i
;
; return the number of iterations (negative if did not converged), and the
; solution in x.
;
; Input Keywords:
;
;   xinit   inital guess for x,                             def. (y-c[0])/c[1]
;   eps     required relative accuracy,                     def. 1e-6
;   niterx  max no of iterations,                           def. 10
;   useLG   flag, if set use Legendre polynomials
;   silent  flag, if set don't blable
;
; <- Last updated: Fri Jun  2 16:27:57 2000 -> SGK
;

; ps-print
;
;   @ps-print: print the postscript plot
;
;  execute:
;     ps_open
;     .g
;     ps_close, gv = gv, noprint = noprint, noid = noid, printer = printer
;
;  assumes that ps_open options are set via ps_opts

; ps-print-c
;
;   @ps-print-c: print the postscript plot, /color
;
;  execute:
;     ps_open, /color
;     .g
;     ps_close, gv = gv, noprint = noprint, noid = noid
;
;  assumes that ps_open options are set via ps_opts

; ps-print-cp
;
;   @ps-print-c: print the postscript plot, /color
;
;  execute:
;     ps_open, /color, /portrait
;     .g
;     ps_close
;
;  assumes that ps_open options are set via ps_opts

; ps-print
;
;   @ps-print: print the postscript plot
;
;  execute:
;     ps_open
;     .g
;     ps_close, /gv
;
;  assumes that ps_open options are set via ps_opts

; ps-print
;
;   @ps-print: print the postscript plot
;
;  execute:
;     ps_open, /portrait
;     .g
;     ps_close
;
;  assumes that any *ADDITIONAL* ps_open options are set via ps_opts

; ps-print
;
;   @ps-print: print the postscript plot
;
;  execute:
;     ps_open
;     .g
;     ps_close, /queue
;
;  assumes that ps_open options are set via ps_opts

; Name:
;
;  PS_Close
;
; Purpose:
;
;    Closes the PostScript plotting device (opened with PS_Open),
;    adds an optional time-stamp in the lower left corner,  
;    sends the PostScript file to the default printer 
;    and restore the plotting device saved by PS_Open.
;
;     the default b/w   printer is $PRINTER,      or `ssplw',
;     the default color printer is $COLORPRINTER, or `psc1',
;
;     the default b/w   print command is $LPCMD,      or `lp',
;     the default color print command is $COLORLPCMD, or `lp',
;
; Calling sequence:
;
;    PS_Close
;
; Keywords:
;
;    NOID - If set, the time-stamp ID is not added to the plot.
;  
;    NOPRINT - If set, the PostScript plotting device is closed, and 
;      the plotting device saved by PS_Open is restore, 
;      but the PostScript file is NOT sent to the printer. 
;
;    GV - set NOPRINT and run GV (ghostview previewer routine)
;  
;    SAVEAS = . Save the PostScript file by copying it to the
;      specified file. The plot is still printed, unless NOPRINT is set.
;  
;    PRINTER = . Send the plot the specified printer.
;      By default the enviroment variable PRINTER (or COLORPRINTER) is used to
;      determine the printer to use. If it is not set the defaul values are
;      ssplw (or psc1).
;
;    TRANSPARENCY - If set, requests a transparency.
;      Not all printers support this option (-SInputSlot=Transparency).
;      (Only the color printers do)
;
;    OPTIONS = . Optional extra options for the pslpr command.
;      Example: OPTIONS = '-SDuplex' to use duplex printing.
;
;    LPR = . Specify the command to use to print the file; by defaut
;      pslpr is used. Note that if this keyword is specified, the keywords
;      PRINTER, TRANSPARENCY and OPTIONS are ignored. 
;      Example: LPR = '/usr/bin/lp'
;
;   SILENT - If set, disable warning messages
;
;   QUEUE  - If set, save the plot to print them all later
;
;   NOEXEC - flag, if set won execute the spawn, cmd (for debug/testing mode)
;
; See also: PS_Open

; Name:
;
;   PS_Open
;
; Purpose:
;
;   Set the plotting device to be PostScript, and save the current plotting
;   device (to restore it when the plot is done).
;
; Calling sequence:
;
;   PS_Open
;
; Keywords:
;
;   PORTRAIT - Normally, PS_Open defines the plotting area as landscape. If
;     this keyword is set, the plotting area will be portrait.
;
;   FILENAME =  - Normally, PS_Open uses '/tmp/idl-$USER.ps' for the
;     PostScript file, the keyword FILENAME can be used to override that value.
;     ($USER is retrieved with a getenv('USER')).
;
;   SIZES = <2-elements array> - Specify the plot size.
;     The default plotting area is 10" x 7.5".
;
;   OFFSETS = <2-elements array> - Specify the plot margins.
;     The default plotting area has 0.5", 0.5" margins.
;
;   SQUARE - if set, sets the plotting area to be square.
;     Since the plotting area includes room for labels to axis, this option 
;     alone does not gives you a square plot (cf: !P.REGION).
;
;   FLUSH - flush (ie ignore) all previously queued plots (see PS_Close)
;
;   FONT - if numeric, set !P.FONT to value of FONT and turn on IsoLatin1
;        - if string,  set !P.FONT=0 and use the given PostScript font name as
;        default (!3), checks the font name against a list, and if doesn't
;        match use 'Helevetica-Narrow-Bold' as font
;        (ie font=' ' equivalent to font='Helevetica-Narrow-Bold')
;
;   PCZ  - set !P.charsize to value PCZ (otherwise set it to zero)
;          saves old value and ps_close restores it
;
;   ENCAPSULATED - produces an encapsulated PostScript plot.
;   
;   BPP =  - Set the number of bits per pixel; default value is 8,
;     valid values are 8, 4, OR 2. A higher no produces a better
;     resolution but also a bigger PostScript file.
;
;   COLOR - If set, produces a color PostScript plot.
;
;   TABLOID - If set, selects tabloid/ledger format (17" x 11" paper).
;     The default plotting area is 16" x 10", with 0.5" margins.
;     Not all printers can print tabloid format.
;
;   LEDGER = TABLOID, /landscape
;
;   PAGE_LENGTH =  - Specify the actual page length.
;     The default lenght is 17" for tabloid format, 11" otherwise. 
;   PAGE_WDITH =   Specify the actual page width.
;     The default lenght is 11" for tabloid format, 8.5" otherwise. 
;     This is needed because IDL's implementation of the X/YOFFSET keywords to
;     DEVICE in landscape mode. The offset must be specified
;     relative to the page width or length. This way PS_Open() offsets are more
;     intuitive. (cf: IDL ref. guide, section: PostScript Positioning).
;
;   NOFLIP - do not flip landscape mode (leave it as seascape)
;
;   OKFontList - string array of valid font names to check font=
;      against 
;
;   SILENT - If set, disable warning messages
;
; See also: PS_Close

; ps_opts - routine to specify options that would be otherwise set in PS_OPEN 
;           this command is ignored unless ps_open has been called first
;           it is provided to specify in a script how to configure the PS
;           device when doing a hardcopy of the plot.
;
; KEYWORDS: 
;
;    fileName
;    encapsulated
;    portrait
;    landscape
;    tabloid
;    sizes
;    offsets
;    color
;    pcz
;    font
;    OKFontList
;    silent

; pTell, i
;
; print the value of i, w/out a NL to display progress of a computation
;
; Keyword
;
;   nDigit - no of digits for i
;   prefix - string to print before i
;   suffix -                 after  i

; Name:
;            Put_ID
;
; Purpose:
;   Put an ID (time stamp, user, & hostname) in the corner of a plot
;
; Calling sequence:
;
;   put_ID, upper = upper, right = right, size = size, $
;     /noProc, /noprint, /noOutput
;
; Used by PS_Close & epsClose
;
; Aug  1 2001: use HELP, /SOURCE to add the $MAIN$ procedure
; Jun  6 2013: added noOuput = noOutput,  noPrint = noPrint

;   x = qeqroots(a, b, c, complex = complex)
;
; solve quadratic equation
;
;   a x^2 + b x + c
;
; return x[0,1] = [x_1,x_2]
;            i
; Input Keywords:
;
;   complex   flag, if set, return complex root,
;             otherwise stop if discriminent is
;   silent    flag, if set, no warning msgs
;
; Output Keywords:
;
;   error     return flag
;
; <- Last updated: Fri Mar 22 15:36:47 2002 -> SGK
;

;  rad2deg(degree)

;
; r = ramp(n, x0, x1)  or  r = ramp(n, x)
;                      or  r = ramp(n, [x0, x1])
;                      or  r = ramp(n, /xrange) [x0,x1 = !x.crange]
;                      or  r = ramp(n, /yrange) [x0,x1 = !y.crange]
;
; return a ramp of N values, ranging from x0 to x1 or 0 to x as in second 
; example  
;
; Keyword:
;
;   double: flag if set, return a double precision array
;         
; <- Last updated: Thu Oct  2 16:21:06 2003 -> SGK

; rcall
;
; execute: return & close, /all

; s = read_rdb(fn)
;
;  read a starbase RDB table, ie tab separated, into struct of strings
;
;   header:    lines before the column header itself
;   verbose:   flag, if set print out some information about the file
;   noOnerror: flag, if set won't do `on_error, 2'
;
; <- Last updated: Wed Jun 28 18:38:46 2006 -> SGK

;  s = read_struct(s, sName = sName, comments = comments)
;
;    read a structure array from a flat ASCII table file, written by
;    write_struct, fn, s
;
;  sName - overwrite saved struct name (to avoid name conflict)
;
; <- Last updated: Tue Sep 27 12:39:19 2016 -> SGK

; data = read_table(fn)
;
; read an ASCII file organized with a constant no. of col. per row, and return
;   a float array. Uses the first line to deduce the number of columns (based
;   on the column separator), unless nCols, format or struct are set. 
;
; Input Keywords:
;
;   nSkip:     no of (header) lines to skip,         def.: 0
;   nCols:     no of columns in the file, (don't try to guess using first line)
;   colSep:    column separator,                     def.: ' '
;   format:    format specification,                 def.: none
;           [must supply nCols when using format, unless struct is given]
;           [if format is supplied, colSep is ignored]
;   autoSkip:  flag, if set skip as many line as needed,
;             skip lines that start w/ the comDel or are empty
;   comDel:    the comments delimitor                def.: #
;   double:    flag, if set return double precision array
;   verbose:   flag, if set print out some information about the file
;   struct:    structure to use to read the data
;   noOnerror: flag, if set won't do `on_error, 2'
;
; Output Keywords:
;
;   header:  header, ie the lines skipped
;         
; <- Last updated: Mon Dec  4 11:12:24 2017 -> SGK

; r = real(v)
;
;   return real part of v
;
; <- Last updated: Thu Dec 17 11:22:47 2009 -> SGK

; PRO relscale, rx, ry, x, y
;
; Relative scaling:
;   return data scaling (x,y) defined in terms of relative coords (rx,ry)
;

; rewind, lu: point_lun, lu, 0

; Name:
;           myhist
; Purpose:
;           compute a histogram, and its corresponding range
; 
; Calling sequence:
;
;          hist = myhist(data, hrange)
; 
; Keywords:
;          min:      minimum
;          max:      maximum value for the histogram
;          nbin:     set the bin-size to be (max-min)/nbin
;          bin:      bin size for the histogram (unless nbin is set)
;          cumul:    return cumulative hist
;          percent:  scale hist in percent
; Output:
;          hist[]:    [cumul] histogram
;          hrange[]:  range vector: ie hist[i] correspond to hrange[i]

; rxyouts: "relative" version of: 
;  
;    xyouts, xPos, yPos, string, ...
;
;    xPos and yPos range being [0., 1.]             
;

;   niter = sanmba(p, ftol)
;
; simulated annealing amoeba minimization, adapted from Numerical Recipes
;
; minimze fmerit(p), a routine that must be suplied
;
;   p (n+1, n):  vertices of the amoeba
;                guess bracket for n parameters
;    ftol:       convergence tolerance factor (ie 1E-6 in SP, 1D-9 in DP)
;
; keywords:
; input:
;
;   tp:       simulated annealing 'temperature', default: 0.
;   seed:     random no generator seed,          default: undef
;   nitex:    max no of iters,                   default: 10*n
;
; output:
;
;   rtol:     reached tolerance
;   pbest:   `best' set of params
;   ybest:   `best' merit value
;          
; <- Last updated: Fri Oct 24 00:14:32 2008 -> SGK
;

; ypp = scnder(x, y, [/nozero])
;
; computes the 2nd derivative of y(x) wrt x using 2nd differences:
;
;    ypp(i) = y1(i)-y1(i-1)/(x1(i)-x1(i-1))
;    where yp(i) = y(i)-y(i-1)/(x(i)-x(i-1))
;    and   x1(i) = (x(i) + x(i+1))/2
;
; keywords:
;
;  nozero: set ypp(0) = ypp(1) and ypp(n) = ypp(n-1)
;
; <- Last updated: Fri Aug 28 12:59:50 1998 -> SGK
;

;
; sdsp, img, wno = wno, xrange = xr, yrange = yr, $
;          xstyle = xstyle, ystyle = ystyle, zrange = zrange, $
;          xsize = xsize, ysize = ysize, noScale = noScale, swFill = swFill, $
;          xOffset = xOff, yOffset = yOff, noPmulti = noPmulti, $
;          nlevels = nlevels, levels = levels, c_lines = c_lines, $
;          zoom = zoomIn, sample = sample, $
;          wtitle = wtitle, xtitle = xtitle, ytitle = ytitle, title = title, $
;          margin1 = w1, margin2 = w2, tickf = tickf, $
;          useSaveImgSz = useSaveImgSz, useIndivImgSz = useIndivImgSz,$
;          absOffset = absOffset, noXC = noXC, _extra = _extra
;
; scaled display of a 2D array (ie image)
;
;   zoomIn can be either a scalar or a 2-elements array
;   if nlevels > 0, coutours are superposed
;   if wno < 0, use current window
;
; uses

; pos = sdspos(/nopm, /pixel)
;
; return position for next plot equiv to sdsp, when using !p.multi
;
; !p.multi=[0,1,2]
; sdsp, img
; plot, line, position = sdspos(), /device, /noerase
; 
; use /nopm  to get pos from the last sdps
;     /pixel to leave pos in pixels, instead of in current device unit
;

; setIDsFromCheckList, name, set, value = value)
;
; (re)set the check mark using checkList for given name
; like, name = 'options.colors'

;;
COMMON c_relpos, k, nx, ny, po, ps, pp,  bCol
;;
IF NOT keyword_set(poIn)   THEN po = [0.05, 0.05] ELSE po = poIn
IF NOT keyword_set(psIn)   THEN ps = [0.90, 0.90] ELSE ps = psIn
IF NOT keyword_set(ppIn)   THEN pp = [0.10, 0.10] ELSE pp = ppIn
bCol = keyword_set(bColIn)
;;
IF keyword_set(kVal) THEN k =  kVal ELSE k = 0
nx = nxIn
ny = nyIn
;;
END
; Name:
;
;        SGKLCT
; Purpose: 
;
;       Load a 'lookat-compatible' color map (SGK's format)
;
; Calling Sequence:
;
;       sgklct, name
;
; Inputs:
;
;       name: string that contains the name of the color map.
;
; Keywords:
;       range_start = integer, starting index of the range to be loaded,
;                     (default=0)
;       range_end   = integer, ending index of the range to be loaded,
;                     (default=255)
;       load_start = integer, starting index of the loading (cf keyword start
;                    in TVLCT; default=0)
;       cmap_dir = string that contains the directory where the color map is
;                  stored (default value: $COLMAP_DIR, 
;                                         otherwise '/home/sylvain/colmap/')
;       cmap_ext = string that contains the extension name of the color map
;                  (default value: '.clr')
;       silent - load silently (by default)
;       verbose - load verbosely
;
;       get_names - flag, if set return cmap names
; Outputs:
;       None.
;
; Common Blocks:
;       Maintains the common block colors.     
;
; Side Effects:
;       One of the color maps may be loaded.
;
; Restrictions:
;       This routine uses the TVLCT routine to load the color table
;
; Modification History:
;       26, August, 1991, Written by SGK, CfA.
;       Sep  9 1998 look for env. var. COLMAP_DIR
;       Sep 22 2005 replaced FINDFILE() by FILE_SEARCH()
;       May 21 2010 add verbose, silent by default now

; Name:
;
;        SGKLCT
; Purpose: 
;
;       Load a 'lookat-compatible' color map (SGK's format)
;
; Calling Sequence:
;
;       sgklct, name
;
; Inputs:
;
;       name: string that contains the name of the color map.
;
; Keywords:
;       range_start = integer, starting index of the range to be loaded,
;                     (default=0)
;       range_end   = integer, ending index of the range to be loaded,
;                     (default=255)
;       load_start = integer, starting index of the loading (cf keyword start
;                    in TVLCT; default=0)
;       cmap_dir = string that contains the directory where the color map is
;                  stored (default value: $COLMAP_DIR, 
;                                         otherwise '/home/sylvain/colmap/')
;       cmap_ext = string that contains the extension name of the color map
;                  (default value: '.clr')
;       silent - load silently
;
; Outputs:
;       None.
;
; Common Blocks:
;       Maintains the common block colors.     
;
; Side Effects:
;       One of the color maps may be loaded.
;
; Restrictions:
;       This routine uses the TVLCT routine to load the color table
;
; Modification History:
;       26, August, 1991, Written by SGK, CfA.
;       Sep  9 1998 look for env. var. COLMAP_DIR

;
; file = sgk_pickfile(dir)
;
; return a picked file 
;
; Keyword:
;
;    group_leader - group leader wigdet for modal mode
;    filter    - file spec filter, def: '*'
;    scrollTo  - scroll to given file, or '@end' or '@beg', def: '@beg'
;    title     - widget base title
;    width     - file name width (chars)
;    height    - file name height
;    newDir    - new dir spec selected
;         
; <- Last updated: Wed Jun 22 15:06:22 2005 -> SGK

; show3D, data, x, y, z, cuts = cuts, $
;         sMin = sMin, sMax = sMax, $
;         size = size, ax = ax, az = az, $
;         xMin = xMin, xMax = xMax, $
;         yMin = yMin, yMax = yMax, $
;         zMin = zMin, zMax = zMax, $
;         topCut = topCut, topTrns = topTrns, $
;         topMin = topCutMin, topMax = topCutMax, $
;         botCut = botCut, botTrns = botTrns, $
;         botMin = botCutMin, botMax = botCutMax, noSwindow = noSwindow, $
;         mark = mark, msymbol = msymbol, msize = msize, $
;         img = img, noSwindow = noSwindow, noDisplay = noDisplay, $
;         charsize = csz, silent = silent, $
;         xtitle = xtitle, ytitle = ytitle, ztitle = ztitle, $
;         tcsz = tcsz, title = title, noAxis = noAxis
;
;   displays volumetric data[*,*,*] using cuts, given x[*], y[*], z[*] regular
;   grid coords 
;
; cuts = replicate(cut, ncuts)
;
; where:
;
;  cut = {cutInfo, index:0L, dir:0L, tMin:0., tMax:0.}
;    index: index of the cut (like data[*,index,*])
;    dir:   direction of the cut;
;            0: data[index, *, *]; 1: data[*, index, *]; 2: data[*, *, index]
;    tMin/tMax: range of values to be transparent
;
;  sMax: scaling max                        def.: 5*cmp_rms(data)
;  sMin: scaling min                        def.: -sMax
;  size: image size                         def.: [1100, 850]
;  ax, az: perspective rotation angles      def.: 40, 40
;  xMin, xMax: min/max scaling for x        def.: x[0], x[n_elements(x)-1]
;  yMin, yMax:                     y
;  zMin, zMax:                     z
;

; showPercent, pc
;
; Creates a widget to indicate fraction completed
;
; Keywords:
;
; upon creation:
;   title:  specify the title,                def.:  'Fraction Completed'
;   text:   text to put after the xx%,        def.:  ''
;   height: window height,                    def.: 200
;   width:  window width,                     def.: 15
;   bg: background color index,               def.: !d.n_colors-1
;   fg: foreground color index,               def.: 0
;  to destroy:
;   destroy: if set, destroy the widget
;
; Example:
;
; showPercent, text = 'done...'
;
;  FOR i = 1, 30 DO BEGIN
;    pc = 100.*i/30
;    showPercent, pc
;    wait,  0.2
;  ENDFOR
;  wait,  1.
;  showPercent, /destroy
;  end
;

; show_font, n
;
;  show the characters in the font N
;
; Keyword:
;
;  symbol:   if set, put a !m (for PS symbols)
;  charsize: character size                                       def.: 2.5
;
;  May  3 1994 / Apr 28 1997 SGK

; Name:
;
;   SPosition
;
; Purpose:
;
;   Returns the appropriate position vector to be used in "position=[],/dev"
;   specification, but properly scaled to work whether the plotting device
;   is an X window or the PostScript device.
;  
; Calling sequence:
;
;   scaled_position = SPosition(position)
;
; Input:
; 
;   position: 4 element position vector in X-window device coords
; 
; Output:
;
;  4 elements vector suitable for position=...,/dev specification
;
; Restriction:
;
;   The SWindow routine must be called first to establish the scaling factor
;   before using SPosition.
;
; Example:
;
;   IDL> image = randomu(seed,200,300)
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stv, image, 50, 50  
;   IDL> plot, findgen(10), /noerase $
;          position = sposition([50, 50, 250, 350]), /dev
;   IDL> sxyouts, 100, 200, 'this is at (100,200)'
;
; See also: SWindow, STV, STVScl, SXYOuts

; Name:
;
;  SQUARE_PLOT
;
; Purpose:
;
;   restrict the plotting area to a relative square position
;
; Calling sequence:
;
;   dev_position = square_plot(position)
;
; Inputs:
;
;  position: 4 element position vector: [x0,x1,y0,y1]
;
; Output:
;
;  4 elements vector suitable for position=...,/dev specification
;
; Example:
;
;   dev_pos = square_plot([.04, .04, .46, .46])
;   plot, x, y, position=dev_pos, /dev

;
; string = strCap(string)
;
; capitalize string
;

;
; string = strCat(array, separator)
;
; concatenate string array in one string with given separator, uses '|' if
; separator argument is missing
;

;
; list = strSep(string, separator [,count = count])
;
; calls str_sep, and returns only the non-empty fields, uses ' ' if separator
; argument is missing
;
; Output Keyword:
;
;  count: no of elements of the list
;

; Name:
;
;   STV
;
; Purpose:
;
;   Performs a "scaled" TV, namely a TV that will be properly scaled to work
;   whether the plotting device is an X window or the PostScript device.
;  
; Calling sequence:
;
;   STV, image, xposition, yposition
;
; Restriction:
;
;   The SWindow routine must be called first to establish the scaling factor
;   before using SPosition.
;
; Example:
;
;   IDL> image = randomu(seed,200,300)*255
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stv, image, 50, 50  
;   IDL> plot, findgen(10), /noerase $
;          position = sposition([50, 50, 250, 350]), /dev
;   IDL> sxyouts, 100, 200, 'this is at (100,200)'
;
; or
;
;   IDL> image = randomu(seed,200,300)*255
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stv, image, 50, 50, /axis, $
;   IDL>   xrange = [0., 2.], yrange = [-15., 15.], $
;   IDL>   xtitle = 'here',  xtickl = -.01, $
;   IDL>   ytitle = 'there', ytickl = -.01, $
;   IDL>   title  = 'demo!c'
;
; See also: SWindow, STVScl, SPosition, SXYOuts
;

; Name:
;
;   STVScl
;
; Purpose:
;
;   Performs a "scaled" TVSCL, namely a TVSCL that will be properly scaled to
;   work whether the plotting device is an X window or the PostScript device.
;  
; Calling sequence:
;
;   STV, image, xposition, yposition
;
; Keywords:
;
;   axis           - flag, if set will draw axis around image
;   xRange, yRange - x/y ranges for axis around image
;
; Additional keywords are passed to the PLOT routine that draw these axis
;
; Restriction:
;
;   The SWindow routine must be called first to establish the scaling factor
;   before using STVSCL
;
; Example:
;
;   IDL> image = randomu(seed,200,300)
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stvscl, image, 50, 50  
;   IDL> plot, findgen(10), /noerase $
;          position = sposition([50, 50, 250, 350]), /dev
;   IDL> sxyouts, 100, 200, 'this is at (100,200)'
;
; or
;
;   IDL> image = randomu(seed,200,300)
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stvscl, image, 50, 50, /axis, $
;   IDL>   xrange = [0., 2.], yrange = [-15., 15.], $
;   IDL>   xtitle = 'here',  xtickl = -.01, $
;   IDL>   ytitle = 'there', ytickl = -.01, $
;   IDL>   title  = 'demo!c'
;
; See also: SWindow, STV, SPosition, SXYOuts
;

; ainv = svdinvert(a, istat, eps = eps, w = w)
;
; compute invert(a) using SVD, and keeps only eigenvalues larger that
;   eps*max(eigenvalues) 
; 
; Input Keywords
;
;  eps   value for eps defined above,                             def. 1e-6
;  noEps flag, if set force eps = 0
;
; Output
;
;  ISTAT: 0: OK, 
;        -N: N eigenvalues ignored
;         1: failed
;            
; Output Keyword
;
;  W     eigenvalues
;
; <- Last updated: Fri Aug 28 13:58:41 1998 -> SGK
;

; Name:
;
;   SWindow
;
; Purpose:
;
;   Performs a "scaled" WINDOW, namely a WINDOW that allows plots to be
;   properly scaled to work whether the plotting device is an X-window or the
;   PostScript device. 
;  
; Calling sequence:
;
;   SWindow, window_index, $
;            xsize = xsize, ysize = ysize, xpos = xpos, ypos = ypos
;
; Keywords (Optional):
;
;   XSIZE, YSIZE: specify the window size
;   XPOS, YPOS:   specify the window position (for X-windows only)
;   TITLE:        specify the window title
;   PIXMAP:       flag, if set will open a pixmap ('X' only)
;   FILL:         flag, if set will fill the printer area ('PS' only)
;         otherwise the aspect ration is preserved

; Restriction:
;
;   Only one scaling factor is kept for scaling (ie the one corresponding to
;   the last call to swindow)
;
; Example:
;
;   IDL> image = randomu(seed,200,300)
;   IDL> swindow, 0, xsize=300, ysize=400
;   IDL> stv, image, 50, 50  
;   IDL> plot, findgen(10), /noerase $
;          position = sposition([50, 50, 250, 350]), /dev
;   IDL> sxyouts, 100, 200, 'this is at (100,200)'
;
; See also: STV, STVScl, SPosition, SXYOuts
;
; History:
;   Apr 28 1994 SGK: added xpos and ypos keywords
;   Dec 11 1998 SGK: preserve aspect ration when destination is PS printer
;   May 26 2005 SGK: added title keyword

; sxyouts: "scaled" version of: 
;  
;    xyouts, /dev, xpos, ypos, string, $
;       alignment = alignment, charsize = charsize, color = color
;
;  when used in conjuction with `swindow', sxyouts will properly position and
;  scale the image on PostScript output to match output on the screen.
;  Note that positions are asumed to be in `screen-device' units
;
;  see also: swindow, stv, stvscl, sposition

; tc24 ==> device, true_color = 24

; topW = topMBW(menuList)
;
; Creates a top level base widget w/ menu bar
;
; The menus are specified in the string array menuList, using the syntax
; outlined in the example; the `value|string' specify a UVALUE for this button
; (default is the upcase(value); a `; //' is used to terminate a cascade,
; while `;' are used to separe the entries.
;
; Additional optional input keywords to top level WIDGET_BASE can be added
; ie (COLUMN, ROW, TITLE, etc...)
;
;  >:    means enable 'checked'
;  name< means check this one
;  the checkList returns info about checked buttons
; warning: no built-in exclusive
;
; Example:
;
; menuList = ['File:    New; Open; Save; Quit', $
;             'Options: Rendering>:  Solid; Wire<;    //' + $
;             '         Shading:     Flat;  Gouraud;  //' + $
;             '         Projection: Orthogonal|PROJ1; Perspective|PROJ2', $
;             'Help:    About this|H1; More stuff|H2']
;
; topW = topMBW(menuList)
; WIDGET_CONTROL, topW, /REALIZE
; XManager, 'test', topW
;

;   tz = tz_integrate(x, y)
;
; trapeze rule integration, ie
;
;   tz = Sum [y(i) + y(i+1)] * [x(i+1)-x(i)]/2.
;         i
;
; <- Last updated: Fri Aug 28 14:08:47 1998   -> SGK
;

;   f = tz_integrate2D(x,y,z)
;
; 2D trapeze rule integration of z[*,*],
;  given on the regular grid defined by x[*], y[*]
;
;
; <- Last updated: Fri Aug 28 14:08:46 1998   -> SGK
;

; Name: UDC
;       
; Purpose:
;
;  use decomposed color model for 24 bit dispays, and backstore by IDL
;
;  ie: device, decomposed = 0, retain = 2
;
; Calling Sequence:
;
;       UDC
;

; display a 2D vector plot
;
;   vec2d, vx, vy, x, y
;
; display V = (vx, vy), for locations (x,y)
;
;   vx - x-component, 2D vector
;   vy - y-component, 2D vector
;   x  - x-location,  1D or 2D vector (optional)
;   y  - y-location,  1D or 2D vector (optional)
;
; keywords:
;
;   scale          - vector scaling                      (def = max(vx^2+vy^2))
;   factor         - additional scaling factor           (def = 1)
;   xrange, yrange - axis ranges                         (def = auto_range(*))
;   xInc, yInc     - draw vectors every x/yInc pts only  (def = 1)
;   dotSize        - specify the size of dots            (def=.5)
;   log            - flag to scale the vector length prop to LOG10(mag)
;   noDots         - flag to supress dots
;   centered       - flag to plot vector centered on (x,y) location
;                    (implies noDots=1)
;   overWrite      - draw (more) vectors on an existing plot
;   arrow          - flag, if set draw arrows
;   aWFract        - arrow width fraction  (def = .15)
;   aLFract        - arrow length fraction (def = .30)
;   noOnError      - flag, if set don't turn on `on_error, 2' statement
;
; extra keywords are passed to the first PLOT (like title, etc...)
;
; see also VECOL2D

; VEC3D,  AMP, ALPHA, BETA, X, Y, Z, $
;    SCALE = SCALE, overWrite = overWrite
; or
;
; VEC3D,  VX, VY, VZ, ALPHA, BETA, X, Y, Z, /useXYZ, $
;    SCALE = SCALE, overWrite = overWrite
;
; makes a 3d vector plot using a dummy
;    SURFACE, /SAVE 
; followed by a 
;    PLOTS, /T3D
;
; if [xyz]ranges are not set, uses SGK's AUTO_RANGE()
;
; The following keywords are supported:
;   AX, AZ, XSTYLE, YSTYLE, ZSTYLE, XRANGE, YRANGE, ZRANGE, 
;   XTITLE, YTITLE, ZTITLE, TITLE, SUBTITLE,
;   CHARSIZE

; display a 2D vector plot, using color coding
;                           (i.e.: dir. -> Hue, mag. ->  Sat.)
;
;   vecol2d, vx, vy
;
; display V = (vx, vy), on implicit equispaced gridded locations
;
;   vx - x-component, 2D vector
;   vy - y-component, 2D vector
;
; keywords:
;
;   scale            - vector scaling                    (def = max(vx^2+vy^2))
;   xrange, yrange   - axis ranges                       (def = auto_range(*))
;   xSize, ySize     - x,y sizes of the window to open
;   xOffset, yOffset - x,y offsets w/in the window
;   swFill           - swindow fill flag (when printing)
;   wno              - window number (keep current if < 0)
;   zoom             - zoom factor (accept 1 or 2 args)
;   noAxis           - set [xy]style to 5 (no axis)
;   sample           - flag to sample instead of interpol. when zooming
;   bgdImg           - background image to use as Value
;   bMIn, bMax       - bgdImg scaling (def min/max of bgdImg)
;   bWrap            - flag, if set will wrap instead of clipping bgdImg
;   hueOff           - hue offset                        (def = 0)
;   gamma            - gamma correction for Sat and Val  (def = 0.)
;   swapSV           - swap Sat and Val codification
;   log              - flag to scale Hue prop to LOG10(mag)
;   noOnError        - flag, if set don't turn on `on_error, 2' statement
;
; extra keywords are passed to the first PLOT (like title, etc...)
;
; see also VEC2D

; vHash, xRange, yRange = y, nHash = nHash, _EXTRA = extra
;
; hash the region defined by xRange[0] to xRange[1]
;
; ie:
;
;   plot, findgen(10)
;   vHash, [4, 6], nHash = 12
;
; <- Last updated: Tue Jul  2 16:37:13 2002 -> SGK

;  vline, xval, linestyle = linestyle, ls0 = ls0
;
; overplot a vertical line at xval (xval can be an array)
;
; Support all oplot keywords

; NAME:
;	WRITExPPM
;
; PURPOSE:
;	Write an image to a PPM (true-color) or PGM (gray scale) file.
;	PPM/PGM format is supported by the PMBPLUS and Netpbm packages.
;
;	PBMPLUS is a toolkit for converting various image formats to and from
;	portable formats, and therefore to and from each other.
;
; modified by SGK to force maxmal in ppm file to be 255
;
; CATEGORY:
;	Input/Output.
;
; CALLING SEQUENCE:
;
;	WRITExPPM, File, Image  ;Write a given array.
;
; INPUTS:
;	Image:	The 2D (gray scale) or 3D (true-color) array to be output.
;
; KEYWORD PARAMETERS:
;	ASCII = if set, formatted ASCII IO is used to write the image data.
;		If omitted, or set to zero, the far more efficient
;		binary IO (RAWBITS) format is used to write the image data.;
;       useMV = use maxval in image
;
; COMMON BLOCKS:
;	None.
;
; SIDE EFFECTS:
;	A file is written.
;
; RESTRICTIONS:
;	This routine only writes 8-bit deep PGM/PPM files of the standard
;	type.
;	Images should be ordered so that the first row is the top row.
;	If your image is not, use WRITE_PPM, File, REVERSE(Image, 2)
;
; MODIFICATION HISTORY:
;	Written Nov, 1994, DMS.
;   CT, RSI, August 2000: Change PRINTF to WRITEU,
;            change output to match PPM spec, add "Created by..." comment.

; NAME:
;	WRITE_MGIFS
;
; PURPOSE:
;	Write an IDL image and color table vectors to a
;	GIF (graphics interchange format) file.
;
; CATEGORY:
;
; CALLING SEQUENCE:
;
;	WRITE_GIF, File, Image  ;Write a given array.
;
;	WRITE_GIF, File, Image, R, G, B  ;Write array with given color tables.
;
;
; INPUTS:
;	Image:	The 2D array to be output.
;
; OPTIONAL INPUT PARAMETERS:
;      R, G, B:	The Red, Green, and Blue color vectors to be written
;		with Image.
; Keyword Inputs:
;	CLOSE = if set, closes any open file if the MULTIPLE images
;		per file mode was used.  If this keyword is present,
;		nothing is written, and all other parameters are ignored.
;	MULTIPLE = if set, write files containing multiple images per
;		file.  Each call to WRITE_GIF writes the next image,
;		with the file remaining open between calls.  The File
;		parameter is ignored, but must be supplied,
;		after the first call.  When writing
;		the 2nd and subsequent images, R, G, and B are ignored.
;		All images written to a file must be the same size.
;
;       LOOP = if set, add the NETSCAPE enhencement for loops (SGK hack)
;
;
; OUTPUTS:
;	If R, G, B values are not provided, the last color table
;	established using LOADCT is saved. The table is padded to
;	256 entries. If LOADCT has never been called, we call it with
;	the gray scale entry.
;
;
; COMMON BLOCKS:
;	COLORS
;
; SIDE EFFECTS:
;	If R, G, and B aren't supplied and LOADCT hasn't been called yet,
;	this routine uses LOADCT to load the B/W tables.
;
; COMMON BLOCKS:
;	WRITE_GIF_COMMON.
;
; RESTRICTIONS:
;	This routine only writes 8-bit deep GIF files of the standard
;	type: (non-interlaced, global colormap, 1 image, no local colormap)
;
;	The Graphics Interchange Format(c) is the Copyright property
;	of CompuServ Incorporated.  GIF(sm) is a Service Mark property of
;	CompuServ Incorporated. 
;
; MODIFICATION HISTORY:
;	Written 9 June 1992, JWG.
;	Added MULTIPLE and CLOSE, Aug, 1996.

; NAME:
;	WRITE_PPM
;
; PURPOSE:
;	Write an image to a PPM (true-color) or PGM (gray scale) file.
;	PPM/PGM format is supported by the PMBPLUS and Netpbm packages.
;
;	PBMPLUS is a toolkit for converting various image formats to and from
;	portable formats, and therefore to and from each other.
;
; CATEGORY:
;	Input/Output.
;
; CALLING SEQUENCE:
;
;	WRITE_PPM, File, Image  ;Write a given array.
;
; INPUTS:
;	Image:	The 2D (gray scale) or 3D (true-color) array to be output.
;
; KEYWORD PARAMETERS:
;	ASCII = if set, formatted ASCII IO is used to write the image data.
;		If omitted, or set to zero, the far more efficient
;		binary IO (RAWBITS) format is used to write the image data.
;
; COMMON BLOCKS:
;	None.
;
; SIDE EFFECTS:
;	A file is written.
;
; RESTRICTIONS:
;	This routine only writes 8-bit deep PGM/PPM files of the standard
;	type.
;	Images should be ordered so that the first row is the top row.
;	If your image is not, use WRITE_PPM, File, REVERSE(Image, 2)
;
; MODIFICATION HISTORY:
;	Written Nov, 1994, DMS.
;   CT, RSI, August 2000: Change PRINTF to WRITEU,
;            change output to match PPM spec, add "Created by..." comment.

; write_rdbfn, s
;
;  write a RDB table, ie tab separated, using the structure s
;
;   noOnerror: flag, if set won't do `on_error, 2'
;   format:    optional format array for struct
;
;  can handle arrays as elements of the structure, 
;   but not structure pointer or object
;
; <- Last updated: Fri Apr 28 10:14:44 2006 -> SGK

;  write_struct, fn, s, $
;    append = append, incremental = incremental, $
;    comments = comments
;
;    write a structure array (s) to a flat ASCII table file (fn)
;
;    can be read back with s = read_struct(fn)
;
; <- Last updated: Sat Feb 23 17:44:42 2019 -> SGK

;  data = xbin(x, y, n)
;
; input keywords:
;
;  min, max:     min/max for x-bins;                   def: min(x) and max(x)
;  nrej, xrej:   rejection params for binning in y
;                see cmp_avg                           def: no rejection
;  mrms          see cmp_avg  
;  useMedian     use median instead of average
;  yNorm         use this as normalization weights
;
; output keywords:
;
;  cnts:         return the no. of values in that bin (after any rejection)
;
; output:
;
;  data[0,*] = x value for the bin
;  data[1,*] = binned value of y
;  data[2,*] = rms(binned value)
;
; <- Last updated: Tue May 24 10:06:27 2016 -> SGK

;
; xBlink, img1, img2
;
;    widget to blink two (byte) images
;
; keywords:
;
;  true  = ie flag for tv, true = true
;  speed = no times per second (Hz, def 5)
;  sMin  = min speed (Hz, def 1)
;  sMax  = max speed (Hz, def 15)
;  title = title to put
;
; <- Last updated: Fri Mar 24 15:53:24 2006 -> SGK

;  xbOPlot, x, y, nBins, nRej = nRej, $
;           useMedian = useMedian, xbin = xb, xmin = xmin, xmax = xmax, $
;           xLog = xLog, yLog = yLog, psym = psym, linestyle = linestyle, $
;           noEB = noEB, _extra = extra 
;
;   over-plot binned values (w/ EB)
;  --------------- -
;= XBOPLOT         - over-plot binned values
; ---------------------------------------------------------------------------

; Name:
;
;   XFontSel
;
; Purpose:
;
;  select an X font, but checks first if !D.name is 'X'
;  
; Calling sequence:
;
;   SetXFont, fontName
;
; Input:
;
;   fontName=  - name of valid X font (as per xlsfonts, or xfontsel)
;
; Keywords:
;
;   RESET   - flag, if set reset from to vector font (size equiv to 8x13)
;   VERBOSE - flag, if set chat about what it's doing
;   DEFCMD  =  - command to execute if no fontName is provided
;                       default value is '/usr/local/X11/bin/xfontsel'

;   sz = XGetScreenSize(noScreens=n)
;
;  return the screen(s) size in 2-elements array
;  faster then get_screen_size, but X-Windows only (uses xdpyinfo)
;

; NAME:
;	XMANAGER
;
; PURPOSE:
;	Provide management for widgets client applications created using IDL.
;
; CATEGORY:
;	Widgets.
;
; CALLING SEQUENCE:
;	XMANAGER [, Name, ID]
;
; OPTIONAL INPUTS:
;	NAME:	A string giving the name of the application that is being
;		registered.
;  
;	ID:	The widget ID of the top level base of the new client.
;
; KEYWORD PARAMETERS:
;	BACKGROUND:
;		-------------------------------------------------------------
;		| PLEASE NOTE: This keyword is OBSOLETE. It's functionality |
;		| is provided by the TIMER keyword to the WIDGET_CONTROL    |
;		| procedure.                                                |
;		-------------------------------------------------------------
;
;	CATCH: If TRUE, tells XMANAGER to use CATCH when dispatching
;		widget events. If FALSE, CATCH is not used and execution
;		halts on error. The default is TRUE. If CATCH is specified,
;		the internal state of XMANAGER is updated and it returns
;		immediately without taking any further action. CATCH
;		is only effective if XMANAGER is blocking to dispatch
;		errors. If active command line event dispatching is in
;		use, it has no effect.
;
;	CLEANUP: This keyword contains a string that is the name of the
;		routine called when the widget dies.  If not specified,
;		no routine is called.  The cleanup routine must accept one 
;		parameter which is the widget id of the dying widget. This
;		routine is set as the KILL_NOTIFY routine for the widget.
;
;	EVENT_HANDLER: The name of the event handling routine that is to be
;		called when a widget event occurs in the registered
;		application. If this keyword is not supplied, the Xmanager
;		will construct a default name by adding the "_EVENT" suffix
;		to the NAME argument. See below for a more detailed
;		explanation.
;
;	GROUP_LEADER: The widget id of the group leader for the application
;		being registered.  When the leader dies, all widgets that have
;		that leader will also die.
;
;		For example, a widget that views a help file for a demo 
;		widget would have that demo widget as it's leader.  When
;		the help widget is registered, it sets the keyword 
;		GROUP_LEADER to the widget id of the demo widget. If 
;		the demo widget is destroyed, the help widget led by 
;		the it would be killed by the XMANAGER.
;
;	JUST_REG:	
;		This keyword tells the manager to just register the widget
;		but not to start doing the event processing.  This is useful
;		when you want to register a group of related top level widgets
;		but need to regain control immediately afterwards.
;
;		NOTE: JUST_REG does not do the same thing as NO_BLOCK. This is
;		explained in detail below under "SIDE EFFECTS".
;
;	 MODAL:
;		--------------------------------------------------------------
;		| PLEASE NOTE: This keyword is OBSOLETE. It's functionality  |
;		| is provided by the MODAL keyword to the WIDGET_BASE        |
;		| procedure.                                                 |
;		--------------------------------------------------------------
;
;		When this keyword is set, the widget that is being registered
;		traps all events and desensitizes all the other widgets.  It
;		is useful when input from the user is necessary before
;		continuing. Once the modal widget dies, the others are
;		resensitized and the normal event processing is restored.
;		XMANAGER is therefore using sensitivity to provide the
;		illusion of modality. The WIDGET_BASE keyword is a newer
;		IDL feature that provides the real thing.
;
;	NO_BLOCK: If set, tells XMANAGER that the registering client
;		does not require XMANAGER to block if active command line
;		event processing is available. If active command line
;		event processing is available *AND* every current XMANAGER
;		client specifies NO_BLOCK, then XMANAGER will not block
;		and the user will have access to the command line while
;		widget applications are running.
;
;		NOTE: NO_BLOCK does not do the same thing as JUST_REG. This is
;		explained in detail below under "SIDE EFFECTS".
;
; OUTPUTS:
;	No outputs.
;
; COMMON BLOCKS:
;	MANAGED
;	XMANAGER_LOCAL:
;		Common blocks used for module state maintenance. These common
;		blocks are considered private to this module and should not
;		be referenced outside RSI supplied routines. They are
;		subject to change without notice.
;	
;
; SIDE EFFECTS:
;
;    JUST_REG vs NO_BLOCK
;    --------------------
;       Although their names imply a similar function, the JUST_REG and
;	NO_BLOCK keywords perform very different services. It is important
;	to understand what they do and how they differ.
;
;       JUST_REG tells XMANAGER that it should simply register a client
;	and then return immediately. The result is that the client becomes
;	known to XMANAGER, and that future calls to XMANAGER will take this
;	client into account. Therefore, JUST_REG only controls how the
;	registering call to XMANAGER should behave. The registered client
;	can still be registered as requiring XMANAGER to block by not setting
;	NO_BLOCK. In this case, future calls to XMANAGER will block.
;
;	NO_BLOCK tells XMANAGER that the registered client does not
;	require XMANAGER to block if the command processing front end
;	is able to support active command line event processing (described
;	below). XMANAGER remembers this attribute of the client until
;	the client exits, even after the call to XMANAGER that registered the
;	client returns. NO_BLOCK is just a "vote" on how XMANAGER should
;	behave. The final decision is made by XMANAGER by considering the
;	NO_BLOCK attributes of all of its current clients as well as the
;	ability of the command front end in use to support the active command
;	line.
;
;    Blocking vs Non-blocking
;    ------------------------
;	The issue of blocking in XMANAGER requires some explanation.
;	IDL places incoming widget events into a queue of pending events.
;	The only way to get these events processed and dispatched is to
;	call the WIDGET_EVENT function. Arranging for WIDGET_EVENT to be
;	called properly is the primary job of XMANAGER. XMANAGER offers
;	two different modes of operation:
;
;	    - The first (outermost) XMANAGER processes events by calling
;	      WIDGET_EVENT as necessary until no managed clients remain on
;	      the screen. This is referred to as "blocking", because XMANAGER
;	      does not return to the caller until it is done, and the IDL
;	      command line is not available.
;
;	    - XMANAGER does not block, and instead, the part of IDL
;	      that reads command input also watches for widget events
;	      and calls WIDGET_EVENT as necessary while also reading
;	      command input. This is referred to as "non-blocking" or
;	      "active command line" mode.
;
;	The default is to block. However, if every currently active
;	application specified the NO_BLOCK keyword to XMANAGER, non-blocking
;	mode is used, if possible.
;
;	There are currently 5 separate IDL command input front end
;	implementations:
;
;		- Apple Macintosh IDE
;		- Microsoft Windows IDE
;		- Motif IDE (Unix and VMS)
;		- Unix plain tty
;		- VMS plain tty
;
;	Except for the VMS plain tty, all of these front ends are able to
;	support the non-blocking active command line. VMS users can have
;	an active command line by using the IDLde interface. The decision
;	on whether XMANAGER blocks to process widget events is determined
;	by the following rules, in order of precedence:
;
;	    - Use of the MODAL keyword will cause XMANAGER to block.
;	    - Setting JUST_REG to 1 ensures that XMANAGER will not block.
;	    - If using the VMS plain tty interface, XMANAGER will block.
;	    - If none of the previous rules apply, XMANAGER will block
;	      if any of its currently active clients were registered without
;	      specifying NO_BLOCK. If NO_BLOCK is specified for every client,
;	      XMANAGER will not block and will instead return and allow
;	      active command line processing to take place.
;
;	When possible, applications should set the NO_BLOCK keyword.
;	This allows the IDL command line to be active while events are
;	being processed, which is highly desirable.
;
;
; RESTRICTIONS:
;	The implementation of XMANAGER may change in the future. Details
;	of its internal implementation must not be relied upon --- only
;	its external definition can be considered stable.
;
;	XMANAGER uses several undocumented features provided by the
;	internal WIDGET routines. These features are private to RSI, and
;	are not guaranteed to remain in IDL or to remain unchanged. They
;	exist only to support XMANAGER and should not be used elsewhere:
;
;		WIDGET_CONTROL, /XMANAGER_ACTIVE_COMMAND
;		WIDGET_CONTROL, /MODAL
;		WIDGET_EVENT,   /BREAK_ON_EXPOSE
;		WIDGET_EVENT,   /EVENT_BREAK
;		WIDGET_EVENT,   /XMANAGER_BLOCK
;		WIDGET_INFO,    /XMANAGER_BLOCK
;
;	These features are undocumented because they are not considered
;	permanent. Research Systems reserves the right to remove or alter
;	these features at any time.
;
; EXAMPLE USE:
;	To create a widget named Example that is just a base widget with a done
;	button using the XMANAGER you would do the following:
;
;
;	;------ first - the event handler routine ------;
;
;     PRO example_event, ev			;this is the routine that 
;						;deals with the events in the 
;						;example widget.
;	
;	WIDGET_CONTROL, ev.id, GET_UVALUE = uv	;the uservalue is retrieved 
;						;from the widget where the 
;						;event occurred
;
;	if(uv eq 'DONE') then $			;if the event occurred in the
;	  WIDGET_CONTROL, ev.top, /DESTROY	;done button then kill the 
;     END					;widget example
;
;
;	;------ second - the main routine ------;
;
;     PRO example				;this is the main routine
;						;that builds the widget and
;						;registers it with the Xmanager
;	
;	base = WIDGET_BASE(TITLE = 'Example')	;first the base is created
;	
;	done = WIDGET_BUTTON(base, $		;next the done button is 
;			     TITLE = 'DONE', $	;created and it's user value
;			     UVALUE = 'DONE')	;set to "DONE"
;
;	WIDGET_CONTROL, base, /REALIZE		;the widget is realized
;
;	XManager, 'example', base		;finally the example widget
;						;is registered with the 
;						;Xmanager
;     END
;
;	notes:	First the event handler routine is listed.  The handler
;		routine has the same name as the main routine with the 
;		characters "_event" added.  If you would like to use another
;		event handler name, you would need to pass it's name in as
;		a string to the EVENT_HANDLER keyword.  Also notice that the
;		event routine is listed before the main routine.  This is 
;		because the compiler will not compile the event routine if
;		it was below the main routine.  This is only needed if both
;		routines reside in the same file and the file name is the same
;		as the main routine name with the ".pro" extension added.
;
;
; PROCEDURE:
;	When the first widget is registered, initialize the lists and then 
;	start processing events.  Continue registering widgets and dispatching
;	events until all the widgets have been destroyed.  When a widget is 
;	killed, destroy all widgets that list the destroyed widget as their 
;	leader, if any.
;
; RELATED FUNCTIONS AND PROCEDURES:
;	XREGISTERED, XMTOOL
;
; MODIFICATION HISTORY: Written by Steve Richards, November, 1990
;	SMR, Mar,  1991	Added a cleanup routine keyword to allow dying
;	    widgets to clean themselves up when dying.
;	SMR, May,  1991 Fixed a bug found by Diane Parchomchuk where an error
;	    occurred when registering a widget  ight after destroying another.
;	SMR & ACY, July, 1991
;	    Fixed a bug found by Debra Wolkovitch where lone widgets being
;	    destroyed and new ones created caused problems.
;	SMR, Sept, 1991	Changed cleanup to use the new WIDGET_INFO routine.
;	SMR & ACY, Oct,  1991
;	    Fixed a bug where a background event that unregistered itself
;	    after a time would result in an XMANAGER error.
; 	SMR, Mar.  1992	Changed XMANAGER to use enhanced widget functions for
;	    event processing.
;	SMR, Nov.  1992 Changed modal widget handling allowing nesting of
;	    modal widgets.  The first modal desensitizes all current widgets
;	    and subsequent modals only desensitize the modal that called them.
;	JIY, Apr.  1993 Changed modal widget handling process to not run the
;	    event loop for nested modal widgets. Allowed for multiple modal
;	    widgets.
;	AB & SMR, 17 November 1993
;	    Added ID validity checking to desensitizing of modal widgets to
;	    fix a bug where already dead widgets were being accessed.
;	DJE, Feb, 1995
;	    Made it so that non-modal widgets created from a modal widget have
;	    events processed in the modal widget's event loop. This fixes a
;	    bug where xmanager wouldn't return immediately if there was a
;	    modal widget somewhere in the nesting, even though a non-modal
;	    widget was being added. The nesting level could get _very_ deep.
;	DJE, Apr 1995
;	    Pass a local variable to WIDGET_EVENT in the MODAL case, instead
;	    of passing the common block variable modalList. This avoids a bug
;	    where modalList gets changed behind WIDGET_EVENT's back.
;	DJE, Apr 1996
;	    Changes for handling asynchronous widget event dispatching.
;	    Complete rewrite. Background tasks are no longer supported. The
;	    MODAL keyword is now obsolete. Added CATCH and BLOCK keywords.
;	AB, May 1996
;	    Made changes so that XMANAGER always blocks under VMS with the
;	    non-GUI interface. This is due to the fact that the SMG$ system
;	    routines used by IDL in the plain tty case cannot support
;	    interleaving of X events with tty input.
;	AB, 9 January 1997
;	    Changed the meaning of the CATCH keyword so that catching is the
;	    default. Removed BLOCK and replaced with NO_BLOCK. Switched
;	    default action back to blocking from unblocking based on feedback
;	    from the IDL 5 beta. Added the ability to block only as long as a
;	    client without NO_BLOCK is running, and then revert to the active
;	    command line.
;	AB, 10 February 1997
;	    Cleaned up code to make it easier to understand and maintain.
;	    Also cleaned up the distinction between real modality (MODAL
;	    keyword to WIDGET_BASE) and XMANAGER's older fake modality
;	    (MODAL keyword to XMANAGER), and fixed bugs in the current
;	    implementation of fake modality.

; XPLOT_IO, X, Y
;
;   logarithmic plot x vs y, works when y is not always positive
;
; Keywords:
;
;   ymin = set plot minimun
;   ymax = set plot maximun
;   yxmar = Y extra margin, default 0.1
;
; accept also:
;
;   xstyle, xrange, psym, linestyle,xtitle, ytitle, title

; NAME:
;       XSGKLCT
; PURPOSE:
;       A graphical interface to the SGKLCT procedure.
;       XSGKLCT displays the current color map and provides
;       an array of buttons, one per availible predefined color
;       table. Using the mouse to press these buttons causes
;       the corresponding color map to be loaded.
; CATEGORY:
;       Widgets
; CALLING SEQUENCE:
;       XSGKLCT
; INPUTS:
;       None.
; Keyword:
;    oo = {window:oWin, view:oView, image:oImg}
;       if wants to associate IDLGr redraw

; NAME:
;       XSGKLCT
; PURPOSE:
;       A graphical interface to the SGKLCT procedure.
;       XSGKLCT displays the current color map and provides
;       an array of buttons, one per availible predefined color
;       table. Using the mouse to press these buttons causes
;       the corresponding color map to be loaded.
; CATEGORY:
;       Widgets
; CALLING SEQUENCE:
;       XSGKLCT
; INPUTS:
;       None.
; KEYWORDS:
;       GROUP = The widget ID of the widget that calls Xsgklct.  When 
;               this ID is specified, a death of the caller results in a 
;               death of Xsgklct
;       SILENT - Normally, no informational message is printed when
;               a color map is loaded. If this keyword is present and
;               zero, this message is printed.
;       DIR =  - the directory specification where the color maps
;                        reside (def: $COLMAP_DIR, 
;                                     otherwise '/home/sylvain/colmap/')
;       EXT =  - the extension name of the colr maps (def: '.clr')
;       NCOL = no of columns to use for the names list (def: 2)
;       LMAX = max no of colmap names to make visible in the list (def: 16)
; OUTPUTS:
;       None.
; COMMON BLOCKS:
;       None.
; SIDE EFFECTS:
;       One of the predefined color maps may be loaded.
; RESTRICTIONS:
;       This routine uses SGK's SGKLCT procedure to do the actual work.
; MODIFICATION HISTORY:
;       24, August, 1990, Written by AB, RSI.
;       March 1, 1992  Mark Rivers added Reverse Table to options menu.
;	7/92, DMS, Added new color tables (allows more than 16).
;	9/92, ACY, Add FILE keyword.
;       9/93, SGK, Took IDL's distribution XLOADCT and modified it
;       Sep  9 1998 look for env. var. COLMAP_DIR

;  s = xsmooth(x,n)
;
;  like IDL's smooth, but does smooth by a variable n at the edges
;
; <- Last updated: Fri Aug 28 14:10:29 1998 -> SGK
;

; xwdel, wno:
;   delete that wno
;

; xwin, [wno]: 
;
; wrapper around window to open a 1100x920 (or 900x850) 'big' window.
;  depending on display screen size.
;  using widget, not window itself. Add print and save options
;
; additional input keywords:
;
;  fScr      - fraction of screen to cover (def: .85)
;  wide      - set width only  for a 'wide' window
;  tall      - set height only for a 'tall' window
;  landscape - set size to 1000 x  750 (11"x8.5" - 1"x1" @ 10pxl/inch)
;  portrait  - set size to  750 x 1000 
;  pc8       - call pc8 (set visual to 8bit pseudocolor)
;  udc       - call UDC (use decomposed color model)
;  plct      - call plct (set color map to 16 basic color), imply pc8
;  csz       - set !p.charsize = csz
;
; <- Last updated: Mon Nov 10 15:46:44 2008 -> SGK

; xwset, wno: 
;   wset, wno for xwin
;

;
;    xylabel, x, y, string
;
;  wrapper for
;
;    xyouts, x, y, label(string)
;               
; support all keywords for XYOUTS, as well as:
;
;   relative: if set, the values of {x, y} are relative value [0, 1] to the
;             current plotting window.
;        
; <- Last updated: Wed Sep  9 11:29:46 1998 -> SGK
;

; data = zbin2D(x, y, z, nx, ny)
;        where x=x[*], y=y[*], z=z[*]
;
; input keywords:
;
;  xmin, xmax:   min/max for x-bins;                   def: min(x) and max(x)
;  ymin, ymax:   min/max for y-bins;                   def: min(y) and max(y)
;  nrej, xrej:   rejection params for binning in y
;                see cmp_avg                           def: no rejection
;
; output:
;
;  data[*,*,0] = x value for the bin
;  data[*,*,1] = y value for the bin
;  data[*,*,2] = binned array
;  data[*,*,3] = rms(binned values)
;
; output keywords:
;
;  cnts[*,*,0]: return the no. of values in the resp. bin
;  cnts[*,*,1]: return the no. of values kept for binning in the resp. bin
;
; <- Last updated: Tue Mar 25 16:19:15 2003 -> SGK

; zoom an array by factor(s) n1, [n2]
;
; za = zoom(a, n1 [, n2],/sample)
; zor a = zoom(a, [n1, n2])
;
; ie, tvscl,zoom(a,2)  equivalent to tvscl, zoom(a,2,2)
; or, tvscl,zoom(a,2,3)
;
; use /sample to prevent interpolation
; preserve symmetry in an odd sized array

; zoom an array to be n1xn2 pixels
;
; za = zoomto(a, n1, n2 [,/sample, [,/exact]] )
;
; <- Last updated: Fri Nov  2 12:20:25 2012 -> SGK
;