Документ взят из кэша поисковой машины. Адрес оригинального документа : http://xmm.vilspa.esa.es/calibration/ept/preview.pl
Дата изменения: Tue Jun 2 16:29:47 2015
Дата индексирования: Sat Apr 9 23:50:54 2016
Кодировка:
#!/usr/bin/perl

use strict;
use Data::Dumper;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

use Storable qw(nstore retrieve);
$Storable::interwork_56_64bit = 1;


my $WEBSERVER;
my $HOSTNAME = `hostname`;
chomp $HOSTNAME;



if ($ENV{'REQUEST_URI'} =~ m/cgi-doc/) {
$WEBSERVER = 1; # internal XMM web; xvsoc01: ~xmmdoc

} elsif ($ENV{'REQUEST_URI'} =~ m/cgi-bin/) {
$WEBSERVER = 2; # external XMM web; xvsoc01

} else {
$WEBSERVER = 0; # local workstation (MK/DH)
}

## my $WEBSERVER = $HOSTNAME eq 'xvsoc01' ? 1 : 0;

# ------------------------------------------- conf ---------------------------------------------------------------

# for the email confirmation
my @EMAIL_TO = ('Marcus.Kirsch@sciops.esa.int');

# patterns that can be a unit (in the log file)
my @UNITS = ('10\^\d\d', 'keV');



# ------------------------------------------ paths ----------------------------------------------------------------


my ($WWW_ROOT , $WWW_CGIBIN, $CGIBIN, $URL_INTERNAL, $OBSIDS_ROOT, $LISTS_ROOT, $FLUX_DIR, $CONVERT_BIN, $IDL_BIN, $CHANDRA_ROOT, $LS_CHANDRA_CMD, $FLUX_CHANDRA_DIR, $TEMPLATE, $SUBTITLE, $xcaldataXMM, $xcaldataCHANDRA, $SUZAKU_ROOT, $xcaldataSUZAKU, $LS_SUZAKU_CMD, $FLUX_SUZAKU_DIR);

