Util::FilenameInfo (version 0.0)


package Util::FilenameInfo;
##############################################################################
#
# DESCRIPTION: This class holds information about generic Swift file names.
#
# HISTORY: 
# HISTORY: $Log: FilenameInfo.pm,v $
# HISTORY: Revision 1.72  2011/12/30 07:21:50  apsop
# HISTORY: proc3.14.1: dssplot
# HISTORY:
# HISTORY: Revision 1.71  2011/01/20 19:20:02  apsop
# HISTORY: Added code to accomodate new level 3 products
# HISTORY:
# HISTORY: Revision 1.70  2009/12/22 19:14:29  apsop
# HISTORY: Fixed list of products files for UVOT
# HISTORY:
# HISTORY: Revision 1.69  2009/12/18 14:37:43  apsop
# HISTORY: This release contains several new items:
# HISTORY:   1. call to Subs::UvotGraspCorr for apsect correction
# HISTORY:   2. call to Subs::UvotProduct, which generates gifs light curves
# HISTORY:   3. call to Subs::XrtGrbLc, which generates gifs light curves for GRB based on XRT data
# HISTORY:
# HISTORY: Revision 1.68  2007/12/18 19:53:19  apsop
# HISTORY: Add mask image type for bat.
# HISTORY:
# HISTORY: Revision 1.67  2007/09/11 17:53:26  apsop
# HISTORY: New file type maskimage, not currently kept.
# HISTORY:
# HISTORY: Revision 1.66  2007/06/28 20:33:15  apsop
# HISTORY: Changes to shared repository to support files indexed by target number.
# HISTORY:
# HISTORY: Revision 1.65  2007/01/31 16:43:08  apsop
# HISTORY: New file type attcorr.
# HISTORY:
# HISTORY: Revision 1.64  2006/05/10 15:09:53  apsop
# HISTORY: New xrt file types tdevent and tdunfilter.
# HISTORY:
# HISTORY: Revision 1.63  2006/04/26 20:38:33  apsop
# HISTORY: New umon file type
# HISTORY:
# HISTORY: Revision 1.62  2006/03/06 17:13:37  apsop
# HISTORY: Remove findchart type, which is handled in generic tdrss. Support new name for uvot genie images.
# HISTORY:
# HISTORY: Revision 1.61  2006/01/20 19:43:16  apsop
# HISTORY: Replace "met" flag with more descriptive "not_seqid" flag.
# HISTORY:
# HISTORY: Revision 1.60  2005/11/16 01:06:35  apsop
# HISTORY: Fix eventaux file name.
# HISTORY:
# HISTORY: Revision 1.59  2005/11/08 16:53:24  apsop
# HISTORY: Change eventaux and qualcal file names. Remove xrtw3 and add xrtcal, tdrawimage, tdskyimage.  Add hk to process instrument.
# HISTORY:
# HISTORY: Revision 1.58  2005/09/26 20:58:03  apsop
# HISTORY: Make types bcatalog and rcatalog repository types.
# HISTORY:
# HISTORY: Revision 1.57  2005/08/16 21:38:14  apsop
# HISTORY: Added HEASARC BAT exposure catalog file.
# HISTORY:
# HISTORY: Revision 1.56  2005/07/29 14:42:09  apsop
# HISTORY: Add in xrtw3 file type.
# HISTORY:
# HISTORY: Revision 1.55  2005/07/05 14:56:17  apsop
# HISTORY: Caught SDC up to date with BAT pipeline with exception of BAT
# HISTORY: position refinement.
# HISTORY:
# HISTORY: Revision 1.54  2005/06/01 13:30:32  apsop
# HISTORY: Add types for failed trigger data, and rationalize bat lc and rate data.  New products ucentroid, umemdump, xrtbd  and burstgti. COmment out eventlog, and fix batrates to pick up 1s ligtcurves.
# HISTORY:
# HISTORY: Revision 1.53  2005/05/04 21:33:13  apsop
# HISTORY: Changes related to implementing BAT mask tagged light curves.
# HISTORY:
# HISTORY: Revision 1.52  2005/04/21 12:55:15  apsop
# HISTORY: Change batrates extension to work as grep as well as glob.
# HISTORY:
# HISTORY: Revision 1.51  2005/04/19 15:05:19  apsop
# HISTORY: New batrates file type for sorting of bat lightcurves.
# HISTORY:
# HISTORY: Revision 1.50  2005/03/15 18:39:04  apsop
# HISTORY: Add notfits specifier to indicate which file types are not fits files.
# HISTORY:
# HISTORY: Revision 1.49  2005/03/07 20:27:42  apsop
# HISTORY: Add eventlog type to processing.
# HISTORY:
# HISTORY: Revision 1.48  2005/02/18 01:59:45  apsop
# HISTORY: Make dpimage type and attlpd type.  Change bat attitude type bat to at.fits
# HISTORY:
# HISTORY: Revision 1.47  2005/02/14 19:24:45  apsop
# HISTORY: Change name of bat attitude file to end in .hk
# HISTORY:
# HISTORY: Revision 1.46  2005/02/08 14:29:35  apsop
# HISTORY: Add new types for uvot fitler specific images and exp maps.
# HISTORY:
# HISTORY: Revision 1.45  2005/01/11 17:24:20  apsop
# HISTORY: Changer pulser type to pulsar.
# HISTORY:
# HISTORY: Revision 1.44  2005/01/08 04:12:37  apsop
# HISTORY: Add pulser file type.
# HISTORY:
# HISTORY: Revision 1.43  2004/12/31 01:30:16  apsop
# HISTORY: Clean up comments a little.
# HISTORY:
# HISTORY: Revision 1.42  2004/12/10 02:14:09  apsop
# HISTORY: Add in new type for uvot db file.
# HISTORY:
# HISTORY: Revision 1.41  2004/11/14 17:03:39  apsop
# HISTORY: Change of several BAT hk and trend files back to being tagged by obsid instead of time.
# HISTORY:
# HISTORY: Revision 1.40  2004/11/09 23:56:16  apsop
# HISTORY: Add in tdnosc type, for non-science tdrss messages.
# HISTORY:
# HISTORY: Revision 1.39  2004/11/08 18:19:38  apsop
# HISTORY: Added BAT exposure map and postage stamp types.  Removed MET qualifier
# HISTORY: from BAT quality map.
# HISTORY:
# HISTORY: Revision 1.38  2004/10/14 19:15:52  apsop
# HISTORY: Fix bug in uvot report filename.
# HISTORY:
# HISTORY: Revision 1.37  2004/10/13 01:43:20  apsop
# HISTORY: Change plot files to gif. Put in proper file names for par and cat files. Add tdrss db file.
# HISTORY:
# HISTORY: Revision 1.36  2004/09/15 22:21:08  apsop
# HISTORY: Change file names to use new underscore convention.
# HISTORY:
# HISTORY: Revision 1.35  2004/09/14 18:56:22  apsop
# HISTORY: Create a hash of tdrss messages and their corresponding instrument.
# HISTORY:
# HISTORY: Revision 1.34  2004/09/03 00:21:45  apsop
# HISTORY: Give mask tagged lc their own type and file class
# HISTORY:
# HISTORY: Revision 1.33  2004/08/30 13:16:51  apsop
# HISTORY: More changes for trend data classes
# HISTORY:
# HISTORY: Revision 1.32  2004/08/27 18:28:12  apsop
# HISTORY: Added UVOT exposure map and source list types.
# HISTORY:
# HISTORY: Revision 1.31  2004/08/22 18:42:25  apsop
# HISTORY: Initial changes for new file classes and repository
# HISTORY:
# HISTORY: Revision 1.30  2004/07/19 16:06:15  apsop
# HISTORY: Fix amdph file type entry to match actual file name.
# HISTORY:
# HISTORY: Revision 1.29  2004/07/06 20:04:03  apsop
# HISTORY: Add tdrss xrt lightcurve.
# HISTORY:
# HISTORY: Revision 1.28  2004/06/29 14:18:58  apsop
# HISTORY: Remove onboardbp file type
# HISTORY:
# HISTORY: Revision 1.27  2004/05/28 19:50:14  apsop
# HISTORY: Put in file type for timing data file.
# HISTORY:
# HISTORY: Revision 1.26  2004/05/19 22:50:54  apsop
# HISTORY: changed gif -> ps
# HISTORY:
# HISTORY: Revision 1.25  2004/05/06 19:58:41  dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.24  2004/04/16 20:20:37  dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################

