array procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

INDX2DIM

[List of Routines]
 NAME:
       INDX2DIM

 PURPOSE:
       Converts one-dimensional indices into multidimensional indices.

 CALLING SEQUENCE:
       Result = INDX2DIM(Array, Index_Array, [, 
       N_DIMENSIONS=variable][, DIMENSIONS=variable] )

 INPUTS:
       ARRAY: a multidimensional array 
       INDEX_ARRAY: array of one-dimensional indices in ARRAY

 OUTPUTS:
       Returns an N_DIMENSIONS by N_elements(index_array) array with
       the multidimensional array indices corresponding to each 
       one-dimensional array index stored in index_array.  If any of
       the input one-dimensional indices are greater than the number
       of total elements in the input array (or less than zero) then
       the multidimensional index returned for each such out-of-range
       index will be a row of -1L.

 OPTIONAL OUTPUTS:
       N_DIMENSIONS = the number of dimensions of ARRAY
       DIMENSIONS = the dimensions of ARRAY; a vector of length N_DIMENSIONS

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       None.

 EXAMPLE:
       Make a 4-D array...
       IDL> x = indgen(2,3,4,5)

       Use WHERE to get the 1-D indices for where array is multiple
       of 25...
       IDL> indx = where(x mod 25 eq 0, nindx)

       Return the multidimensional array indices 
       IDL> dim = indx2dim(x,indx,N_DIMENSIONS=ndim,DIMENSIONS=dims)

       Check the dimensions of the array x...
       IDL> print, dims
                  2           3           4           5

       Check the size of the returned multidimensional array; it should
       be N_DIMENSIONS by N_elements(indx)...
       IDL> help, ndim, nindx, dim
       NDIM            LONG      =            4
       NINDX           LONG      =            5
       DIM             LONG      = Array[4, 5]

       Finally, what are the multidimensional indices...
       IDL> print, dim
                  0           0           0           0
                  1           0           0           1
                  0           1           0           2
                  1           1           0           3
                  0           2           0           4

 NOTES:
       This routine now exists in IDL 6.0 and is named
       ARRAY_INDICES(). However, if you pass in an index that is out
       of bounds, ARRAY_INDICES() crashes and gives a warning.

       The returned array has size N_DIMENSIONS by N_elements(index_array).
       This is because the user will most likely be using a loop to access
       each of the returned multidimensional indices: it is faster to loop
       over the second dimension of the returned 2-D array. E.g., in the
       above example, you would access each of the multidimensional
       indices like this...

       IDL> for i = 0, nindx-1 do print, dim[*,i]

       We are accessing each row, which is faster than accessing each
       column, hence my choice for the orientation of the returned array.

 MODIFICATION HISTORY:
   15 Feb 2004  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/array/indx2dim.pro)


astro procs

astro procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

CHDOPPLER

[Next Routine] [List of Routines]
 NAME: chdoppler
       
 PURPOSE: 
       computes the projected velocity of the telescope wrt 
       four coordinate systems: geo, helio, bary, lsr.
	negative velocities mean approach

       the standard LSR is defined as follows: the sun moves at 20.0 km/s
       toward ra=18.0h, dec=30.0 deg in 1900 epoch coords

 CALLING SEQUENCE:
        result = chdoppler( ra, dec, julday, obspos_deg=obspos_deg, path=path, light=light)

 INPUTS: fully vectorized...
       ra[n] - the source ra in decimal hours, equinox 2000
       dec[n] - the source dec in decimal hours, equinox 2000
	julday[n] - the julian day

 KEYWORDS:
	/obspos_deg: observatory [lat, wlong] in degrees. default is arecibo.
	/path - path for the station file. obspos_deg takes precedence.
       /light - returns the velocity as a fraction of c

 NOTE:
	if path is not specified, default long, lat are arecibo. if
path is specified, it reads long, lat from the file
		path + .station

 OUTPUTS: 
       program returns the velocity in km/s, or as a faction of c if
       the keyword /light is specified. the result is a 4-element
	vector whose elements are [geo, helio, bary, lsr]. quick
	comparison with phil's C doppler routines gives agreement to 
	better than 100 m/s one arbitrary case.

 REVISION HISTORY: carlh 29oct04. 
	from idoppler_ch; changed calculation epoch to 2000
	19nov04: correct bad earth spin calculation
	7 jun 2005: vectorize to make faster for quantity calculations.

(See /dzd2/heiles/idl/gen/astro/chdoppler.pro)


DOPPLER

[Previous Routine] [Next Routine] [List of Routines]
NAME: DOPPLER

PURPOSE:
	GIVE DOPPLER VELOCITY KM/S WITH RESPECT TO BARYCENTER AND ALSO LSR. 

CALLING SEQUENCE:
	doppler, ra_hrs, dec_deg, equinox, julday, obslongitude, obslatitude, $
	v_barycen, v_lsr

INPUTS:
	RA, DEC ARE OF THE SPECIFIED EQUINOX. UNITS ARE DECIMAL HOURS, DEGREES
	EQUINOX: EQUINOX OF THE RA, DEC, IN YEARS. E.G. 2000.	
	JULDAY: THE JULIAN DAY IN DBL PRECISION, TELLS THE EXACT TIME.
	OBSLONGITUDE, OBSLATITUDE: OBSERVER'S LONGITUDE, LATITUDE IN DEGREES.
		LONGITUDE IS WEST LONG, E.G. CALIFORNIA IS +122.
		IF LATITUDE LT ZERO, IT GIVES VELOCITY OF EARTH'S CENTER.

OUTPUTS:
	V_BARYCEN IS VELOCITY WRT BARYCENTER AND V_LSR IS WRT LSR. 
		NEGATIVE VELOCITIES MEAN APPROACH, OR
		HIGHER FREQUENCIES FROM THE DOPPLER SHIFT

COMMENTS, RESTRICTIONS, ETC:
	THE LSR IS BASED ON THE CLASSIC RADIO ASTRONOMY ONE, 
		20 KM/S TOWARDS (RA,DEC)_1900 = (18:00, 30:00)
	WE NEGLECT THE OBSERVER'S HEIGHT ABOVE SEA LEVEL. THIS ISN'T
		GOOD FOR HIGH PLACES LIKE MAUNA KEA!
	ACCURACY SHOULD BE 1 M/S. BASED ON GSFC BARYVEL.

TO COMPUTE JULDAY, YOU CAN USE JDCNV. EXAMPLE: GMT 5.5 HRS ON 15-FEB-1994,
	JDCNV, 1994, 2, 15, 5.5, JULDAY

(See /dzd2/heiles/idl/gen/astro/doppler.pro)


EQ2AZ

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       EQ2AZ

 PURPOSE:
       To convert between the HOUR ANGLE-DECLINATION and AZIMUTH-ZENITH 
       ANGLE coordinate systems.

 CALLING SEQUENCE:
       EQ2AZ, ha, dec, az, za, latitude [, /REVERSE]

 INPUTS:
       latitude  - the latitude (a scalar) of the observatory, measured 
                   in decimal degrees

 KEYWORD PARAMETERS:
       /REVERSE : if this keyword is set, the program takes the azimuth 
                  and zenith angle as inputs and returns the hour angle 
                  and the declination.  The default behavior, as the module 
                  name suggests, is to return the azimuth and zenith angle 
                  given the hour angle and declination.

 INPUTS OR OUTPUTS (DEPENDING ON /REVERSE KEYWORD) :
       ha  - hour angle, measured in decimal hours; scalar or array
       dec - declination, measured in decimal degrees; scalar or array
       az  - azimuth, measured in decimal degrees; scalar or array
       za  - zenith angle (the complementary angle to the elevation), 
             measured in decimal degrees; scalar or array

 COMMON BLOCKS:
       None.

 RESTRICTIONS:
       Hour angle must be given in decimal hours.  Declination, azimuth,
       zenith angle, and latitude must be given in decimal degrees.

 EXAMPLE:
       Find the azimuth and zenith angle of Altair [RA (J2000): 19 50 47 
       Dec (J2000): 08 52 06] at LST 19h at Arecibo [LONG: 66 45 10.8
       LAT: 18 21 14.2]

       IDL> eq2az, 19.0-ten(19,50,47), ten(08,52,06), az, za, $
       IDL> ten(18,21,14.2)
       IDL> help, az, za
       AZ              DOUBLE    =        125.90073
       ZA              DOUBLE    =        15.549609

 NOTES:
       Went through pain to assure that if a scalar is input, a scalar 
       is returned, but even more pain to allow multi-dimensional
       arrays to be input (and to make the output have the same 
       dimensions!) Also, if inputs are double precision, the calculations 
       will be done in double precision.  The azimuth is returned in the 
       range 0 -> 360 degrees.

 MODIFICATION HISTORY:
       20 May 2004  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/astro/eq2az.pro)


EQTOAZ -- CONVERT HA, DEC TO AZ, ZA OR VICE VERSA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
eqtoaz -- CONVERT HA, DEC TO AZ, ZA or vice versa
CONVERT HA, DEC TO AZ, ZA IF DIRECTION=+1
CONVERT AZ, ZA TO ZA, DEC IF DIRECTION=-1
HA, DEC ARE IN DECIMAL HRS, DEG
AZ, ZA ARE IN DECIMAL DEG, DEG

IN COMMON ANGLESTUFF, OBSLONG AND OBSLAT ARE ASSUMED TO BE IN DEGREES.

(See /dzd2/heiles/idl/gen/astro/eqtoaz.pro)


LDS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       LDS
     
 PURPOSE:

     
 EXPLANATION:

     
 CALLING SEQUENCE:

     
 INPUTS:

     
 OPTIONAL INPUTS:

     
 OUTPUTS:


 OPTIONAL OUTPUTS:


 KEYWORDS:


 COMMON BLOCKS:


 SIDE EFFECTS:


 RESTRICTIONS:


 PROCEDURES CALLED:
       PLOTSPECTRUM
       ZOOMIN
       AVERAGE
       TZOOMIN
       FITSPEC
       PS_SPEC_EVENT
       PS_SPEC
       SELECT_EVENT
       SELECT

       ROUNDTOHALF
       VTOBIN

       GETMEAN
       CUTOFF
       MODEL
       INDIPLOT
       CLEAR
       FITLDS
       EDGECORRECTION
       GFIT
       GCURV

 EXAMPLE:


 NOTES:


 RELATED PROCEDURES:


 MODIFICATION HISTORY:
       Written Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/astro/lds.pro)


LSRVEL -- GIVE LSR VELOCITY TOWARDS AN RA, DEC

[Previous Routine] [Next Routine] [List of Routines]
NAME:
LSRVEL -- give LSR velocity towards an ra, dec

PURPOSE:
	GIVE THE COMPONENT OF LSR VELOCITY TOWARDS THE GIVEN ELL, BEE
	'LSR' MOVES WITH 20.000 KM/S TOWARDS ra1900, dec1900 = 18.000, 30.000

CALLING SEQUENCE:
	LSRVEL, RA_EPOCH, DEC_EPOCH, EQUINOX, VLSR

INPUTS:
	RA_EPOCH: the R.A. of the position, DECIMAL HOURS.
	DEC_EPOCH, THE DEC IN DECIMAL DEGREES.
	EQUINOX: THE EQUINOX OF THE POSITIONS, E.G. 2000.

OUTPUTS:
	DELVLSR: the velocity in the LSR frame.

HISTORY:
	Written by Carl Heiles. 12 JUN 2000.

IF YOU NEED TO CONVERT FROM GALACTIC TO EQUATORIAL BEFORE ENTERING THIS:
CONVERT INPUT GALACTIC COORDS TO 1900 EPOCH EQUATORIAL COORDS...
	glactc, ra1900, dec1900, 1900.0, ell, bee, 1

(See /dzd2/heiles/idl/gen/astro/lsrvel.pro)