# LOCAL workstation (MK: xmmwl11)
#
if ($WEBSERVER == 0) {
$WWW_ROOT = '/home/mkirsch/apache/previewtool/html/';
$WWW_CGIBIN = '/home/mkirsch/apache/previewtool/';
$CGIBIN = '/cgi-bin/preview.pl';
$URL_INTERNAL = 'http://172.24.1.11:8080/'; # for putting it in the mail
$OBSIDS_ROOT = '/xdata/xcaldata/XMM/';
$LISTS_ROOT = '/xdata/xcaldata/lists/';
$IDL_BIN = '/usr/local/bin/idl';
$CONVERT_BIN = 'convert -page A4+0+0 ';
$FLUX_DIR = '/xdata/xcaldata/previewtool/flux/';
$TEMPLATE = 'preview.html';
$SUBTITLE = '(local-mk)';
$xcaldataXMM = 'xcaldataXMM'; # APACHE-Alias: Alias /xcaldataXMM/ "/xdata/xcaldata/XMM/"

# chandra
$CHANDRA_ROOT = '/xdata/xcaldata/CHANDRA/XMM_Chandra/';
$LS_CHANDRA_CMD = 'ls /xdata/xcaldata/CHANDRA/XMM_Chandra/*/*/SAS*/*result*';
$FLUX_CHANDRA_DIR = '/home/mkirsch/apache/previewtool/fluxChandra/';
$xcaldataCHANDRA = 'xcaldataCHANDRA/XMM_Chandra'; # APACHE-Alias: Alias /xcaldataCHANDRA/ "/stage/xcaldata/XMM_Chandra/"

# INTERNAL XMM web; xvsoc01: ~xmmdoc
#
} elsif ($WEBSERVER == 1) {
# xvsoc01
$WWW_ROOT = '/data/xmm/xmmdoc/public_html/internal/int_cal_instr_supp/epic/ept/html/'; # absolute path to the html directory
$WWW_CGIBIN = '/data/xmm/xmmdoc/public_html/internal/int_cal_instr_supp/epic/ept/'; # absolute path to the cgi directory
$CGIBIN = '/cgi-doc/ept/'; # realtive path to the cgi-directory
$URL_INTERNAL = 'http://xmm2.esac.esa.int/~xmmdoc/internal/int_cal_instr_supp/epic/ept/html/'; # url to hmtl directory
$OBSIDS_ROOT = '/stage/xcaldata/XMM/'; # main data ( rsync with /xdata/xcaldata/XMM/ )
$LISTS_ROOT = '/stage/xcaldata/lists/'; # lists ( rsync with /xdata/xcaldata/lists/ )
$IDL_BIN = '/usr/local/bin/idl';
$CONVERT_BIN = '/data/xmm/xmmdoc/bin/convert -page A4+0+0';
$FLUX_DIR = '/data/xmm/xmmdoc/cgi-bin/ept/flux/';
$TEMPLATE = 'preview.html';
$SUBTITLE = '(internal)';
$xcaldataXMM = 'xcaldataXMM'; # APACHE-Alias: Alias /xcaldataXMM/ "/xdata/xcaldata/XMM/"

# chandra
$CHANDRA_ROOT = '/stage/xcaldata/CHANDRA/XMM_Chandra/';
$LS_CHANDRA_CMD = 'ls /stage/xcaldata/CHANDRA/XMM_Chandra/*/*/SAS*/*result*';
$FLUX_CHANDRA_DIR = '/data/xmm/xmmdoc/cgi-bin/ept/fluxChandra/';
$xcaldataCHANDRA = 'xcaldataCHANDRA/XMM_Chandra'; # APACHE-Alias: Alias /xcaldataCHANDRA/ "/stage/xcaldata/XMM_Chandra/"

# suzaku
$SUZAKU_ROOT = '/stage/xcaldata/SUZAKU/XMM_Suzaku/';
$LS_SUZAKU_CMD = 'ls /stage/xcaldata/SUZAKU/XMM_Suzaku/*/*/*/*.model';
$FLUX_SUZAKU_DIR = '/data/xmm/xmmdoc/cgi-bin/ept/fluxSuzaku/';
$xcaldataSUZAKU = 'xcaldataSUZAKU/XMM_Suzaku'; # APACHE-Alias

# EXTERNAL XMM web; xvsoc01: ~wmaster
#
} else {
# xvsoc01
$WWW_ROOT = '/data/xmm/html/htdocs/external/xmm_sw_cal/calib/ept/html/'; # absolute path to the html directory
$WWW_CGIBIN = '/data/xmm/html/cgi-bin/ept/'; # absolute path to the cgi directory
$CGIBIN = '/cgi-doc/ept/'; # relative path to the cgi-directory
$URL_INTERNAL = 'http://xmm2.esac.esa.int/external/xmm_sw_cal/calib/ept/html/'; # url to hmtl directory
$OBSIDS_ROOT = '/stage/xcaldata/XMM_PUBLIC/'; # main data ( rsync with /xdata/xcaldata/XMM/ )
$LISTS_ROOT = '/stage/xcaldata/lists_public/';
$IDL_BIN = '/usr/local/bin/idl';
$CONVERT_BIN = '/data/xmm/wmaster/bin/convert -page A4+0+0';
$FLUX_DIR = '/data/xmm/html/cgi-bin/ept/flux/';
$TEMPLATE = 'preview_public.html';
$SUBTITLE = ' ';
$xcaldataXMM = 'xcaldataXMM_PUBLIC'; # APACHE-Alias: Alias /xcaldataXMM/ "/xdata/xcaldata/XMM_PUBLIC/"

# chandra
$CHANDRA_ROOT = '/stage/xcaldata/CHANDRA_PUBLIC/XMM_Chandra/';
$LS_CHANDRA_CMD = 'ls /stage/xcaldata/CHANDRA_PUBLIC/XMM_Chandra/*/*/SAS*/*result*';
$FLUX_CHANDRA_DIR = '/data/xmm/html/cgi-bin/ept/fluxChandra/';
$xcaldataCHANDRA = 'xcaldataCHANDRA_PUBLIC/XMM_Chandra'; # APACHE-Alias: Alias /xcaldataCHANDRA_PUBLIC/ "/stage/xcaldata/XMM_Chandra/"

# suzaku
$SUZAKU_ROOT = '/stage/xcaldata/SUZAKU_PUBLIC/XMM_Suzaku/';
$LS_SUZAKU_CMD = 'ls /stage/xcaldata/SUZAKU/XMM_Suzaku/*/*/*/*.model';
$FLUX_SUZAKU_DIR = '/data/xmm/xmmdoc/cgi-bin/ept/fluxSuzaku/';
$xcaldataSUZAKU = 'xcaldataSUZAKU_PUBLIC/XMM_Suzaku'; # APACHE-Alias
}

