#!/bin/sh
# UPDSRTUNQ
#-----------------------------------------------------------------
#! Process .UPD files
## Update
#-----------------------------------------------------------------------
#;  Copyright (C) 1995, 1997, 2001
#;  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
#-----------------------------------------------------------------------
#   Remove all entries in the .UPD file with base name given as
#   the first argument that are dated before the date given as the
#   second argument and delete unwanted modules (those in SYSLOCAL
#   etc.). Sort the resulting .UNQ file and remove redundant
#   entries.
#
#   Modified order of arguments on sort command line; HP's don't
#   like the -o fff after the input filespec.  But use original
#   for older systems like SUN4.
#-----------------------------------------------------------------
UPDLSTDAT $1.UPD $2 | sed -n -f UPDSRTUNQ.SED > $1.UNQ
case $ARCH in
#                                       Old sorts
   SUN4)
#                                       Sort into descending order
#                                       of date:
      sort -br +2 -3  -o $1.UNQ $1.UNQ
#                                       Sort by module name,
#                                       eliminating duplicate
#                                       references:
      sort -bu +3 -6  -o $1.UNQ $1.UNQ
#                                       Sort into ascending order of
#                                       date:
      sort -r +2 -3  -o $1.UNQ $1.UNQ
      ;;
   *)
#                                       Everything else understands the
#                                       newer sort syntax.
#                                       Sort by name then descending
#                                       date
      sort -k 4b,6 -k 3r -o $1.UNQ $1.UNQ
#                                       Throw out duplicate names
      sort -m -u -k 4b,6 -o $1.UNQ $1.UNQ
#                                       Back to time order
      sort -k 3 -k 2 -o $1.UNQ $1.UNQ
      ;;
esac
exit 0
