SKYADJ_CUBE
Name
       
        SKYADJ_CUBE
Purpose
     
       Sky adjust the planes of a datacube.
Explanation
     
       When removing cosmic rays from a set of images, it is desirable that
      
       all images have the same sky level.    This procedure (called by
      
       CR_REJECT) removes the sky from each image in a data cube.    
Calling Sequence
     
       SKYADJ_CUBE,Datacube,Skyvals,Totsky
  
 MODIFIED ARGUMENT:
      
       Datacube:  3-D array with one image of same field in each plane.
                  
                  Returned with sky in each plane adjusted to zero.
Output Arguments
     
       Skyvals:   Array of sky values used on each plane of datacube.
                  
                  For a scalar sky, this parameter is a vector
                  
                  containing the sky value for each image plane.  For a
                  
                  vector sky, this parameter is a 2-D array where each
                  
                  line corresponds to one image plane.
Input Keyword Parameters
      
       REGION   - [X0,X1,Y0,Y1] to restrict area used for computation
                  
                  of sky.  Default is 0.1*Xdim, 0.9*Xdim, 0.1*Ydim,
                  
                  0.9*Ydim.  If INPUT_MASK is specified, the two 
                  
                  specs are combined, i.e., the intersection of the
                  
                  areas is used.
      
       VERBOSE  - Flag.  If set, print information on skyvals.
      
       NOEDIT   - Flag.  If set, return sky values without changing
                  
                  datacube.
      
       XMEDSKY  - Flag.  If set, return vector sky as a function of X.
      
       SELECT   - Array of subscripts of planes of the cube to process.
                  
                  (Default=all)
      
       EXTRAPR  - Applies only in XMEDSKY mode.
                  
                  Subregion to use for polynomial extrapolation of sky
                  
                  vector into portions excluded by REGION parameter.
                  
                  (Default=first and last 10% of pixels; set to zero
                  
                  to defeat extrapolation)
      
       EDEGREE  - Applies only in XMEDSKY mode.  
                  
                  Degree of polynomial for extrapolation (Default=1)
      
       INPUT_MASK - Cube of flags corresponding to data cube.  If used,
                  
                  the sky computation is restricted to the smallest 
                  
                  contiguous rectangle containing all the pixels flagged
                  
                  valid (with 1 rather than 0).
Procedure
     
       Uses astronomy library "sky" routine for scalar sky and
      
       column-by-column median for vector sky.
Modification History
 
   10 Jul. 1997   - Written.  R. S. Hill, Hughes STX
  
   20 Oct. 1997   - 1-D sky option.  RSH
    
    7 Aug. 1998   - SELECT keyword.  RSH
    
    6 Oct. 1998   - Extrapolation.  RSH
    
    7 Oct. 1998   - INPUT_MASK added.  RSH
  
   21 Oct. 1998   - Fallback to 3-sigma clipped mean if mode fails.  RSH
  
   22 Mar. 2000   - Combine mask with region rather having mask
                    
                    override region.  Improve comments.  RSH
  
   16 June 2000   - On_error and message used.  Square brackets for array 
                    
                    subscripts.  EXTRAP included in this file.  
                    
                    WBL & RSH, 16 June 2000