use strict;


#########################
# constructor
#########################
sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my $self={};

    @{$self->{'inst_list'}} = ('b', 'u', 'x', 's', 'f', 'p');

    ####################################
    # file name extensions
    ####################################
    $self->{'b'} = {'unfiltered'  => {ext => '_uf.evt'},
		    'tdunfilter'  => {ext => '_uf.evt', tdrss=>1},
		    'event'       => {ext => '_cl.evt'},
		    'eventaux'    => {ext => 'evtr.fits'},
		    'rawmtlc'     => {ext => 'mt[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_rw.lc'},
		    'mtlc'        => {ext => 'mt[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].lc'},
		    'pulsar'      => {ext => 'pl[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].fits'},
		    'rawlc'       => {ext => '_rw.lc'},
		    'batrates'    => {ext => 'rt[a-z1][a-z].lc'},
		    'lightcurve'  => {ext => '.lc'},
		    'spectrum'    => {ext => '.pha'},
		    'response'    => {ext => '.rsp'},
		    'dpimage'     => {ext => '_dt.img'},
		    'skyimage'    => {ext => '_sk.img'},
		    'expimage'    => {ext => '_ex.img'},
		    'maskimage'   => {ext => '_mk.img'},
		    'postimg'     => {ext => '.postimg'},
		    'lcplot'      => {ext => '_lc.gif'},
		    'specplot'    => {ext => '_ph.gif'},
		    'skyplot'     => {ext => '_skim.gif'},
		    'sumdph'      => {ext => '_sm.dph'},
		    'rawdph'      => {ext => '.dph', 'gain' => 1,'off' => 1},
		    'dph'         => {ext => '.dph'},
		    'hk'          => {ext => '.hk'},
		    'tdhk'        => {ext => '.hk', tdrss=>1},
		    'enhk'        => {ext => 'en.hk'},
		    'amspec'      => {ext => 'am.fits', 'gain' => 1,'off' => 1},
		    'maskwt'      => {ext => 'mw[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].fits'},
		    'shelllog'    => {ext => 'shtb.log', 'notfits' => 1},
		    'tdmess'      => {ext => '.fits', tdrss=>1},
		    'tdlcurve'    => {ext => '.lc', tdrss=>1},
		    'tdscalemap'  => {ext => '_sm.fits', tdrss=>1},
		    'report'      => {ext => 'ir.html', 'notfits' => 1},
		    'attitude'    => {ext => 'at.fits'},
		    'attlpd'      => {ext => 'at.hk'},
		    'tdattlpd'    => {ext => 'at.hk', tdrss=>1},
		    'batlcatt'    => {ext => 'atlc.fits'},
		    'tdrsslcatt'  => {ext => 'atlc.fits', tdrss=>1},
		    'burstgti'    => {ext => 'evbu.gti'},

		    'bscalemap'   => {ext => 'smcb.fits', 'not_seqid' => 1, repository => 'OBSID'},
		    'rscalemap'   => {ext => 'smcb[hrl]p.fits', 'not_seqid' => 1},
		    'bsegment'    => {ext => 'sgcb.fits', 'not_seqid' => 1},
		    'rsegment'    => {ext => 'sgcb[hrl]p.fits', 'not_seqid' => 1},
		    'bcatalog'    => {ext => 'cttb.fits', 'not_seqid' => 1, repository => 'TIME'},
		    'rcatalog'    => {ext => 'cttb[hrl]p.fits', 'not_seqid' => 1, repository => 'TIME'},
		    'btbveto'     => {ext => 'vttb.fits', 'not_seqid' => 1},
		    'rtbveto'     => {ext => 'vttb[hrl]p.fits', 'not_seqid' => 1},
		    'btblongtr'   => {ext => 'lttb.fits', 'not_seqid' => 1},
		    'rtblongtr'   => {ext => 'lttb[hrl]p.fits', 'not_seqid' => 1},
		    'btbshorttr'  => {ext => 'sttb.fits', 'not_seqid' => 1},
		    'rtbshorttr'  => {ext => 'sttb[hrl]p.fits', 'not_seqid' => 1},
		    'btbratetr'   => {ext => 'rttb.fits', 'not_seqid' => 1},
		    'rtbratetr'   => {ext => 'rttb[hrl]p.fits', 'not_seqid' => 1},
		    'btbimgtr'    => {ext => 'ittb.fits', 'not_seqid' => 1},
		    'rtbimgtr'    => {ext => 'ittb[hrl]p.fits', 'not_seqid' => 1},
		    'btbratedg'   => {ext => 'rdtb.fits', 'not_seqid' => 1},
		    'rtbratedg'   => {ext => 'rdtb[hrl]p.fits', 'not_seqid' => 1},
		    'btbrun'      => {ext => 'rstb.fits', 'not_seqid' => 1},
		    'rtbrun'      => {ext => 'rstb[hrl]p.fits', 'not_seqid' => 1},
		    'bcomman'     => {ext => 'cdtb.fits', 'not_seqid' => 1},
		    'rcomman'     => {ext => 'cdtb[hrl]p.fits', 'not_seqid' => 1},
		    'bshelllg'    => {ext => 'shtb.fits', 'not_seqid' => 1},
		    'rshelllg'    => {ext => 'shtb[hrl]p.fits', 'not_seqid' => 1},
		    'btrigflx'    => {ext => 'fxcb.fits', 'not_seqid' => 1},
		    'rtrigflx'    => {ext => 'fxcb[hrl]p.fits', 'not_seqid' => 1},

		    'bgain'       => {ext => 'cb.fits', 'gain' => 1},
		    'boffset'     => {ext => 'cb.fits', 'off' => 1},
		    'bamdph'      => {ext => 'amcb.dph', 'gain' => 1,'off' => 1},
		    'bamgaoff'    => {ext => 'amcb.fits', 'gain' => 1,'off' => 1},
		    'bdetflag'    => {ext => 'decb.fits', 'not_seqid' => 1, repository => 'TIME'},
		    'bgaoff'      => {ext => 'cb.fits', 'gain' => 1,'off' => 1, 
				      repository => 'TIME', 'not_seqid' => 1},
		    'qualcal'     => {ext => 'dqcb.hk'},
		    'bdaphk'      => {ext => 'dp.hk', 'not_seqid' => 1},

		    'filter'      => {ext => '.mkf'},
		    'gti'         => {ext => '.gti'},
		    'dpi'         => {ext => '.dpi'},
		    'specfit'     => {ext => '.specfit'},
		    'specfitplot' => {ext => 'specfit.gif', 'notfits' => 1},
		   };

    $self->{'x'} = {'unfiltered'  => {ext => '_uf.evt'},
		    'tdunfilter'  => {ext => '_uf.evt', tdrss=>1},
		    'reconst'     => {ext => '_ufre.evt'},
		    'xrtcal'      => {ext => 'cb_uf.evt'},
		    'event'       => {ext => '_cl.evt'},
		    'tdevent'     => {ext => '_cl.evt', tdrss=>1},
		    'xrawmode'    => {ext => 'rf_rw.img'},
		    'xbiasmode'   => {ext => 'bf_rw.img'},
		    'xtam'        => {ext => 'tm_rw.img'},
		    'rawimage'    => {ext => '_rw.img'},
		    'skyimage'    => {ext => '_sk.img'},
		    'skyplot'     => {ext => 'sk.gif'},
		    'imageplot'   => {ext => 'im.gif'},
		    'expimage'    => {ext => '_ex.img'},
		    'lightcurve'  => {ext => '.lc'},
		    'lcplot'      => {ext => 'lc.gif', 'notfits' => 1},
		    'spectrum'    => {ext => '.pha'},
		    'specplot'    => {ext => 'ph.gif'},
		    'respfunc'    => {ext => 'sr.arf'},
		    'hk'          => {ext => '.hk'},
		    'enhk'        => {ext => 'en.hk'},
		    'tdmess'      => {ext => '.fits', 'tdrss' => 1},
		    'tdspec'      => {ext => '.pha', 'tdrss' => 1},
		    'tdimage'     => {ext => '.img', 'tdrss' => 1},
		    'tdrawimage'  => {ext => '_rw.img', 'tdrss' => 1},
		    'tdskyimage'  => {ext => '_sk.img', 'tdrss' => 1},
		    'tdlcurve'    => {ext => '.lc', tdrss=>1},
		    'report'      => {ext => 'ir.html', 'notfits' => 1},

		    'pixlist'     => {ext => '.pixlist'},
		    'filter'      => {ext => '.mkf'},
		    'detimage'    => {ext => 'dt.img'},
		    'corrimage'   => {ext => 'cr.img'},
		    'detplot'     => {ext => 'dtim.gif', 'notfits' => 1},
		    'calspec'     => {ext => '.pical'},
		    'calspecplot' => {ext => '_pical.gif', 'notfits' => 1},
		    'gti'         => {ext => '.gti'},
		   };

    $self->{'u'} = {'unfiltered'  => {ext => '_uf.evt'},
		    'event'       => {ext => '_cl.evt'},
		    'lightcurve'  => {ext => '.lc'},
		    'lcplot'      => {ext => '_lc.gif', 'notfits' => 1},
		    'rawimage'    => {ext => '_rw.img'},
		    'detimage'    => {ext => '_dt.img'},
		    'skyimage'    => {ext => '_sk.img'},
		    'filterimg'   => {ext => '[bgwvmu][lu2v1gbhn]_sk.img'},
		    'skyplot'     => {ext => 'skim.gif', 'notfits' => 1},
		    'dssplot'     => {ext => 'dss_skim.gif', 'notfits' => 1},
		    'detplot'     => {ext => 'dtim.gif', 'notfits' => 1},
		    'hk'          => {ext => '.hk'},
		    'enhk'        => {ext => 'en.hk'},
		    'ucentroid'   => {ext => 'cn.hk'},
		    'umemdump'    => {ext => 'md.hk'},
		    'spectrum'    => {ext => '.pha'},
		    'specplot'    => {ext => '_ph.gif', 'notfits' => 1},
		    'tdmess'      => {ext => '.fits', 'tdrss' => 1},
		    'tdrawimage'  => {ext => '_rw.img', 'tdrss' => 1},
		    'report'      => {ext => 'ir.html', 'notfits' => 1},
		    'expimage'    => {ext => '_ex.img'},
		    'maskimage'   => {ext => '_mk.img'},
		    'filterexp'   => {ext => '[bgwvmu][lu2v1gbhn]_ex.img'},
		    'attcorr'     => {ext => 'at.fits'},
		    'srclist'     => {ext => '.cat'},
		    'badimage'    => {ext => '_bp.img'},
		    'filter'      => {ext => '.mkf'},
		    'corrimage'   => {ext => '_cr.img'},
		    'gti'         => {ext => '.gti'},
		    'ucmp'        => {ext => 'cm.fits'},
		    'umon'        => {ext => 'mo.fits'}
		   };

    $self->{'s'} = {'attitude'    => {ext => 'at.fits'},
		    'scenhk'      => {ext => 'en.hk'},
		    'hk'          => {ext => '.hk'},
		    'tdmess'      => {ext => '.fits', 'tdrss' => 1},
		    'tdnosc'      => {ext => 'di.fits', 'tdrss' => 1},

		    'attorb'      => {ext => 'ao.fits'},
		    'filter'      => {ext => '.mkf'},
		    'gti'         => {ext => '.gti'},
		    'timedata'    => {ext => 'ti.fits'},
		    'filterplot'  => {ext => 'fl.gif', 'notfits' => 1}
		   };

    $self->{'f'} = {'tdmess'      => {ext => '.fits', 'tdrss' => 1}
		   };

    $self->{'p'} = {'joblog'      => {ext => 'jl.html', 'notfits' => 1},
		    'logindex'    => {ext => 'in.html', 'notfits' => 1},
		    'header'      => {ext => 'su.html', 'notfits' => 1},
		    'errlog'      => {ext => 'er.html', 'notfits' => 1},
		    'fileinfo'    => {ext => 'fi.html', 'notfits' => 1},
		    'checksum'    => {ext => 'cs.txt', 'notfits' => 1},
		    'tdref'       => {ext => 'ob.cat', 'tdrss' => 1},
		    'tddb'        => {ext => 'tddb.fits'},
		    'uvdb'        => {ext => 'uvdb.fits'},
                    'xrdb'        => {ext => 'xrdb.fits'},
                    'badb'        => {ext => 'badb.fits'},
 		    'jobpar'      => {ext => 'jb.par', 'notfits' => 1},
		    'procpar'     => {ext => 'pr.par', 'notfits' => 1},
		    'tapecat'     => {ext => 'ob.cat', 'notfits' => 1},
		    'attcorr'     => {ext => 'at.fits'},
		    'hk'          => {ext => '.hk'}
		   };
    ####    'eventlog'    => {ext => 'evlg.xml', 'notfits' => 1}
    
    ################################################################
    # The 'all' hash is only for listing all available file types, 
    # 'ext' and other settings are meaningless
    ################################################################
    $self->{'all'} = {%{$self->{s}}, 
                      %{$self->{b}},
                      %{$self->{x}}, 
                      %{$self->{u}},
		      %{$self->{f}},
		      %{$self->{p}}
		     };

    foreach my $type (keys %{$self->{'all'}}) {
      $self->{'all'}->{$type} = 'T';
    }

    foreach my $inst (@{$self->{'inst_list'}}) {
      foreach my $type (keys %{$self->{$inst}}){
	#################################################################################
	# Build an 'anti-type' list.  For each file type, get a list of other file types 
	# whose extensions might conflict with it.
	#################################################################################
	my $ext = quotemeta $self->{$inst}->{$type}->{ext};
	foreach my $otype (keys %{$self->{$inst}}){
	  next if $otype eq $type;

	  push @{$self->{$inst}->{$type}->{'anti'}}, $otype
	    if $self->{$inst}->{$otype}->{ext} =~ /${ext}$/;
	}

        #################################################################################
        # Build a hash of all tdrss message types
        #################################################################################
        if( $self->{$inst}->{$type}->{'tdrss'} ){
	  push @{$self->{'tdrss'}->{$type}}, $inst;
	}
      }
    }

    bless($self,$class);
    return $self;

}

#################
# ACCESSORS
#################

##############################################################################
# return the file name extension for a given instrument and type
##############################################################################
sub ext {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{ext};
}

##############################################################################
# returns true if the given instrument and type is a TDRSS message file
##############################################################################
sub is_tdrss {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{'tdrss'};
}

sub is_gain {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{'gain'};
}

sub is_offset {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{'off'};
}

sub not_seqid {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{'not_seqid'};
}

sub is_repository{
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    return $self->{$inst}->{$type}->{'repository'}
      if $self->{$inst}->{$type}->{'repository'};

    return '';
}


##############################################################################
# returns true if the file name for a particular type can be generated using
# the information contained in this class.
##############################################################################
sub is_generic {
    my $self = shift;
    my $type = shift;

    foreach my $inst (@{$self->{'inst_list'}}) {

        if($self->{$inst}->{$type}) { return 1; }
    }

    return 0;
} # is_generic

##############################################################################
# returns true if files exist for the given instrument and type
##############################################################################
sub is_valid_instrument {
    my $self = shift;
    my $type = shift;
    my $inst = shift;

    if( $self->{$inst}->{$type} && $self->{$inst}->{$type}->{ext} ){ return 1; }
    else                        { return 0; }
}


1;