ISOPHOT Interactive Analysis (PIA)

PIA serendipity

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: Fri Mar 24 12:48:58 2000.


List of Routines


Routine Descriptions

BIWEIGHT_MEAN

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

 PURPOSE:
	Calculate the center and dispersion (like mean and sigma) of a
	distribution using bisquare weighting.

 CALLING SEQUENCE:
	Mean = BIWEIGHT_MEAN( Vector, [ Sigma, Weights ] )

 INPUTS:
	Vector = Distribution in vector form

 OUTPUT:
	Mean - The location of the center.

 OPTIONAL OUTPUT ARGUMENTS:

	Sigma = An outlier-resistant measure of the dispersion about the
	center, analogous to the standard deviation. The half-width of the 95%
	confidence interval = |STUDENT_T( .95, .7*(N-1) )*SIGMA/SQRT(N)|,
	where N = number of points.

	Weights = The weights applied to the data in the last iteration.

SUBROUTINE CALLS:
	MED, which calculates a median

 REVISION HISTORY
	Written,  H. Freudenreich, STX, 12/89
	Modified 2/94, H.T.F.: use a biweighted standard deviation rather than
		median absolute deviation.
	Modified 2/94, H.T.F.: use the fractional change in SIGMA as the
		convergence criterion rather than the change in center/SIGMA.

(See ser/pia_sm_background.pro)


BPRECESS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       BPRECESS
 PURPOSE:
       Calculate the mean place of a star at B1950.0 on the FK4 system from the
       mean place at J2000.0 on the FK5 system.

 CALLING SEQUENCE:
       bprecess, ra, dec, ra_1950, dec_1950, [ MU_RADEC = , PARALLAX =
                                       RAD_VEL =, EPOCH =   ]

 INPUTS:
       RA,DEC - Input J2000 right ascension and declination in *degrees*.
               Scalar or N element vector

 OUTPUTS:
       RA_1950, DEC_1950 - The corresponding B1950 right ascension and
               declination in *degrees*.    Same number of elements as
               RA,DEC but always double precision.

 OPTIONAL INPUT-OUTPUT KEYWORDS
       MU_RADEC - 2xN element double precision vector containing the proper
                  motion in seconds of arc per tropical *century* in right
                  ascension and declination.
       PARALLAX - N_element vector giving stellar parallax (seconds of arc)
       RAD_VEL  - N_element vector giving radial velocity in km/s

       The values of MU_RADEC, PARALLAX, and RADVEL will all be modified
       upon output to contain the values of these quantities in the
       B1950 system.  The parallax and radial velocity will have a very
       minor influence on the B1950 position.

       EPOCH - scalar giving epoch of original observations, default 2000.0d
           This keyword value is only used if the MU_RADEC keyword is not set.
 NOTES:
       The algorithm is taken from the Explanatory Supplement to the
       Astronomical Almanac 1992, page 186.
       Also see Aoki et al (1983), A&A, 128,263

       BPRECESS distinguishes between the following two cases:
       (1) The proper motion is known and non-zero
       (2) the proper motion is unknown or known to be exactly zero (i.e.
               extragalactic radio sources).   In this case, the reverse of
               the algorithm in Appendix 2 of Aoki et al. (1983) is used to
               ensure that the output proper motion is  exactly zero. Better
               precision can be achieved in this case by inputting the EPOCH
               of the original observations.

       The error in using the IDL procedure PRECESS for converting between
       B1950 and J1950 can be up to 1.5", mainly in right ascension.   If
       better accuracy than this is needed then BPRECESS should be used.

       An unsystematic comparison of BPRECESS with the IPAC precession
       routine available at ned.ipac.caltech.edu always gives differences
       less than 0.1".
 EXAMPLE:
       The SAO2000 catalogue gives the J2000 position and proper motion for
       the star HD 119288.   Find the B1950 position.

       RA(2000) = 13h 42m 12.740s      Dec(2000) = 8d 23' 17.69''
       Mu(RA) = -.0257 s/yr      Mu(Dec) = -.090 ''/yr

       IDL> mu_radec = 100D* [ -15D*.0257, -0.090 ]
       IDL> ra = ten(13, 42, 12.740)*15.D
       IDL> dec = ten(8, 23, 17.69)
       IDL> bprecess, ra, dec, ra1950, dec1950, mu_radec = mu_radec
       IDL> print, adstring(ra1950, dec1950,2)
               ===> 13h 39m 44.526s    +08d 38' 28.63"

 REVISION HISTORY:
       Written,    W. Landsman                October, 1992
       Vectorized, W. Landsman                February, 1994
       Treat case where proper motion not known or exactly zero  November 1994
       Handling of arrays larger than 32767   Lars L. Christensen, march, 1995

(See ser/pia_sm_fitfind.pro)


DER_SMCHDR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       DER_SMCHDR
 PURPOSE:
	Derive a SMC Header file, adding to the SRD header (SRDHDR) 
	keywords indicating signal selection criteriae for SMC derivation.

 CALLING SEQUENCE:
       DER_SMCHDR, srdhdr, smchdr

 INPUT:
       SRDHDR 	: SRD-header

 OUTPUT:
       SMCHDR 	: SMC-header

 COMMON BLOCKS:
	phtacc

 RESTRICTIONS:

 PROCEDURES USED: 

 MODIFICATION HISTORY:
       Written by P. Merluzzi            		June 1995
	SMDHDR -> SMCHDR	                   (SB, 19/07/96)
       New SMC structure, new header keywords     (SB, 28/01/97)

(See ser/der_smchdr.pro)


FILL_SMC

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

 PURPOSE:
	FILLS a temporary structure into the dynamical structure PHTSMC  

 CATEGORY:
	PIA - I/O

 CALLING SEQUENCE:
       FILL_SMC, tmp [,newheader] [,REPLACE=replace]

 INPUT:
       tmp 	: SMC like temporary structure

 OPTIONAL INPUT:
	newheader:  New header to be change into the structure

 KEYWORD:
	REPLACE : IF set (different to 0) put structure into this PHTSMC position

 RESTRICTIONS:
       tmp must be a valid phtsmc like temporary structure

 PROCEDURES USED: 
       Common Block(s) or @ procedure(s):
               phtsmc

 MODIFICATION HISTORY:
       Written by: S. Bogun  (MPIA)		June 97

(See ser/fill_smc.pro)


FIT_RAMPS_SM

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

 PURPOSE:
	Fit a polynomial to the voltage ramps of a measurement returning 
	the slopes, their uncertainties and the fitted lines.

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
    FIT_RAMPS_SM, IPIX, Xall, Yall, Ndeg, Dr, St, Tint, Ylin, Yslop, Yslopr, $
	        Yflag, Ytime, Yresi, Ynros

 INPUTS:
	ipix	: The pixel number
	Yall	: Array containing values of read-outs from a measurement [V]
	Xall	: Array containing the independent variable [t]  (same size)
	Ndeg	: Polynomial degree
	Dr	: Read-out status (0 = NDR, 1 = DR) 
	St	: Flag status (0 = OK, 1 = bad flag)
	Tint	: On chip integration time applied in the measurement

 OUTPUTS:
	Ylin	: Array containing the fitted lines
	Yslop	: Array of found slopes 
	Yslopr	: Array of uncertainties in slopes
	Yflag	: Array of flags (0:ok; 1:2 read-outs used; 2:bad)
	Ytime	: Slopes times   
	Yresi	: Array with effective reset intervals used
	Ynros	: Array with effective number of read-outs used

 RESTRICTIONS:
	Yall, Xall, Dr and Tint must have the same number of elements

 PROCEDURES USED:
	None

 MODIFICATION HISTORY:
	Written by:	Carlos Gabriel		
	Modified (last) by CG:	October 1996
	V5.x
	Flagging with 1 pseudo_ramps with less than !subd_ramp/2. 
	 to avoid problems with too small uncertainties
	Bug fixed: start time of pseudo-ramp was shifted one read-out (CG)
	V6.3 
       modified for use with Serendipity subdivided ramps (SB) June 1997
       absolute path for the cal file 'c200_debcorr.sav' (SB)  December 1997

(See ser/fit_ramps_sm.pro)


GENCHO_SM

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

 PURPOSE:
	Definition of the common block GENCHO_SM for inclusion into other routines.  By defining
	The common block GENCHO_SM contains different flags for driving automatic
	processing.

 CATEGORY:
       PIA - common block

 CALLING SEQUENCE:
	@gencho_sm

 COMMON BLOCK PARAMETERS:
	gen_(several parameters driving the processing)

 MODIFICATION HISTORY:
	Wrtten by: Stefan Bogun (MPIA)			August 1996
	modified:   some new parameters (SB)		June 1997
                   Completely new design according to SESAME-V4.0 (SB)
                                                       December 1997
	Reset Interval Correction flag added (CG)	April 1998
	V7.1

(See ser/gencho_sm.pro)


GENCHO_SM_INIT

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

 PURPOSE:
       Initializes the structure COMMON block GENCHO_SM used for Serendipity
	batch processing.

 CATEGORY:
       PIA - initialization

 CALLING SEQUENCE:
       @gencho_sm_init

 MODIFICATION HISTORY:
       Written by: S. Bogun (MPIA)			August 1996
	modified:   some new parameters (SB)		June 1997
                   Completely new design according to SESAME-V4.0 (SB)
                                                       December 1997

(See ser/gencho_sm_init.pro)


IA_START_NOX

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

 PURPOSE:
	To initialize the Interactive Analysis with the relevant 
	parameters from Calibration G files or elsewhere, which 
	do not change at all or just do it infrequently

 CATEGORY:
	PIA - initialisation

 CALLING SEQUENCE:
	IA_START_NOX

 INPUTS:
	None

 OUTPUTS:
	None

 COMMON BLOCKS:
               adm
               adm_init
               colour_indices
               phtaap
               phtcla
               phtcs
               phtdarkcur
               phtdietrans
               phterd
               phtfilter_prop
               phtiiph
               phtscp
               phtsm
               phtsmc
		gencho_sm
               phtspd
               phtsrd
		
 PROCEDURE:
	Calibration G files are used eventually together with parameters
	which are direcly written into this routine and do not change
	frequently. 

 PROCEDURES USED:
	PIA LIB: darkcur_init
	         darkcur_str_init
	         die_trans_init
	         fcspow_str_init
	         phtcap_init
	         phtfilter_prop_init
	         respons_str_init
	         scp_init
	         set_colours
	         smc_init
	         spd_init
	         srd_init
	         write_acc

	         phtaap_init (batch file)
	         phtcla_init (batch file)
	         phtcs_init (batch file)
	         phterd_init (batch file)
	         phtiiph_init (batch file)
	         phtscp_init (batch file)
                phtsm_init (batch file)
	         phtsmc_init (batch file)
	         phtspd_init (batch file)
	         phtsrd_init (batch file)

 MODIFICATION HISTORY:
	Written by:	Carlos Gabriel, ESA/VILSPA	October 1995
	Modified (last) by CG				January 1997
	V5.5.1
	Initialisation of PIA_BUFINFO added to avoid
	 problems (CG)					May 1997
	V6.3 
       

(See ser/ia_start_nox.pro)


