#!/bin/sh
#-----------------------------------------------------------------------------
# adate: Report the date in AIPS++ standard format
#-----------------------------------------------------------------------------
#
#   Copyright (C) 1992,1993,1995,1996,1998,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 Mass Ave, Cambridge, MA 02139, USA.
#
#   Correspondence concerning AIPS++ should be addressed as follows:
#          Internet email: aips2-request@nrao.edu.
#          Postal address: AIPS++ Project Office
#                          National Radio Astronomy Observatory
#                          520 Edgemont Road
#                          Charlottesville, VA 22903-2475 USA
#
#-----------------------------------------------------------------------------
# Usage: adate [-d] [-l | -u]
#-----------------------------------------------------------------------------
# Report the date in AIPS++ standard format.
#
# Options:
#   -d     Omit the day-of-week.
#   -l     Report local time rather than GMT.
#   -u     Report GMT (default).
#
# Status return values:
#    0:  success
#    1:  usage error
#
# Notes:
#    1) Not all unix 'date' commands have the formatting capability of
#       the SunOS version.
#
#    2) AIX refers to GMT as CUT (can you believe it!).
#
#    3) Allows for the time zone to be specified as any number of words but
#       only transcribes the first two.
#
# Original: 1992/06/03 by Mark Calabretta, ATNF
# $Id$
#=============================================================================
# Set the correct locale.
  LC_TIME=C
  export LC_TIME

# Parse command input.
  DOW=1
  MODE=-u

  while [ "$#" -gt 0 ]
  do
     case $1 in
     -d)
        DOW=""
        ;;
     -l)
        MODE=""
        ;;
     -u)
        MODE="-u"
        ;;
     *)
        echo "Usage: adate [-d] [-l | -u]"
        exit 1
        ;;
     esac

     [ "$2" = "" ] && break

     shift
  done

  set `date $MODE`

  YEAR=`eval echo "$""$#"`

  case $2 in
     Jan) MONTH=01 ;;
     Feb) MONTH=02 ;;
     Mar) MONTH=03 ;;
     Apr) MONTH=04 ;;
     May) MONTH=05 ;;
     Jun) MONTH=06 ;;
     Jul) MONTH=07 ;;
     Aug) MONTH=08 ;;
     Sep) MONTH=09 ;;
     Oct) MONTH=10 ;;
     Nov) MONTH=11 ;;
     Dec) MONTH=12 ;;
     *)   MONTH=?? ;;
  esac

  case $3 in
  [1-9])
     DAY="0$3"
     ;;
  *)
     DAY="$3"
     ;;
  esac

  case $MODE in
  -u)
     ZONE="GMT"
     ;;
  *)
     case $# in
        6)
           ZONE="$5"
           ;;
        *)
           ZONE="$5 $6"
           ;;
     esac
     ;;
  esac


  if [ "$DOW" != "" ]
  then
     echo "$1 $YEAR/$MONTH/$DAY $4 $ZONE"
  else
     echo "$YEAR/$MONTH/$DAY $4 $ZONE"
  fi

  exit 0
