package Util::SWCatalogue;
##############################################################################
#
# DESCRIPTION: Add an instrument column to the catalogue files
#
# HISTORY:
# HISTORY: $Log: SWCatalogue.pm,v $
# HISTORY: Revision 1.5 2005/06/01 13:32:52 apsop
# HISTORY: Add support for file types with multiple classes.
# HISTORY:
# HISTORY: Revision 1.4 2004/05/06 19:58:41 dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.3 2004/04/16 20:20:37 dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################
use Util::Catalog;
@ISA = ("Util::Catalog");
use strict;
#########################
# constructor
#########################
sub new {
my $proto=shift;
my $class = ref($proto) || $proto;
my $self=$proto->SUPER::new(@_);
${$self->{HEADER_TEMPLATE}} = "FILENAME 64A\n"
. "FORMAT 16A\n"
. "TYPE 32A\n"
. "INSTRUMENT 32A\n"
. "FILECLAS 32A\n"
. "DESCRIP 64A\n"
. "FILESIZE 1J kilobytes\n"
. "ARCHSIZE 1J kilobytes\n"
. "CHECKSUM 1J\n"
. "GZIP_CRC 8A\n";
bless($self,$class);
return $self;
}
######################################
# add a file to the catalog
######################################
sub add_file {
my $self=shift;
my $file=shift;
my $type=shift;
my $inst=shift;
my $classes=shift;
my $description=shift;
#print "file=|$file| type=|$type| inst=|$inst| class=|$class| desc=|$description|\n";
my $format=$self->format($file);
my $size =$self->size($file);
$self->{ALL_FILES}->{$file}=$type;
if($format eq 'FITS' ) { $self->{FITS_FILES}->{$file}=$type }
foreach my $class (@$classes){
$self->{DATA}.="$file $format $type $inst $class '$description' ";
$self->{DATA}.="$size 0 0 'ffffffff'\n";
}
}
###################################################
# add all the files of a given type to the catalog
###################################################
sub add_type {
my $self=shift;
my $type=shift;
my $filename = $self->{FILENAME};
my $description=$filename->description($type);
my $classes =$filename->class($self->{CAT_TYPE},$type);
my ($file, $inst);
foreach $file ($self->files_of_type($type) ) {
if( $filename->isGeneric($type) ){
my @fields = $filename->parse($file,$type);
if( $fields[0] ){
$inst = $filename->instrument_name( $fields[0] );
}else{
$self->{LOG}->entry("Cannot get instrument for file $file. Will set to 'swift'");
$inst = 'swift';
}
}else{
$inst = 'swift';
}
$self->add_file($file,$type,$inst,$classes,$description);
}
}
1;