MAKE_LDS_CUBE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       MAKE_LDS_CUBE

 PURPOSE:
       To make an (l,b,v) cube of a subset of the Leiden/Dwingeloo Survey 
       of Galactic neutral hydrogen.

 CALLING SEQUENCE:
       make_lds_cube, lcen, bcen, dl, db [, VRANGE=[min,max]] 
                      [, FILENAME=string]

 INPUTS:
       lcen - central Galactic longitude of cube [degrees]
       bcen - central Galactic latitude of cube [degrees]
       dl - the half-width of the cube in the longitude direction[degrees]
       db - the half-width of the cube in the latitude direction [degrees]

 KEYWORD PARAMETERS:
       VRANGE = 2-element vector with minimum and maximum VLSR velocities 
                [km/s] in the cube.  Default is to use entire velocity
                range.
       FILENAME = name of the output FITS file.  Default is to write to a
                  file named lds_cube.fits in the current working directory.

 OUTPUTS:
       None.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       A FITS cube is written.

 PROCEDURES CALLED:
       TABINV, FITS_ADD_AXIS_PAR

 EXAMPLE:
       IDL> make_lds_cube, 90, 0, 30, 10, VRANGE=[-100,100]

 MODIFICATION HISTORY:
       15 Sep 2004  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/astro/make_lds_cube.pro)


MODANGLE360 -- CONVERT ANGLES TO THE INTERVAL 0 TO 360 DEG.

[Previous Routine] [Next Routine] [List of Routines]
NAME:
modangle360 --  CONVERT ANGLES TO THE INTERVAL 0 TO 360 DEG.
 CONVERT ANGLES TO THE INTERVAL 0 TO 360 DEG.
 ALL ANGLES ARE IN DEGREES.
 if negpos is set, interval is -180 to 180

(See /dzd2/heiles/idl/gen/astro/modangle360.pro)


SPHERICAL1_TO_SPHERICAL2

[Previous Routine] [Next Routine] [List of Routines]
NAME
spherical1_to_spherical2 -- CONVERTS LONGITUDE AND LATITUDE between 2 systems

purpose:
CONVERTS LONGITUDE AND LATITUDE IN SYSTEM 1 TO THOSE IN SYSTEM 2
USES THE ROTATION MATRIX RTOT
ALL ANGLES ARE IN ***DEGREES***.
VECTORIZED BUT REUTNRS ALL INPUTS IN 1-D.

(See /dzd2/heiles/idl/gen/astro/spherical1_to_spherical2.pro)


VTOBIN

[Previous Routine] [List of Routines]
 NAME:
   vtobin
     
 PURPOSE:
   Finds the bin number(s) in a velocity vector closest to some v.
     
 CALLING SEQUENCE:
   bin = vtobin(vlsr, v)
     
 INPUTS:
   vlsr : velocity vector
   v    : velocity or velocities whose corresponding bins you want
     
 REVISION HISTORY:
   17-Nov-2000 Written T. Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/astro/vtobin.pro)


color procs

color procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

BGFILL

[Next Routine] [List of Routines]
 NAME:
       BGFILL
     
 PURPOSE:
       Fills the background of a plot window with a specified color.
     
 CALLING SEQUENCE:
       BGFILL, BGCOLOR
     
 INPUTS:
       BGCOLOR - Color table index (8-bit color) or 24-bit color
                 index of the color with which you would like to 
                 fill the background.

 OUTPUTS:
       None.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
        Display device is filled with the input color.

 RESTRICTIONS:
       The /NOERASE keyword MUST be sent to any plotting routine that
       you call after using this routine!
       This causes problems if you are using !p.multi values
       other than zero.  See example below for how to do this.

 EXAMPLE:
       Fill the background with the color in the 0th index of the
       color table, then plot a line:

        IDL> bgfill, 0
        IDL> plot, findgen(30), /NOERASE

       In order to use !p.multi with this method, you must explicitly
       place each plot with a !p.multi assignment (since you must include 
       the /NOERASE keyword when starting a new plot!)  Remember the
       first element of !p.multi is the number of empty sectors remaining
       on the page and the default order of placement (the 5th element of
       !p.multi) is left-right and top-bottom. Here's an example:

        IDL> bgfill, 0
        IDL> !p.multi=[4,2,2]
        IDL> plot, findgen(30), /NOERASE
        IDL> !p.multi=[3,2,2]
        IDL> plot, findgen(30)^2, /NOERASE
        IDL> !p.multi=[2,2,2]
        IDL> plot, findgen(30)^3, /NOERASE

 NOTES:
       Note that in order for this to work, you need to set the
       /NOERASE keyword to any plotting routine you call directly
       after using this routine!

 MODIFICATION HISTORY:
       01 Mar 2002  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/color/bgfill.pro)


COLOR24

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       COLOR24

 PURPOSE:
       Return the 24-bit color index for an RGB triplet.

 CALLING SEQUENCE:
       RESULT = COLOR24(R, G, B)

 INPUTS:
       R - 8-bit red color index.
       G - 8-bit green color index.
       B - 8-bit blue color index.

 KEYWORD PARAMETERS:
       None.

 OUTPUTS:
       RESULT - the 24-bit color index for the RGB triplet.

 COMMON BLOCKS:
       None.

 EXAMPLE:
       Return the 24-bit color index for pure green:

       IDL> print, color24(0,255,0)

 MODIFICATION HISTORY:
   02 Mar 2003  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/color/color24.pro)


CT_FIDDLE -- FIDDLE INDEPENDENTLY R,G,B COLORTABLES IN DIRECT COLOR.

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       ct_fiddle -- fiddle independently r,g,b colortables in direct color.

 PURPOSE:
       To fiddle with the color table.  The user can select which channels 
       of the color table to manipulate.  The user can change the gamma 
       correction and the range of the color table indices.

 CALLING SEQUENCE:
	CT_FIDDLE [, CHANNELS] [, LOW=value] [, HIGH=value] [,
	GAMMA=value] [, GRANGE=[min,max]]

 OPTIONAL INPUTS:
       CHANNELS: A string argument.  CHANNELS sets which color
                 channels ('R' for red, 'G' for green, 'B' for blue) 
                 will be manipulated in the color table.  The user
                 can manipulate one, two or all channels.  To fiddle
                 with the red and blue channels simultaneously,
                 set channels equal to the string 'rb'.

 KEYWORD PARAMETERS:
	LOW = The lowest pixel value to use.  If this parameter is omitted,
	      0 is assumed.  Appropriate values range from 0 to the number 
	      of available colors-1.

	HIGH = The highest pixel value to use.  If this parameter is omitted,
	       the number of colors-1 is assumed.  Appropriate values range 
	       from 0 to the number of available colors-1.

	GAMMA =	Gamma correction factor.  If this value is omitted, 1.0 is 
		assumed.  Gamma correction works by raising the color indices
		to the Gamma power, assuming they are scaled into the range 
		0 to 1.

       GRANGE = The desired range of the gamma axis, a 2-element
                vector.  The first element is the axis minimum, and 
                the second is the maximum. The default is [0.1,10.0].

 OUTPUTS:
       None.

 COMMON BLOCKS:
	COLORS:	The common block that contains R, G, and B color
		tables loaded by LOADCT, HSV, HLS and others.

 SIDE EFFECTS:
	Image display color tables are changed.

 RESTRICTIONS:
       If using TrueColor visual class, color decomposition must be 
       switched off in order for this routine to work.

 EXAMPLE:
       Load the BLUE/GREEN/RED/YELLOW color table and fiddle with 
       the red and blue channels:

       IDL> loadct, 4
       % LOADCT: Loading table BLUE/GREEN/RED/YELLOW
       IDL> ct_fiddle, 'rb'

 MODIFICATION HISTORY:
   08 May 2004  Written by Tim Robishaw, Berkeley
   Heavily modified version of Carl Heiles's DIDDLE.

(See /dzd2/heiles/idl/gen/color/ct_fiddle.pro)


CT_REVERSE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	CT_REVERSE

 PURPOSE:
	Reverse the image display color tables over a specified range.

 CATEGORY:
	Image processing, point operations.

 CALLING SEQUENCE:
	CT_REVERSE, Low, High [, /OVERWRITE]

 OPTIONAL INPUTS:
	Low:	The lowest pixel value to use.  If this parameter is omitted,
		0 is assumed.  Appropriate values range from 0 to the number 
		of available colors-1.

	High:	The highest pixel value to use.  If this parameter is omitted,
		the number of colors-1 is assumed.  Appropriate values range 
		from 0 to the number of available colors-1.

 KEYWORD PARAMETERS:
       /OVERWRITE: The original color table stored in the "colors"
                   common block is overwritten with the reversed
                   color table.

 OUTPUTS:
	No explicit outputs.

 COMMON BLOCKS:
	COLORS:	The common block that contains R, G, and B color
		tables loaded by LOADCT, HSV, HLS and others.

 SIDE EFFECTS:
	Image display color tables are loaded.

 RESTRICTIONS:
	Common block COLORS must be loaded before calling CT_REVERSE.

 EXAMPLE:
	Load the STD GAMMA-II color table by entering:

		LOADCT, 5

	Create and display an image by entering:

		TVSCL, DIST(300)

       Now reverse the color table:
               CT_REVERSE

       Now reverse just the color table indices between 50 and 100:
               CT_REVERSE, 50, 100

 MODIFICATION HISTORY:
       19 Mar 2004  Written by Tim Robishaw, Berkeley
       Added /OVERWRITE keyword. TR, 07 May 2004

(See /dzd2/heiles/idl/gen/color/ct_reverse.pro)


CT_STRETCH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	CT_STRETCH

 PURPOSE:
	Stretch the image display color tables so the full range 
	runs from one color index to another.

 CATEGORY:
	Image processing, point operations.

 CALLING SEQUENCE:
	CT_STRETCH, Low, High [, Gamma] [, /CHOP] [, /OVERWRITE]

 INPUTS:
	Low:	The lowest pixel value to use.  If this parameter is omitted,
		0 is assumed.  Appropriate values range from 0 to the number 
		of available colors-1.

	High:	The highest pixel value to use.  If this parameter is omitted,
		the number of colors-1 is assumed.  Appropriate values range 
		from 0 to the number of available colors-1.

 OPTIONAL INPUTS:
	Gamma:	Gamma correction factor.  If this value is omitted, 1.0 is 
		assumed.  Gamma correction works by raising the color indices
		to the Gamma power, assuming they are scaled into the range 
		0 to 1.

 KEYWORD PARAMETERS:
	/CHOP:	If this keyword is set, color values above the upper threshold
		are set to color index 0.  Normally, values above the upper 
		threshold are set to the maximum color index.

       /OVERWRITE: The original color table stored in the "colors"
                   common block is overwritten with the reversed
                   color table.

 OUTPUTS:
	No explicit outputs.

 COMMON BLOCKS:
	COLORS:	The common block that contains R, G, and B color
		tables loaded by LOADCT, HSV, HLS and others.

 SIDE EFFECTS:
	Image display color tables are loaded.

 RESTRICTIONS:
	Common block COLORS must be loaded before calling CT_STRETCH.

 PROCEDURE:
	New R, G, and B vectors are created by linearly interpolating
	the vectors in the common block from Low to High.  Vectors in the 
	common block are not changed.

	If NO parameters are supplied, the original color tables are
	restored.

 EXAMPLE:
	Load the STD GAMMA-II color table by entering:

		LOADCT, 5

	Create and display an image by entering:

		TVSCL, DIST(300)

	Now adjust the color table with CT_STRETCH.  Make the entire 
       color table fit in the range 0 to 70 by entering:

		CT_STRETCH, 0, 70

	Notice that pixel values above 70 are now colored white.
	Restore the original color table by entering:

		CT_STRETCH

       To reverse the color table:
               CT_STRETCH, !D.TABLE_SIZE-1, 0

       To reverse the color table over only the range 50 to 120:
               CT_STRETCH, 120, 50

 NOTES: 
       RSI's STRETCH routine didn't cut the mustard.  (a) If the
       color table hasn't been loaded, it creates a color table with
       maximum values of (!D.TABLE_SIZE-1) rather than 255; (b) it
       uses LONG() to interpolate the color table rather than
       BYTSCL().
 
 MODIFICATION HISTORY:
       19 Mar 2004  Written by Tim Robishaw, Berkeley
	Most of documentation from DMS, RSI.
       Added /OVERWRITE keyword. TR, 07 May 2004

(See /dzd2/heiles/idl/gen/color/ct_stretch.pro)


