Subs::Spacecraft2FITS (version 0.0)


package Subs::Spacecraft2FITS;
##############################################################################
#
# DESCRIPTION: This subroutine converts Spacecraft HK telemetry to FITS
#
# HISTORY: 
# HISTORY: $Log: Spacecraft2FITS.pm,v $
# HISTORY: Revision 1.10  2007/02/05 15:32:45  apsop
# HISTORY: Make snapshot GTIs from NFI intervals if BAT intervals are not available.
# HISTORY:
# HISTORY: Revision 1.9  2006/01/31 17:30:52  apsop
# HISTORY: Add TSTART TSTOP keywords to pri header of snapshot gti file.
# HISTORY:
# HISTORY: Revision 1.8  2006/01/31 16:46:25  apsop
# HISTORY: Make shapshot GTI file from B entries in *.queue file.
# HISTORY:
# HISTORY: Revision 1.7  2004/05/06 20:02:34  dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.6  2004/04/28 13:47:35  dah
# HISTORY: Make one method for extracting hk, and put it in Swift2FTIS superclass.
# HISTORY:
# HISTORY: Revision 1.5  2004/04/16 20:21:18  dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################


use Subs::Swift2FITS;
use Util::Tool;
use Util::FITStable;

@ISA = ("Subs::Swift2FITS");
use strict;

sub new {
    my $proto=shift;
    my $self=$proto->SUPER::new();

    $self->{DESCRIPTION}="Decoding Spacecraft Telemetry";

    return $self;
}

##################
# METHODS:
##################

sub body {
    my $self=shift;

    my $log     =$self->log();
    my $filename=$self->filename();
    my $procpar =$self->procpar();
    my $jobpar  =$self->jobpar();

    $self->hk_extract('swift');
    $self->hk_combine('swift');

    ###############################################
    # Construct snapshot gti's from the queue file
    ###############################################
    my $qname = $jobpar->read('sequence') . '.queue';
    if( -f $qname ){
      if( open(QUEUE, "$qname") ){
	my @intervals;
	while(<QUEUE>){
	  my %temp;
	  @temp{'type', 'id', 'start', 'stop'} = split(' ');
	  push @intervals, \%temp;
	}
        close QUEUE;

	my @db = ( {name => 'START',
		    type => '1D',
		    unit => 's',
		    key => 'START'},

		   {name => 'STOP',
		    type => '1D',
		    unit => 's',
		    key => 'STOP'});

	my $db = Util::FITStable->new(\@db,
				      log => $log,
				      which => 'timeline',
				     );

	my @uintervals = grep $_->{type} eq 'B', @intervals;
	@uintervals = grep $_->{type} eq 'T', @intervals
	  unless @uintervals;
	$db->set(START => [map $_->{start}, @uintervals]);
	$db->set(STOP  => [map $_->{stop}, @uintervals]);

	my $outfile = $filename->get('gti', 's', 'ss', 0);
	$db->write($outfile);

	my $fits = Util::FITSfile->new($outfile);
	$fits->keyword('EXTNAME', 'GTI');

	$fits->ext(0);
	$fits->keyword('TSTART', $jobpar->{TIMELIST}->{start});
	$fits->keyword('TSTOP', $jobpar->{TIMELIST}->{stop});
      }else{
	$log->error(1, "Unable to open $qname, $!");
      }
    }

} # end of body method