package MakeCIF;
use strict;
use English;
use Carp;
use vars
qw(@ISA $VERSION $name $author $date $version @instList $numberOfStreams);
@ISA = qw(Module);
use ModuleResources;
# Declare identity, version, author, date, etc.
$name = __PACKAGE__;
$VERSION = '1.23';
$version = $VERSION;
$author="Richard West, Dean Hinshaw, Duncan John Fyfe, Duncan Law-Green, Ed Chapin";
$date="2013-06-11";
#
# ChangeLog
# =========
#
# Version 1.23 - 2013-06-11 (EC)
# ------------
#
# + Merge changes from SOC version.
# + This version includes for the first time the changes made to this module in
# slew pipeline (1.20->1.22).
#
# Version 1.22 - 2010-06-17 (DLG)
# ------------
#
# + SLEW ONLY: Manual fix of incorrect OBS_ID in slew observations
#
# Version 1.21 - 2010-01-26 (DLG)
# ------------
#
# + Manual set of parameters in addattribute call
#
# Version 1.20 - 2009-06-22 (DLG)
#
# + Add check for non-zero parameters in addattribute call (trap for observer, pointing
# in slew observations).
#
# Version 1.19 - 2006-08-24 (DJF)
# ------------
#
# + Change cifbuild observationdate source. Now taken from the sequence observationdate parameter.
# This parameter defaults to obs_start (old behaviour) unless overridden on the sequence command line.
#
# Version 1.18 - 2006-07-05 (DJF)
# ------------
#
# + Changed numberOfStreams to use standerdized function.
#
# Version 1.17 - 2003-06-26 (DJF)
# ------------
#
# + Call to get obs_start and procdate for cifbuild was using
# upper case parameter names in a case-sensitive environment
# where lower case was required. Fixed.
#
# Version 1.16 - 2003-06-25 (DJF)
# ------------
#
# + Added information to help identify a problem with cfibuild parameters.
#
# Version 1.15 - 2001-12-06 (DH)
# ------------
#
# + Remove any apostophes in keyword values,
# as apostophes cause problems for the addattribute command line.
#
# Version 1.14 - 2001-12-06 (DH)
# ------------
#
# + Bug fixes for 1.13.
#
# Version 1.13 - 2001-12-06 (DH)
# ------------
#
# + Write standard keywords (OBS_ID, etc) into cif product
# file.
#
# Version 1.12 - 2001-05-09 (DH)
# ------------
#
# + Change withccfpath parameter to 'no'. Value for
# ccf path is now set via a configuration parameter.
#
# Version 1.11 - 2001-05-04 (DH)
# ------------
#
# + Change the value of fullpath parameter to 'no'
#
# Version 1.10 - 2001-05-01 (DH)
# ------------
#
# + Add withccfpath=yes to cifbuild arguments
#
# Version 1.09 - 2001-04-25 (DH)
# ------------
#
# + Take /raid/ccf/willbepublic back out of the CCF directory
# search path.
#
# Version 1.08 - 2001-04-11 (DH)
# ------------
#
# + Add /raid/ccf/willbepublic to the CCF directory
# search path.
#
# Version 1.07 - 2001-03-26 (DH)
# ------------
#
# + Print out version number in performAction() for
# tracking purposes.
#
# Version 1.06 - 2001-01-23 (DH)
# ------------
#
# + Change start rule to depend on VerifyODF
#
# Version 1.05 - 2000-12-19 (DH)
# ------------
#
# + Fix bug introduced in 1.04
#
#
# Version 1.04 - 2000-12-19 (DH)
# ------------
#
# + Put procdate for CIF back to today
#
# Version 1.03 - 2000-12-14 (DH)
# ------------
#
# + First production version.
#
@instList=qw(all);
sub numberOfStreams
{
return 1;
}
sub evaluateRules {
start() if complete(module => 'VerifyODF', instrument => 'all');
}
my $kwtrans = {'obs_mode' => 'OBS_MODE',
'obs_id' => 'OBS_ID',
'obs_start' => 'DATE-OBS',
'obs_stop' => 'DATE-END',
'ra_pnt' => 'RA_PNT',
'dec_pnt' => 'DEC_PNT',
'observer' => 'OBSERVER',
'object' => 'OBJECT'};
my $kwcomments = {'obs_mode' => 'Observation mode (pointing or slew)',
'obs_id' => 'Observation identifier',
'obs_start' => 'Date observations were made',
'obs_stop' => 'Date observations ended',
'ra_pnt' => 'RA of instrument pointing (degrees)',
'dec_pnt' => 'DEC of instrument pointing',
'observer' => 'Name of PI',
'object' => 'Name of observed object'};
sub performAction {
info("Module version number: $version");
my $info = getObservationProperties();
# Create CIF for this sequence
my $obsdate=$info->{observationdate};
my $obs_start=$info->{obs_start};
# Log manipulation of observation date
info("'observationdate' has been overridden. It has been changed from $obs_start to $obsdate.")
if ($obsdate ne $obs_start)
;
my $procdate=$$info{"procdate"};
if (defined $obsdate) {
info("Observation start defined as >$obsdate<");
} else {
info("Observation start undefined.");
}
if (defined $procdate) {
info("Processing date defined as >$procdate<");
} else {
info("Processing date undefined.");
}
# Comment-out by EC, seems like it is not needed and might cause problems fro SLEW
# set SAS_RAND_SEED
# my $obsidcheck = $info->{obs_id};
# info("## DEBUG obsidcheck = $obsidcheck");
# $ENV{'SAS_RAND_SEED'} = $obsidcheck;
# my $sasexport = `export SAS_RAND_SEED = "$obsidcheck"`;
# get SAS_RAND_SEED
# my $sas_rand = $ENV{'SAS_RAND_SEED'};
# info("## DEBUG MakeCIF: SAS_RAND_SEED: $sas_rand");
my $cifFile=newFile(class => 'product',
content => 'Calibration index file');
doCommand('cifbuild'
,calindexset => $cifFile
,fullpath => 'no'
,observationdate => $obsdate
,analysisdate => $procdate
,withccfpath => 'no'
) or return exception();
# Add standard product keywords to the cif file.
my (@name, @type, @svalue, @rvalue, @comment, @withcomment);
push @name, 'TELESCOP';
push @type, 'string';
push @svalue, 'XMM';
push @comment, 'Telescope (mission) name';
push @withcomment, 'y';
# Add fixed headers for SLEW observations
if ( $ENV{PCMS_ISSLEW} )
{
push @name, 'OBJECT';
push @type, 'string';
push @svalue, 'Slew Pointing';
push @comment, 'Name of observed object';
push @withcomment, 'y';
push @name, 'RA_PNT';
push @type, 'real';
push @rvalue, '0.0';
push @comment, 'RA of instrument pointing';
push @withcomment, 'y';
push @name, 'DEC_PNT';
push @type, 'real';
push @rvalue, '0.0';
push @comment, 'DEC of instrument pointing';
push @withcomment, 'y';
push @name, 'OBS_MODE';
push @type, 'string';
push @svalue, 'SLEW';
push @comment, 'Observation mode (pointed or slew)';
push @withcomment, 'y';
my $obs_id = $ENV{'ODFID'}; # Hack for valid OBS_ID
push @name, 'OBS_ID';
push @type, 'string';
push @svalue, $obs_id;
push @comment, 'Observation identifier';
push @withcomment, 'y';
push @name, 'OBSERVER';
push @type, 'string';
push @svalue, 'XMM-Newton';
push @comment, 'Observer';
push @withcomment, 'y';
}
# Loop over remaining headers (all strings)
if ( $ENV{PCMS_ISSLEW} )
{
foreach my $prop ('obs_start', 'obs_stop'){
push @name, $$kwtrans{$prop};
push @type, 'string';
push @svalue, $$info{$prop};
# $svalue[-1] =~ s/\.\d+// if $prop=~/obs_id/ ;
# $svalue[-1] =~ s/'//g;
push @comment, $$kwcomments{$prop};
push @withcomment, 'y';
}
}
else
{
foreach my $prop (keys %$kwtrans){
push @name, $$kwtrans{$prop};
if($prop=~/_pnt/){
push @type, 'real';
push @rvalue, $$info{$prop};
}else{
push @type, 'string';
push @svalue, $$info{$prop};
$svalue[-1] =~ s/\.\d+// if $prop=~/obs_id/ ;
$svalue[-1] =~ s/'//g;
}
push @comment, $$kwcomments{$prop};
push @withcomment, 'y';
}
}
doCommand('addattribute', set => $cifFile,
attributename => [@name],
attributetype => [@type],
stringvalue => [@svalue],
realvalue => [@rvalue],
attributecomment => [ @comment ] )
or return exception();
# Make an intermediate copy called ccf.cif
copyFile(source => $cifFile, destination => "intermediate/ccf.cif");
success();
}
1;