GETCOLOR -- RETURN THE COLOR TABLE INDEX OF THE COLOR CORRESPONDING TO THE COLOR NAME

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
GETCOLOR -- return the color table index of the color corresponding to the color name 
     
 PURPOSE:
       This function returns the color table index of the color
       corresponding to the color name which is input.  If the
       line plot color names and color table indices are not
       provided, SETCOLORS is called to set up basic line plot
       colors. Designed to work correctly on both X Window and 
       PostScript devices.
     
 CALLING SEQUENCE:
      color = getcolor(colorname, names, tableindx)

      OR

      color = getcolor(colorname[, DECOMPOSED=decomposed]) 
     
 INPUTS:
       COLORNAME: A string whose value is the name of a line plot
                  color.  Must not be an array.
     
 OPTIONAL INPUTS:
       COLORNAMES: An array of strings which correspond to line
                   plot colors that are available to the user.

       TABLEINDICES: An array of the color table indices (8-bit) or 
                     24-bit integers corresponding to the line plot colors.
     
 OUTPUTS:
       Function value returned = color table index of input color name.

 KEYWORDS:
       DECOMPOSED = Set this keyword to explicitly use decomposed color
                    on 24-bit machines. Has no effect on devices which 
                    do not support decomposed color. Set this keyword
                    to 0 to turn off decomposed color on 24-bit
                    devices. If COLORNAMES and TABLEINDICES are set,
                    this keyword has no effect.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       If the line plot color name COLORNAME is not found in the
       list of available line plot colors COLORNAMES, the value of
       the system plot color, !p.color, is returned.  If only
       COLORNAME is input and color decomposition is not on, the line 
       plot colors are added to the top of the current color table.

 RESTRICTIONS:
       Only supported by IDL v5.2 or higher. 

 PROCEDURES CALLED:
       FILE_WHICH
       SETCOLORS

 EXAMPLE:
       Once an array of line plot color names and their corresponding
       color table indices (8-bit) or 24-bit integers have been
       established, use GETCOLOR to obtain one of these values:

       IDL> setcolors, NAMES=cnames, VALUES=cindx
       IDL> plot, findgen(30), color=getcolor('orange',cnames,cindx)

       If no line plot color information exists, call GETCOLOR with
       only a color name and SETCOLORS will be called to establish
       a set of basic colors:

       IDL> plot, findgen(30), color=getcolor('cyan')

       If referencing many colors, this is much slower than the
       the previous example.  However, it's likely that if you're
       plotting something, you're not aiming for speed anyway!

 RELATED PROCEDURES:
       SETCOLORS

 MODIFICATION HISTORY:
   Written Tim Robishaw, Berkeley 13 Aug 2001

(See /dzd2/heiles/idl/gen/color/getcolor.pro)


SETCOLORS

[Previous Routine] [List of Routines]
 NAME: 
       SETCOLORS
     
 PURPOSE: 
       To set up device independent line plot colors. Designed to
       work correctly on both X Window and PostScript devices.
     
 CALLING SEQUENCE:
       SETCOLORS [, NAMES=string array][, VALUES=array][, 
                 NPLOTCOLORS=variable][, TABLESIZE=variable][,
                 DECOMPOSED={0|1}][,/SYSTEM_VARIABLES][,
                 /GETINFO][,/SILENT][,/TEST][,/START][,
                 PLOTCOLORS=string array, R_PLOT=array, G_PLOT=array, 
                 B_PLOT=array][,/PSEUDO256]
     
 INPUTS: 
       None.

 OPTIONAL INPUTS:
       (You can provide your own set of line plot colors, but you
        must provide all four of the following keywords and they
        must all have the same size! (See EXAMPLE.) If omitted,
        a set of 12 basic colors is used.)

       PLOTCOLORS = A string array of user-defined line plot color names.

       R_PLOT = The RED values of line plot colors.

       G_PLOT = The GREEN values of line plot colors.

       B_PLOT = The BLUE values of line plot colors.
     
 OUTPUTS:
       None.

 OPTIONAL OUTPUTS:
       NAMES = Returns a string array of the line plot color names.

       VALUES = Returns an array of the color table indices (8-bit) or 
                24-bit integers corresponding to the line plot colors.

       NPLOTCOLORS = Returns the number of line plot colors defined.

       TABLESIZE = Returns the number of color table indices.

 KEYWORDS:
       DECOMPOSED = Set this keyword to explicitly use decomposed color
                    on 24-bit machines. Has no effect on devices which 
                    do not support decomposed color. Set this keyword
                    to 0 to turn off decomposed color on 24-bit devices.

       /SYSTEM_VARIABLES: Define system variables with the name of each
                          color and the value of the color table index
                          or the 24-bit integer corresponding to each
                          color, i.e. for 24-bit color, !orange=32767L.
                          This is very useful since system variables have
                          global scope, therefore these colors can be
                          used in any procedure once defined.

       /GETINFO: Do not do anything to the color table, just print
                 out IDL color information.

       /SILENT: Do not print out IDL color information. Default is to 
                print info.

       /TEST: Display the entire color table and the names of
              the line plot colors in their respective colors.

       /START: Put the line plot colors at the start of the color 
               table. Default is to store them at the top.

       /NOCOLORS: Do not load line plot colors into color table!
                  Has no effect if color undecomposed.

       /PSEUDO256: Default is to establish PseudoColor visual using
                   only the available color indices when the first
                   window is created.  This keyword forces IDL to
                   use all 256 colors.

 COMMON BLOCKS:
       COLORS: The IDL color common block.

 SIDE EFFECTS:
       The color table may be modified.  If a window is not open, a
       pixmap is created then destroyed to establish the visual class
       and depth.  If the /TEST keyword is set and the device is X
       Windows, a free window is created to display the color table
       and line plot colors.

 RESTRICTIONS:
       Only supported by IDL v5.2 or higher. 

 PROCEDURES CALLED:
       None.

 EXAMPLE:
       To view the color table and line plot names and colors:

       IDL> setcolors, /test


       To define system variables with the names of each color
       and values of the corresponding color table index or 24-bit
       long integer:

       IDL> setcolors, /SYSTEM_VARIABLES


       To use the line plot colors (set DECOMPOSED=1 if 24-bit display):

       IDL> setcolors, NAMES=cnames, VALUES=cindx
       IDL> plot, findgen(30), co=cindx[(where(cnames eq 'yellow'))[0]]
       *OR*
       IDL> plot, findgen(30), co=getcolor('yellow',cnames,cindx)


       If you'd like to display an image but you've added line plot
       colors to the color table, you need to scale the image to
       avoid using the plotcolors:

       IDL> setcolors, NPLOTCOLORS=nplotcolors, TABLESIZE=tablesize
       IDL> tv, bytscl(image, top=tablesize-nplotcolors-1)
       If you load the line plot colors at the start of the color table:

       IDL> setcolors, NPLOTCOLORS=nplotcolors, TABLESIZE=tablesize, /START
       IDL> tv, bytscl(image, top=tablesize-nplotcolors-1)+nplotcolors

       (Do not use TVSCL!  "If color is important to you (and it almost
        always is), then you probably never want to use the TVScl command.
        Instead, you will want to scale your image data yourself, and use
        the TV command to display it." - David W. Fanning)


       To load your own line plot colors:

       IDL> setcolors, PLOTCOLORS=['red','yellow','blue','green'], $
       IDL> R_PLOT=[255,255,0,0], G_PLOT=[0,255,0,255], $
       IDL> B_PLOT=[0,0,255,0], NAMES=cnames, VALUES=cindx

       (Color 'WHITE' will be appended to the top of the color table
        to protect !p.color/!p.background.  If /START is set, color
        'BLACK' is appended to bottom of color table.)


       If you want to make a grayscale image and add colored
       annotation (when color decomposition is off):

       IDL> setcolors, NPLOTCOLORS=nplotcolors, TABLESIZE=tablesize, $
       IDL> NAMES=cnames, VALUES=cindx
       IDL> tv, bytscl(image, top=tablesize-nplotcolors-1)
       IDL> xyouts, 200, 150, 'M31', /dev, $
       IDL> co=cindx[(where(cnames eq 'cyan'))[0]]
       *OR*
       IDL> xyouts, 200, 150, 'M31', /dev, co=getcolor('cyan',cnames,cindx)

       WARNING!  After opening a PostScript file you should run
       SETCOLORS!  If you're using a 24-bit visual device,
       the system variables and color indices will be 24-bit longword
       integers (with values greater than 256) but PostScript is an
       8-bit device with only 256 colors available, so right after opening
       a PostScript file, you should run SETCOLORS to re-establish the
       color system variables color indices. Likewise, when you close
       a PostScript image, you should run SETCOLORS again in order to
       re-establish the colors for X Windows.

 NOTES:
       Once a window is open, the visual class is established for the IDL
       session.  There is no way to change it once it is established.
       However, if no window is open (there's no way to tell if one has
       been opened in the past) we open a pixmap and delete it just to
       establish the visual class and depth.

       I thought at first it would be convenient to store the color table
       indices of each color in a variable named after the corresponding
       color and storing each color variable in a common block.  However, I
       was convinced by two very bright folks that common blocks should be
       avoided, especially for this use.

 RELATED PROCEDURES:
       GETCOLOR

 MODIFICATION HISTORY:
       Written by Tim Robishaw, Berkeley 13 Aug 2001
       Added /NOCOLORS keyword. TR, Berkeley 03 Oct 2001
       Added /SYSTEM_VARIABLES keyword. TR, 07 Feb 2002
       Added /PSEUDO256 keyword. TR, 15 Feb 2002
       Removed IDL's STRETCH. TR, 19 Mar 2004
       Made sue r,g,b_curr get defined. TR, 07 May 2004

(See /dzd2/heiles/idl/gen/color/setcolors.pro)


colortest procs

colortest procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

CT_FIDDLE

[List of Routines]
 NAME:
       ct_fiddle

 PURPOSE:
       To fiddle with the color table.  The user can select which channels 
       of the color table to manipulate.  The user can change the gamma 
       correction and the range of the color table indices.

 CALLING SEQUENCE:
	CT_FIDDLE [, CHANNELS] [, LOW=value] [, HIGH=value] [,
	GAMMA=value] [, GRANGE=[min,max]]

 OPTIONAL INPUTS:
       CHANNELS: A string argument.  CHANNELS sets which color
                 channels ('R' for red, 'G' for green, 'B' for blue) 
                 will be manipulated in the color table.  The user
                 can manipulate one, two or all channels.  To fiddle
                 with the red and blue channels simultaneously,
                 set channels equal to the string 'rb'.

 KEYWORD PARAMETERS:
	LOW = The lowest pixel value to use.  If this parameter is omitted,
	      0 is assumed.  Appropriate values range from 0 to the number 
	      of available colors-1.

	HIGH = The highest pixel value to use.  If this parameter is omitted,
	       the number of colors-1 is assumed.  Appropriate values range 
	       from 0 to the number of available colors-1.

	GAMMA =	Gamma correction factor.  If this value is omitted, 1.0 is 
		assumed.  Gamma correction works by raising the color indices
		to the Gamma power, assuming they are scaled into the range 
		0 to 1.

       GRANGE = The desired range of the gamma axis, a 2-element
                vector.  The first element is the axis minimum, and 
                the second is the maximum. The default is [0.1,10.0].

 OUTPUTS:
       None.

 COMMON BLOCKS:
	COLORS:	The common block that contains R, G, and B color
		tables loaded by LOADCT, HSV, HLS and others.

 SIDE EFFECTS:
	Image display color tables are changed.

 RESTRICTIONS:
       If using TrueColor visual class, color decomposition must be 
       switched off in order for this routine to work.

 EXAMPLE:
       Load the BLUE/GREEN/RED/YELLOW color table and fiddle with 
       the red and blue channels:

       IDL> loadct, 4
       % LOADCT: Loading table BLUE/GREEN/RED/YELLOW
       IDL> ct_fiddle, 'rb'

 MODIFICATION HISTORY:
   08 May 2004  Written by Tim Robishaw, Berkeley
   Heavily modified version of Carl Heiles's DIDDLE.

(See /dzd2/heiles/idl/gen/colortest/ct_fiddle.pro)


display procs

display procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

CBLINK -- BLINK BETWEEN A SET OF WINDOWS WITH OPTION TO SAVE ONE.

[List of Routines]
 NAME:
CBLINK -- blink between a set of windows with option to save one.
 PURPOSE:
	To allow the user to alternatively examine two or more windows within
	a single window.
 CALLING SEQUENCE:
	BLINK, Wndw [, T]
 INPUTS:
	Wndw  A vector containing the indices of the windows to blink.
	T     The time to wait, in seconds, between blinks.  This is optional
	      and set to 1 if not present.  
 OUTPUTS:
	None.
 PROCEDURE:
	The images contained in the windows given are written to a pixmap.
	The contents of the the windows are copied to a display window, in 
	order, until a key is struck.
 EXAMPLE:
       Blink windows 0 and 2 with a wait time of 3 seconds

         IDL> blink, [0,2], 3 
 MODIFICATION HISTORY:
	Written by Michael R. Greason, STX, 2 May 1990.
       Allow different size windows   Wayne Landsman    August, 1991
	Retain the blink window Carl Heiles 2 nov 98

(See /dzd2/heiles/idl/gen/display/cblink.pro)


fits procs

fits procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

FITS_ADD_AXIS_PAR

[Next Routine] [List of Routines]
 NAME:
       FITS_ADD_AXIS_PAR

 PURPOSE:
       Add to FITS header the FITS parameters necessary to
       specify a coordinate axis.

 CALLING SEQUENCE:
       FITS_ADD_AXIS_PAR, axis, hdr, axisnum

 INPUTS:
       AXIS - vector containing values of coordinate axis.
       HDR - FITS header.
       AXISNUM - The number of the coordinate axis.

 KEYWORD PARAMETERS:
       CTYPE - name of the coordinate axis, a character string.
       CUNIT - name of units of coordinate, a character string.
       AXIS_PAR - Set this keyword to a variable in order to
                  return the AXIS_PAR stucture:
                  .NAXIS - size of the axis
                  .CDELT - coordinate increment along axis
                  .CRPIX - coordinate system reference pixel
                  .CRVAL - coordinate system value at reference pixel
                  .CTYPE - name of the coordinate axis

 OUTPUTS:
       None.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       The coordinate axis header keywords are added or changed in 
       the FITS header.

 PROCEDURES CALLED:
       FITS_GET_AXIS_PAR(), SXPAR(), SXADDPAR

 EXAMPLE:
       Create a header for a data cube...
       IDL> cube = bytarr(512,12,36)
       IDL> mkhdr, hdr, cube

       Now make coordinate axes for the cube...
       IDL> axis1 = findgen(512)*0.33 - 100
       IDL> axis2 = findgen(12)
       IDL> axis3 = findgen(36)*0.5 + 50

       Add the NAXISn, CRVALn, CRPIXn and CRDELTn header
       keywords to HDR...
       IDL> fits_add_axis_par, axis1, hdr, 1
       IDL> fits_add_axis_par, axis2, hdr, 2
       IDL> fits_add_axis_par, axis3, hdr, 3

       Also add the CTYPEn and CUNITn keywords...
       IDL> fits_add_axis_par, axis1, hdr, 1, $
       IDL> CTYPE='Right Ascension (B1950)', CUNIT='deg'

 RELATED PROCEDURES:
       FITS_MAKE_AXIS()

 MODIFICATION HISTORY:
   20 Aug 2003  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/fits/fits_add_axis_par.pro)


FITS_GET_AXIS_PAR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       FITS_GET_AXIS_PAR

 PURPOSE:
       Return, in structure form, the FITS parameters necessary to
       specify a coordinate axis.

 CALLING SEQUENCE:
       Result = FITS_GET_AXIS_PAR(axis)

 INPUTS:
       AXIS - vector containing values of coordinate axis.

 OUTPUTS:
       Returns the AXIS_PAR structure:
       AXIS_PAR.NAXIS - size of the axis
               .CDELT - coordinate increment along axis
               .CRPIX - coordinate system reference pixel
               .CRVAL - coordinate system value at reference pixel
               .CTYPE - name of the coordinate axis

 COMMON BLOCKS:
       None.

 EXAMPLE:
       AXIS is vector containing the values of an axis...
       IDL> axis_par = fits_get_axis_par(axis)
       IDL> help, axis_par, /structure
       ** Structure <39fc40>, 4 tags, length=16, refs=1:
       NAXIS           LONG              2048
       CDELT           FLOAT           1.00000
       CRPIX           FLOAT           1025.00
       CRVAL           FLOAT           1024.00

 RELATED PROCEDURES:
       FITS_ADD_AXIS_PAR, FITS_MAKE_AXIS()

 MODIFICATION HISTORY:
   20 Aug 2003  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/fits/fits_get_axis_par.pro)


FITS_MAKE_AXIS -- CREATE AXIS VALUES FROM A FITS HEADER

[Previous Routine] [List of Routines]
 NAME:
FITS_MAKE_AXIS -- create axis values from a FITS header

 PURPOSE:
       To create the axis values from the NAXISn, CDELTn, CRPIXn, and
       CRVALn keyword values stored in a FITS header.

 CALLING SEQUENCE:
       Result = FITS_MAKE_AXIS(hdr, axisnum)

 INPUTS:
       HDR - FITS header (string array)
       AXISNUM - The number of the axis to be created.

 KEYWORD PARAMETERS:
       None.

 OUTPUTS:
       Returns a vector of length NAXISn containing the axis values.

 COMMON BLOCKS:
       None.

 PROCEDURES CALLED:
       SXPAR()

 EXAMPLE:
       Get the header from a FITS file...
       IDL> hdr = headfits('datacube.fits')

       Make the 1st and 2nd axes...
       IDL> xaxis = fits_make_axis(hdr,1)
       IDL> yaxis = fits_make_axis(hdr,2)

 RELATED PROCEDURES:
       FITS_ADD_AXIS_PAR

 MODIFICATION HISTORY:
   20 Aug 2003  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/fits/fits_make_axis.pro)


fitting procs

fitting procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:25 2005.


List of Routines


Routine Descriptions

GET_XLEG -- TRANSFORM XIN TO OPTIMUM RANGE FOR LEGENDRE FITTING

[Next Routine] [List of Routines]
NAME:
GET_XLEG -- transform xin to optimum range for legendre fitting

SEE DOC IN LEGENDREFIT OR LEGENDREFIT_SVD. REPEAT THOSE IMPORTANT NOTES:
       (1) GODDARD'S FLEGENDRE IS MUCH FASTER THAN IDL'S LEGENDRE!
       (2) TO EVALUATE: YFIT= POLYLEG( XDATA, COEFFS)
       (3) PAY ATTENTION TO DOUBLE PRECISION FOR HARD PROBLEMS!!!
       (4) THE XDATA MUST LIE BETWEEN 0 AND 1. WHAT'S MORE...
       (5) IF POINTS ARE UNIFORMLY SPACED, TO OBTAIN MAX ORTHOGONALITY:
               (A) YOU HAVE nrt POINTS
               (B) THESE nrt POINTS SPAN A TOTAL RANGE range
               (C) THEN THE INTERVAL BETWEEN POINTS IS delta= range/(nrt-1)
               (D) MAKE THE INPUT X VALUES BE...

                       XLEG = (2*findgen(nrt) - (nrt-1))/nrt

                   which corresponds to half a bin away from the (-1,1) ends.
                   suppose the original nrt uniformly-spaced values have values f=frt.
                   then an alternative set of equation (good for arbitrary f) is

                       frtspan= max( frt)- min( frt)
                       dfrtspan= frtspan/( nrt-1)
                       sfrtspan= max( frt)+ min( frt)
                       XLEG = (2.*frt - sfrtspan)/(frtspan+ dfrtspan)
       OR              XLEG = (2.*f - sfrtspan)/(frtspan+ dfrtspan)

HERE, SETTING QUICK USES EQN (1) ABOVE; OTHERWISE THE SET (2) IS USED.
	USING (1) IMPLIES XIN IS UNIFORMLY SPACED, WITH QUICK=NR OF POINTS.