# Overwrite for dharbarth localhost
#
if ($HOSTNAME eq 'gunsling3r') {

$WWW_ROOT = '/home/dharbarth/esa/previewtool/html/';
$WWW_CGIBIN = '/home/dharbarth/esa/previewtool/';
$CGIBIN = '/cgi-bin/preview.pl';
$URL_INTERNAL = 'http://localhost:8080/'; # for putting it in the mail
$OBSIDS_ROOT = '/home/dharbarth/esa/chandra/stage/xcaldata/XMM/';
$LISTS_ROOT = '/home/dharbarth/esa/chandra/stage/xcaldata/lists/';
$IDL_BIN = '/usr/local/bin/idl';
$CONVERT_BIN = 'convert -page A4+0+0 ';
$FLUX_DIR = '/home/dharbarth/esa/previewtool/flux/';
$TEMPLATE = 'preview.html';
$SUBTITLE = '(gunsling3r)';
$xcaldataXMM = 'xcaldataXMM'; # APACHE-Alias: Alias /xcaldataXMM/ "/xdata/xcaldata/XMM/"

# chandra
$CHANDRA_ROOT = '/home/dharbarth/esa/chandra/stage/xcaldata/CHANDRA/XMM_Chandra/';
$LS_CHANDRA_CMD = 'ls /home/dharbarth/esa/chandra/stage/xcaldata/CHANDRA/XMM_Chandra/*/*/SAS*/*result*';
$FLUX_CHANDRA_DIR = '/home/dharbarth/esa/previewtool/fluxChandra/';
$xcaldataCHANDRA = 'xcaldataCHANDRA/XMM_Chandra'; # APACHE-Alias: Alias /xcaldataCHANDRA/ "/stage/xcaldata/XMM_Chandra/"

}


# templates, main page, idl directory, etc
my $NEWS_HTML = $WWW_ROOT .'news.html';
my $TMPL_OBSID = $WWW_ROOT . 'obsid.tmpl';
my $TMPL_CAM = $WWW_ROOT . 'cam.tmpl';
my $IDL_DIR = $WWW_CGIBIN .'idl/';

# ------------------------------------------ CHANDRA THINGS ----------------------------------------------------------------

my $TMPL_OBSID_CHANDRA = $WWW_ROOT . 'obsid_chandra.tmpl';

my @CHANDRA_INSTS_MICHEALNAMING = qw(combined pn m1 m2 r1 r2 aciss-heg\+1 aciss-heg-1 aciss-meg\+1 aciss-meg-1 aciss-leg\+1 aciss-leg-1 hrcs-leg\+... hrcs-leg-... hrci-leg\+... hrci-leg-...);


# ------------------------------------------ misc ----------------------------------------------------------------

require 'linuxlib.pm';

# for statistic
my $OBSIDS_IN_TARGET_FOUND = 0;

# ------------------------------------------ tmp ----------------------------------------------------------------

my $ip = $ENV{'REMOTE_ADDR'};
debuglog("ip -------- $ip");
#if(!($ip =~ /10\.68\.18.*/)){
# print header();
# print "site is currently under maintenance. we will be back soon (within next hours)";
# exit;
#}

# ------------------------------------------ env ----------------------------------------------------------------

# set env for the convert command
my $EXPORT_VARS = {
GS_LIB => '/usr/openwin/lib/X11/fonts/Type1:/usr/openwin/lib/X11/fonts/Type3:/usr/local/share/ghostscript/6.0/lib/fonts',
GS_FONTPATH => '/usr/openwin/lib/X11/fonts/Type1/outline',
};
# export needed variables
foreach my $k (keys %$EXPORT_VARS) {
$ENV{$k} = $EXPORT_VARS->{$k};
}


debuglog("start " . $WEBSERVER );

# -----------------------------------------------------------------------------------------------------------
# ////////////////////////////////////////////////////////////////////////////////////////////////////////////
# Dispatcher
# ////////////////////////////////////////////////////////////////////////////////////////////////////////////
print header();
#taketime("start");
my $aktionp = strparam('action');
debuglog("action " . $aktionp );
my %aktion = (
'mainpage' => \&mainPage, # Main Page
'arequest' => \&arequest, # a Ajax Request -> send it to the Ajax dispatcher
'publish' => \&publish, # the mini-cms. create a new issue/news
'email' => \&email, # send a email for confirmation
'confirmed' => \&confirmed, # s.b. has confirmed the issue
'getAllFlux' => \&getAllFlux, # save Flux for all Observations to files

'plotParameterOverTarget'=> \&plotParameterOverTarget,
'plotFluxOverTarget' => \&plotFluxOverTarget,
'showAllJoints' => \&showAllJoints, # show all available fits
'getfluxTables' => \&getfluxTables,
);


if ( $aktion{$aktionp} ) {
$aktion{$aktionp}->();
exit;
} else {
&mainPage();
exit;
}

# -----------------------------------------------------------------------------------------------------------
# Ajax dispatcher
# -----------------------------------------------------------------------------------------------------------