IIPH_INIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       iiph_init
 PURPOSE:
       Initializes the structure PHTIIPH defining the contents as
	a template structure PHTIIPH_TYPE. It can be used for clearing
	the whole IIPH structure, in case this should show as necessary. 

 CALLING SEQUENCE:
       IIPH_INIT

 INPUT PARAMETERS:
	None       

 OUTPUT PARAMETERS: 
	None

 PROCEDURES USED:
       It uses the batch file phtiiph_init

 MODIFICATION HISTORY:
       Copied by P. Merluzzi from SRD_init written by C. Gabriel     June 1995

(See ser/iiph_init.pro)


LOWESS

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

 PURPOSE:
	Robust smoothing of 1D data. A non-parametric way of drawing a smooth
	curve to represent data. (For 2D (map) data, use LOESS.)

 CALLING SEQUENCE:
	YSmooth = LOWESS( X, Y, Window, NDeg, Noise )

 INPUT ARGUMENTS:
	X = X values
	Y = Y values, to be smoothed
	WINDOW = width of smoothing window
	NDEG   = degree of polynomial to be used within the window (1 or 2
		recommended)

 OUTPUT:
	Ysmooth - LOWESS returns the vector of smoothed Y values

 OPTIONAL OUTPUT ARGUMENT:
	Noise = the robust std. deviation w.r.t. the fit, at each point

 NOTE:
	This routine uses a least-squares fit within a moving window. The fit
	is weighted by statistical weights and weights that are a function of
	distance from the center of the window. This is a "local weighted
	polynomial regression smoother" (Cleveland 1979, Journal of the Amer.
	Statistical Association, 74, 829-836).
	A polynomial of degree NDEG+1 is fitted directly to the first and last
	WINDOW/2 points.

	This routine is fairly slow.

 SUBROUTINES CALLED:
	ROBUST_LINEFIT
	ROBUST_POLY_FIT
	ROB_CHECKFIT
	ROBUST_SIGMA
	POLYFITW
	MED

 REVISION HISTORY:
	Written,  H.T. Freudenreich, HSTX, 1/8/93
	H.T. Freudenreich, 2/94 Return sigma rather than slope

(See ser/pia_sm_background.pro)


