package Subs::Spacecraft2FITS; ############################################################################## # # DESCRIPTION: This subroutine converts Spacecraft HK telemetry to FITS # # HISTORY: # HISTORY: $Log: Spacecraft2FITS.pm,v $ # HISTORY: Revision 1.12 2007/07/03 19:50:29 apsop # HISTORY: Fix bug in setting of GTI extension name. # HISTORY: # HISTORY: Revision 1.11 2007/06/28 20:49:00 apsop # HISTORY: Merge bat and NFI timelines when making snapshot GTI. # HISTORY: # 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 = sort { $a->{start} <=> $b->{start} or $a->{stop} <=> $b->{stop} } @intervals; $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->keyword('TIMESYS', 'TT', 'time system'); $fits->keyword('MJDREFI', 51910, 'MJD reference day 01 Jan 2001 00:00:00'); $fits->keyword('MJDREFF', 7.428703700000000E-04, 'MJD reference (fraction of day) 01 Jan 2001 00:00:00'); $fits->keyword('CLOCKAPP', 'F', 'If clock correction are applied (F/T)'); $fits->keyword('TIMEUNIT', 's', 'Time unit for timing header keywords'); $fits->ext(0); $fits->keyword('TSTART', $jobpar->{TIMELIST}->{start}); $fits->keyword('TSTOP', $jobpar->{TIMELIST}->{stop}); my $temp = "ssgti.tmp"; Util::Ftool->new('mgtime') ->params({ingtis => "$outfile\[GTI\] $outfile\[GTI\]", outgti => $temp, merge => 'OR'}) ->run(); rename $temp, $outfile; $fits->ext(1); $fits->keyword('EXTNAME', 'GTI'); }else{ $log->error(1, "Unable to open $qname, $!"); } } } # end of body method