package Util::FilenameInfo;
##############################################################################
#
# DESCRIPTION: This class holds information about generic Swift file names.
#
# HISTORY:
# HISTORY: $Log: FilenameInfo.pm,v $
# 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'},
'event' => {'ext' => '_cl.evt'},
'mtlc' => {'ext' => 'mt[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_rw.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'},
'lightcurve' => {'ext' => '.lc'},
'spectrum' => {'ext' => '.pha'},
'response' => {'ext' => '.rsp'},
'dpimage' => {'ext' => '_dt.img'},
'skyimage' => {'ext' => '_sk.img'},
'expimage' => {'ext' => '_ex.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'},
'bgaoff' => {'ext' => 'cb.fits', 'gain' => 1,'off' => 1},
'hk' => {'ext' => '.hk'},
'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'},
'batlcatt' => {'ext' => 'atlc.fits'},
'tdrsslcatt' => {'ext' => 'atlc.fits', tdrss=>1},
'bscalemap' => {'ext' => 'smcb.fits', 'met' => 1},
'rscalemap' => {'ext' => 'smcb[hrl]p.fits', 'met' => 1},
'bsegment' => {'ext' => 'sgcb.fits', 'met' => 1},
'rsegment' => {'ext' => 'sgcb[hrl]p.fits', 'met' => 1},
'bcatalog' => {'ext' => 'cttb.fits', 'met' => 1},
'rcatalog' => {'ext' => 'cttb[hrl]p.fits', 'met' => 1},
'btbveto' => {'ext' => 'vttb.fits', 'met' => 1},
'rtbveto' => {'ext' => 'vttb[hrl]p.fits', 'met' => 1},
'btblongtr' => {'ext' => 'lttb.fits', 'met' => 1},
'rtblongtr' => {'ext' => 'lttb[hrl]p.fits', 'met' => 1},
'btbshorttr' => {'ext' => 'sttb.fits', 'met' => 1},
'rtbshorttr' => {'ext' => 'sttb[hrl]p.fits', 'met' => 1},
'btbratetr' => {'ext' => 'rttb.fits', 'met' => 1},
'rtbratetr' => {'ext' => 'rttb[hrl]p.fits', 'met' => 1},
'btbimgtr' => {'ext' => 'ittb.fits', 'met' => 1},
'rtbimgtr' => {'ext' => 'ittb[hrl]p.fits', 'met' => 1},
'btbratedg' => {'ext' => 'rdtb.fits', 'met' => 1},
'rtbratedg' => {'ext' => 'rdtb[hrl]p.fits', 'met' => 1},
'btbrun' => {'ext' => 'rstb.fits', 'met' => 1},
'rtbrun' => {'ext' => 'rstb[hrl]p.fits', 'met' => 1},
'bcomman' => {'ext' => 'cdtb.fits', 'met' => 1},
'rcomman' => {'ext' => 'cdtb[hrl]p.fits', 'met' => 1},
'bshelllg' => {'ext' => 'shtb.fits', 'met' => 1},
'rshelllg' => {'ext' => 'shtb[hrl]p.fits', 'met' => 1},
'btrigflx' => {'ext' => 'fxcb.fits', 'met' => 1},
'rtrigflx' => {'ext' => 'fxcb[hrl]p.fits', 'met' => 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', 'met' => 1},
'qualcal' => {'ext' => 'dq.hk'},
'bdaphk' => {'ext' => 'dp.hk', 'met' => 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'},
'reconst' => {'ext' => '_ufre.evt'},
'event' => {'ext' => '_cl.evt'},
'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' => '_skim.gif'},
'expmap' => {'ext' => '_ex.img'},
'lightcurve' => {'ext' => '.lc'},
'lcplot' => {'ext' => '_lc.gif', 'notfits' => 1},
'spectrum' => {'ext' => '.pha'},
'specplot' => {'ext' => '_ph.gif', 'notfits' => 1},
'effarea' => {'ext' => '.arf'},
'hk' => {'ext' => '.hk'},
'enhk' => {'ext' => 'en.hk'},
'tdmess' => {'ext' => '.fits', 'tdrss' => 1},
'tdspec' => {'ext' => '.pha', 'tdrss' => 1},
'tdimage' => {'ext' => '.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},
'detplot' => {'ext' => 'dtim.gif', 'notfits' => 1},
'hk' => {'ext' => '.hk'},
'enhk' => {'ext' => 'en.hk'},
'spectrum' => {'ext' => '.pha'},
'specplot' => {'ext' => '_ph.gif', 'notfits' => 1},
'tdmess' => {'ext' => '.fits', 'tdrss' => 1},
'findchart' => {'ext' => '_fc.img', 'tdrss' => 1},
'report' => {'ext' => 'ir.html', 'notfits' => 1},
'expimage' => {'ext' => '_ex.img'},
'filterexp' => {'ext' => '[bgwvmu][lu2v1gbhn]_ex.img'},
'srclist' => {'ext' => '.cat'},
'badimage' => {'ext' => '_bp.img'},
'filter' => {'ext' => '.mkf'},
'corrimage' => {'ext' => '_cr.img'},
'gti' => {'ext' => '.gti'},
'ucmp' => {'ext' => 'cm.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'},
'jobpar' => {'ext' => 'jb.par', 'notfits' => 1},
'procpar' => {'ext' => 'pr.par', 'notfits' => 1},
'tapecat' => {'ext' => 'ob.cat', 'notfits' => 1},
'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 is_met {
my $self = shift;
my $type = shift;
my $inst = shift;
return $self->{$inst}->{$type}->{'met'};
}
sub is_repository{
my $self = shift;
my $type = shift;
my $inst = shift;
return $self->{$inst}->{$type}->{'repository'};
}
##############################################################################
# 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;