#!/bin/sh
#-----------------------------------------------------------------------
#;  Copyright (C) 1995, 1996
#;  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
#-----------------------------------------------------------------------
# Usage: PROG program-name [other program-name...]
#-----------------------------------------------------------------------
# Show where a program is in the AIPS hierarchy without using find.
# This procedure first creates a temporary file listing all program
# areas, and then checks only these areas for the existence of the
# program names in the argument list.  Example:
#
#     PROG [ -l | -s ] MX
#
# will return the full path for file MX.FOR in the appropriate
# directory.  The -l qualifier anywhere in the line forces the output to
# be long, i.e. as in "ls -l" whereas the -s option (the default) just
# prints the filename.
#
# Needs PRINTENV which should be in $SYSLOCAL as either a shell script,
# a binary, or a symlink to a system printenv or env.
#-----------------------------------------------------------------------
#
tempname=/tmp/PROG_$$
trap 'rm -f $tempname' 1 2 3 15
if [ "x$APLPGM" = "x" ] ; then
  echo "PROG: AIPS programming variables not defined"
  exit 1
fi
PRINTENV | grep /PGM | awk -F= '{print $2}' >$tempname
lflag=""
for i
do
   [ "x$i" = "x-l" ] && lflag="-l" && continue
   [ "x$i" = "x-s" ] && lflag="" && continue
   name=`echo $i | awk -F. '{print $1}'`
   for j in `cat $tempname` ; do
      [ -f $j/${i}*.FOR ] && ls $lflag $j/${i}*.FOR
   done
done
rm -f $tempname
