any_filename (version 1.7)

You can also look at:
#! /usr/bin/ksh

###########################################################################
#
# 
# SYNTAX: any_filename type
#
# DESCRIPTION: This utility returns a list of all files of a given type
# DESCRIPTION: which are present in the working directory.
#
# VERSION: 1.7
#
# HISTORY: 0.0 -> 1.0 8/19/96 
# HISTORY: teldef now lists both SIS and GIS calibration
# HISTORY: files.
# HISTORY: 
# HISTORY: 1.0 -> 1.1 10/17/96
# HISTORY: added blanksky, bethick, and gisgrid, ecdata
# HISTORY: 
# HISTORY: 1.1 -> 1.2 12/9/96
# HISTORY: changed region to read possible file names from parfile
# HISTORY: now GIS cal source region files are included in the region type
# HISTORY: 
# HISTORY: 1.2 -> 1.3 12/31/96
# HISTORY: added ghkcurve
# HISTORY: 
# HISTORY: 1.3 -> 1.4 2/18/97
# HISTORY: added rmf as a special case to accomodate differing numbers of 
# HISTORY: GIS PHA channels
# HISTORY: 
# HISTORY: 1.4 -> 1.5 3/12/97
# HISTORY: added "frame" as a special case
# HISTORY: Corrected typo channel to nchannels for rmf when getting name of
# HISTORY: GIS3 rmf with 128 channels.
# HISTORY: 
# HISTORY: 1.5 -> 1.6 3/24/97
# HISTORY: Removed orbit as a special case since it can be gotten from 
# HISTORY: generate_filename
# HISTORY: 
# HISTORY: 1.6 -> 1.7 4/28/97
# HISTORY: Added chipmask as a special case 
# HISTORY: changed ghkcurve to accomodate different bitrates
# HISTORY: Changed region to accomodate different region filters for 
# HISTORY: spread discriminator on and off.
#
##############################################################################
#DEBUG=1

type="$1"

case "$type" in
     ########################
     # date-based file names
     ########################
filter)     list="ft*.mkf";;
filterplot) list="ft*mkf[cms].ps";;
ghf)        list="ft*.ghf";;
science)    list="ft*[HML].fits";;
house)      list="ft*HK.fits";;
telemetry)  list="ft*[0-9]";;
attitude)   list="fa*[0-9]";;
ghkcurve)   list="ft*G[23]HK*.lc";;
frame)      list="fr??????_????_????S[01]???04[HML].fits";;

region)     
     ####################################################
     # GIS extraction region and cal source region files
     ####################################################
     list=""
     for inst in g2 g3; do

          ##########################
          # standard region filters
          ##########################
          for dimen in 256 64; do
               for spread in ON OFF; do
                    file=$($UTIL/read_parfile $PARFILE \
                                              ${inst}region${dimen}${spread} )
                    list="$list $file"
               done
          done

          ##############################
          # calsource region filters
          ##############################
          for dimen in 256 64; do
               file=$($UTIL/read_parfile $PARFILE ${inst}calregion${dimen} )
               list="$list $file"
          done

     done
     ;;

     #######################
     # calibration file names
     ########################
teldef) list="s[01]_teldef_ascalin.fits"
        for key in g2onpow  g3onpow  g2onflf  g3onflf \
                   g2offpow g3offpow g2offflf g3offflf ; do

             file=$($UTIL/read_parfile $PARFILE $key)
             list="$list $file"
        done
        ;;

     #########################
     # blank sky event files
     #########################
blanksky) list=""
          for inst in s0 s1 g2 g3; do
               file=$($UTIL/read_parfile $PARFILE ${inst}blanksky )
               list="$list $file"
          done
          ;;

bethick) list=""
         for inst in g2 g3; do
              file=$($UTIL/read_parfile $PARFILE ${inst}bethick )
              list="$list $file"
         done
         ;;


gisgrid) list=""
         for inst in g2 g3; do
              file=$($UTIL/read_parfile $PARFILE ${inst}grid )
              list="$list $file"
         done
         ;;

ecdata) list=""
        for inst in 0 1; do
             for chip in 0 1 2 3; do
                  for split in 40; do
                       file=$($UTIL/read_parfile $PARFILE \
                                                 ecd${inst}c${chip}p${split} )

                       list="$list $file"
                  done
              done
         done
         ;;
          

rmf) list=$($UTIL/generate_filename rmf s[01] any any any any )
     for inst in g2 g3; do
          for nchannels in 1024 256; do
               file=$($UTIL/read_parfile $PARFILE ${inst}_${nchannels}rmf )
               list="$list $file"
          done
     done 
     inst=g3
     nchannels=128
     file=$($UTIL/read_parfile $PARFILE ${inst}_${nchannels}rmf )
     list="$list $file"
     ;;

chipmask)
     ###########################################
     # SIS region files to mask off-chip areas
     ###########################################
     list=""
     for inst in s0 s1; do
          mask=$($UTIL/read_parfile $PARFILE ${inst}offchip )
          list="$list $mask"
          for chip in 0 1 2 3; do
               mask=$($UTIL/read_parfile $PARFILE ${inst}notchip${chip} )
               list="$list $mask"
          done
     done
     ;;

 

*) 
     ###################################
     # try looking in the par file
     ###################################
     rm -f stderr.log
     list=$($FTOOLS/pget ./$PARFILE $type 2>stderr.log)
     if [ $? -ne 0 -o -s stderr.log ]; then
          #######################################################
          # not in the par file, generate with sequence number
          ######################################################
          list=$($UTIL/generate_filename "$type" any any any any any )
     fi
     rm -f stderr.log
     ;;
esac

######################
# debugging output
#######################
if [ -n "$DEBUG" ]; then
     echo ${0##*/}: list=$list
fi

if [ -n "$list" ]; then
     ls $list 2>/dev/null
fi




exit 0