CALLING SEQUANCE:
	RESULT= GET_XLEG( XIN, XMIN, XMAX, DELX, [QUICK=NPTS]

INPUTS:
	XIN, the x values for which transformed valuse of XLEG are desired
	XMIN, the minimum value of X for the transformation
	XMAX, the maximum value of X for the transformation
	DELX, the interval between x values for uniformly spaced array

OPTIONAL INPUT:
	QUICK. YOU CAN SET THIS EUAL TO NR OF POINTS FOR A UNIFORMLY 
SPACED ARRAY AND NOT USE THE OTHER STANDARD INPUTS.

OUTPUT:
	XLEG, the transformed values of the inputs.  For a uniformly
spaced array containing NRT elements, the values of XLEG lie between
[-(nrt-1)/nrt] and [+(nrt-1)/nrt]

EXAMPLE:

	you have NRT=512 uniformly spaced values of frequency (FRT) and
you want to do a legendre-nomial fit.  transform the original values to
the proper range (XLEG)

		xleg= get_xleg( quick=512)

altenatively, use 
		frtmin= min(frt)
		frtmax= frt(max)
		delfrt= (frtmax- frtmin)/( nrt-1)
		xleg= get_xleg( frt, frtmin, frtmax, delfrt)

then do the fit (you should use legendrefit_svd for hard problems)...

	legendrefit, xlegfit[indxwb_incl], spwb_c[ indxwb_incl], degree, $
        coeffs, sigcoeffs, yfit, residbad= 4., problem=problem

	after doing the fit you want to apply these coefficients to an
arbiTrary set of frequencies (FRA). 

		xra= get_xleg( fra, frtmin, frtmax, delfrt)
		xrafit = polyleg( xra, coeffs)

(See /dzd2/heiles/idl/gen/fitting/get_xleg.pro)


LEGENDREFIT -- LEGENDRE FIT USING STANDARD LEAST SQUARES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
LEGENDREFIT -- legendre fit using standard least squares

IMPORTANT NOTES: 
	(1) GODDARD'S FLEGENDRE IS MUCH FASTER THAN IDL'S LEGENDRE!
	(2) TO EVALUATE: YFIT= POLYLEG( XDATA, COEFFS)
       (3) PAY ATTENTION TO DOUBLE PRECISION FOR HARD PROBLEMS!!!
       (4) THE XDATA MUST LIE BETWEEN 0 AND 1. WHAT'S MORE...
       (5) IF POINTS ARE UNIFORMLY SPACED, TO OBTAIN MAX ORTHOGONALITY:
               (A) YOU HAVE nrt POINTS
               (B) THESE nrt POINTS SPAN A TOTAL RANGE range
               (C) THEN THE INTERVAL BETWEEN POINTS IS delta= range/(nrt-1)
               (D) MAKE THE INPUT X VALUES BE...

                       X = (2*findgen(nrt) - (nrt-1))/nrt

                   which corresponds to half a bin away from the (-1,1) ends.
                   suppose the original nrt uniformly-spaced values have values f=frt.
                   then an alternative set of equation (good for arbitrary f) is

                       frtspan= max( frt)- min( frt)
                       dfrtspan= frtspan/( nrt-1)
                       sfrtspan= max( frt)+ min( frt)
                       x = (2.*frt - sfrtspan)/(frtspan+ dfrtspan)
       OR              x = (2.*f - sfrtspan)/(frtspan+ dfrtspan)

TIME:
       (1) LEGENDRE FIT IS ABOUT 20% SLOWER THAN POLYNOMIAL FIT.
       (2) FOR BOTH, SVD VERSION IS ABOUT 3 TIMES SLOWER THAN ORDINARY VERSION.

PURPOSE:
    like a polynomial fit but uses legendre functions, which are 
orthogonal over the interval (-1,1). the input data must be 
within this range.

CALLING SEQUENCE:
    LEGENDREFIT, xdata, ydata, degree, coeffs, sigcoeffs, yfit, $
	sigma, nr3bad, cov

INPUTS:
     xdata: the x-axis data points. 
     ydata: the y-axis data points.
     degree: the degree of the legendre fit. e.g. linear fit has degree=1.
KEYWORDS:
     residbad: if set, excludes points those residuals exceed residbad*sigma
	goodindx: the array of indices actually used in the fit.
	problem: nonzero if there was a problem with the fit.
OUTPUTS:
     coeffs: array of coefficients.
     sigcoeffs: me's of the coefficients.
     yfit: the fitted points evaluated at datax.
     sigma: the sigma (mean error) of the data points.
     nr3sig: the nr of datapoints lying more than 3 sigma away from the fit.
     ncov: the normalized covariance matrix.
     cov: the covariance matrix.

HISTORY;

(See /dzd2/heiles/idl/gen/fitting/legendrefit.pro)


LEGENDREFIT_SVD -- LEGENDRE FIT USING STANDARD LEAST SQUARES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
LEGENDREFIT_SVD -- legendre fit using standard least squares

IMPORTANT NOTES:
       (1) GODDARD'S FLEGENDRE IS MUCH FASTER THAN IDL'S LEGENDRE!
       (2) TO EVALUATE: YFIT= POLYLEG( XDATA, COEFFS)
	(3) PAY ATTENTION TO DOUBLE PRECISION FOR HARD PROBLEMS!!!
	(4) THE XDATA MUST LIE BETWEEN 0 AND 1. WHAT'S MORE...
	(5) IF POINTS ARE UNIFORMLY SPACED, TO OBTAIN MAX ORTHOGONALITY:
		(A) YOU HAVE nrt POINTS
		(B) THESE nrt POINTS SPAN A TOTAL RANGE range
		(C) THEN THE INTERVAL BETWEEN POINTS IS delta= range/(nrt-1)
		(D) MAKE THE INPUT X VALUES BE...

			X = (2*findgen(nrt) - (nrt-1))/nrt

		    which corresponds to half a bin away from the (-1,1) ends.
		    suppose the original nrt uniformly-spaced values have values f=frt.
		    then an alternative set of equation (good for arbitrary f) is

			frtspan= max( frt)- min( frt)
			dfrtspan= frtspan/( nrt-1)
			sfrtspan= max( frt)+ min( frt)
			x = (2.*frt - sfrtspan)/(frtspan+ dfrtspan)
	OR		x = (2.*f - sfrtspan)/(frtspan+ dfrtspan)

TIME: 
	(1) LEGENDRE FIT IS ABOUT 20% SLOWER THAN POLYNOMIAL FIT.
	(2) FOR BOTH, SVD VERSION IS ABOUT 3 TIMES SLOWER THAN ORDINARY VERSION.

PURPOSE:
    like a SVD polynomial fit but uses legendre functions, which are 
orthogonal over the interval (-1,1). the input data must be 
within this range.

CALLING SEQUENCE:
    LEGENDREYFIT_SVD, xdata, ydata, degree, coeffs, sigcoeffs, yfit, $
	sigma, nr3bad, cov

INPUTS:
     xdata: the x-axis data points. 
     ydata: the y-axis data points.
     degree: the degree of the legendre fit. e.g. linear fit has degree=1.
KEYWORDS:
     residbad: if set, excludes points those residuals exceed residbad*sigma
	goodindx: the array of indices actually used in the fit.
	problem: nonzero if there was a problem with the fit.
OUTPUTS:
     coeffs: array of coefficients.
     sigcoeffs: me's of the coefficients.
     yfit: the fitted points evaluated at datax.
     sigma: the sigma (mean error) of the data points.
     nr3sig: the nr of datapoints lying more than 3 sigma away from the fit.
     ncov: the normalized covariance matrix.
     cov: the covariance matrix.

HISTORY;

(See /dzd2/heiles/idl/gen/fitting/legendrefit_svd.pro)


LSFIT_SVD -- DO LSFIT USING SVD INSTEAD OF INVERSE NORMAL EQUATIONS.

[Previous Routine] [Next Routine] [List of Routines]
NAME:
LSFIT_SVD -- do lsfit using SVD instead of inverse normal equations.

	The equations of condition are

	X a = y

where X is a the equation-of-conditon matrix, A is the vector of unknowns,
and y are the measured values.

	This returns the solution vector x, its variances and sigmas,
and the normalizedd covariance matrix. These are the standard ls fit things.
It also returns the vector of SVD weights and the V matrix (see NM section
2.6 ('SVD of a Square Matrix') and chapter 15 (least squares solution by SVD).

CALLING SEQUENCE:
lsfit_svd, X, y, U, V, $
	wgt, a, vara, siga, ncov, s_sq, $
	xxinv_svd=xxinv_svd, wgt_inv=wgt_inv, ybar=ybar, cov=cov

INPUTS:
	X, the equation-of-conditon matrix
	y, the vector of measured values
	U, NM's matrix U (input only if WGT_INV is used; see discussion below)
	V, NM's matrix V (input only if WGT_INV is used; see discussion below)

OUTPUTS:
	U, NM's U matrix. also an input; see discussion below
	V, NM's V matrix, the matrix whose columns are the 
orthonormal eigenvectors. also an input; see discussion below
	WGT, the vector of weights of V (see discussion below)
	A, the vector of unknowns
	vara, a vector containing the variance of a
	siga, a vector containing the sigma of a (sqrt variance)
	ncov, the normalized covariance matrix
	s_sq, the variance of the datapoints

KEYWORDS:
	WGT_INV, the vector of reciprocal weights (equal to 1/WGT unless you
change them yourself). If WGT_INV is specified, then the procedure assumes
that  you have already run it once, examined the weight vector WGT and
found a problem, and specified the new vector of WGT_INV=1/WGT. It uses this
modified WGT_INV and it uses the values of U and V given as inputs
(because they have already been computed). If WGT_INV is not specified, it
evaluates U and V and returns them as outputs.
See COMMENTARIES below.

	XXINV_SVD, the effective inverse of X obtained using WGT_INV. 
If WGT_INV is left unmodified, XXINV_SVD is the inverse of X. But the
whole point of SVD is to modify WGT_INV by setting certain elements to 
zero so a to eliminate an effectively degenerate inverse of X. 
See COMMENTARIES below.

	COV, the usual covariance matrix

	YBAR, the fitted values of the datapoints

IMPORTANT COMMENTARIES REGARDING USE OF SVD!!!
	Read NM's discussion of WGT. Each element of WGT refers to the 
corresponding column of V; consider each column of V to be an eigenvector
in the space defined by the X matrix. 
If a particular value of WGT is small, then the projection of the
corresponding eigenvector in V is small. 

	As discussed in NM, you should then rerun the solution with the 
corresponding elements of WGT_INV set equal to 1/WGT, except for the problem 
value which should be set equal to zero (yes, if a particular element of
WGT is small the corresponding WGT_INV element is large; you set it equal to
zero to remove it from the solution).

HISTORY: written by carl heiles while flying back from Arecibo in july 2004.
mistakes in covariance matrix and associated parameter errors 27 feb 05.
	29jun05: replace SVDC (which doesn't always converge) 
with LA_SVD (needs idl 5.6)
	23aug05: use !version to choose svd routine. warn if svdc.

(See /dzd2/heiles/idl/gen/fitting/lsfit_svd.pro)


LS_XY_3 -- FITS MULTIVARIATE SLOPES PLUS CONSTANT

[Previous Routine] [Next Routine] [List of Routines]
NAME: 
LS_XY_3 -- FITS MULTIVARIATE SLOPES PLUS CONSTANT

PURPOSE: FITS MULTIVARIATE SLOPES PLUS CONSTANT, E.G.
	ZZ = A0*U + A1*V + a2*W +...

assumes U, V, W... are the independent variables (or functions of 
independent variables)


************************* CAVAET ******************************
tests by my ay250 class in 2005 indicate that the variances of 
derived parameters may not be correct. however, there appears to
be no bias in the derived parameters.
****************************************************************

INPUTS:
	XXIN, the X matrix of the independent variables, of the form...
		 _                  _
		| u_0   v_0   w_0  ... |
		| u_1   v_1   w_1  ... |
		| u_2   v_2   w_2  ... |
		| ...   ...   ...  ... |
		|_                    _|

	SIGMAXX, the intrinsic sigmas (uncertainties) of the U, V values, 
	in which ONE of the independent variables can have nonzero errors.
	This makes SIGMAXX to be of the form...

		 _                       _
		| sig(u_0)    0    0  ... |
		| sig(u_0)    0    0  ... |
		| sig(u_0)    0    0  ... |
		|  ...       ...  ... ... |
		|_                       _|

	ZZIN, a 'horizontal' vector of the ZZ measurements
	SIGMAZZ, the intrinsic measurement errors (sigmas) of the ZZ values.

KEYWORDS:
	TOLERANCE, the maximum change in any derived parameter. 
	default is 1e-3
OUTPUTS:
	A_LS, the vector of results for the 'conventional' ls fit 
		(the one that assumes no errors in U,  V...
	ATRY, the vector of results for the ls fit
	CHISQ, the chisq of the fit
	CHISQ_REDUCED, the reduced chisq of the fit
	SIGSQA, the sigma-squared of ATRY
	ZZBAR, the predicted z-values from the derived ls parameters

COMMENTS, RESTRICTIONS: See lsfit2005 writeup. max nr iterations is
nr_iterate_max, currently set for max of 100.

chisq definition is questionable (divided by
	number of variables).

	I'm not sure about the exact value of chisq...seems to be off 
	(too small) by a little bit.

HISTORY: 10 June 2002 by Carl Heiles
updated mar2004...extraneous stuff removed and documentation firmed up.
	tested only one a single independent variable.
updated feb2005...more testing, realized errors can exist only for one
	independent variable. For more generasl solns see Jefferys AJ 85, 177.

(See /dzd2/heiles/idl/gen/fitting/ls_xy_3.pro)


POLYFIT -- POLYNOMIAL FIT USING STANDARD LEAST SQUARES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
POLYFIT -- polynomial fit using standard least squares

PURPOSE:
    Polynomial fits, like IDL's POLY_FIT, but returns sigmas of
	the coefficients, the fitted line, and the normalized covariance
	matrix also.

CALLING SEQUENCE:
    POLYFIT, xdata, ydata, degree, coeffs, sigcoeffs, yfit, sigma, nr3bad, cov

INPUTS:
     xdata: the x-axis data points. 
     ydata: the y-axis data points.
     degree: the degree of the polynomial. e.g. linear fit has degree=1.
KEYWORDS:
     residbad: if set, excludes points those residuals exceed residbad*sigma
	goodindx: the array of indices actually used in the fit.
	problem: nonzero if there was a problem with the fit.
OUTPUTS:
     coeffs: array of coefficients.
     sigcoeffs: me's of the coefficients.
     yfit: the fitted points evaluated at datax.
     sigma: the sigma (mean error) of the data points.
     nr3sig: the nr of datapoints lying more than 3 sigma away from the fit.
     ncov: the normalized covariance matrix.
     cov: the covariance matrix.

HISTORY;
	30 sep i tested to see if la_invert is better than invert.
there is no essential diff, so we stick with invert.

(See /dzd2/heiles/idl/gen/fitting/polyfit.pro)


POLYFIT_MEDIAN -- PERFORM A LEAST-ABS-DEV (MEDIAN) POLYNOMIAL FIT

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   POLYFIT_MEDIAN -- perform a least-abs-dev (median) polynomial fit

PURPOSE:
    Polynomial MEDIAN fits.

CALLING SEQUENCE:
    POLYFIT_MEDIAN, xdata, ydata, degree, $
	coeffs, sigcoeffs, yfit, sigma, ncov

INPUTS:
     XDATA: the x-axis data points. 
     YDATA: the y-axis data points.
     DEGREE: the degree of the polynomial. e.g. linear fit has degree=1.

OUTPUTS:
     COEFFS: array of coefficients.
     SIGCOEFFS: me's of the coefficients. SEE NOTE BELOW
     YFIT: the fitted points evaluated at datax.
     SIGMA: the sigma (mean error) of the data points. SEE NOTE BELOW
     NCOV: the normalized covariance matrix.

NOTE ON SIGMA AND SIGCOEFFS:
	SIGMA and SIGCOEFFS are calculated as if we were doing a least
squares fit.  this is appropriate for Gaussian statistics, but not for
others, so this is relatively meaningless. For example, a single large
discrepant point will contribute a lot to sigma, and to sigcoeffs, but
because this is a median fit it is ignored.

(See /dzd2/heiles/idl/gen/fitting/polyfit_median.pro)


POLYFIT_SVD -- POLYNOMIAL FIT USING SVD.

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   POLYFIT_SVD -- polynomial fit  using SVD.

PURPOSE:
    Polynomial fits USING SVD. like IDL's POLY_FIT and my POLYFIT, 
	but uses SVD. POLYFIT is less accurrate thaN POLY_FIT, which
	in turn is less accurate than POLYFIT_SVD. Returns sigmas of
	the coefficients, the fitted line, and the normalized covariance
	matrix also.

TIME: SVD VERSION IS ABOUT 3 TIMES SLOWER THAN ORDINARY VERSION.

   Has an option to exclude points whose residuals exceed RESIDBAD.

CALLING SEQUENCE:
    POLYFIT_SVD, xdata, ydata, degree, $
	coeffs, sigcoeffs, yfit, sigma, nr3bad, ncov, cov, 
	[residbad], [goodindx], [problem], $
	wgts=wgts, u=u, wgt_inv=wgt_inv, v=v, auto=auto
INPUTS:
     XDATA: the x-axis data points. 
     YDATA: the y-axis data points.
     DEGREE: the degree of the polynomial. e.g. linear fit has degree=1.
KEYWORDS:
     RESIDBAD: if set, excludes points those residuals exceed residbad*sigma
	GOODINDX, the indices of the points included in the fit
       PROBLEM: nonzero if a problem. -2 means too many points discarded
	WGTS, the svd weights.
	WGT_INV: you can modify these to eliminate degeneracies; see
documentation for LSFIT_SVD 
	U, the returned U matrix from LSIT_SVD
	V, the returned V matrix from LSIT_SVD
	AUTO: if nonzero, does the WGT_INV business automatically, zeroing the
inverse weights when the ratio is smaller than AUTO. if AUTO is set equal
to >= one, it defaults to 1e-12

OUTPUTS:
     COEFFS: array of coefficients.
     SIGCOEFFS: me's of the coefficients.
     YFIT: the fitted points evaluated at datax.
     SIGMA: the sigma (mean error) of the data points.
     NR3SIG: the nr of datapoints lying more than 3 sigma away from the fit.
     NCOV: the normalized covariance matrix.
     COV: the covariance matrix.

HOW TO USE YOUR OWN WGT_INV: (it's easier to use AUTO keyword!)

	first invoke this procedure. it returns the native WGTS and
WGT_INV, and also the U and V as optional outputs. 
	then modify WGT_INV and call this proc again using the 
modified WGT_INV, U and V as optional inputs

suppose WGTS spans a huge range, say 10^20. do something like...
	indx= where( wgts/max( wgts) lt 1e-12)
	wgt_inv= 1./wgts
	wgt_inv[ indx]= 0.
and then call this proc again, specifying U, V, and WGT_INV as optional inputs.

(See /dzd2/heiles/idl/gen/fitting/polyfit_svd.pro)


POLYFIT_WGT -- POLYNOMIAL FITS OF WEIGHTED DATAPOINTS

[Previous Routine] [Next Routine] [List of Routines]
NAME:
POLYFIT_WGT -- polynomial fits of weighted datapoints

PURPOSE:
    Polynomial fits, like IDL's POLY_FIT, but allows weighting the input eq's of cond.
	returns sigmas of
	the coefficients, the fitted line, and the normalized covariance
	matrix also.

CALLING SEQUENCE:
    POLYFIT_WGT, xdata, ydata, wgts, degree, coeffs, sigcoeffs, yfit, sigma, nr3bad, cov

INPUTS:
     xdata: the x-axis data points. 
     ydata: the y-axis data points.
	wgts, the weighting factors applied to eqns of cond. these get squared
		then the normal equations are calculated.
     degree: the degree of the polynomial. e.g. linear fit has degree=1.
KEYWORDS:
     residbad: if set, excludes points those residuals exceed residbad*sigma
	goodindx: the array of indices actually used in the fit.
	problem: nonzero if there was a problem with the fit.
OUTPUTS:
     coeffs: array of coefficients.
     sigcoeffs: me's of the coefficients.
     yfit: the fitted points evaluated at datax.
     sigma: the sigma (mean error) of the data points.
     nr3sig: the nr of datapoints lying more than 3 sigma away from the fit.
     ncov: the normalized covariance matrix.
     cov: the covariance matrix.

IMPORTANT COMMENT: i have not checked whether the returned errors are right, nor whether it 
behaves properly when eliminating bad points.

(See /dzd2/heiles/idl/gen/fitting/polyfit_wgt.pro)


POLY_COS_CALC

[Previous Routine] [Next Routine] [List of Routines]
PURPOSE: calculate the fits generated ty poly_cos_fit_svd for any set of frequencies.
INPUTS:
	POLYCOEFFS, the array of polynomial coefficients
	TIMES, the times at which the fourier coeffs coscoeffs are evaluated
	coscoeffs, the array of fourier coefficients
	FRQS, the freq arraay for which  you want result;

RETURNS: the calculated fitted spectrum.

OUTPUTS:
	res_poly, the polynomial portion of the fit
	res_cos, the fourier portion of the fit
	cospower, the fourier power versus time

(See /dzd2/heiles/idl/gen/fitting/poly_cos_calc.pro)


POLY_COS_FIT_SVD

[Previous Routine] [Next Routine] [List of Routines]
POLY_FT_FIT -- fit polynomial plus cosine terms to a spectrum.

CALLING SEQUENCE: 
POLY_FT_FIT, frqin, ydata, degree, times, $
	coeffs, sigcoeffs, yfit, sigma, nr3bad, ncov, cov, $
	residbad=residbad, goodindx=goodindx, problem=problem, $
        polycoeffs=polycoeffs, coscoeffs=coscoeffs, cospower=cospower, $
	yfit_poly= yfit_poly, yfit_cos=yfit_cos

INPUTS:
	FRQIN, the array of input freqs for the spectrum
	YDATA, the array of spectral points
	DEGREE, the degree of the polynomial to fit
	TIMES, the times for whichi the fourier components are fitted

OUTPUTS:
	COEFFS, the array of fitted coefficients. the first (degree+1)
coefficients are for the polynomial; the remaining ones are for the
cosines, the numbver of which is equal to the nr of elements in times. 
	SIGCOEFFS, sigmas of coeffs
	YFIT, the fitted datapoints
	SIGMA, the sigma of the fitted points
	NR3BAD, the nr of bad points on the last iteration. should be zero.
	NCOV, the normalized covariance matrix
	COV, the covariance matrix

OPTIONALS:
	RESIDBAD: toss out points that depart by more that this times sigma.
e.g., if residbad is 3, it eliminates points haveing resids gt 3 sigma
	GOODINDX, the indx of good points (the points that it actually 
included in the fit)
	PROBLEM, nonzero if there is a problem
	POLYCOEFFS, the set of coeffs in the polynomial fit
	COSCOEFFS, the set of coeffs for the cosines
	SIGCOSCOEFFS, sigmas of coscoeffs
	COSPOWER, the power in each cosine component (square of coefficient)
	SIGCOSPOWER, the power in each cosine component (square of coefficient)
	YFIT_POLY, THE fitted polynomial curve
	YFIT_COS, THE fitted cosine curve
	ITMAX, the max nr of iterations in svdc.
	NOTE: yfit= yfit_poly+ yfit_cosine

EXAMPLE OF USE:
	you've got a lousy ripple in the spectrum. the ripple is represented
by yfit_cos. ydata-yfit_cos is the ripple-free spectrum.

HISTORY: carl h, 11june2005, adapted from poly_ft_fit_svd

(See /dzd2/heiles/idl/gen/fitting/poly_cos_fit_svd.pro)


POLY_FT_CALC

[Previous Routine] [Next Routine] [List of Routines]
PURPOSE: calculate the fits generated ty poly_ft_fit_svd for any set of frequencies.
INPUTS:
	POLYCOEFFS, the array of polynomial coefficients
	TIMES, the times at which the fourier coeffs FCOEFFS are evaluated
	FCOEFFS, the array of fourier coefficients
	FRQS, the freq arraay for which  you want result;

RETURNS: the calculated fitted spectrum.

OUTPUTS:
	res_poly, the polynomial portion of the fit
	res_f, the fourier portion of the fit
	fpower, the fourier power versus time

(See /dzd2/heiles/idl/gen/fitting/poly_ft_calc.pro)


POLY_FT_EVAL

[Previous Routine] [Next Routine] [List of Routines]
POLY_FT_EVAL -- using results from poly_ft_fit, calculate the fitted spectrum 

CALLING SEQUENCE: 
poly_ft_eval, frqin, degree, times, coeffs, sigcoeffs, $
	yeval, yeval_poly, yeval_fourier

INPUTS:
	FRQIN, the array of input freqs at which to evaluate the spectrum
	DEGREE, the degree of the polynomial to fit
	COEFFS, the set of coeffs from the original fit
	TIMES, the times for whichi the fourier components are fitted

OUTPUTS:
	YEVAL, the evaluated points
	YEVAL_POLY, the contribution to YEVAL from the polynomial part
	YEVAL_FOURIER, the contribution to YEVAL from the fourier part

HISTORY: carl h, 02sep2005

(See /dzd2/heiles/idl/gen/fitting/poly_ft_eval.pro)


POLY_FT_FIT_SVD

[Previous Routine] [List of Routines]
POLY_FT_FIT -- fit polynomial plus fourier terms to a spectrum.

CALLING SEQUENCE: 
POLY_FT_FIT, frqin, ydata, degree, times, $
	coeffs, sigcoeffs, yfit, sigma, nr3bad, ncov, cov, $
	residbad=residbad, goodindx=goodindx, problem=problem, $
        polycoeffs=polycoeffs, fcoeffs=fcoeffs, fpower=fpower, $
	yfit_poly= yfit_poly, yfit_fourier=yfit_fourier

INPUTS:
	FRQIN, the array of input freqs for the spectrum
	YDATA, the array of spectral points
	DEGREE, the degree of the polynomial to fit
	TIMES, the times for whichi the fourier components are fitted

OUTPUTS:
	COEFFS, the array of fitted coefficients. the first (degree+1)
coefficients are for the polynomial; the remaining ones are paired,
the number of pairs is equal to the nr of elements in times. the first
member of each pair is the cosine term, the second the sine.
	YFIT, the fitted datapoints
	SIGMA, the sigma of the fitted points
	NR3BAD, the nr of bad points on the last iteration. should be zero.
	NCOV, the normalized covariance matrix
	COV, the covariance matrix

OPTIONALS:
	RESIDBAD: toss out points that depart by more that this times sigma.
e.g., if residbad is 3, it eliminates points haveing resids gt 3 sigma
	GOODINDX, the indx of good points (the points that it actually 
included in the fit)
	PROBLEM, nonzero if there is a problem
	POLYCOEFFS, the set of coeffs in the polynomial fit
	FCOEFFS, the set of coeffs that are fourier pairs
	FPOWER, the power in each fourier component (quad sum of cos and sin)
	YFIT_POLY, THE fitted polynomial curve
	YFIT_FOURIER, THE fitted fourier curve
	ITMAX, the max nr of iterations in svdc.
	NOTE: yfit= yfit_poly_ yfit_fourier

EXAMPLE OF USE:
	you've got a lousy ripple in the spectrum. the ripple is represented
by yfit_fourier. ydata-yfit_fourier is the ripple-free spectrum.

HISTORY: carl h, 24june2005

(See /dzd2/heiles/idl/gen/fitting/poly_ft_fit_svd.pro)


gaussians procs

gaussians procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:26 2005.


List of Routines


Routine Descriptions

GCURV -- CALCULATE MULTIPLE (N) GAUSSIANS + OFFSET.

[Next Routine] [List of Routines]
NAME:
GCURV --  Calculate multiple (N) Gaussians + offset.

PURPOSE:
    Calculate multiple (N) Gaussians + offset.

CALLING SEQUENCE:
    GCURV, xdata, zro1, hgt1, cen1, wid1, tfit

INPUTS:
     xdata: the x-values at which the data points exist.
     zro1: the estimated constant zero offset of the data points.
     hgt1: the array of N estimated heights of the Gaussians.
     cen1: the array of N estimated centers of the Gaussians.
     wid1: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the calculated points.

EXAMPLE:
    You have two Gaussians.
     The heights are hgt1=[1.5, 2.5], the centers cen1=[12., 20.],
     and the widths are wid1=[5., 6.]. There are  
     100 values of x (xdata). 

	GCURV, xdata, zro1, hgt1, cen1, wid1, tfit

RELATED PROCEDURES:
	GFIT 
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gcurv.pro)


GCURV2D

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GCURV2D

PURPOSE:
    Calculate multiple (N) Gaussians + offset.

CALLING SEQUENCE:
    GCURV2D, xdata, ydata, zro1, hgt1, cenx1, ceny1, wid1, tfit

INPUTS:
     xdata: the x-values at which the data points exist.
     ydata: the y-values at which the data points exist.
     zro1: the estimated constant zero offset of the data points.
     hgt1: the array of N estimated heights of the Gaussians.
     cenx1: the array of N estimated x-centers of the Gaussians.
     ceny1: the array of N estimated y-centers of the Gaussians.
     wid1: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the calculated points.

EXAMPLE:
    You have two Gaussians.
     The heights are hgt1=[1.5, 2.5], the centers cen1=[12., 20.],
     and the widths are wid1=[5., 6.]. There are  
     100 values of x (xdata). 

	GCURV, xdata, zro1, hgt1, cen1, wid1, tfit

RELATED PROCEDURES:
	GFIT2D 
HISTORY:
	GCURV Written by Carl Heiles. 21 Mar 1998.
       Upgraded to 2D by Paul Demorest 6 jan 2003

(See /dzd2/heiles/idl/gen/gaussians/gcurv2d.pro)


GCURVSLOPE -- CALCULATE MULTIPLE (N) GAUSSIANS + OFFSET + SLOPE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
GCURVSLOPE --  Calculate multiple (N) Gaussians + offset + SLOPE

PURPOSE:
    Calculate multiple (N) Gaussians + offset + SLOPE

CALLING SEQUENCE:
    GCURV, xdata, zro1, slp1, hgt1, cen1, wid1, tfit

INPUTS:
     xdata: the x-values at which the data points exist.
     zro1: the zero offset of the data points.
     slp1: the slope.
     hgt1: the array of N estimated heights of the Gaussians.
     cen1: the array of N estimated centers of the Gaussians.
     wid1: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the calculated points.

EXAMPLE:
    You have two Gaussians.
     The heights are hgt1=[1.5, 2.5], the centers cen1=[12., 20.],
     and the widths are wid1=[5., 6.]. There are  
     100 values of x (xdata). 

	GCURV, xdata, zro1, slp1, hgt1, cen1, wid1, tfit

RELATED PROCEDURES:
	GFITSLOPE
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gcurvslope.pro)


GFIT -- FIT MULTIPLE (N) GAUSSIANS + AN OFFSET TO A ONE-D ARRAY OF DATA POINTS

[Previous Routine] [Next Routine] [List of Routines]
NAME:
GFIT --  Fit multiple (N) Gaussians + an offset to a one-d array of data points

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points

CALLING SEQUENCE:
    GFIT, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, 
	  problem, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated constant zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset.
     hgt1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: the 'error of the mean' of the fitted zero offset.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: the array of errors of the N fitted centers.
     sigwid1: the array of errors of the N fitted widths.
     problem: 0, OK; -1, excessive width; -2, >50 loops; -3, negative sigmas,
; 4, bad derived values.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values NO LONGER NEED be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

	gfit, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma

    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.
	Modified 16 jul 98, with 'problems' enhancement.
	Modified 7 apr 2002, restriction on asymptotic x removed.

(See /dzd2/heiles/idl/gen/gaussians/gfit.pro)


GFIT2D

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GFIT2D

PURPOSE:
    Fit multiple (N) Gaussians to a 2-d array of data points

CALLING SEQUENCE:
    GFIT2D, look, xdata, ydata, tdata, zro0, hgt0, cenx0, ceny0, wid0, 
         tfit, sigma,
         zro1, hgt1, cenx1, ceny1, wid1, 
         sigzro1, sighgt1, sigcenx1,sigceny1, sigwid1, 
	  problem, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     ydata: the y-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated constant zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cenx0: the array of N estimated x-centers of the Gaussians.
     ceny0: the array of N estimated y-centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset.
     hgt1: the array of N fitted heights. 
     cenx1: the array of N fitted x-centers.
     ceny1: the array of N fitted y-centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: the 'error of the mean' of the fitted zero offset.
     sighgt1: the array of errors of the N fitted heights.
     sigcenx1: the array of errors of the N fitted x-centers.
     sigceny1: the array of errors of the N fitted y-centers.
     sigwid1: the array of errors of the N fitted widths.
     problem: 0, OK; -1, excessive width; -2, >50 loops; -3, negative sigmas,
; 4, bad derived values.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values NO LONGER NEED be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

	gfit, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma

    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV2D
HISTORY:
	GFIT Written by Carl Heiles. 21 Mar 1998.
	Modified 16 jul 98, with 'problems' enhancement.
	Modified 7 apr 2002, restriction on asymptotic x removed.
       Upgraded to 2D by Paul Demorest 6 jan 2003.

(See /dzd2/heiles/idl/gen/gaussians/gfit2d.pro)


GFITCFIX

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GFITCFIX

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points; 
    THIS VERSION KEEPS THE CENTER FIXED but **DOES** FIT THE ZERO OFFSET.

CALLING SEQUENCE:
    GFITCFIX, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset.
     hgt1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: the error in the fitted zero offset.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: the array of errors of the N fitted centers.
     sigwid1: the array of errors of the N fitted widths.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values should be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

	gfit, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma
    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gfitcfix.pro)


GFITCWFIX

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GFITCWFIX

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points; 
    THIS VERSION KEEPS THE CENTER AND THE WIDTH FIXED.

CALLING SEQUENCE:
    GFITCWFIX, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.
     BECAUSE THIS IS NOT A NONLINEAR FIT, THE NUMERICAL VALUES OF THE
	ABOVE DON'T MATTER AT ALL...

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset.
     hgt1: the array of N fitted heights. 
     cen1: the array of centers--equal to cen0.
     wid1: the array of widths--equal to wid0.
     sigzro1: the error in the fitted zero offset.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: meaningless--equal to 0.
     sigwid1: meaningless--equal to 0.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    none--this is not a nonlinear fit, so no iterations are required.

EXAMPLE:
    You have two Gaussians whose centers, widths are known.
	you think that The heights are hgt0=[1.5, 2.5], 
	the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). 

	gfitcwfix, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma
    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gfitcwfix.pro)