sub arequest
{
# dispatcher for ajax requests
my $aktionp = strparam('func');
debuglog("ajax " . $aktionp );
my %aktion = (
'showobsid' => \&showObsid,
'getDatFile' => \&getDatFile,
'getDatFile_Chandra' => \&getDatFile_Chandra,
'getDatFile_Suzaku' => \&getDatFile_Suzaku, # see Parameter
'getLogFile' => \&getLogFile,
'getReadme' => \&getReadme,
'getModel' => \&getModel,
'getDatFile_allValues' => \&getDatFile_allValues, # see Params 4 all cameras
'getDatFile_allValues_Chandra' => \&getDatFile_allValues_Chandra,
'getDatFile_allValues_Suzaku' => \&getDatFile_allValues_Suzaku,
'plot_parameter' => \&plot_parameter,
'plot_flux' => \&plot_flux,
'getFlux' => \&getFlux,
'getFlux_Chandra' => \&getFlux_Chandra,
'getFlux_Suzaku' => \&getFlux_Suzaku,
'getGifPopup' => \&getGifPopup,
);

if ( $aktion{$aktionp} ) {
$aktion{$aktionp}->();
exit;
} else {
print("no function defined for " .$aktionp . "\n");
exit;
}
}



# ----------------------------------------------------------------------------------------------- #
# ----------------------------------- main page-------------------------------------------------- #
# ----------------------------------------------------------------------------------------------- #
sub mainPage
{
# 1. get and parse the data (targets and obsids) (XMM and CHANDRA data)
# 2. store data (into files)
# 3. build up the main page


if (strparam('test') ne '') {
print "test";
exit;
}
if (strparam('chandra') eq '1') {
debuglog("chandra start ...");
chandraMain();
exit;
}
if (strparam('suzaku') eq '1') {
debuglog("suzaku start ...");
suzakuMain();
exit;
}

# DEBUG flags
my $DYNAMIC_LOAD_FILES = 0; # search on filesystem or take previous search (dump from Storable)
if (strparam('rescan') == 1){
$DYNAMIC_LOAD_FILES = 1;
}


# build the Target data strucure
my $targets; # XMM
if ($DYNAMIC_LOAD_FILES == 1) {
$targets = scanTargets(); # scan the filsystem
} else {
$targets = retrieve('targets_data'); # take the dump
}


# build the obsid structure
my $obsids; # XMM
if ($DYNAMIC_LOAD_FILES == 1) {
$obsids = scanObsidsFromTargetList($targets); # scan the filesystem
} else {
$obsids = retrieve('obsids_data');
}

if ($DYNAMIC_LOAD_FILES == 1) {
# store the data
nstore $targets, 'targets_data';
nstore $obsids, 'obsids_data';
}

#taketime("building mainpage 4 xmm ...");

# build and print the main html page
my $html = build_mainpage($targets,$obsids);
print $$html;

# statistics
if ($DYNAMIC_LOAD_FILES == 1) {
printl("scan statistics:\n\n");
printl((scalar keys %$targets ). "
targetlists found at " . $LISTS_ROOT);
printl(" ( --> containing $OBSIDS_IN_TARGET_FOUND obsids)\n");
printl((scalar keys %$obsids) . "
obsids have been found at " . $OBSIDS_ROOT);
}
#dumpit($obsids);
#dumpit($targets);


#if (strparam('obsid') ne '') {
# my $id = strparam('obsid');
#
# debuglog("id selected. will open obsid $id ....");
#
# #showObsid($id);
#
#}

#taketime("end mainpage");
exit;
}

sub suzakuMain
{

# DEBUG flags
my $DYNAMIC_LOAD_FILES = 0; # search on filesystem or take previous search (dump from Storable)
if (strparam('rescan') == 1){
$DYNAMIC_LOAD_FILES = 1;
}

my $targets;
if ($DYNAMIC_LOAD_FILES == 1) {
$targets = scanSuzakuTargets();
} else {
$targets = retrieve('targets_SUZAKU_data'); # take the dump
}



# build the obsid structure
my $obsids;
if ($DYNAMIC_LOAD_FILES == 1) {
$obsids = scanObsids_Suzaku($targets); # scan the filesystem
} else {
$obsids= retrieve('obsids_SUZAKU_data');
}

if ($DYNAMIC_LOAD_FILES == 1) {
nstore $targets, 'targets_SUZAKU_data';
nstore $obsids, 'obsids_SUZAKU_data';
}


my $html = build_mainpage($targets,$obsids);
print $$html;

# statistics
if ($DYNAMIC_LOAD_FILES == 1) {
printl("scan statistics for suzaku :\n\n");
printl((scalar keys %$targets ). "
targets found ");
printl((scalar keys %$obsids) . " obsids have been found at " . $SUZAKU_ROOT);
}

#taketime("end mainpage");
exit;
}


sub chandraMain
{

# DEBUG flags
my $DYNAMIC_LOAD_FILES = 0; # search on filesystem or take previous search (dump from Storable)
if (strparam('rescan') == 1){
$DYNAMIC_LOAD_FILES = 1;
}

my $targetsC; # CHANDRA
if ($DYNAMIC_LOAD_FILES == 1) {
$targetsC = scanChandraTargets();
} else {
$targetsC = retrieve('targets_CHANDRA_data'); # take the dump
}



# build the obsid structure
my $obsidsC; # CHANDRA
if ($DYNAMIC_LOAD_FILES == 1) {
$obsidsC = scanObsids_C($targetsC); # scan the filesystem
} else {
$obsidsC= retrieve('obsids_CHANDRA_data');
}

if ($DYNAMIC_LOAD_FILES == 1) {
# CHANDRA
nstore $targetsC, 'targets_CHANDRA_data';
nstore $obsidsC, 'obsids_CHANDRA_data';
}

my $html = build_mainpage($targetsC,$obsidsC);
print $$html;

# statistics
if ($DYNAMIC_LOAD_FILES == 1) {
printl("scan statistics for chandra :\n\n");
printl((scalar keys %$targetsC ). "
targets found ");
printl((scalar keys %$obsidsC) . " obsids have been found at " . $CHANDRA_ROOT);
}

#taketime("end mainpage");
exit;

}
sub build_mainpage
{
my $targets = shift;
my $obsids = shift;

# parse and print out the main page

# # build the two selectboxes
# = build the "targets" JavaScript datastructure
# + build the "obsidstati" (also a JavaScript datastructure/object)
#
# it will look like this:
# targets['1ES0102.2-7219']=new Array();
# targets['1ES0102.2-7219'][0]='select a OBSID';
# targets['1ES0102.2-7219'][1]='0123110201';
# obsidstati['0123110201'] = 0;
# targets['1ES0102.2-7219'][2]='0123110301';
# obsidstati['0123110301'] = 0;
# ...

my $target_options = "";
my $target_array = "";

my $target_only = ""; # target selectbox for the fit pictures (gif)
my $targets_with_count = ""; # target selectbox for the plots (plot over target)

for my $target (sort keys %$targets){
$target_only .= "";
my @obsids_from_targetlist = @{ $targets->{$target} };


my $js_tmpl = "\ntargets['$target']=new Array();\n";
$js_tmpl .= "targets['$target'][0]='select a OBSID';\n";
my $count = 1;
my $targetStatus = 999;


#taketime("building mainpage obsidstatus ...");
my $obsids_count_good = 0;

for my $obsid (@obsids_from_targetlist){

my $rev = getRevolution($obsid);
$js_tmpl .= "\ttargets['$target'][$count]='${obsid} (rev: ${rev})';\n";
my $obsidStatus = getObsidStatus($obsid,$obsids);
$js_tmpl .= "\obsidstati['$obsid (rev: ${rev})'] = " . $obsidStatus . ";\n";

if ($obsidStatus == 0) {
if ($targetStatus == 999) {
$targetStatus = 0;
}
}
if ($obsidStatus == 1) {
if ($targetStatus == 999 || $targetStatus == 0) {
$targetStatus = 1;
}
}
if ($obsidStatus == 999) {
## 999 = good
$obsids_count_good++;
}
$count++;
}
my $class = '';


if ($targetStatus == 0) {
$class = " class='notavailable'";
} elsif ($targetStatus == 1) {
$class = " class='notcomplete'";
}
#debuglog("$target - $targetStatus - $class");

$target_array .= $js_tmpl;
$target_options .= "";

}
#taketime("ok. parse and replace the file");

# parse and replace the file

# CHANDRA
my $chandra = strparam('chandra') eq '1' ? 1 : 0;

# SUZAKU
my $suzaku = strparam('suzaku') eq '1' ? 1 : 0;

# link to the other satelite
my $link_to_other = '';

my $title = 'no';
my $cams = '';

my $goto_xmm = '    go to XMM    ';
my $goto_chandra = '  go to Chandra  ';
my $goto_suzaku = '   go to Suzaku   ';

if ($chandra) {
$title = 'Chandra ' . ${SUBTITLE};
$link_to_other = ''.$goto_xmm.'';
$link_to_other .= '
'.$goto_suzaku.'';
$cams =<