package Subs::UVOT2FITS;
##############################################################################
#
# DESCRIPTION: This subroutine decodes the UVOT telemetry.
#
# HISTORY:
# HISTORY: $Log: UVOT2FITS.pm,v $
# HISTORY: Revision 1.27 2012/01/27 16:15:13 apsop
# HISTORY: Changed "Uvot damaged image file" error from E2 to E1.
# HISTORY:
# HISTORY: Revision 1.26 2007/06/28 20:46:55 apsop
# HISTORY: Throw error if uvot damaged image file is created.
# HISTORY:
# HISTORY: Revision 1.25 2007/04/18 22:28:25 apsop
# HISTORY: Set maximum image file size to 250 MB.
# HISTORY:
# HISTORY: Revision 1.24 2007/01/31 17:24:43 apsop
# HISTORY: New parameter for uvot2fits, maximagesize set to default for now.
# HISTORY:
# HISTORY: Revision 1.23 2006/06/15 22:13:59 apsop
# HISTORY: Exclude event data from first 992 only if image data is actually present.
# HISTORY:
# HISTORY: Revision 1.22 2006/04/27 15:52:00 apsop
# HISTORY: Create new uvot trend monitoring file.
# HISTORY:
# HISTORY: Revision 1.21 2005/07/29 14:31:53 apsop
# HISTORY: Selective uvot proccessing changed to occur only for 992 segments.
# HISTORY:
# HISTORY: Revision 1.20 2005/07/08 19:03:47 apsop
# HISTORY: Turn down chatter on uvot2fits from 8 to 4.
# HISTORY:
# HISTORY: Revision 1.19 2005/06/01 15:59:44 apsop
# HISTORY: Only process image data is this is the first time image data was available.
# HISTORY:
# HISTORY: Revision 1.18 2005/04/19 15:24:24 apsop
# HISTORY: Do not run uvot2fits unless there is science data.
# HISTORY:
# HISTORY: Revision 1.17 2005/03/25 19:48:52 apsop
# HISTORY: Pass apid 866 to uvot2fits.
# HISTORY:
# HISTORY: Revision 1.16 2004/12/10 02:20:31 apsop
# HISTORY: Changes to support mission pneumonic other than sw.
# HISTORY:
# HISTORY: Revision 1.15 2004/11/09 23:52:24 apsop
# HISTORY: Add in uvot2fits support for apids 776 and 782.
# HISTORY:
# HISTORY: Revision 1.14 2004/10/20 18:49:46 apsop
# HISTORY: Add in additonal apids which are handled by uvot2fits.
# HISTORY:
# HISTORY: Revision 1.13 2004/06/08 13:28:42 apsop
# HISTORY: Bug fix for analyzing memory dump data
# HISTORY:
# HISTORY: Revision 1.12 2004/06/07 23:59:55 apsop
# HISTORY: Add apids for memory dumps.
# HISTORY:
# HISTORY: Revision 1.11 2004/05/28 19:49:02 apsop
# HISTORY: Put in APID for GENIE image.
# HISTORY:
# HISTORY: Revision 1.10 2004/05/06 20:02:34 dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.9 2004/04/28 13:47:35 dah
# HISTORY: Make one method for extracting hk, and put it in Swift2FTIS superclass.
# HISTORY:
# HISTORY: Revision 1.8 2004/04/16 20:21:18 dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################
use Subs::Swift2FITS;
use Util::Tool;
@ISA = ('Subs::Swift2FITS');
use strict;
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Decoding UVOT 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();
##############################
# collect the science APIDs
##############################
my $apid605 = $filename->get("telemetry", "uvot", "*", 605);
my $apid688 = $filename->get("telemetry", "uvot", "*", 688); #GeNIe Image Packet (TDRSS)
my $apid704 = $filename->get("telemetry", "uvot", "*", 704); #Segmented Finding Chart
my $apid776 = $filename->get("telemetry", "uvot", "*", 776); #Channel Boundary Data
my $apid782 = $filename->get("telemetry", "uvot", "*", 782); #Intensifier Characteristics
my $apid843 = $filename->get("telemetry", "uvot", "*", 843); #Merged GeNIe data
my $apid848 = $filename->get("telemetry", "uvot", "*", 848); #Exposure end
my $apid850 = $filename->get("telemetry", "uvot", "*", 850); #Exposure start
my $apid853 = $filename->get("telemetry", "uvot", "*", 853); #Finding Chart
my $apid854 = $filename->get("telemetry", "uvot", "*", 854); #Centroid Confirmation
my $apid855 = $filename->get("telemetry", "uvot", "*", 855); #Uncompressed Image Data
my $apid856 = $filename->get("telemetry", "uvot", "*", 856); #Compressed Image Data
my $apid857 = $filename->get("telemetry", "uvot", "*", 857); #Uncompressed Event Data
my $apid858 = $filename->get("telemetry", "uvot", "*", 858); #Compressed Event Data
my $apid860 = $filename->get("telemetry", "uvot", "*", 860); #Aspect Following Report
my $apid861 = $filename->get("telemetry", "uvot", "*", 861); #DPU Memory dump
my $apid866 = $filename->get("telemetry", "uvot", "*", 866); #ICU Housekeeping
my $apid1104 = $filename->get("telemetry", "uvot", "*", 1104); #ICU Memory dump
#####################################################################
# If this is an 992 uvot only obs target, only process event data if
# image data was processed in a previous processing
#####################################################################
my $seq = $jobpar->read('sequence');
if( ! $jobpar->{DATALIST}->{uvot_image} && $seq%1000==992 && ($apid855 || $apid856) ){
undef $apid857;
undef $apid858;
}
#############################
# replace blanks with "NONE"
#############################
my $got_something=0;
foreach ($apid605, $apid688, $apid704, $apid843, $apid848, $apid850, $apid853,
$apid854, $apid855, $apid856, $apid857, $apid858, $apid860, $apid861,
$apid1104) {
unless($_) { $_ = "NONE"; }
else { ++$got_something; }
}
foreach ($apid866, $apid782, $apid776) {
unless($_) { $_ = "NONE"; }
}
######################################
# set up and run UVOT2fits
######################################
if($got_something) {
my $mission = $jobpar->read("mission");
my $filename_base = $mission . $jobpar->read("sequence");
my $bin = $procpar->read("uvot2fits");
my $uvot2fits = Util::PseudoFtool->new("$bin/uvot2fits");
$uvot2fits->params({fitsname=>$filename_base,
path => "./",
override => $mission eq 'sw' ? 'no' : 'yes',
maximgsize => 250,
apid605 => $apid605,
apid688 => $apid688,
apid704 => $apid704,
apid776 => $apid776,
apid782 => $apid782,
apid843 => $apid843,
apid848 => $apid848,
apid850 => $apid850,
apid853 => $apid853,
apid854 => $apid854,
apid855 => $apid855,
apid856 => $apid856,
apid857 => $apid857,
apid858 => $apid858,
apid860 => $apid860,
apid861 => $apid861,
apid866 => $apid866,
apid1104 => $apid1104,
clobber => "yes",
chatter => 4 });
############################
# running uvot2fits
############################
$log->entry("Running ".$uvot2fits->name() );
$uvot2fits->run();
if( $mission ne 'sw' ){
foreach my $file ( glob 'sw???????????msu*' ){
my $newfile = $file;
$newfile =~ s/^sw/${mission}/;
rename $file, $newfile;
}
}
} else {
$log->entry("No UVOT science telemetry");
}
###########################
# now extract HK data
###########################
$self->hk_extract('uvot');
my @hkfiles = $filename->get('hk', 'uvot', '30[8e]x[0-9][0-9][0-9]', 0);
if(@hkfiles){
my $monfile = $filename->get('umon', 'uvot', '', 0);
$self->fits_combine($monfile, @hkfiles);
}
$self->hk_combine('uvot');
if( $filename->get('rawimage', 'uvot', 'di', '*') ){
$log->error(1, "Uvot damaged image file created.");
}
} # end of body method
1;