; SDLSF
;---------------------------------------------------------------
;! least squares fit to channels and subtracts from SD uv data
;# TASK UV SPECTRAL EDITING SINGLEDISH
;-----------------------------------------------------------------------
;;  Copyright (C) 1996-1997, 1999
;;  Associated Universities, Inc. Washington DC, USA.
;;
;;  This program is free software; you can redistribute it and/or
;;  modify it under the terms of the GNU General Public License as
;;  published by the Free Software Foundation; either version 2 of
;;  the License, or (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU General Public License for more details.
;;
;;  You should have received a copy of the GNU General Public
;;  License along with this program; if not, write to the Free
;;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
;;  MA 02139, USA.
;;
;;  Correspondence concerning AIPS should be addressed as follows:
;;         Internet email: aipsmail@nrao.edu.
;;         Postal address: AIPS Project Office
;;                         National Radio Astronomy Observatory
;;                         520 Edgemont Road
;;                         Charlottesville, VA 22903-2475 USA
;-----------------------------------------------------------------------
SDLSF     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SDLSF     Least squares fit baseline and subtracts from SD data
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK            0.0        9.0   Input UV file disk unit #
OUTNAME                            Output UV file name (name)
OUTCLASS                           Output UV file name (class)
OUTSEQ           -1.0     9999.0   Output UV file name (seq. #)
OUTDISK           0.0        9.0   Output UV file disk unit #.
CHANSEL                            Select channels to fit: NOTE
                                   this is start,end,increment
                                   for each region
ORDER             0.0        1.0   Order of the baseline (0/1)
DOALL            -1.0        1.0   > 0 => fit the average of all
                                   spectra at a given time.
DOOUTPUT         -1.0        1.0   > 0 => write fit baseline as
                                   a continuum uv data base
CHANNEL           0.0     9999.0   Channel of fit to be written
                                   as continuum: 0 -> reference
FLUX              0.0              Flag data if residual flux in
                                   any fit channel is > FLUX
                                   0 -> 10**20
CUTOFF            0.0              Flag data if RMS of residual
                                   in fit channels > CUTOFF
                                   0 -> 10**20
PRTLEV            0.0              Print summary of data flagged
                                   > 0 => detail by channel
----------------------------------------------------------------
SDLSF
Task:  This task does a spectral baseline subtraction.  It fits a
       straight line (with optional slope) to a set of selected spectral
       channels using either each observation individually or the
       average of all observations at a given time.  It then subtracts
       the fitted baseline from each spectrum used in the average.
       Optionally, it can flag data having excess residuals in the
       channels used for the baseline fitting.  This is a good method
       for detecting and deleting data damaged by RFI.  The whole
       process is useful for producing better initial data for the
       imaging operations and may well eliminate the need for baseline
       removal from the images (TRANS-IMLIN-TRANS).  (If SDLSF is used
       to remove the "weather" (estimated from the average of multiple
       feeds pointing in different directions at any given time), then
       some spectral baseline may well remain after the initial SDIMG.)
Adverbs:
  INNAME.....Input (SD) UV file name (name).      Standard defaults.
  INCLASS....Input (SD) UV file name (class).     Standard defaults.
  INSEQ......Input (SD) UV file name (seq. #).    0 => highest.
  INDISK.....Disk drive # of input (SD) UV file.  0 => any.
  OUTNAME....Output (SD) UV file name (name).     Standard defaults.
  OUTCLASS...Output (SD) UV file name (class).    Standard defaults.
  OUTSEQ.....Output (SD) UV file name (seq. #).   0 => highest unique
  OUTDISK....Disk drive # of output (SD) UV file. 0 => highest with
             space for the file.
  CHANSEL....Select up to 10 groups of channels to fit as sets of
             (Start,end,inc), i.e., CHANSEL = 6,37,1, 92,123,1
             Defaults: if CHANSEL(1,1) and CHANSEL(2,1) are <= 0,
             use all channels.  Else use CHANSELs until CHANSEL(1,i) and
             CHANSEL(2,i) are both <= 0 ignoring ones >= i.
             CHANSEL(1,j) defaults to 1, CHANSEL(2,j) < CHANSEL(1,j)
             defaults to Nchan.  CHANSEL(3,j) < 1 or > CHANSEL(2,j) -
             CHANSEL(1,j) + 1 defaults to 1.
  ORDER......Order of the baseline: 0 no slope, 1 a slope is also fit.
             NCOUNT=1 is highly recommended unless the data are very
             noisy and only a few channels available for the baseline
             fit.
  DOALL......> 0 => fit the average of all observations occuring at the
             same time (and consecutively in the data set).  <= 0 => fit
             each observation individually.
             If there is a single pointing position at a given time,
             DOALL TRUE will get the average baseline for, for example,
             the two polarizations at that time with somewhat greater
             reliability than it would fitting the two individually.
             For multiple pointing positions at a single time (e.g., the
             8-beam system), DOALL TRUE obtains the average baseline for
             several positions at once.  This may be a good measure of
             the "weather" at that time but may not be such a good
             measure of the baselines at each of the 8 positions
             (especially if one or more of the feeds has instrumental
             offsets or other problems).  If you use DOALL TRUE with
             multi-feed data, you may anticipate the need for additional
             baseline removal after the images are made.
  DOOUTPUT...<= 0 => write out only the subtracted uv data.
             > 0 => write also a data set with the fit baseline as a
             single-channel (SD) UV data set.
  CHANNEL....When DOOUTPUT > 0, write the continuum data with the fit
             evaluated at spectral channel CHANNEL.
             0 => reference channel.
  FLUX.......If the residual flux in any channel used to fit the
             baseline exceeds FLUX, then the spectrum for that time, IF,
             and polarization is fully flagged.  <= 0 => 1.0E20
  CUTOFF.....If the RMS flux in the channels used to fit the baseline
             exceeds CUTOFF, then the spectrum for that time, IF, and
             polarization is fully flagged.      <= 0 => 1.0E20
  PRTLEV.....A summary of points flagged is printed.  To print (in the
             message file) any channel having >= PRTLEV samples flagged
             for excess residuals, set PRTLEV > 0.  = 0 => print only
             the totals.
----------------------------------------------------------------
