;QUOUT
;---------------------------------------------------------------
;! writes text file of Q, U versus frequency to be used by RLDIF
;# Task UV Calibration polarization
;-----------------------------------------------------------------------
;;  Copyright (C) 2011
;;  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
;-----------------------------------------------------------------------
QUOUT     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
QUOUT:  Task to write Q/U spectrum to text file for RLDIF
INNAME                             UV or image data (name).
INCLASS                            UV or image data (class).
INSEQ             0.0    9999.0    UV or image data (seq. #).
                                      0 => high
INDISK                             Disk unit #.       0 => any
FORMAT            0.0       4.0    = 0,1 write Q, U
                                   = 2 write polarization angle
OUTTEXT                            Output text file
SOURCES                            UV: Source list from CP/SU
INVERS                             UV: CP table version #
BLC                                MA: Bottom left corner
TRC                                MA: Top left corner
----------------------------------------------------------------
QUOUT
Type:  Task
Use:   RLDIF requires a spectrum of the expected polarization angle of
       the polarization calibrator as a function of frequency.  One
       way to provide those data is via a text file.  QUOUT will write
       that text file from a UV data set using the CP or SU table
       values of Q and U.  NOTE that those values must be fully
       calibrated - i.e. from a data set on which RLDIF has already
       been run.  QUOUT is then used to transfer the calibration of a
       source to another data set.

       If the input is an image "cube", then QUOUT will determine the
       output by fitting Q and U in a small window set by BLC and TRC.
       The cube may be a four-dimensional (or more) image with Q and U
       on a polarization axis or it may be an output of COMB of
       polarization angle (OPCODE 'POLA') in three or more
       dimensions.  The "Q" and "U" written from a POLA image are just
       the cos and sin of the average of twice the position angles
       rather than properly scaled fluxes.
Adverbs:
  INNAME.....UV or image file name (name).  Standard defaults.
  INCLASS....UV or image file name (class).  Standard defaults.
  INSEQ......UV or image file name (seq. #).  0 => highest.
  INDISK.....Disk unit #.                     0 => any.
  FORMAT.....Write OUTTEXT with Freq, Q, U, source number when FORMAT
             is < 1.5.  Write it with Freq, Polarization angle, source
             number when FORMAT > 1.5.
  OUTTEXT....Outout text file.  Contents described below.
For UV input
  SOURCES....List of sources to be listed. '  '=> all.
  INVERS.....CP (calibrator polarization) table version number.  If
             < 0 or there are no CP tables, use  the SU (source)
             table.
For image data
  BLC........Bottom left corner of area over which image is
             integrated.
  TRC........Top right corner

OUTTEXT file format:
   1. Begins with a line which defines the contents of the file
         ;FQUS   for columns of frequency, Q, U, and source number.
         ;FAS    for columns of frequency, polarization angle, and
                 source number
   2. Comment lines at any point begin in column 1 with either a
      ; or a # character.
   3. Data lines contain the specified type of data columns:
         ;FQUS   frequency in GHz, Q, U in the same units, and
                 optionally source number
         ;FAS    frequency in GHz, polarization angle in degrees
                 (= ATAN2 (U, Q) / 2.0), and optionally source number
      The source number may be omitted or set to 0 if there is only
      one source included.

Example 1:
;FQUS
# QUOUT run 12-JAN-2011 11:24:35 using CP version    2
  4.988000000    0.348104    0.780174      0
  4.990000000    0.348104    0.780174      0
  4.992000000    0.346920    0.780659      0
  4.994000000    0.344028    0.781819      0
  4.996000000    0.338668    0.783813      0
  4.998000000    0.336427    0.784259      0

Example 2:
;FAS
# QUOUT run 12-JAN-2011 11:27:03 using CP version    2
  4.988000000    32.97708      0
  4.990000000    32.97708      0
  4.992000000    33.01998      0
  4.994000000    33.12441      0
  4.996000000    33.31594      0
  4.998000000    33.39096      0
----------------------------------------------------------------
