any_filename (version 3.0)

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

##############################################################################
#
# 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: 3.0
#
# HISTORY: 0.0 -> 1.0 8/19/96
# HISTORY: teldef now lists both SIS and GIS calibration 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 of "channel" to "nchannels" for rmf when getting
# HISTORY: name of 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.
# HISTORY:
# HISTORY: 1.7 -> 1.8 5/15/97
# HISTORY: Now includes frame mode file ending in "99.fits".
# HISTORY:
# HISTORY: 1.8 -> 1.9 7/9/97
# HISTORY: Now includes split threshold=20 in ecdata possibilities.
# HISTORY:
# HISTORY: 1.9 -> 1.10 8/11/97
# HISTORY: Changed frame mode template to work with Dotani's file name
# HISTORY: conventions.
# HISTORY: 
# HISTORY: 1.10 -> 2.0 1/21/98
# HISTORY: added "corrupt" telemetry corruption data files
# HISTORY: 
# HISTORY: 2.0 -> 3.0 1999-05-07
# HISTORY: Converted from ksh to perl
#
# CALLS: $UTIL/read_parfile
# CALLS: $UTIL/generate_filename
# CALLS: $FTOOL/pget
#
##############################################################################
#$DEBUG = 1;

use File::Basename;

$type = $ARGV[0];

$UTIL = $ENV{"UTIL"};
$FTOOL = $ENV{"FTOOL"};
$PARFILE=$ENV{"PARFILE"};

for ( $type ) {
    ########################
    # Date-based file names
    ########################
    /^filter$/     and do { $list = "ft*.mkf"; last; };
    /^filterplot$/ and do { $list = "ft*mkf[cms].ps"; last; };
    /^ghf$/        and do { $list = "ft*.ghf"; last; };
    /^science$/    and do { $list = "ft*[HML].fits"; last; };
    /^house$/      and do { $list = "ft*HK.fits"; last; };
    /^telemetry$/  and do { $list = "ft*[0-9]"; last; };
    /^attitude$/   and do { $list = "fa*[0-9]"; last; };
    /^ghkcurve$/   and do { $list = "ft*G[23]HK*.lc"; last; };
    /^frame$/      and do { $list = "fr??????_????.????_s[01]c?m??.fits"; 
                            last; };
    /^corrupt$/    and do { $list = "ft*[0-9].corrupt"; last; };

    /^region$/ and do {
	####################################################
	# GIS extraction region and cal source region files
	####################################################
	$list = "";
	foreach $inst (g2, g3) {

	    ##########################
	    # Standard region filters
	    ##########################
	    foreach $dimen (256, 64) {
		foreach $spread (ON, OFF) {
		    chomp($file = `$UTIL/read_parfile $PARFILE \\
                                            ${inst}region${dimen}${spread}`);
		    $list .= " $file";
		}
	    }

	    ###########################
	    # Calsource region filters
	    ###########################
	    foreach $dimen (256, 64) {
		chomp($file = `$UTIL/read_parfile $PARFILE \\
                                                  ${inst}calregion${dimen}`);
		$list .= " $file";
	    }
	}
	last;
    };

    /^teldef$/ and do {
	#########################
	# Calibration file names
	#########################
	$list = "s[01]_teldef_ascalin.fits";
	foreach $key (g2onpow, g3onpow, g2onflf, g3onflf, g2offpow, g3offpow,
		      g2offflf, g3offflf) {
	    chomp($file = `$UTIL/read_parfile $PARFILE $key`);
	    $list .= " $file";
	}
	last;
    };

    /^blanksky$/ and do {
	########################
	# Blank sky event files
	########################
	$list = "";
	foreach $inst (s0, s1, g2, g3) {
	    chomp($file = `$UTIL/read_parfile $PARFILE ${inst}blanksky`);
	    $list .= " $file";
	}
	last;
    };

    /^bethick$/ and do {
	$list = "";
	foreach $inst (g2, g3) {
	    chomp($file = `$UTIL/read_parfile $PARFILE ${inst}bethick`);
	    $list .= " $file";
	}
	last;
    };

    /^gisgrid$/ and do {
	$list = "";
	foreach $inst (g2, g3) {
	    chomp($file = `$UTIL/read_parfile $PARFILE ${inst}grid`);
	    $list .= " $file";
	}
	last;
    };

    /^ecdata$/ and do {
	$list = "";
	foreach $inst (0, 1) {
	    foreach $chip (0, 1, 2, 3) {
		foreach $split (20, 40) {
		    chomp($file = `$UTIL/read_parfile $PARFILE \\
                                            ecd${inst}c${chip}p${split}`);
		    $list .= " $file";
		}
	    }
	}
	last;
    };

    /^rmf$/ and do {
	chomp($list = `$UTIL/generate_filename rmf s[01] any any any any`);
	foreach $inst (g2, g3) {
	    foreach $nchannels (1024, 256) {
		chomp($file = `$UTIL/read_parfile $PARFILE \\
                                                  ${inst}_${nchannels}rmf`);
		$list .= " $file";
	    }
	}
	$inst = g3;
	$nchannels = 128;
	chomp($file = `$UTIL/read_parfile $PARFILE ${inst}_${nchannels}rmf`);
	$list .= " $file";
	last;
    };

    /^chipmask$/ and do {
	##########################################
	# SIS region files to mask off-chip areas
	##########################################
	$list = "";
	foreach $inst (s0, s1) {
	    chomp($mask = `$UTIL/read_parfile $PARFILE ${inst}offchip`);
	    $list = "$list $mask";
	    foreach $chip (0, 1, 2, 3) {
		chomp($mask = `$UTIL/read_parfile $PARFILE \\
                                                  ${inst}notchip${chip}`);
		$list .= " $mask";
	    }
	}
	last;
    };

    /.*/ and do {
	##############################
	# Try looking in the par file
	##############################
	unlink 'stderr.log';
	chomp($list = `$FTOOL/pget ./$PARFILE $type 2>stderr.log`);
	if ( $?  or -s "stderr.log" ) {
	    #####################################################
	    # Not in the par file, generate with sequence number
	    #####################################################
	    chomp($list = `$UTIL/generate_filename "$type" any any any any any`);
	}
	unlink 'stderr.log';
	last;
    };

    last;
}

###################
# Debugging output
###################
if ( "$DEBUG" ) {
    print "basename($0): list = $list\n";
}

###############################
# list all the files
###############################
if ( "$list" ) {
    system("ls $list 2>/dev/null");
}

exit 0;