package Subs::UvotGraspCorr;
##############################################################################
#
# DESCRIPTION: Apply uvotgraspcorr
#
# HISTORY: $Log: UvotGraspCorr.pm,v $
# HISTORY: Revision 1.8 2013/08/14 07:06:29 apsop
# HISTORY: Added the VERSION comment, which lets comN.N/tools/doc
# HISTORY: create the HTML documentation for this file.
# HISTORY:
# HISTORY: Revision 1.7 2013/08/13 19:38:01 apsop
# HISTORY: Handle the case of having ONLY grism data..
# HISTORY:
# HISTORY: Revision 1.6 2013/07/16 07:27:23 apsop
# HISTORY: Rename the resulting grism aspect correction HDU to GRASPCORR,
# HISTORY: so it's different than the non-grism correction's (ASPCORR).
# HISTORY:
# HISTORY: Revision 1.5 2012/01/12 06:52:03 apsop
# HISTORY: Changes going to proc3.15.03
# HISTORY:
#
# VERSION: $Revision: 1.8 $
#
##############################################################################
use Subs::Sub;
use Util::GTIfile;
use Util::SWCatalogue;
use Util::FITSfile;
@ISA = ("Subs::Sub");
use strict;
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Apply uvotgraspcorr";
return $self;
}
##################
# METHODS:
##################
sub body {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
my $jobpar =$self->jobpar();
#########################
# Apply uvotgraspcorr
#########################
$self->apply_uvot_grasp_corr();
} # end of body method
#############################################################################
# Apply uvotgraspcorr
#############################################################################
sub apply_uvot_grasp_corr {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
my $jobpar=$self->jobpar();
my $procpar =$self->procpar();
my $corrfile = $filename->get('hk', 'u', 'ac', 0);
if(! $corrfile ){
$log->error(1, "Uvot aspect corr $corrfile file not exist, exit 1");
return ;
}
my @infile1=$filename->get('detimage', 'uvot','*', '*');
if(! @infile1 ){
$log->error(1, "Uvot detimage @infile1 file not exist, exit 1");
return ;
}
my $infile=join(",",@infile1);
my $catspec = $procpar->read('starcatalog');
my $uvotgraspcorr=Util::HEAdas->new("uvotgraspcorr")->is_script( 1 );
$uvotgraspcorr->params({
infile => $infile,
catspec => $catspec,
starid => 'NONE',
distfile => 'DEFAULT',
chatter => 5,
history => 'yes',
clobber => 'yes',
outfile => "uac.hk",
cleanup => 'yes'#,
# mode => 'ql'
});
$uvotgraspcorr->run();
#########DEVELOP VERSION ENV
#my $cmd="source /software/lheasoft/develop/headas.sh;";
#my $cmd="export HEADAS=/net/data/sdc1/apsop/tools/headas/headas-6.7/i686-pc-linux-gnu-libc2.2.5;source \$HEADAS/headas-init.sh ;";
#my $uvt="uvotgraspcorr infile=$infile catspec=$catspec starid=NONE distfile=DEFAULT chatter=5 history=yes clobber=yes outfile=uac.hk cleanup=yes";
#print "$cmd$uvt\n";
#system($cmd.$uvt);
# export HEADAS=/net/data/sdc1/apsop/tools/headas/headas-6.7/i686-pc-linux-gnu-libc2.2.5;source $HEADAS/headas-init.sh ;uvotgraspcorr infile=sw00349510000ugu_dt.img catspec=/ssdc/usnob1/usnob1.b18,/ssdc/usnob1/usnob1.alt starid=NONE distfile=DEFAULT chatter=5 history=yes clobber=yes outfile=uac.hk cleanup=yes
#########DEVELOP VERSION ENV
if (-e 'uac.hk' ) {
if (-e $corrfile) {
my $append = Util::HEAdas->new('ftappend');
$append->params({infile => "uac.hk[1][col #EXTNAME='GRASPCORR']",
outfile => $corrfile})
->run();
} else {
# rename the grism aspect corrections and update EXTNAME
if (rename('uac.hk', $corrfile)) {
my $tmp = Util::FITSfile->new($corrfile, 1);
$tmp->keyword('EXTNAME', 'GRASPCORR');
} else {
$log->(1, "unable to rename grism aspect corrections to $corrfile: $!");
}
}
} else {
$log->error(1,"Uvotaspectcorr output file uac.hk does not exist, exit 1");
}
} # end of apply_uvot_grasp_corr