GFITCWZFIX

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GFITCWZFIX

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points; 
    THIS VERSION KEEPS THE CENTER, WIDTH, and ZERO POINT FIXED.

CALLING SEQUENCE:
    GFITCWZFIX, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.
     BECAUSE THIS IS NOT A NONLINEAR FIT, THE NUMERICAL VALUES OF THE
	ABOVE DON'T MATTER AT ALL...

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the zero offset, equal to zro0.
     hgt1: the array of N fitted heights. 
     cen1: the array of centers--equal to cen0.
     wid1: the array of widths--equal to wid0.
     sigzro1: meaningless--equal to 0.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: meaningless--equal to 0.
     sigwid1: meaningless--equal to 0.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    none--this is not a nonlinear fit, so no iterations are required.

EXAMPLE:
    You have two Gaussians whose centers, widths are known.
	you think that The heights are hgt0=[1.5, 2.5], 
	the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). 

	gfitcwfix, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma
    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gfitcwzfix.pro)


GFITCZFIX

[Previous Routine] [Next Routine] [List of Routines]
NAME:
   GFITCZFIX

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points; 
    THIS VERSION KEEPS THE CENTER FIXED AND ALSO THE ZERO OFFSET FIXED.

CALLING SEQUENCE:
    GFITCZFIX, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the  zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: equal to zro0, the inputted zero offset.
     hgt1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: meaningless. Set equal to zero.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: the array of errors of the N fitted centers.
     sigwid1: the array of errors of the N fitted widths.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values should be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

	gfit, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma
    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 21 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gfitczfix.pro)