NON_LIN_LSQ[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       Non_Lin_Lsq
 PURPOSE:
       Non-linear least squares fit of a function of an
       arbitrary number of parameters, to 2-D data set.
       Function may be any non-linear function where
       the partial derivatives are known or can be approximated.
 CATEGORY:
       Mathematical Functions
 CALLING:
       Non_Lin_Lsq, Xi, Yi, Zd, Parms, sigmas, FUNC_NAME="name of function"
 INPUTS:
       Xi = vector of independent variables.
       Zd = vector of dependent variable to be fit with func_name (Xi, Yi),
                                                 same length as Xi.
       Parms = vector of nterms length containing the initial estimate
              for each parameter.  If Parms is double precision, calculations
              are performed in double precision, otherwise in single prec.
              The initial guess of the parameter values should be as close to
              the actual values as possible or the solution may not converge.
 KEYWORDS:
       FUNC_NAME = function name (string)
              Calling mechanism should be:  F = func_name (Xi, Yi, Parms, Pderiv)
         where:
              F = vector of NPOINT values of function.
              Xi = vector of NPOINT independent variables, input.
              Yi = vector of NPOINT independent variables, input.
              Parms = vector of NPARM function parameters, input.
              Pderiv = array, (NPOINT, NPARM), of partial derivatives.
                     Pderiv(I,J) = derivative of function at ith point with
                     respect to jth parameter.  Optional output parameter.
                     Pderiv should not be calculated if parameter is not
                     supplied in call (Unless you want to waste some time).
       WEIGHTS = vector of weights, same length as x and y.
              For equal (Gaussian) weighting w(i) = 1. (this is default),
              instrumental (Poisson) weighting w(i) = 1./y(i), etc.
      /INFO causes Chi-Sq. to be printed each iteration,
              INFO > 1 causes current parameter estimates to also print.
       MAX_ITERATIONS = maximum # of gradient search iterations, default=20.
       TOLERANCE = ratio of Chi-Sq. change to previous Chi-Sq. at which
                     to terminate iterations ( default = 1.e-4 = 0.1% ).
 OUTPUTS:
       Parms = vector of parameters giving best fit to the data.
 OPTIONAL OUTPUT PARAMETERS:
       sigmas = Vector of standard deviations for parameters Parms.
       chisq = final Chi-Sqr deviation of fit.
       Yfit = resulting best fit to data.
 PROCEDURE:
       Copied from "CURFIT", least squares fit to a non-linear
       function, pages 237-239, Bevington, Data Reduction and Error
       Analysis for the Physical Sciences.
       "This method is the Gradient-expansion algorithm which
       compines the best features of the gradient search with
       the method of linearizing the fitting function."
 MODIFICATION HISTORY:
       Written, DMS, RSI, September, 1982.
       Modified, Frank Varosi, NASA/GSFC, 1992, to use call_function.

(See ser/pia_sm_fitfind.pro)


NON_LIN_LSQ[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       Non_Lin_Lsq
 PURPOSE:
       Non-linear least squares fit of a function of an
       arbitrary number of parameters, to 1-D data set.
       Function may be any non-linear function where
       the partial derivatives are known or can be approximated.
 CATEGORY:
       Mathematical Functions
 CALLING:
       Non_Lin_Lsq, Xi, Yd, Parms, sigmas, FUNC_NAME="name of function"
 INPUTS:
       Xi = vector of independent variables.
       Yd = vector of dependent variable to be fit with func_name( Xi ),
                                                 same length as Xi.
       Parms = vector of nterms length containing the initial estimate
              for each parameter.  If Parms is double precision, calculations
              are performed in double precision, otherwise in single prec.
              The initial guess of the parameter values should be as close to
              the actual values as possible or the solution may not converge.
 KEYWORDS:
       FUNC_NAME = function name (string)
              Calling mechanism should be:  F = func_name( Xi, Parms, Pderiv )
         where:
              F = vector of NPOINT values of function.
              Xi = vector of NPOINT independent variables, input.
              Parms = vector of NPARM function parameters, input.
              Pderiv = array, (NPOINT, NPARM), of partial derivatives.
                     Pderiv(I,J) = derivative of function at ith point with
                     respect to jth parameter.  Optional output parameter.
                     Pderiv should not be calculated if parameter is not
                     supplied in call (Unless you want to waste some time).
       WEIGHTS = vector of weights, same length as x and y.
              For equal (Gaussian) weighting w(i) = 1. (this is default),
              instrumental (Poisson) weighting w(i) = 1./y(i), etc.
      /INFO causes Chi-Sq. to be printed each iteration,
              INFO > 1 causes current parameter estimates to also print.
       MAX_ITERATIONS = maximum # of gradient search iterations, default=20.
       TOLERANCE = ratio of Chi-Sq. change to previous Chi-Sq. at which
                     to terminate iterations ( default = 1.e-4 = 0.1% ).
 OUTPUTS:
       Parms = vector of parameters giving best fit to the data.
 OPTIONAL OUTPUT PARAMETERS:
       sigmas = Vector of standard deviations for parameters Parms.
       chisq = final Chi-Sqr deviation of fit.
       Yfit = resulting best fit to data.
 PROCEDURE:
       Copied from "CURFIT", least squares fit to a non-linear
       function, pages 237-239, Bevington, Data Reduction and Error
       Analysis for the Physical Sciences.
       "This method is the Gradient-expansion algorithm which
       compines the best features of the gradient search with
       the method of linearizing the fitting function."
 MODIFICATION HISTORY:
       Written, DMS, RSI, September, 1982.
       Modified, Frank Varosi, NASA/GSFC, 1992, to use call_function.

(See ser/pia_sm_fitfind.pro)


PHTIIPH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PHTIIPH
 PURPOSE:
	This is not an IDL routine as such, but contains the definition of the
	common block PHTIIPH for inclusion into other routines.  By defining
	the common block in one place, the problem of conflicting definitions
	is avoided.

	This file is included into routines that need this common block with
	the single line (left justified)

				  @phtiiph


 MODIFICATION HISTORY:

(See ser/phtiiph.pro)


PHTIIPH_INIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PhtIIPH_init
 PURPOSE:
       Initializes the structure PHTIIPH defining the contents as
	a template structure PHTIIPH_TYPE. It can be used for clearing
	the whole IIPH structure, in case this should show as necessary. 

 CALLING SEQUENCE:
       PHTIIPH_INIT

 INPUT PARAMETERS:
	None       

 OUTPUT PARAMETERS: 
	None

 PROCEDURES USED:
       None

 MODIFICATION HISTORY:
       Written by P. Merluzzi                       June 1995
       Sky coordinates and roll angle                  August 1995
       uncertainties added
	modified due to changes of IIPH format		SB, December 1995
	ADMN, SPR removed			        SB, July 1996
	modified due to changes of IIPH format		SB, November 1996

(See ser/phtiiph_init.pro)


PHTSM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PHTSM
 PURPOSE:
       COMMON blocks for PIA_SM_.. routines

 CALLING SEQUENCE:
       @phtsm

 INPUT PARAMETERS:

 OPTIONAL INPUT:

 OPTIONAL OUTPUT:

 RESTRICTIONS:

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
       25JUL1996 RoBaS - created document, first code
	pia_sm_cmn -> phtsm, according to gen. PIA rules (SB)	August 1996
	COMMON pia_sm_cmn deleted, obsolete (SB)		August 1996	
	flg_srccand introduced (SB)				December 1996
	smp_bckit introduced, smp_snrps deleted (SB)	      	January 1997
	several modifications (RA)			      	February 1997
	smp_logfp, smp_objfp deleted (SB)	       	      	February 1997
       all smp_* values deleted (SB)                           December 1997

(See ser/phtsm.pro)


PHTSMC

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

 PURPOSE:
	Definition of the common block PHTSMC (Edited Raw Data) for inclusion
	into other routines.

 CATEGORY:
       PIA - common block

 CALLING SEQUENCE:
	@phtsmc


 MODIFICATION HISTORY:
 	Written by:	Carlos Gabriel (ESA/ESTEC)
	smc_first_handle, smc_last_handle added (WMT/SB)	July 1996
	PHTSMC_DESC added	(WMT/SB)			July 1996
	Oct 95 Version 3.5

(See ser/phtsmc.pro)


PHTSMC_INIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PhtSmc_init
 PURPOSE:
       Initializes the structure PHTSMC defining the contents as
	a template structure PHTSMC_TYPE. It can be used for clearing
	the whole SMC structure, in case this should show as necessary. 

 CALLING SEQUENCE:
       PHTSMC_INIT

 INPUT PARAMETERS:
	None       

 OUTPUT PARAMETERS: 
	None

 PROCEDURES USED:
       None

 MODIFICATION HISTORY:
       Written by P. Merluzzi                      	August 1995
       Sky coordinates and roll angle                  August 1995
       uncertainties added
	smc_first_handle, smc_last_handle and phtsmc_desc
	added			(WMT)			May 1996
       MNPW/MNPU -> FLX/FLXU, ITUT removed (SB)        July 1996
       New SMC structure (SB)				January 1997

(See ser/phtsmc_init.pro)


PHTSM_INIT

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

 PURPOSE:
       Initializes the structure COMMON block PHTSM used for Serendipity
	processing.

 CATEGORY:
       PIA - initialization

 CALLING SEQUENCE:
       @phtsm_init

 MODIFICATION HISTORY:
       Written by: R. Assendorp (AIP Potsdam)		August 1996
	Modified:
	  smp_bckit introduced, smp_snrps deleted (SB, January 1997)
	  point_source_type initialized (SB, February 1997)
	  all smp_* values except smp_vel deleted (SB, December 1997)

(See ser/phtsm_init.pro)


PIA_GENCHO_SM

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

 PURPOSE:
	Menu for general choices within an automatic PIA procedure.

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
	PIA_gencho_sm

 INPUTS:
	
 KEYWORD PARAMETERS:
	GROUP
		The group leader of the widget hirarchy
	
 OUTPUTS:
	none
	
 SIDE EFFECTS:
	several variables are defined in two common blocks, which drive
	the automatic measurements processing	
	
 PROCEDURES USED:
	INTERNAL: 
		pia_gencho_sm_event

 COMMON BLOCKS:
	pia_gencho_sm_cmn	for internal use
	gencho_sm_cmn	for returning several variables
	pia_gencho_sm_wid 	for internal use
	
 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			July 1996
	adapted from PIA_GENCHO written by Carlos Gabriel
	modified:     new design for PSE (SB)			January 1997
	              usage of subdivided ramps (SB)		June 1997
	              flatfielding (SB)		                August 1997
                     Completely new design according to SESAME-V4.0 (SB)
                                                               December 1997
	Reset Interval Correction setting added (CG)		April 1998
	V7.1
	Modal defined as prescribed by IDL >= 5.0 (CG)		February 1999
	V7.3.1

(See ser/pia_gencho_sm.pro)


PIA_PROC_BATCH_MANAGER_SM

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

 PURPOSE:
       Menu and procedure within the PIA to get automatically
       a sequence of steps to be performed, without major interaction
	for Serendipity measurements.
       Data reduction from ERD up to SMC level and point source extraction, 
	including calibration.
	This menu is on top of PIA_PROC_BATCH_SM and loop over several files

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_PROC_BATCH_MANAGER_SM

 INPUTS:

 KEYWORD PARAMETERS:

 OUTPUTS:
	none


 COMMON BLOCKS:
	phterd:		ERD dynamical structure
	phtsrd:		SRD dynamical structure
	phtsmc:		SMC dynamical structure
       gencho_sm_cmn   for returning several variables
       phtacc		for selection criteria
	batch_sm_wid:   widget information

 PROCEDURES USED:
	PIA Procedure(s):
	Internal:
		pia_proc_batch_manager_sm_event

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			July 1996
	adapted from PIA_PROC_BATCH_MANAGER written by Carlos Gabriel

	cleaning all buffers (SB, October 1996)
	also cleaning IIPH buffer (SB, November 1996)
	correct handling of CANCEL button  (SB, November 1996)
	processing window remains the same (SB, November 1996)
	changing path in file selectors works now (SB, December 1996)
	reading files from !XDRDIR rather than !INTDIR (SB, February 1997)
       slight corrections due to changed parameters (SB, December 1997)

(See ser/pia_proc_batch_manager_sm.pro)


PIA_PROC_BATCH_MANAGER_SM_NOX

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

 PURPOSE:
       Menu and procedure within the PIA to get automatically
       a sequence of steps to be performed, without major interaction
	for Serendipity measurements.
       Data reduction from ERD up to SMC level and point source extraction, 
	including calibration.
	This menu is on top of PIA_PROC_BATCH_SM_NOX and loop over several files

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_PROC_BATCH_MANAGER_SM_NOX

 INPUTS:

 KEYWORD PARAMETERS:

 OUTPUTS:
	none


 COMMON BLOCKS:
	phterd:		ERD dynamical structure
	phtsrd:		SRD dynamical structure
	phtsmc:		SMC dynamical structure
       gencho_sm_cmn   for returning several variables
       phtacc		for selection criteria

 PROCEDURES USED:
	PIA Procedure(s):

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			July 1996
	adapted from PIA_PROC_BATCH_MANAGER written by Carlos Gabriel

	cleaning all buffers (SB, October 1996)
	also cleaning IIPH buffer (SB, November 1996)
	correct handling of CANCEL button  (SB, November 1996)
	processing window remains the same (SB, November 1996)
	changing path in file selectors works now (SB, December 1996)
	reading files from !XDRDIR rather than !INTDIR (SB, February 1997)
       slight corrections due to changed parameters (SB, December 1997)

(See ser/pia_proc_batch_manager_sm_nox.pro)


PIA_PROC_BATCH_SM

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

 PURPOSE:
       Menu and procedure within the PIA to get automatically
       a sequence of steps to be performed for Serendipity.
       Data reduction from ERD up to SMC level, including point source extr.

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_PROC_BATCH_SM

 INPUTS:
	MEAS:	List of measurements in ERD buffer to be processed

 KEYWORD PARAMETERS:
	GROUP:	The group leader of this widget hierarchy

 OUTPUTS:
	none


 COMMON BLOCKS:
	phtcs:		CS dynamical structure
	phterd:		ERD dynamical structure
	phtsrd:		SRD dynamical structure
	phtscp:		SCP dynamical structure
	phtsm:		Serendipity dynamical structure
	phtsmc:		SMC dynamical structure
	phtresact:	actual responsivities 
	deglitch_param: parameters for deglitching procedure
	gencho_sm_cmn:	for returning several variables
	batch_sm_wid:   widget information

 PROCEDURES USED:
	PIA Procedure(s):
		deglitch_param_init
		lin_voltages
		pia_gencho
		pia_load_ics
		pia_load_ierd
		pia_load_iscp
		pia_load_isrd
		pia_sm_load_ismc
		pia_pickfile
		pia_respons
		pia_rodisc
		pia_sigdisc
		pia_write_ics
		pia_sm_write_smc
               pia_sm_psework_init
               pia_sm_psework_create
               pia_sm_psework_init
               pia_sm_psework_to_phtismc
		pickmeas
		process_erd
		process_srd
		read_erd
		respons_interpol
		write_smc
	Internal:

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			July 1996
	adapted from PIA_PROC_BATCH written by Carlos Gabriel
	Modified:
	   WAIT, 10 -> WAIT, 5 (SB)				October 1996
	   More detailed output in batch window (SB)		October 1996
	   modified check for saturated pixels (SB)		October 1996
	   check if enough samples are above slew speed threshold (SB)
								October 1996
	   processing window remains the same (SB, November 1996)
	   two iterations of PSE process (SB)			December 1996
	   OPENW for log/obj files deleted (SB)			December 1996
	   PSE processing before saving (SB)			December 1996
	   new ISMC structure, work structure, point source
            structure, new processing sequence for ISMC (SB)	December 1996
          exclude revolutions with zero FCS power from FCS calibration (SB)
                                                               February 1997
	   reading internal files from !XDRDIR (rather than from !INTDIR) (SB)
								February 1997
	   slight cosmectic changes, point_sources already initialized (SB)
								February 1997
          generation of PSE working structure exernal now (SB) February 1997
          Signal deglitching updated according to PIA V6.2 (SB) April 1997
          pia_respons_sm call replaced by pia_respons (SB)     April 1997
          small bug fix (drift recognition failed, SB)         April 1997
          usage of subdivided ramps possible (SB)              June 1997
          modified for use with PIA V6.4 (SB)                  July 1997
          flatfielding introduced (SB)                         July 1997
          slight corrections due to changed parameters (SB)    December 1997
          modifications due to SESAME-V4.0 (SB)                December 1997

	   Dark current subtraction now orbital dependent (CG)	
	   Also inclusion of Reset Interval Correction (CG)	
	   Process_tmperd replacing obsolete process_erd (CG)   April 1998
	   V7.1

(See ser/pia_proc_batch_sm.pro)


PIA_PROC_BATCH_SM_NOX

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

 PURPOSE:
       Menu and procedure within the PIA to get automatically
       a sequence of steps to be performed for Serendipity.
       Data reduction from ERD up to SMC level, including point source extr.

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_PROC_BATCH_SM_NOX

 INPUTS:
	MEAS:	List of measurements in ERD buffer to be processed

 KEYWORD PARAMETERS:

 OUTPUTS:
	none


 COMMON BLOCKS:
	phtcs:		CS dynamical structure
	phterd:		ERD dynamical structure
	phtsrd:		SRD dynamical structure
	phtscp:		SCP dynamical structure
	phtsm:		Serendipity dynamical structure
	phtsmc:		SMC dynamical structure
	phtresact:	actual responsivities
	deglitch_param: parameters for deglitching procedure
	gencho_sm_cmn:	for returning several variables
	batch_sm_wid:   widget information

 PROCEDURES USED:
	PIA Procedure(s):
		deglitch_param_init
		lin_voltages
		pia_gencho
		pia_load_ics
		pia_load_ierd
		pia_load_iscp
		pia_load_isrd
		pia_sm_load_ismc
		pia_pickfile
		pia_respons
		pia_rodisc
		pia_sigdisc
		pia_write_ics
		pia_sm_write_smc
               pia_sm_psework_init
               pia_sm_psework_create
               pia_sm_psework_init
               pia_sm_psework_to_phtismc
		pickmeas
		process_erd
		process_srd
		read_erd
		respons_interpol
		write_smc
	Internal:

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			July 1996
	adapted from PIA_PROC_BATCH written by Carlos Gabriel
	Modified:
	   WAIT, 10 -> WAIT, 5 (SB)				October 1996
	   More detailed output in batch window (SB)		October 1996
	   modified check for saturated pixels (SB)		October 1996
	   check if enough samples are above slew speed threshold (SB)
								October 1996
	   processing window remains the same (SB, November 1996)
	   two iterations of PSE process (SB)			December 1996
	   OPENW for log/obj files deleted (SB)			December 1996
	   PSE processing before saving (SB)			December 1996
	   new ISMC structure, work structure, point source
            structure, new processing sequence for ISMC (SB)	December 1996
          exclude revolutions with zero FCS power from FCS calibration (SB)
                                                               February 1997
	   reading internal files from !XDRDIR (rather than from !INTDIR) (SB)
								February 1997
	   slight cosmectic changes, point_sources already initialized (SB)
								February 1997
          generation of PSE working structure exernal now (SB) February 1997
          Signal deglitching updated according to PIA V6.2 (SB) April 1997
          pia_respons_sm call replaced by pia_respons (SB)     April 1997
          small bug fix (drift recognition failed, SB)         April 1997
          usage of subdivided ramps possible (SB)              June 1997
          modified for use with PIA V6.4 (SB)                  July 1997
          flatfielding introduced (SB)                         July 1997
          slight corrections due to changed parameters (SB)    December 1997
          modifications due to SESAME-V4.0 (SB)                December 1997

	   Dark current subtraction now orbital dependent (CG)	April 1998
	   Also inclusion of Reset Interval Correction (CG)	April 1998
	   V7.1

(See ser/pia_proc_batch_sm_nox.pro)


PIA_SM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PIA_SM
 PURPOSE:
       This is the first procedure for the analysis of the Serendipity Mode
	(SeM) observations. Here the SeM standard structure for is created: 
	PHTSMC. It is the root procedure that opens the SM Data Display for 
	the data processing. It allows to display the surface brightness versus
	time and sky position.
                
 CALLING SEQUENCE:
	PIA_SM, TMPDATA, SRDHDR, RESP, SMCPOS

 INPUT PARAMETERS:
	tmpdata	: structure to be use as input for the SM data analysis
	SRDHDR	: a header to be taken instead of tmpdata.hdr
	RESP	: Responsivity choice flag - 0=default, 1=from FCS, 
		  (2=responsivity history over orbit, not available so far).
	
 OPTIONAL INPUT:

 OPTIONAL OUTPUT:
	SMCPOS	: Array containing the positions of the produced SMC
		  data within the PHTSMC structure 

 RESTRICTIONS:

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
	Written by P. Meroluzzi                      	May 1995
       Add IIPH reading procedure                      June 1995
       Add the time conversions and interpolations     July 1995
       in order to produce the structure SMDPS with
       sky coordinates and signals
       Sky coordinates and roll angle                  August 1995 
       uncertainties added
       Correction for the file name IIPH               September 1995
       (FITDIR added)
	Correction of the flag: the discarded data	January 1996
	are registered, but not the deglitched ones
	Correction of the selection criteria (PM)        
       Correction of the CS selection (PM)

       RoBaS
       18JUN1996 correct CS file PSTI/PSTA

	general review, many things modified, loops replaced by WHERE syntax,
	conversion to surface brightness included, SMD structure removed,
						       (SB, 18/07/96)
	RA and ROLL flip problem fixed		       (SB, 17/09/96)
	PHTSMC.FLAG = PHTSRD.FLAG, sig_disc used       (SB, 29/10/96)
	correction for UTC time offset		       (SB, 06/11/96)
	new PHTIIPH usage; pointing shift correction   (SB, 14/11/96)
	little bug in pointing shift correction corr.  (SB, 19/11/96)
	new PHTSMC structure			       (SB, 28/01/97)
	responsivity uncertainty not used	       (SB, 30/01/97)
       initialize SMFL flag here                      (SB, 03/04/97)
       Previously flatfielded data can be processed   (SB, 01/08/97)
       Gyro drift correction only for OLP < 6.1       (SB, 12/09/97)

	Default responsivity orbital dependent (CG)	April 1998
	V7.1

(See ser/pia_sm.pro)


PIA_SM_BACKGROUND[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME
	 MED
 PURPOSE
	Compute the median of an array, which may be of even length.

 CALLING SEQUENCE:
 	MID_VALUE = PIA_SM_MED(A)

 OUTPUTS
 	The median of array A
 REVISION HISTORY:
	H.T. Freudenreich, ?/89

(See ser/pia_sm_background.pro)


PIA_SM_BACKGROUND[2]

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

 PURPOSE:
        Routine for Modeling of Background, taking care of various switches
        and loops over all detector pixels


 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
        PIA_SM_Background     Data, InMask, Background, OutlierMask,   $
                      OnlySecond=OnlySecond, PolySmooth=PolySmooth,    $
                      Debug=Debug, Plot=Plot, _EXTRA=EXTRA
 INPUTS:


 KEYWORD PARAMETERS:

 OUTPUTS:

 COMMON BLOCKS:

 PROCEDURES USED:

 NOTES:

 REVISION HISTORY:

(See ser/pia_sm_background.pro)


PIA_SM_BACKGROUND[2]

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

 PURPOSE:
        Routine for Modeling of Background, taking care of various switches
        and loops over all detector pixels


 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
        PIA_SM_Background     Data, InMask, Background, OutlierMask,   $
                      OnlySecond=OnlySecond, PolySmooth=PolySmooth,    $
                      Debug=Debug, Plot=Plot, _EXTRA=EXTRA
 INPUTS:


 KEYWORD PARAMETERS:

 OUTPUTS:

 COMMON BLOCKS:

 PROCEDURES USED:

 NOTES:

 REVISION HISTORY:
        Ver 1.0     M. Stickel, MPIA/IDC    December 1996
                    ... written
        Ver 1.1     M. Stickel, MPIA/IDC    January 1997
                    2 - step -algorithm with keywords
        Ver 1.2     M. Stickel, MPIA/IDC    January 1997
                    quick mode : interpolate and poly_smooth

(See ser/pia_sm_background.pro)


PIA_SM_COMPNOISE

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

 PURPOSE:
         Computes Global Statistics (Mean, Sigma)

 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
         PIA_SM_CompNoise, Data, Mask, GlobalStatistics, [/NoMask, /Debug]

 INPUTS:
        Data (i,*) : data streams
        Mask (i,*) : associated mask streams, >0 means good

                     i = 0 , ... , NoDetectors-1

 KEYWORD PARAMETERS:
        /NoMask    : No Mask available, use all samples in all streams
        /Debug     : switch on printouts for debugging

 OUTPUTS:
        GlobalStatistics (i, 0) : mean of each data stream
        GlobalStatistics (i, 1) : standard deviation of the distribution
                                  for each data stream

                     i = 0 , ... , NoDetectors-1

 COMMON BLOCKS:

 PROCEDURES USED:

 NOTES:

 REVISION HISTORY:
        Written   Ver 1.0     M. Stickel, MPIA/IDC    December 18, 1996

(See ser/pia_sm_noise.pro)


PIA_SM_COMPSENS

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

 PURPOSE:
         Computes Sensitivities (ScaleFactors)

 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
         PIA_SM_CompSens, Data, Mask, ScaleFactors, [/NoMask, /Debug]

 INPUTS:
        Data (i,*) : data streams, scalefactors are averages thereof
        Mask (i,*) : associated mask streams, >0 means good

                     i = 0 , ... , NoDetectors-1

 KEYWORD PARAMETERS:
        /NoMask    : No Mask available, use all samples in all streams
        /Debug     : switch on printouts for debugging

 OUTPUTS:
        ScaleFactors (i) : computed and renormalized sensitivities

                     i = 0 , ... , NoDetectors-1

 COMMON BLOCKS:

 PROCEDURES USED:

 NOTES:

 REVISION HISTORY:
        Written   Ver 1.0     M. Stickel, MPIA/IDC    December 18, 1996

(See ser/pia_sm_sensitivity.pro)


PIA_SM_DIS2SMC

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

 PURPOSE:
	Menu for PIA SMC Data display.
	This is a fourth level menu in the PIA hierarchy.

	This routine should only be called by the PIA Display Data routine
	and should not be called directly from the command line.

 CATEGORY:
	PIA - graphics

 CALLING SEQUENCE:
	PIA_SM_DIS2SMC, GROUP=group, DATA=data, NV=nv, REDRAW=redraw
	
 KEYWORD PARAMETERS:
	GROUP:	The group leader of the widget hirarchy
       DATA:   An element of the PHTSMC dynamical structure
       NV:     Number of Views (1 <= NV <= 4)
       REDRAW: To redraw same data
	
 COMMON BLOCKS:
	adm
	colour_indices
	phtacc
	phtcs
	phtsm
	phtsmc
	dsp2smc_cmn (internal)
	pia_dsp2ch5_cmn (internal)
	dsp2smc_widg (internal)
	pia_dspchz_cmn (internal)
	dispcust_cmn (internal)
	smc2text (internal)
	pia_sm_widget_info (internal)

 RESTRICTIONS:
       DATA must be a valid element of PHTSMC dynamical structure
		
 PROCEDURES USED:
	PIA LIB:
		decode_admn
		get_convwh
		get_pht_hk
		pia_dis2smc
		pia_disp_cs
		pia_disp_hdr
		pia_dispcust
		pia_sm_load_ismc
		pia_multmeas
		pia_oplot
		pia_pixchoice
		pia_plot
		pia_pubplot
		pia_showstr
		pia_sigdisc
		pia_sm_write_ismc
               pia_sm_psework_create
               pia_sm_psework_init
               pia_sm_psework_to_phtismc
         	pia_xplot
		pickmeas
		write_smc
		xdisp_hk
       ASTRO LIB:
		avg
		fxpar
		sigma
		precess
		euler
       INTERNAL:
		pixbut2event5
		view2event5
		average2nonch5
		average2event5
		median2nonch5
		median2event5
		zoom2event5
		zoom2fourier5
		zoom2sync5
		zoomn2sync5
		zoom2it5
		pia_reset2view5
		pia_dsmc2_event
	OTHER:
		sphdist
		deriv

 MODIFICATION HISTORY:
       Written by: S. Bogun, MPIA, August 1996 
		    based on PIA_DIS2SRD written by C. Gabriel
	Modified:
	  usage of tmpdata.flag modified (discarded == 2) (SB, October 1996)
	  warning messages when too many samples are discarded
							  (SB, October 1996)
	  SM flags now variables			  (SB, November 1996)
	  updated according to new PHTSMC structure, new working structure
							  (SB, December 1996)
         IF flag THEN ... changed to IF flag NE 0 THEN ..(SB, January 1997)
	  new ISMC structure, work structure, point source
            structure, new processing sequence for ISMC  (SB, January 1997)
         generation of PSE working structure exernal now (SB, February 1997)

(See ser/pia_sm_dis2smc.pro)


PIA_SM_DISPSMC

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

 PURPOSE:
	Menu for PIA SMC Data display.
	This is a fourth level menu in the PIA hierarchy.

	This routine should only be called by the PIA Display Data routine
	and should not be called directly from the command line.

 CATEGORY:
	PIA - graphics

 CALLING SEQUENCE:
	PIA_SM_DISPSMC, GROUP=group, DATA=data, NV=nv, REDRAW=redraw
	
 KEYWORD PARAMETERS:
	GROUP:	The group leader of the widget hirarchy
       DATA:   An element of the PHTSMC dynamical structure
       NV:     Number of Views (1 <= NV <= 4)
       REDRAW: To redraw same data
	
 COMMON BLOCKS:
	adm
	colour_indices
	phtacc
	phtcs
	phtsm
	phtsmc
	pia_dspsmc_cmn (internal)
	pia_dspch5_cmn (internal)
	dspsmc_widg (internal)
	pia_dspchz_cmn (internal)
	dispcust_cmn (internal)
	smctext (internal)
	pia_sm_widget_info (internal)

 RESTRICTIONS:
       DATA must be a valid element of PHTSMC dynamical structure
		
 PROCEDURES USED:
	PIA LIB:
		decode_admn
		get_convwh
		get_pht_hk
		pia_dis2smc
		pia_disp_cs
		pia_disp_hdr
		pia_dispcust
		pia_sm_load_ismc
		pia_multmeas
		pia_oplot
		pia_pixchoice
		pia_plot
		pia_pubplot
		pia_showstr
		pia_sigdisc
		pia_sm_write_ismc
               pia_sm_psework_create
               pia_sm_psework_init
               pia_sm_psework_to_phtismc
		pia_xplot
		pickmeas
		write_smc
		xdisp_hk
       ASTRO LIB:
		avg
		fxpr
		sigma
		precess
		euler
       INTERNAL:
		pixbutevent5
		viewevent5
		averagenonch5
		averageevent5
		mediannonch5
		medianevent5
		zoomevent5
		zoomfourier5
		zoomsync5
		zoomnsync5
		zoomit5
		pia_resetview5
		pia_dsmc_event
	OTHER:
		sphdist
		deriv

 MODIFICATION HISTORY:
       Written by: S. Bogun, MPIA, August 1996 
		    based on PIA_DISPSRD written by C. Gabriel
	Modified:
	  usage of tmpdata.flag modified (discarded == 2) (SB, October 1996)
	  warning messages when too many samples are discarded
							  (SB, October 1996)
         SM flags now variables                          (SB, November 1996)
         updated according to new PHTSMC structure, new working structure
                                                         (SB, December 1996)
	  IF flag THEN ... changed to IF flag NE 0 THEN ..(SB, January 1997)
	  new ISMC structure, work structure, point source
            structure, new processing sequence for ISMC  (SB, January 1997)
         generation of PSE working structure exernal now (SB, February 1997)

(See ser/pia_sm_dispsmc.pro)


PIA_SM_DISP_FSC_LIST

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

 PURPOSE:
	Display the list of IRAS point sources that are closer than DIST_MAX to
       the slew specified by the working structure TMPDATA.

 CATEGORY:
	PIA - graphics

 CALLING SEQUENCE:
	PIA_sm_disp_fsc_list, tmpdata, dist_max

 INPUTS:
       TMPDATA:  A Serendipity working structure as created by
                 PIA_SM_PSEWORK_CREATE.

       DIST_MAX: The maximum distance from (in degrees) at which IRAS point
                 sources should be searched.

 KEYWORD PARAMETERS:

 OUTPUTS:
	No explicit outputs.  A file viewing widget is created.

 COMMON BLOCKS:
	pia_sm_disp_fsc_list_cmn

 SIDE EFFECTS:
	Triggers the XMANAGER if it is not already in use.

 PROCEDURE:
	Open a file and create a widget to display its contents.

 PROCEDURES USED:
       INTERNAL:
		PIA_Disp_Print_File_evt

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	August 1997
			

(See ser/pia_sm_disp_fsc_list.pro)


PIA_SM_DISP_IRASGAL_LIST

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

 PURPOSE:
	Display the list of IRAS galaxies that are closer than DIST_MAX to
       the slew specified by the working structure TMPDATA.

 CATEGORY:
	PIA - graphics

 CALLING SEQUENCE:
	PIA_sm_disp_irasgal_list, tmpdata, dist_max

 INPUTS:
       TMPDATA:  A Serendipity working structure as created by
                 PIA_SM_PSEWORK_CREATE.

       DIST_MAX: The maximum distance from (in degrees) at which IRAS galaxies
                 should be searched.

 KEYWORD PARAMETERS:

 OUTPUTS:
	No explicit outputs.  A file viewing widget is created.

 COMMON BLOCKS:
	pia_sm_disp_irasgal_list_cmn

 SIDE EFFECTS:
	Triggers the XMANAGER if it is not already in use.

 PROCEDURE:
	Open a file and create a widget to display its contents.

 PROCEDURES USED:
       INTERNAL:
		PIA_Disp_Print_File_evt

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997
			

(See ser/pia_sm_disp_irasgal_list.pro)


PIA_SM_DISP_PSC_LIST

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

 PURPOSE:
	Display the list of IRAS point sources that are closer than DIST_MAX to
       the slew specified by the working structure TMPDATA.

 CATEGORY:
	PIA - graphics

 CALLING SEQUENCE:
	PIA_sm_disp_psc_list, tmpdata, dist_max

 INPUTS:
       TMPDATA:  A Serendipity working structure as created by
                 PIA_SM_PSEWORK_CREATE.

       DIST_MAX: The maximum distance from (in degrees) at which IRAS point
                 sources should be searched.

 KEYWORD PARAMETERS:

 OUTPUTS:
	No explicit outputs.  A file viewing widget is created.

 COMMON BLOCKS:
	pia_sm_disp_psc_list_cmn

 SIDE EFFECTS:
	Triggers the XMANAGER if it is not already in use.

 PROCEDURE:
	Open a file and create a widget to display its contents.

 PROCEDURES USED:
       INTERNAL:
		PIA_Disp_Print_File_evt

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997
			

(See ser/pia_sm_disp_psc_list.pro)


PIA_SM_FITFIND

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

    FLAGNAN

*CLASS:

*CATEGORY:

*PURPOSE:

    To flag and/or replace IEEE NaN values in an IDL array.

*CALLING SEQUENCE:

    FLAGNAN,ARRAY,IND,COUNT,nvalue

*PARAMETERS:

    ARRAY (REQ) (IO) (012) (RD)
       IDL array.

    IND (REQ) (O) (1) (I)
       indices of found NaN values

    COUNT (REQ) (O) (0) (IL)
       number of found NaN values. (0 if none found.)

    nvalue (OPT) (I) (0) (BILF)
       optional parameter specifying replacement value.
       If not specified, user is prompted for value.

*EXAMPLES:

*SYSTEM VARIABLES USED:

*INTERACTIVE INPUT:

*SUBROUTINES CALLED:

   PARCHECK

*FILES USED:

*SIDE EFFECTS:

       If no NaN values are found, or if ARRAY is not of type float, double
       precision, or complex, then -1 is returned, and COUNT is set to 0.

*RESTRICTIONS:

       ARRAY must be of type float, double-precision, or complex.

*PROCEDURE:

       The bit patterns of the numbers being tested are compared against the
       IEEE NaN standard.

*INF_1:

*NOTES:

       tested with IDL Version 2.2.0 (sunos sparc)   14 Nov 91
       tested with IDL Version 2.2.0 (ultrix mipsel) 14 Nov 91
       tested with IDL Version 2.2.0 (ultrix vax)    14 Nov 91
       tested with IDL Version 2.3.2 (vax vms)       19 Oct 92

*MODIFICATION HISTORY:

       written by Bill Thompson 2/92
        8-14-92 rwt add nvalue option, change from a function to a
               procedure & print out results
       10-19-92 rwt make ind and count required output parameters

(See ser/pia_sm_fitfind.pro)


PIA_SM_FLATFIELD

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

 PURPOSE:
	This routine applies a default flatfield to Serendipity SRD data

 CATEGORY:
       PIA - processing

 CALLING SEQUENCE:
       PIA_SM_FLATFIELD, Input_signal, Detector_name, Output_signal

 INPUTS:
       Input_signal: A 2-dim array. The first dim is the number of pixels

 OUTPUTS:
       Output_signal: Same dim as the input signal with the flatfield
                      correction

 COMMON BLOCKS:
       c200_srd_flat

 RESTRICTIONS:

 PROCEDURE:

 PROCEDURES USED:

 MODIFICATION HISTORY:
       Written by:	Stefan Bogun
                       August 1997
	Modified (last) by SB:	December 1997
       absolute path for the cal file 'c200_flat_corr_pixel1.sav' 
                                                        (SB)  December 1997

(See ser/pia_sm_flatfield.pro)


PIA_SM_FSC_ASSOC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PIA_SM_FSC_ASSOC
 PURPOSE:
       This routine searches the IRAS point source catalog for all objects
       closer than RADIUS to the position specified by RA and DEC. RA and
       DEC are specified in J2000. PIA_SM_FSC_ASSOC returns
       a structure array containing all associations to the specified position.
                
 CALLING SEQUENCE:
	RESULT = PIA_SM_FSC_ASSOC(RA, DEC, RADIUS, NASSOC)

 INPUT PARAMETERS:
	RA	: float scalar, containing the right ascension of the search
                 position (degrees, J2000).
	DEC	: float scalar, containing the declination of the search
                 position (degrees, J2000).
	RADIUS	: float scalar, containing the search radius (degrees).
	
 OPTIONAL INPUT:

 OUTPUTS:
       PIA_SM_FSC_ASSOC returns a structure array containing the matching 
       associations plus the spatial distance.

       NASSOC: integer scalar, containing the number of associations.

 OPTIONAL OUTPUT:

 RESTRICTIONS:
       PIA_SM_FSC_ASSOC needs the IRAS point source catalog stored in a special
       format in different save files (splitted into bins of 15 x 15 degrees).

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997

Needed common blocks : 
       fsc_assoc: handles for the FSC buffer

(See ser/pia_sm_fsc_assoc.pro)


PIA_SM_IRASGAL_ASSOC[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PIA_SM_IRASGAL_ASSOC
 PURPOSE:
       This routine searches the IRAS catalogued galaxies and quasars for all
       objects
       closer than RADIUS to the position specified by RA and DEC. RA and
       DEC are specified in J2000. PIA_SM_IRASGAL_ASSOC returns
       a structure array containing all associations to the specified position.
                
 CALLING SEQUENCE:
	RESULT = PIA_SM_IRASGAL_ASSOC(RA, DEC, RADIUS, NASSOC)

 INPUT PARAMETERS:
	RA	: float scalar, containing the right ascension of the search
                 position (degrees, J2000).
	DEC	: float scalar, containing the declination of the search
                 position (degrees, J2000).
	RADIUS	: float scalar, containing the search radius (degrees).
	
 OPTIONAL INPUT:

 OUTPUTS:
       PIA_SM_IRASGAL_ASSOC returns a structure array containing the matching 
       associations plus the spatial distance.

       NASSOC: integer scalar, containing the number of associations.

 OPTIONAL OUTPUT:

 RESTRICTIONS:
       PIA_SM_IRASGAL_ASSOC needs the IRAS extragalactic catalog stored in a 
       special
       format in different save files (splitted into bins of 30 x 30 degrees).

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997

Needed common blocks :
       irasgal_assoc: handles for the PSC buffer

(See ser/pia_sm_irasgal_assoc.pro)


PIA_SM_IRASGAL_ASSOC[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PIA_SM_IRASGAL_ASSOC
 PURPOSE:
       This routine searches the IRAS catalogued galaxies and quasars for all
       objects
       closer than RADIUS to the position specified by RA and DEC. RA and
       DEC are specified in J2000. PIA_SM_IRASGAL_ASSOC returns
       a structure array containing all associations to the specified position.

 CALLING SEQUENCE:
	RESULT = PIA_SM_IRASGAL_ASSOC(RA, DEC, RADIUS, NASSOC)

 INPUT PARAMETERS:
	RA	: float scalar, containing the right ascension of the search
                 position (degrees, J2000).
	DEC	: float scalar, containing the declination of the search
                 position (degrees, J2000).
	RADIUS	: float scalar, containing the search radius (degrees).

 OPTIONAL INPUT:

 OUTPUTS:
       PIA_SM_IRASGAL_ASSOC returns a structure array containing the matching
       associations plus the spatial distance.

       NASSOC: integer scalar, containing the number of associations.

 OPTIONAL OUTPUT:

 RESTRICTIONS:
       PIA_SM_IRASGAL_ASSOC needs the IRAS extragalactic catalog stored in a
       special
       format in different save files (splitted into bins of 30 x 30 degrees).

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997

Needed common blocks :
       irasgal_assoc: handles for the PSC buffer

(See ser/pia_sm_plotlog.pro)


PIA_SM_LOAD_ISMC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PIA_SM_load_ISMC
 PURPOSE:
	Write a PHT-SMC (Serendipity Mode Calibrated Data) measurement from the dynamical 
	structure SMCDAT (PHTSMC type) onto a temporary structure 
 CALLING SEQUENCE:
       PIA_SM_load_ISMC, SMCDAT, tmpsmc

 INPUT:
       SMCDAT 	: PHTSMC like dynamical structure


 RESTRICTIONS:
       SMCDAT must exist

 PROCEDURES USED: 

 MODIFICATION HISTORY:
       Written by P. Merluzzi                      	August 1995
       Sky coordinates and roll angle                  August 1995
       uncertainties added
	updated according to new SMC structure		(SB, 26/07/96)
	updated according to new SMC structure		(SB, 28/01/97)

(See ser/pia_sm_load_ismc.pro)


PIA_SM_NOISE

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

 PURPOSE:
         PIA_SM - Interface to PIA_SM_CompNoise
         Interpretes switches and prepares data and masks accordingly

 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
         PIA_SM_Noise, WorkStructure

 INPUTS:
        PHT_SM_WorkStructure

 KEYWORD PARAMETERS:
        any other keyword parameters are passed to all other routines

 OUTPUTS:
        Results are in-place written to
                    WorkStructure.gnoi

 COMMON BLOCKS:

 PROCEDURES USED:
        PIA_SM_CompNoise

 NOTES:

 REVISION HISTORY:
        Written   Ver 1.0     M. Stickel, MPIA/IDC    January 29, 1997

(See ser/pia_sm_noise.pro)


PIA_SM_PSC_ASSOC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PIA_SM_PSC_ASSOC
 PURPOSE:
       This routine searches the IRAS point source catalog for all objects
       closer than RADIUS to the position specified by RA and DEC. RA and
       DEC are specified in J2000. PIA_SM_PSC_ASSOC returns
       a structure array containing all associations to the specified position.
                
 CALLING SEQUENCE:
	RESULT = PIA_SM_PSC_ASSOC(RA, DEC, RADIUS, NASSOC)

 INPUT PARAMETERS:
	RA	: float scalar, containing the right ascension of the search
                 position (degrees, J2000).
	DEC	: float scalar, containing the declination of the search
                 position (degrees, J2000).
	RADIUS	: float scalar, containing the search radius (degrees).
	
 OPTIONAL INPUT:

 OUTPUTS:
       PIA_SM_PSC_ASSOC returns a structure array containing the matching 
       associations plus the spatial distance.

       NASSOC: integer scalar, containing the number of associations.

 OPTIONAL OUTPUT:

 RESTRICTIONS:
       PIA_SM_PSC_ASSOC needs the IRAS point source catalog stored in a special
       format in different save files (splitted into bins of 10 x 10 degrees).

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997

Needed common blocks : 
       psc_assoc: handles for the PSC buffer

(See ser/pia_sm_psc_assoc.pro)


PIA_SM_PSEWORK_CREATE

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

 PURPOSE:
       Creates a PIA Serendipity working structure using a PIA phtismc 
       structure

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_SM_PSEWORK_CREATE, PHTISMC, HDR, PSEWORK

 INPUTS:
       PHTISMC: PIA phtismc structure
       HDR:     PHTISMC header

 KEYWORD PARAMETERS:

 OUTPUTS:
	PSEWORK: PIA Serendipity working structure

 COMMON BLOCKS:
	phtsm:		Serendipity dynamical structure

 PROCEDURES USED:
       sphdist

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			February 1997

(See ser/pia_sm_psework_create.pro)


PIA_SM_PSEWORK_INIT

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

 PURPOSE:
       Initializes a PIA Serendipity working structure

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_SM_PSEWORK_INIT, PSEWORK, HDR

 INPUTS:
       PSEWORK: PIA Serendipity working structure
       HDR:     PHTISMC header

 KEYWORD PARAMETERS:

 OUTPUTS:
	PSEWORK: PIA Serendipity working structure
       HDR:     PHTISMC header

 COMMON BLOCKS:
	phtsm:		Serendipity dynamical structure

 PROCEDURES USED:

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			February 1997

       correct initialization of SMFL flag                     (SB, 03/04/97)

(See ser/pia_sm_psework_init.pro)


PIA_SM_PSEWORK_TO_PHTISMC

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

 PURPOSE:
       Stores the data from a PIA Serendipity working structure back to
       a phtismc structure

 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
       PIA_SM_PSEWORK_INIT, PSEWORK, HDR, PHTISMC

 INPUTS:
	PSEWORK: PIA Serendipity working structure
       HDR:     PHTISMC header

 KEYWORD PARAMETERS:

 OUTPUTS:
       PHTISMC: PIA phtismc structure

 COMMON BLOCKS:

 PROCEDURES USED:

 MODIFICATION HISTORY:
       Written by: 	Stefan Bogun (MPIA)			February 1997

(See ser/pia_sm_psework_to_phtismc.pro)


PIA_SM_READ_IIPH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PIA_SM_READ_IIPH
 PURPOSE:
	Read a IIPH file accomodating the data in structure PHTIIPH  
 CALLING SEQUENCE:
       PIA_SM_READ_IIPH, NAME, [ILUN], [PATH = PATH]

 INPUT:
       NAME 	: Name of IIPH FITS file to be read

 OPT. INPUT:
       PATH    : optional path for the file

 OPT. OUTPUTS:
	ILUN	: Array containing the indices of the measurements in the
		  PHTIIPH structure

 RESTRICTIONS:
       File must be a valid IIPH FITS file

 PROCEDURES USED:
       MERGEHDR 

 MODIFICATION HISTORY:
       Written by P. Merluzzi                      	June 1995
       Sky coordinates and roll angle                  August 1995
       uncertainties added
	modified according to increased primary header size
							SB, December 1995
       correct the sky coordinates arrays              SB & PM January 1996
	modifications according to new IIPH file structure
	and many other modifications                    SB, July 1996
	correct calculation of OLP version		SB, November 1996
	modified due to changes of IIPH format		SB, November 1996
	modified due to changes of IIPH format for OLP V6.1
                                                 	SB, September 1997

(See ser/pia_sm_read_iiph.pro)


PIA_SM_SENSITIVITY

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

 PURPOSE:
         PIA_SM_Interface to PIA_SM_CompSens
         Interpretes switches and prepares data and masks accordingly

 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
         PIA_SM_Sensitivity, WorkStructure, [/Use_Flux, /Use_Back]

 INPUTS:
        PHT_SM_WorkStructure

 KEYWORD PARAMETERS:
        any other keyword parameters are passed to all other routines

 OUTPUTS:
        Results are in-place written to
                    WorkStructure.sens     (Sensitivity Factors)

 COMMON BLOCKS:

 PROCEDURES USED:
        PIA_SM_CompSens

 NOTES:

 REVISION HISTORY:
        Written   Ver 1.1     M. Stickel, MPIA/IDC    April 10, 1997
        Written   Ver 1.0     M. Stickel, MPIA/IDC    January 29, 1997

(See ser/pia_sm_sensitivity.pro)


PIA_SM_SEPREP

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

 PURPOSE:
        Main Routine for Modeling of Background, equalizing sensitivities and
        calculating global statistics of Serendipity Slews

 CATEGORY:
        ISOPHOT, PIA, Serendipity Survey

 CALLING SEQUENCE:
        PIA_SM_SEPREP, PHT_SM_WorkStructure

 INPUTS:
        PHT_SM_WorkStructure

 KEYWORD PARAMETERS:
        any keyword parameters are passed to all other routines

 OUTPUTS:
        Results are written to
               WorkStructure.back     (Background)
               WorkStructure.sens     (Sensitivity Factors)
               WorkStructure.gnoi     (Global Noise data)

 COMMON BLOCKS:

 PROCEDURES USED:
        PIA_SM_Background
        PIA_SM_Sensitivity
        PIA_SM_Noise

 NOTES:

 REVISION HISTORY:
        Written   Ver 1.0     M. Stickel, MPIA/IDC    December 18, 1996
        Written   Ver 1.1     M. Stickel, MPIA/IDC    April, 1997

(See ser/pia_sm_sesame.pro)


PIA_SM_SLEWSHOW

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

 PURPOSE:
       PIA_SM_SLEWSHOW shows the slew specified by the phtismc structure
	on one ISSA map. If the slew hits more than one plate, then you can
       navigate through all plates. A PS file can be generated as well as 
       instantanious output on a printer.
       
 CATEGORY:
       Infrared Space Observatory

 CALLING SEQUENCE:
       PIA_SM_SLEWSHOW, PHTISMC

 INPUTS:
       PHTISMC: PHTISMC data structure

 OPTIONAL INPUT PARAMETERS:
      None.

 OPTIONAL INPUT KEYWORDS:
      None.

 OUTPUTS:
       Always a XWindow plot. A  PS file can be generated.

 OPTIONAL OUTPUT PARAMETERS:
	None

 OPTIONAL OUTPUT KEYWORDS:
       None.

 COMMON BLOCKS:
       xslews_vars

 SIDE EFFECTS:
       None.

 RESTRICTIONS:
	System variables that have to be defined:
       !PIA_SERDIR: output directory (is set by PIA)
	$PRINTER: the UNIX variable PRINTER determines the printer device

 MODIFICATION HISTORY:
       created by: Christian Straka        MPIA Heidelberg
                   July, 1997

(See ser/pia_sm_slewshow.pro)


PIA_SM_WND

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PIA_SM_WND
 PURPOSE:
       Set flag for all data where the slew velocity is less than smp_vel

 CALLING SEQUENCE:
       PIA_SM_WND, TMPDATA

 INPUT PARAMETERS:
       tmpdata : structure to be use as input for the SM data analysis

 OPTIONAL INPUT:

 OPTIONAL OUTPUT:

 RESTRICTIONS:

 METHOD:

 PROCEDURES USED:

 MODIFICATION HISTORY:
       25JUL1996 RoBaS - created document, first code
       12JUG1996 - output to logfile
       21AUG1996 - fixed for SeM-1.0
       02SEP1996 - better algorithme to find first/last sample to use (x0,x1)
       29OCT1996 - proper handling of PIA flag
       30JAN1997 - new data structure and logfile handling
       12FEB1997 - initialise smp_file, smp_slew
       24FEB1997 - don't initialize smp_file, smp_slew (SB)

Needed common blocks : phtsm

(See ser/pia_sm_wnd.pro)


PIA_SM_WRITE_ISMC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PIA_SM_WRITE_ISMC
 PURPOSE:
	Write a PHT-SMC (Serendipity Surface brightness data) measurement 
	from a temporary structure SMCDAT (PHTSMC type) onto an IDL savefile  
 CATEGORY:
	PIA - graphics
	PIA - I/O
 CALLING SEQUENCE:
       PIA_SM_WRITE_ISMC, SMCDAT, TMPHDR

 INPUT:
       PHTISMC : PHTSMC like temporary structure

 OPTIONAL INPUT:
       TMPHDR 	: Temporary header

 OUTPUT:
       IDL save file

 RESTRICTIONS:

 PROCEDURES USED:

 MODIFICATION HISTORY:
       Written by: S. Bogun
	August 96 Version 3.5
	updated according to new SMC structure		(SB, 28/01/97)

(See ser/pia_sm_write_ismc.pro)


POINT_SOURCE_INIT

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

 PURPOSE:
       Initializes the structure point_sources used for Serendipity
	processing.

 CATEGORY:
       PIA - initialization

 CALLING SEQUENCE:
       @point_source_init

 MODIFICATION HISTORY:
       Written by: S. Bogun (MPIA)			February 1997

(See ser/point_source_init.pro)


POLY_SMOOTH

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

 PURPOSE:
	Reduce noise in 1-D data (e.g. time-series, spectrum)
	but retain dynamic range of variations in the data by
	applying a least squares smoothing polynomial filter,

	also called the Savitzky-Golay smoothing filter, cf. Numerical
	Recipes (Press et al. 1992, Sec.14.8)

	The low-pass filter coefficients are computed by effectively
	least-squares fitting a polynomial in moving window,
	centered on each data point, so the new value will be the
	zero-th coefficient of the polynomial. Approximate first derivates
	of the data can be computed by using first degree coefficient of
	each polynomial, and so on. The filter coefficients for a specified
	polynomial degree and window width are computed independent of any
	data, and stored in a common block. The filter is then convolved
	with the data array to result in smoothed data with reduced noise,
	but retaining higher order variations (better than SMOOTH).

 CATEGORY:
       Array

 CALLING SEQUENCE:

	spectrum = poly_smooth( data, [ width, DEGREE = , NLEFT = , NRIGHT =
					DERIV_ORDER = ,COEFF = ]

 INPUTS:
	data = 1-D array, such as a spectrum or time-series.

	width = total number of data points to use in filter convolution,
		(default = 5, using 2 past and 2 future data points),
		must be larger than DEGREE of polynomials, and a guideline is
		make WIDTH between 1 and 2 times the FWHM of desired features.

 KEYWORDS:

	DEGREE = degree of polynomials to use in designing the filter
		via least squares fits, (default DEGREE = 2), and
		the higher degrees will preserve sharper features.

	NLEFT = # of past data points to use in filter convolution,
		excluding current point, overrides width parameter,
		so that width = NLEFT + NRIGHT + 1.  (default = NRIGHT)

	NRIGHT = # of future data points to use (default = NLEFT).

	DERIV_ORDER = order of derivative desired (default = 0, no derivative).

	COEFFICIENTS = optional output of the filter coefficients applied,
		but they are all stored in common block for reuse, anyway.
 RESULTS:
	Function returns the data convolved with polynomial filter coefs.

 EXAMPLE:

	Given a wavelength - flux spectrum (w,f), apply a 31 point quadratic
	smoothing filter and plot

	IDL> plot, w, poly_smooth(f,31)
 COMMON BLOCKS:
	common poly_smooth, degc, nlc, nrc, coefs, ordermax

 PROCEDURE:
	As described in Numerical Recipies, 2nd edition sec.14.8,
	Savitsky-Golay filter.
	Matrix of normal eqs. is formed by starting with small terms
	and then adding progressively larger terms (powers).
	The filter coefficients of up to derivative ordermax are stored
	in common, until the specifications change, then recompute coefficients.
	Coefficients are stored in convolution order, zero lag in the middle.
 MODIFICATION HISTORY:
	Written, Frank Varosi NASA/GSFC 1993.

(See ser/pia_sm_background.pro)


PROCESS_ERD_SM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	PROCESS_ERD_SM
 PURPOSE:
	Fit voltage ramps of chosen measurements, taken into 
	account diverse selections or flags and put the resulting
	ramps slopes, uncertainties, etc. into the structure
       phtsrd 
 CATEGORY:
	PIA - processing

 CALLING SEQUENCE:
	PROCESS_ERD_SM, FILES, NDEG, HDR, SRDPS, ERDPS

 INPUT PARAMETERS:
	FILES	: Array containing the names (phterd.admn) of the buffers
		  to be processed or the positions within the phterd buffer
	NDEG	: Degree of the polynomial to be fitted

  Example: FILES=['C10000100104','C10100100104','C20011111101']	 
	processes two C100 measurements (first and second of original
	P1ER00100104 FITS file and first of P2ER11111101 

 INPUT KEYWORDS:
	div_ramp: A factor for subdividing ramps when processing

 OPTIONAL INPUT:
	HDR	: String Array containing the file (updated) header

 OPTIONAL OUTPUT:
	SRDPS	: Array containing the positions of the produced SRD 
		  data within the PHTSRD structure
	ERDPS	: Array containing the positions of the input
		  data within the PHTERD structure

 RESTRICTIONS:

 METHOD:

 PROCEDURES USED:
       Common Block(s) or @ procedure(s):
               adm
               phterd
               phtsrd
       PIA Procedure(s):
               acc_flg
               acc_volt
               decode_pixf
               der_shdr
               fit_ramps
               red_ramps

 MODIFICATION HISTORY:
	Written by: C. Gabriel
	Oct 95 Version 3.5
	Extension for effective integration times and number of 
	 used readouts (CG)					January 1996
	Forcing flag array as integer array (CG)		July 1996
	Keyword div_ramp added for separating ramps (CG)	July 1996
	Filling FITV on ERD level only for not separated ramps  February 1997
	V6.1
	Bug (inexistent variable for uncertainties) fixed (CG)	April 1997
	V6.2.1 
	Ramp splitting using CB splitramp_par (CG)		May 1997
	V6.3
	Chopper step check included (CG)			June 1997
	V6.4
	Chopper position check included and step corrected (CG) September 1997
	V6.5
       modified for use with Serendipity subdivided ramps (SB) December 1997

(See ser/process_erd_sm.pro)


RADEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       RADEC
 PURPOSE:
       To convert right ascension and declination from decimal degrees to
       sexigesimal hours (for R.A.)  and degrees( for Dec.).

 CALLING SEQUENCE:
       pia_sm_radec, ra, dec, ihr, imin, xsec, ideg, imn, xsc, idegsign

 INPUTS:
       ra   - right ascension in decimal DEGREES, scalar or vector
       dec  - declination in decimal DEGREES, scalar or vector, same number
               of elements as RA

 OUTPUTS:
       ihr  - right ascension hours   (INTEGER*2)
       imin - right ascension minutes (INTEGER*2)
       xsec - right ascension seconds  (REAL*4 or REAL*8)
       ideg - declination degrees (INTEGER*2)
       imn  - declination minutes (INTEGER*2)
       xsc  - declination seconds (REAL*4 or REAL*8)
       idecsign - sign of declination (INTEGER*2)

 RESTRICTIONS:
       RADEC does minimal parameter checking.

 REVISON HISTORY:
       Written by B. Pfarr, STX, 4/24/87
       Sign of declination : M. Stickel , MPIA/IDC 3/97

(See ser/pia_sm_fitfind.pro)


RADEC2SLEWCOORD[1]

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

 PURPOSE:
	Converts celestial coordinates (RA,DEC) into slew coordinates (X,Y),
       which are cartesian coordinates with X being parallel to the slewing
       direction and Y perpendicular. The conversion is only valid locally.

 CATEGORY:
	PIA - Serendipity

 CALLING SEQUENCE:
	radec2slewcoord, ra, dec, ra_slew, dec_slew, index, X, Y

 INPUTS:
       RA, DEC:            Celestial positions to be converted into (X,Y).
                           Can be scalars or arrays.

       RA_SLEW, DEC_SLEW:  The slew coordinates (or an excerpt of the slew
                           around the reference point 
                           (RA_SLEW(INDEX),DEC_SLEW(INDEX)). Must be arrays.

       INDEX:              An scalar integer or float pointing to one slew 
                           position specified by (RA_SLEW,DEC_SLEW).

 KEYWORD PARAMETERS:
	None.

 OUTPUTS:
       X, Y:               The slew coordinates corresponding to the input
                           positions (RA,DEC). Same dimensions as RA and DEC.
                           (RA_SLEW(INDEX),DEC_SLEW(INDEX)) is converted to
                           (0,0).

 COMMON BLOCKS:
	None.

 RESTRICTIONS:
       The conversion is only correct locally.

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997
			

(See ser/radec2slewcoord.pro)


RADEC2SLEWCOORD[2]

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

 PURPOSE:
	Converts slew coordinates (X,Y) into celestial coordinates (RA,DEC).
       (X,Y) are cartesian coordinates with X being parallel to the slewing
       direction and Y perpendicular. The conversion is only valid locally.

 CATEGORY:
	PIA - Serendipity

 CALLING SEQUENCE:
	slewcoord2radec, X, Y, ra_slew, dec_slew, index, ra, dec

 INPUTS:
       X, Y:               The slew coordinates to be converted into (RA,DEC).
                           (0,0) is converted to (RA_SLEW(INDEX),
                           DEC_SLEW(INDEX)).

       RA_SLEW, DEC_SLEW:  The slew coordinates (or an excerpt of the slew
                           around the reference point 
                           (RA_SLEW(INDEX),DEC_SLEW(INDEX)). Must be arrays.

       INDEX:              An scalar integer or float pointing to one slew 
                           position specified by (RA_SLEW,DEC_SLEW).

 KEYWORD PARAMETERS:
	None.

 OUTPUTS:
       RA, DEC:            The celestial coordinates corresponding to (X,Y).
                           Same dimensions as X, Y.

 COMMON BLOCKS:
	None.

 RESTRICTIONS:
       The conversion is only correct locally.

 MODIFICATION HISTORY:
	Written by S. Bogun (MPIA)                   	June 1997
			

(See ser/slewcoord2radec.pro)


READ_SMC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       READ_SMC
 PURPOSE:
	READ a PHTSMC (Serendipity Surface Brightness Data) fits file 
	into the dynamical structure PHTSMC  
 CATEGORY:
	PIA - I/O
 CALLING SEQUENCE:
       READ_SMC, NAME

 INPUT:
       NAME 	: SMC-fitsfile name

 OPT. INPUT:
	PATH    : path for the file

 RESTRICTIONS:
       NAME must be a valid PHTSMC fits file 

 PROCEDURES USED: 
       Common Block(s) or @ procedure(s):
               adm
               phtsmc
       PIA Procedure(s):
               mergehdr
       Astronomical Library:
               fxpar

 MODIFICATION HISTORY:
       Written by: S. Bogun, MPIA, August 96
       based on READ_SRD written by W. M. Tai and C. Gabriel
	updated according to new SMC structure		(SB, 28/01/97)	
	reading SMC files from !XDRDIR (rather than from !FITDIR)
							(SB, 06/02/97)

(See ser/read_smc.pro)


RESISTANT_MEAN

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

 PURPOSE:
	An outlier-resistant determination of the mean and its standard
	deviation.  It trims away outliers using the median and the median
	absolute deviation.

 CALLING SEQUENCE:
	RESISTANT_MEAN,VECTOR,SIGMA_CUT, MEAN,SIGMA,NUM_REJECTED

 INPUT ARGUMENT:
	VECTOR    = Vector to average
	SIGMA_CUT = Data more than this number of standard deviations from the
		median is ignored. Suggested values: 2.0 and up.

 OUTPUT ARGUMENT:
	MEAN  = the mean
	SIGMA = the standard deviation of the mean
	NUM_REJECTED = the number of points trimmed

 SUBROUTINE CALLS:
	MED, which calculates a median

 REVISION HISTORY:
	Written, H. Freudenreich, STX, 1989; Second iteration added 5/91.

(See ser/pia_sm_background.pro)


ROBUST_LINEFIT

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

 PURPOSE:
	An outlier-resistant two-variable linear regression. Either Y on X
	or, for the case in which there is no true independent variable, the
	bisecting line of Y vs X and X vs Y is calculated. No knowledge of
	the errors of the input points is assumed.

 CALLING SEQUENCE:
	COEFF = ROBUST_LINEFIT( X, Y, YFIT, SIG, COEF_SIG, [ BISECT = ,
			BiSquare_Limit = , Close_factor = , NumIT = ] )

 INPUTS:
	X = Independent variable vector, floating-point or double-precision
	Y = Dependent variable vector

 OUTPUTS:
	Function result = coefficient vector.
	If = 0.0 (scalar), no fit was possible.
	If vector has more than 2 elements (the last=0) then the fit is dubious.

 OPTIONAL OUTPUT PARAMETERS:
	YFIT = Vector of calculated y's
	SIG  = The "standard deviation" of the fit's residuals. If BISECTOR
		is set, this will be smaller by ~ sqrt(2).
	COEF_SIG  = The estimated standard deviations of the coefficients. If
		BISECTOR is set, however, this becomes the vector of fit
		residuals measured orthogonal to the line.

 OPTIONAL INPUT KEYWORDS:
	NUMIT = the number of iterations allowed. Default = 25
	BISECT  if set, the bisector of the "Y vs X" and "X vs Y" fits is
		determined.  The distance PERPENDICULAR to this line is used
		in calculating weights. This is better when the uncertainties
		in X and Y are comparable, so there is no true independent
		variable.  Bisquare_Limit  Limit used for calculation of
		bisquare weights. In units of outlier-resistant standard
		deviations. Default: 6.
		Smaller limit ==>more resistant, less efficient
 Close_Factor  - Factor used to determine when the calculation has converged.
		Convergence if the computed standard deviation changes by less
		than Close_Factor * ( uncertainty of the std dev of a normal
		distribution ). Default: 0.03.
 SUBROUTINE CALLS:
	MED, to calculate the median
	ROB_CHECKFIT
	ROBUST_SIGMA, to calculate a robust analog to the std. deviation

 PROCEDURE:
	For the initial estimate, the data is sorted by X and broken into 2
	groups. A line is fitted to the x and y medians of each group.
	Bisquare ("Tukey's Biweight") weights are then calculated, using the
	a limit of 6 outlier-resistant standard deviations.
	This is done iteratively until the standard deviation changes by less
	than CLOSE_ENOUGH = CLOSE_FACTOR * {uncertainty of the standard
		deviation of a normal distribution}

 REVISION HISTORY:
	Written, H. Freudenreich, STX, 4/91.
	4/13/93 to return more realistic SS's HF
	2/94 --more error-checking, changed convergence criterion HF
	5/94 --added BISECT option. HF.
       8/94 --added Close_Factor and Bisquare_Limit options  Jack Saba.

(See ser/pia_sm_background.pro)


ROBUST_POLY_FIT

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

 PURPOSE:
	An outlier-resistant polynomial fit.

 CALLING SEQUENCE:
	COEFF = ROBUST_POLY_FIT(X,Y,NDEGREE  ,[ YFIT,SIG, NUMIT =] )

 INPUTS:
	X = Independent variable vector, floating-point or double-precision
	Y = Dependent variable vector

 OUTPUTS:
	Function result = coefficient vector, length NDEGREE+1.
	IF COEFF=0.0, NO FIT! If N_ELEMENTS(COEFF) > degree+1, the fit is poor
	(in this case the last element of COEFF=0.)
	Either floating point or double precision.

 OPTIONAL OUTPUT PARAMETERS:
	YFIT = Vector of calculated y's
	SIG  = the "standard deviation" of the residuals

 RESTRICTIONS:
	Large values of NDEGREE should be avoided. This routine works best
	when the number of points >> NDEGREE.

 PROCEDURE:
	For the initial estimate, the data is sorted by X and broken into
	NDEGREE+2 sets. The X,Y medians of each set are fitted to a polynomial
	 via POLY_FIT.   Bisquare ("Tukey's Biweight") weights are then
	calculated, using a limit  of 6 outlier-resistant standard deviations.
	The fit is repeated iteratively until the robust standard deviation of
	the residuals changes by less than .03xSQRT(.5/(N-1)).

 REVISION HISTORY
	Written, H. Freudenreich, STX, 8/90. Revised 4/91.
	2/94 -- changed convergence criterion

(See ser/pia_sm_background.pro)


ROBUST_SIGMA

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

 PURPOSE:
	Calculate a resistant estimate of the dispersion of a distribution.
	For an uncontaminated distribution, this is identical to the standard
	deviation.

 CALLING SEQUENCE:
	result = ROBUST_SIGMA( Y, [ /ZERO ] )

 INPUT:
	Y = Vector of quantity for which the dispersion is to be calculated
 OPTIONAL INPUT KEYWORD:
	ZERO - if set, the dispersion is calculated w.r.t. 0.0 rather than the
		central value of the vector. If Y is a vector of residuals, this
		should be set.

 OUTPUT:
	ROBUST_SIGMA returns the dispersion. In case of failure, returns
	value of -1.0

 SUBROUTINE CALLS:
	MED, which calculates the median

 PROCEDURE:
	Use the median absolute deviation as the initial estimate, then weight
	points using Tukey's Biweight. See, for example, "Understanding Robust
	and Exploratory Data Analysis," by Hoaglin, Mosteller and Tukey, John
	Wiley & Sons, 1983.

 REVSION HISTORY:
	H. Freudenreich, STX, 8/90

(See ser/pia_sm_background.pro)


ROB_CHECKFIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	ROB_CHECKFIT
 PURPOSE:
	Used by ROBUST_... routines to determine the quality of a fit and to
	return biweights.
 CALLING SEQUENCE:
	status = ROB_CHECKFIT( Y, YFIT, EPS, DEL, SIG, FRACDEV, NGOOD, W, B
				BISQUARE_LIMIT = )
 INPUT:
	Y     = the data
	YFIT  = the fit to the data
	EPS   = the "too small" limit
	DEL   = the "close enough" for the fractional median abs. deviations
 RETURNS:
	Integer status. if =1, the fit is considered to have converged

 OUTPUTS:
	SIG   = robust standard deviation analog
	FRACDEV = the fractional median absolute deviation of the residuals
	NGOOD   = the number of input point given non-zero weight in the
		calculation
	W     = the bisquare weights of Y
	B     = residuals scaled by sigma

 OPTIONAL INPUT KEYWORD:
	BISQUARE_LIMIT = allows changing the bisquare weight limit from
			default 6.0
 REVISION HISTORY:
	Written, H.T. Freudenreich, HSTX, 1/94

(See ser/pia_sm_background.pro)


SMC_INIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       smc_init
 PURPOSE:
       Initializes the structure PHTSMC defining the contents as
	a template structure PHTSMC_TYPE. It can be used for clearing
	the whole SMC structure, in case this should show as necessary. 

 CALLING SEQUENCE:
       SMC_INIT

 INPUT PARAMETERS:
	None       

 OUTPUT PARAMETERS: 
	None

 PROCEDURES USED:
       It uses the batch file phtsmc_init

 MODIFICATION HISTORY:
	Written by Wai-Ming Tai			May 1996

(See ser/smc_init.pro)


SPHDIST

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

 PURPOSE:
	SPHDIST calculates the distance between two points on a sphere.
	SPHDIST is also able to calculate the distance between a single point
	and a series of points or between two series of points. 

 CATEGORY:
       Astronomy.

 CALLING SEQUENCE:
	RESULT = SPHDIST( RA1, DEC1, RA2, DEC2 )

 INPUTS:
	RA1:	Flt scalar or array; specifying the right ascension of point 1
		[degrees].
	DEC1:	Flt scalar or array; specifying the declination of point 1
		[degrees].
	RA2:	Flt scalar or array; specifying the right ascension of point 2
		[degrees].
	DEC2:	Flt scalar or array; specifying the declination of point 2
		[degrees].

 OPTIONAL INPUT PARAMETERS:
       None.

 OPTIONAL INPUT KEYWORDS:
	None.

 OUTPUTS:
	SPHDIST returns the distance on the sphere between [RA1,DEC1] and
	[RA2,DEC2] [degrees]. If the input variables are arrays, SPHDIST
	returns an array of the same size.

 OPTIONAL OUTPUT PARAMETERS:
	None.

 OPTIONAL OUTPUT KEYWORDS:
	None.

 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
       None.

 RESTRICTIONS:
	RA1 and DEC1 must have the same dimensions, as well as RA2 and DEC2.
	If RA1, DEC1 are arrays, then RA2, DEC2 must either have the same size
	or must be scalars. In this case, the distance of [RA2,DEC2] to each
	of the points specified in [RA1,DEC1] is returned. The same applies to
	the opposite case.

 MODIFICATION HISTORY:
       created by: Stefan Bogun            MPIA Heidelberg
       	    March, 1995

(See ser/sphdist.pro)


WHERENAN

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

 PURPOSE:
	Find the positions of all values within an array that correspond to the
	IEEE NaN (not-a-number) special values.

 CATEGORY:
       Array

 CALLING SEQUENCE:
	Result = WHERENAN( ARRAY [, COUNT ] )

 INPUT PARAMETERS:
	ARRAY	= Array to test against the IEEE NaN special values.  Must be
		  of either floating point, double-precision, or complex type.

 OUTPUTS:
	The result of the function is the indices of all values of ARRAY
	corresponding to the IEEE NaN specification, similar to the IDL WHERE
	function.

 OPTIONAL OUTPUT PARAMETERS:
	COUNT	= Number of values found corresponding to IEEE NaN.

 OPTIONAL KEYWORD PARAMETERS:
	None.

 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
	If no NaN values are found, or if ARRAY is not of type float, double
	precision, or complex, then -1 is returned, and COUNT is set to 0.

 RESTRICTIONS:
	ARRAY must be of type float, double-precision, or complex.

 PROCEDURE:
	The bit patterns of the numbers being tested are compared against the
	IEEE NaN standard.

 MODIFICATION HISTORY:
	William Thompson, Feb. 1992.
	William Thompson, Oct. 1992, fixed bug regarding order of bytes on VAX
		machines.
       Added to idlmeteo from the
       Astronomy User's Library         Nov-1992    oet@sma.ch

(See ser/pia_sm_fitfind.pro)


WRITE_ISMC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       WRITE_ISMC
 PURPOSE:
	Write a PHT-SMC (Signal Data) measurement from the dynamical 
	structure PHTSMC onto an IDL savefile  
 CATEGORY:
	PIA - I/O
 CALLING SEQUENCE:
       WRITE_ISMC, PHTSMC_INDEX, FNAME = FNAME, PATH =PATH

 INPUT:
       PHTSMC_INDEX 	: Index of the measurement within PHTSMC

 OPTIONAL KEYWORD:
	FNAME   :  name of the save file, by default PHTSMC.ADMN is used
	PATH	:  directory where the internal file is saved

 OUTPUT:
	IDL save file

 RESTRICTIONS:
       PHTSMC(PHTSMC_INDEX) must exist

 PROCEDURES USED:
       Common Block(s) or @ procedure(s):
               phtsmc

 MODIFICATION HISTORY:
       Written by: C. Gabriel
	Oct 95 Version 3.5
	Modification to include options path and fname (JAcosta) 	Apr. 97

(See ser/write_ismc.pro)


WRITE_SMC

[Previous Routine] [List of Routines]
 NAME:
     WRITE_SMC
 PURPOSE:
	Write a PHT-SMC (Serendipity Surface Brightness Data) measurement from
	a temporary structure PHTSMC onto a fits file
 CATEGORY:
	PIA - I/O
 CALLING SEQUENCE:
       WRITE_SMC, TMPDATA

 INPUT:
       tmpdata	: PHTSMC structure

 OPTIONAL INPUT:
       tmphdr	: A temporary header
       filename: filename to store the fitsfile


 RESTRICTIONS:
       tmpdata must be a valid PHTSMC structure

 PROCEDURES USED: 
       Common Block(s) or @ procedure(s):
               phtsmc

 MODIFICATION HISTORY:
       Written by: S. Bogun, MPIA, August 96
	based on WRITE_SRD written by W. M. Tai and C. Gabriel
	updated according to new SMC structure		(SB, 28/01/97)	

(See ser/write_smc.pro)