; MSORT
;---------------------------------------------------------------
;! Sort a UV dataset into a specified order
;# TASK UV CALIBRATION
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1997-1998, 2003, 2008
;;  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
;-----------------------------------------------------------------------
MSORT     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
MSORT:  Task which sorts UV data
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0    9999.0    Input UV file name (seq. #)
INDISK                             Disk unit # of input UV data
OUTNAME                            Sorted UV file name (name)
OUTCLASS                           Sorted UV file name (class)
OUTSEQ           -1.0    9999.0    Sorted UV file name (seq. #)
OUTDISK                            Disk unit # of sorted UV data
                                     0 => highest with space
                                   If outfile spec. equals the
                                   infile spec., output will
                                   overwrite the input
SORT                               Two char. sort order, eg.'TB'
                                   blank => 'TB'
PRTLEV                             -1 -> no messages
                                   0 -> major progress messages
                                   1 -> show progress
----------------------------------------------------------------
MSORT
Type:  Task
 Use:  To sort UV data into a specified order.  Two keys are always
       used in the sort.

       This task differs from UVSRT in that no (large) scratch file is
       required.  It uses techniques that are very efficient in
       sorting data that are nearly in the correct sort order.  These
       techniques degrade non-linearly as the sort problem becomes
       worse - i.e. the visibility record size gets larger and the
       average separation between the current record position and the
       desired record position increases.  For large records, MSORT
       has a different brute-force disk-read sort that will work with
       reasonable efficiency, but only if the input and output disk
       files are not the same.

       NOTE: this task does NOT apply flagging or calibration tables
       to the input UV data.  Run SPLIT first if that operation is
       desired.
Adverbs:
  INNAME.....Input UV file name (name).   Standard defaults.
  INCLASS....Input UV file name (class).  Standard defaults.
  INSEQ......Input UV file name (seq. #). 0 => highest.
  INDISK.....Disk drive # of input UV.    0 => any.
  OUTNAME....Output UV file name (name).  Standard defaults.
  OUTCLASS...Output UV file name (class). Standard defaults.
  OUTSEQ.....Output UV file name (seq. #).0 = > highest unique.
  OUTDISK....Disk drive # of output UV.  0 => highest with space
             If the outfile specification equals the infile
             specification, the output data file will overwrite
             the input data file.
  SORT.......Sort order of output.  blank => 'TB' and is the
             sort order needed for calibration routines
             The sort order is specified by two keys which are
             characters selected from:
             blank => X = descending ABS(u)
                 B => baseline number
                 T => time order
                 U => u spatial freq. coordinate
                 V => v spatial freq. coordinate
                 W => w spatial freq. coordinate
                 R => baseline length.
                 P => baseline position angle.
                 X => descending ABS(u)
                 Y => descending ABS(v)
                 Z => ascending ABS(u)
                 M => ascending ABS(v)
             see HELP SORT for more information
----------------------------------------------------------------
MSORT:  Task which sorts UV data
DOCUMENTOR: K.M.Desai (NRAO/VLA)
RELATED PROGRAMS: UVSRT

                         PURPOSE

     MSORT will sort a UV data base into a specified order.  It is
almost functionally equivalent to UVSRT.  The primary differences are
that UVSRT allows ROTATion of the U-V axes and that MSORT requires no
scratch disk space.  The sorting operations are done in memory
resulting in a considerable speed up in execution time for certain
types of sorting problems.

This task is a heavy user of CPU power and memory.

                         COMMENTS

OUTNAME, OUTCLASS, OUTSEQ, OUTDISK:
     If the outfile specification is identical to the infile
specification (including defaults used in both file specifications),
then the sorted data will overwrite the input data.  Make sure the
input data set is properly backed up before you overwrite since a
computer crash may destroy the input data set.

TIMING:
     Early testing results suggest that this program runs about
3 times faster when working on nearly sorted data and about 50%
slower when working on randomly sorted data as compared to
UVSRT.