GFITFLEX -- FIT N GAUSSIANS KEEPING ANY ARRBITRARY SET OF PARAMETERS FIXED

[Previous Routine] [Next Routine] [List of Routines]
NAME:
GFITFLEX -- fit N gaussians keeping any arrbitrary set of parameters fixed

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points, 
	keeping any arbitrary set of parameters fixed and not included
	in the fit.

CALLING SEQUENCE:
    GFITFLEX, look, xdata, tdata, zro0, hgt0, cen0, wid0, $
	zro0yn, hgt0yn, cen0yn, wid0yn, $
	tfit, sigma, zro1, hgt1, cen1, wid1, $
	sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.
     xrange: 2n-element vector: 2 values for each of n index ranges
	specifying which indices of tdata to include in the fit.

     zro0: the estimated constant zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

     zr0yn: if 0, does not fit zero level; if 1, it does.
     hgt0yn: array of N 0 or 1; 0 does not fit the hgt, 1 does.
     cen0yn: array of N 0 or 1; 0 does not fit the hgt, 1 does.
     wid0yn: array of N 0 or 1; 0 does not fit the hgt, 1 does.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset (held constant if zro0yn=0).
     hgt1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: the error of the fitted zero offset; zero if zr0yn=0.
     sighgt1: the array of errors of the N fitted heights; zero if hgt0yn=0).
     sigcen1: the array of errors of the N fitted centers; zero if cen0yn=0).
     sigwid1: the array of errors of the N fitted widths; zero if wid0yn=0).
     problem: 0, OK; -1, excessive width; -2, >50 loops; -3, negative sigmas,
	; 4, bad derived values.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values should be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
	easy case; for the estimated parameters, you need not be accurate
	at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
	and the widths are [5., 6.]. You wish to hold the width of the second
    Gaussian fixed in the fit, so you set wid0yn=[1,0]. 
    There are 100 data points (tdata) at 
	100 values of x (xdata) and you want to fit indices 25-75 and
	77-80 only, so
	you set xrange=[50,75,77,80]. 
    You don't wish to see plots of the iterations,
	you don't care about the uncertainties, but you want the fitted
	 points and also the rms of the residuals.

    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Original GFIT Written by Carl Heiles. 21 Mar 1998.
	FLEX options added 4 feb 00.

(See /dzd2/heiles/idl/gen/gaussians/gfitflex.pro)


GFITSLOPE -- FIT N GAUSSIANS PLUS AN OFFSET AND SLOPE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
GFITSLOPE -- fit n gaussians plus an offset and slope

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points.
	ALSO FITS A ZERO OFFSET AND SLOPE.

CALLING SEQUENCE:
    GFITSLOPE, look, xdata, tdata, zro0, slp0, hgt0, cen0, wid0, 
	tfit, sigma, zro1, slp1, hgt1, cen1, wid1, 
	sigzro1, sigslp1, sighgt1, sigcen1, sigwid1, problem, cov

INPUTS:
     look: if >=0, plots the iterated values for the Gaussian
     whose component number is equal to look. Then it prompts you to plot 
     a different Gaussian component number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated constant zero offset of the data points.
     slp0: the estimated slope.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     zro1: the fitted zero offset
     slp1: the fitted slope
     hgt1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N fitted half-power widths.
     sigzro1: the 'error of the mean' of the fitted zero offset.
     sigslp1: the 'error of the mean' of the fitted slope.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: the array of errors of the N fitted centers.
     sigwid1: the array of errors of the N fitted widths.
     problem: 0, OK; -1, excessive width; -2, >50 loops; -3, negative sigmas,
; 4, bad derived values.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values should be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

    gfitslope, look, xdata, tdata, zro0, slp0, hgt0, cen0, wid0, tfit, sigma

    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURVSLOPE
HISTORY:
	Written by Carl Heiles. 11 Jul 1998.
	Modified 16 jul 98, with 'problems' enhancement.

(See /dzd2/heiles/idl/gen/gaussians/gfitslope.pro)


GFITWZFIX

[Previous Routine] [List of Routines]
NAME:
   GFITWZFIX

PURPOSE:
    Fit multiple (N) Gaussians to a one-d array of data points.
    The WFIX means that the Widths are FIXED to be the values in wid0.

CALLING SEQUENCE:
    GFIT, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma,
         zro1, hgt1, cen1, wid1, sigzro1, sighgt1, sigcen1, sigwid1, cov

INPUTS:
     look: if >=0, plots the iteratited values for the Gaussian
     whose number is equal to look. Then it prompts you to plot 
     a different Gaussian number.

     xdata: the x-values at which the data points exist.
     tdata: the data points.

     zro0: the estimated constant zero offset of the data points.
     hgt0: the array of N estimated heights of the Gaussians.
     cen0: the array of N estimated centers of the Gaussians.
     wid0: the array of N estimated halfwidths of the Gaussians.

OUTPUTS:
     zro1: the array of N fitted heights. 
     cen1: the array of N fitted centers.
     wid1: the array of N half-power widths; they are equal to wid0.
     tfit: the fitted values of the data at the points in xdata.
     sigma: the rms of the residuals.
     sigzro1: the 'error of the mean' of the fitted zero offset.
     sighgt1: the array of errors of the N fitted heights.
     sigcen1: the array of errors of the N fitted centers.
     sigwid1: the array of errors of the N fitted widths.
     cov: the normalized covariance matrix of the fitted coefficients.

RESTRICTIONS:
    The data and x values should be in asympototic x order, 
    either increasing or decreasing.
    Gaussians are not an orthogonal set of functions! 
    This doesn't matter for many cases; convergence is unique UNLESS...
    Convergence is NOT unique when Gaussians are close together or when
    multiple Gaussians lie within a single peak. In these cases, you
    can get different outputs from different inputs.
    And sometimes in these cases the fits will not converge!

    This procedure uses the classical nonlinear least squares technique,
    which utilizes analytically-calculated derivatives, to iteratively
    solve for the least squares coefficients. Some criteria on the
    parameters used to update the iterated coefficients are used to
    make the fit more stable (and more time-consuming). The number
    of iterations is limited to 50; if you need more, enter the routing
    again, using the output parameters as input for the next attampt.

EXAMPLE:
    You have two Gaussians that are well-separated. This counts as an
    easy case; for the estimated parameters, you need not be accurate
    at all. The heights are hgt0=[1.5, 2.5], the centers cen0=[12., 20.],
    and the widths are [5., 6.]. There are 100 data points (tdata) at 
     100 values of x (xdata). You don't wish to see plots of the iterations,
     you don't care about the uncertainties, but you want the fitted
     points and also the rms of the residuals.

	gfit, look, xdata, tdata, zro0, hgt0, cen0, wid0, tfit, sigma
    If you have two Gaussians that are mixed, you must be careful in
    your estimates!

RELATED PROCEDURES:
	GCURV
HISTORY:
	Written by Carl Heiles. 24 Mar 1998.

(See /dzd2/heiles/idl/gen/gaussians/gfitwzfix.pro)


general procs

general procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:26 2005.


List of Routines


Routine Descriptions

DEL_VAR

[Next Routine] [List of Routines]
 NAME:
       DEL_VAR

 PURPOSE:
       Program deletes an IDL variable from memory management.
       Unlike DELVAR, it can be called from program modules.

 CALLING SEQUENCE:
       DEL_VAR, variable

 INPUTS:
       variable: variable to be deleted

 OUTPUTS:
       None.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       The variable is now undefined.

 EXAMPLE:
       Define a variable...
       IDL> f = 1024
       IDL> help, f
       F               INT       =     1024

       Delete the variable...
       IDL> del_var, f
       IDL> help, f
       F               UNDEFINED = 

 MODIFICATION HISTORY:
   15 Feb 2004  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/general/del_var.pro)


DOC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       doc

 PURPOSE:
       Shorthand for doc_library.

 CALLING SEQUENCE:
       doc, name

 INPUTS:
       Name - A string containing the name of the IDL routine in question. 

 KEYWORD PARAMETERS:
       All keywords accepted by DOC_LIBRARY are also accepted here.

 OUTPUTS:
       None.

 NOTES:
       If a routine is compiled but the directory of the routine is not
       in !PATH, then in order to get the documentation, you need to specify
       the DIRECTORY keyword must be set to the directory of the routine.

 MODIFICATION HISTORY:
   26 Feb 2003  Written by Tim Robishaw, Berkeley
   03 Oct 2005  TR.  Added _REF_EXTRA options.

(See /dzd2/heiles/idl/gen/general/doc.pro)


GETNCOL

[Previous Routine] [List of Routines]
 NAME:
       GETNCOL

 PURPOSE:
       Read data array of given number of columns from an ASCII data file.

 CALLING SEQUENCE:
       GETNCOL, FNAME, NUMCOL, RESULT, [,/BYTE|/INT|/LONG|/FLOAT|/DOUBLE]
       [,SKIP=skip][,LINES=lines][,/SILENT]

 INPUTS:
       FNAME - File name.
       NUMCOL - Number of columns in the file.

 KEYWORD PARAMETERS:
       /BYTE - if set, data read as byte type.
       /INT - if set, data read as integer type.
       /LONG - if set, data read as long integer type.
       /FLOAT - if set, data read as floating-point type.
       /DOUBLE - if set, data read as double-precision 
                 floating-point type.
       SKIP - The number of lines to skip at the start of the file.
       LINES - Set this keyword to a named variable that stores the
               number of lines read into the data array.
       /SILENT - Set this keyword to prevent messages.

 OUTPUTS:
       RESULT - Array containing the data read from file.

 COMMON BLOCKS:
       None.

 RESTRICTIONS:
       All data are assumed to be of the same data type.

 EXAMPLE:
       Read in 12 columns of byte type data from the file file.dat,
       skipping the first 3 lines and suppressing messages:

       IDL> GETNCOL, 'file.dat', 12, data, /BYTE, /SILENT

 NOTES:
       If no data type keyword is specifies, then floating-point 
       is assumed.

 MODIFICATION HISTORY:
   02 Mar 2003  Written by Tim Robishaw, Berkeley

(See /dzd2/heiles/idl/gen/general/getncol.pro)


idlutils_carl procs

idlutils_carl procs

This page was created by the IDL library routine mk_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? mk_html_help

at the IDL command line prompt.

Last modified: Tue Dec 20 11:48:26 2005.


List of Routines


Routine Descriptions

BAR

[Next Routine] [List of Routines]

 A program to create a progress bar within a loop.

 Call sequence:
   BAR, I, IMAX

 Inputs:
   I - The index being advanced in the loop.
   IMAX - The value at the loop's finish.

 Outputs:
   Prints out a simple empty bar that fills up with 10 dashes as the
   loop completes.

 Calls:
   DELVARX (Goddard Routine)

Katie Peek August 2004

(See /dzd2/heiles/idl/gen/idlutils_carl/bar.pro)


COUNT

[Previous Routine] [Next Routine] [List of Routines]
NAME
COUNT -- This procedure exists only as example of overwriting the screen in place
with a running number without skipping lines.

(See /dzd2/heiles/idl/gen/idlutils_carl/count.pro)


FILLARR -- GENERATE AN ARRAY FROM MIN TO MAX WITH STEP SIZE DEL.

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
FILLARR --  generate an array from MIN to MAX with step size DEL. 


 PURPOSE:
       This function generates an array from MIN to MAX with
       step size DEL. If an integer number of steps cannot be
       fit between MIN and MAX, then MAX will be adjusted to
       be as close as the specified maximum as possible.
 CATEGORY:



 CALLING SEQUENCE:
       f = fillarr(n, min, max [,fan=, transfan=, /double])


 INPUTS:

       DEL:  The desired step size
       MIN:  The value of the first array element in F
       MAX:  The value of the last array element in F if
             (MAX-MIN)/DEL is an integer. Adjusted otherwise.

 OPTIONAL INPUTS:

 KEYWORD PARAMETERS:

       FAN:        Number of times the array is to be repeated.
                   The final dimensions of F  will be 
                   fix((MAX-MIN)/DEL) + 1 columns by FAN rows.

       /TRANSPOSE  Final dimensions of F wil be FAN columns by 
                   fix((MAX-MIN)/DEL) + 1 rows if FAN is specified. 

 OUTPUTS:

       F:    Final array. If input parameters are double precision,
             then F will be double as well. F is float otherwise.


 OPTIONAL OUTPUTS:



 COMMON BLOCKS:



 SIDE EFFECTS:



 RESTRICTIONS:



 PROCEDURE:



 EXAMPLE:

         For an array that runs from 2 to 5 in steps of .7

         IDL> f = fillarr(.7,2,5)
         IDL> print, f
            2.00000      2.70000      3.40000     4.10000    4.80000
         
 MODIFICATION HISTORY:
 Written by John "JohnJohn" Johnson 21-Feb-2002
 22-Feb-2002 JohnJohn- Fixed precision bug
 23-Feb-2002 JohnJohn- Calculations performed in double precision. 
                       Output in double precision if input is 
                       double.
 01-Mar-2002 JohnJohn- Much props to Tim Robishaw (Tdogg) for helping
                       me understand machine precision and truly fix
                       the precision bug.

(See /dzd2/heiles/idl/gen/idlutils_carl/fillarr.pro)


INDXTODIMS -- CONVERT BETWEEN A 1-D INDEX AND AN N-DIMENSIONAL INDEX OR VICE-VERSA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
INDXTODIMS --  convert between a 1-d index and an n-dimensional index or vice-versa

PURPOSE:
    converts between a 1-d index and an n-dimensional index for an
	array of the given size. Goes either direction.

CALLING SEQUENCE:
	INDXTODIMS, array, indx, dims, direction

INPUTS:
	array: an N-dimensional input array. Not changed or used except
to define the dimensions for which the outputs are computed.
	indx: the one-d index. an INPUT if direction=+1, an OUTPUT otherwise.
	dims: a vector of size N containing the three indices in N-d space.
An INPUT if direction=-1, an OUTPUT otherwise.
	direction: the direction of conversion: 
		+1 to go from INDX ---> DIMS
		-1 to go from DIMS ---> INDX

IMPORTANT: INDX can be an N-element array, where N is the nr of indices
		to treat.
	    DIMS can be an N by M element array, where N is the nr of indices
		to treat and M is the nr of dimensions in ARRAY.
OUTPUTS:
	indx: the one-d index. an INPUT if direction=+1, an OUTPUT otherwise.
If indx is an INPUT, it may be a 1-d array, in which case dims will
be an array whose first dimension is that of indx.
	dims: a vector of size N containing the three indices in N-d space.
An INPUT if direction=-1, an OUTPUT otherwise.

EXAMPLE:
	you have a 3-d vector X(541,541,9) and a 1-d index returned from
the 'where' function equal to 880212.

	INDXTODIMS, X, 880212, dims, +1

returns dims=[5,4,3].
HISTORY:
	Written by Carl Heiles. 18 Sep 1998.

(See /dzd2/heiles/idl/gen/idlutils_carl/indxtodims.pro)


LOOP_BAR

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

 LOOP_BAR
 A program to create a progress bar within a loop.

 Call sequence:
   BAR, I, IMAX [, IMIN=integer]

 Inputs:
   I - The index being advanced in the loop.
   IMAX - The value at the loop's finish.

 Outputs:
   Prints out a simple empty bar that fills up with 10 dashes as the
   loop completes.  Also prints percent complete and estimates time
   remaining.

 Keyword:
   IMIN - Include if IMIN is nonzero.  Default IMIN = 0.

 Calls:
   DELVARX (Goddard Routine)

 Katie Peek / August 2004
  Updated to include remaining time estimate - August 2005

(See /dzd2/heiles/idl/gen/idlutils_carl/loop_bar.pro)


MAKEARR -- GENERATE AN N-EL ARRAY RUNNING FROM VALUES MIN TO MAX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
MAKEARR -- generate an N-el array running from values MIN to MAX


 PURPOSE:
       This procedure will generate an array of lenght N which
       runs from values MIN to MAX

 CATEGORY:



 CALLING SEQUENCE:
       f = makearr(n, min, max [,fan=, transfan=, /double])


 INPUTS:

       N:    The number of desired array elements in F
       MIN:  The value of the first array element in F
       MAX:  The value of the last array element in F

 OPTIONAL INPUTS:

 KEYWORD PARAMETERS:

       FAN:        Number of times the array is to be repeated.
                   The final dimensions of F  will be N columns 
                   by FAN rows.
       /TRANSPOSE  Final dimensions of F wil be FAN columns by N 
                   rows if FAN is specified. 

 OUTPUTS:

       F:    Final array

 OPTIONAL OUTPUTS:



 COMMON BLOCKS:



 SIDE EFFECTS:



 RESTRICTIONS:



 PROCEDURE:



 EXAMPLE:

      If you want a 5 element array which runs from 2 to 4:

         IDL> f = makearr(5,2,4)
         IDL> print, f
             2.00000      2.50000      3.00000      3.50000      4.00000
         
 MODIFICATION HISTORY:
 Written by John "JohnJohn" Johnson somewhere around Oct-2001
 20 Feb 2002 JohnJohn- Added /FAN and /TRANSPOSE keywords.
 23 Feb 2002 JohnJ