#!/www/server/vo/inst/bin/perl -w
#
# Handle a processing request from a DataScope query.
#
use strict;
use lib "/www/server/vo/inst/local/lib";
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use VO::Display;
use VO::Display::State;
use VO::Util;
use VO::CacheManager;
use VO::Display::VOTableRenderer;
use VO::Service::SIAP;
use VO::Service::Tarrer;
use VO::Service::Aladin;
use VO::Service::Oasis;
# Try to repair the CGI environment.
$ENV{LD_LIBRARY_PATH} = "/lib.full:/usr/lib.full";
# These filters do special handling of certain services.
my %filters =
(
"ADS" => sub {
my ($data, $ucd) = @_;
my $lnk = webcode($$data[0]);
$$data[0] = " $$data[0] ";
return 1;
},
"NED(sources)" => sub {
my ($data, $ucd) = @_;
my $lname = $$data[1];
$lname =~ s/^\*//; # Get rid of initial asterisks which are not part of the real NED name
$lname = webcode($lname);
$$data[1] = " $$data[1] ";
},
"Simbad" => sub {
my ($data, $ucd) = @_;
my $lname = webcode($$data[2]);
$$data[2] = "$$data[2] ";
}
);
$| = 1;
my $cgi = CGI->new;
my $action = $cgi->param("action");
if (defined($action)) {
my $actor;
if ($action =~ /save locally/i) {
$actor = VO::Service::Tarrer->new();
} elsif ($action =~ /Aladin/i) {
$actor = VO::Service::Aladin->new();
} elsif ($action =~ /Oasis/i) {
$actor = VO::Service::Oasis->new();
}
$actor->execute;
exit;
}
print "Content-type: text/html\n\n";
my $cdirectory = $cgi->param("cacheDir");
my $directory = webdecode($cdirectory);
my $id = $cgi->param("selectedID");
# If JavaScript is disabled we may get a link from
# an image input elements of the form selectedID.12.x (and .y)
# TCL browser does selectedID.12
if (!defined($id) || $id < 0) {
my @params = $cgi->param;
foreach (@params) {
if (/^selectedID\.(\d+)(\.(x|y))?/) {
$id = $1;
$cgi->param("selectedID", $1);
last;
}
}
}
my $position = webdecode($cgi->param("position"));
if (!defined($directory) || !defined($id) ) {
VO::Display::error("Unable to display data without ID and cache location", 1);
}
my $cache = VO::CacheManager->new($directory,
mode => "r"
);
my $state = VO::Display::State->new($cache, $cgi);
my ($filePrefix, $urlPrefix) = $cache->prefixes();
# Initialize the state to enable translation between keys and ids.
my $tag = $state->id($id);
my $tg = $tag;
$tg =~ s/\.\d+$//;
# Now get the information we are going to display.
my $meta = $cache->getDatum("meta", $tag);
if (!defined($meta)) {
VO::Display::error("Unable to get metadata for $tg", 1);
}
my $xtit = $$meta{Title};
print <$xtit
EOT
my $count;
my ($colPrefix, $ucdPrefix, $rowPrefix);
my $singlet = 1;
my $file = $cache->check($tag);
my $fileURL = $cache->fileToURL($file);
$file =~ s/.*htdocs\/vo//;
my $url = $cache->getDatum("id", $tag);
my $plotURL = "../voplot/loadjvt.pl?suffix=$file";
my $statURL = "http://vostat.org/cgi-bin/vostat/vostat.cgi/load?filetype=votable&uploaded_url=$VO::urlHost$VO::urlBase$file";
my $suffix = "";
my $optString = <New query -
Metadata -
Raw VOTable -
VOPlot -
VOStat -
Feedback -
DataScope help
EOT
VO::Util::printPageHeader("VO DataScope: $xtit", $optString);
while ($position =~ /\%\d\d/) {
$position = webdecode($position);
}
print < VOTable for resource $tg near $position
EOT
my $filter = $filters{$tg};
if ($$meta{ServiceType} =~ /SIAP/i) {
# These will be used in the closure following.
$count = $cache->getDatum("count", $tag);
my $info = $cache->getDatum("info", $tag);
my $fitsCount = $$info{fitsCount};
my $qlCount = $$info{qlCount};
my $fits = $$info{fits};
my $ql = $$info{ql};
my $ids = $$info{ids};
my $resTitle = $$meta{Title};
my $urls = $$info{urls};
my $formats = $$info{formats};
my $qlSinglet;
if ($qlCount > 0) {
my $index0;
my $tag0;
if ($count == 1) {
$index0 = $$ql[0];
$tag0 = 0;
} else {
my ($xid) = $$ids{$resTitle};
if (defined($xid)) {
big: foreach my $good (@$xid) {
for (my $i=0; $igetAndCache($url, $xtag, $suffix);
my $first= "";
if ($qlCount > 1) {
$first = "First";
}
print " ";
print "$first Quicklook Image";
}
}
# This is going to generate a closure because we want
# to be able to reference the current count and info variables
$filter =
sub {
my ($data, $ucds, $row) = @_;
my $cucds = {};
my $format = VO::Service::SIAP::getUCDCol("format", $ucds);
if ($fitsCount > 0 && $$data[$format] !~ /fits/) {
return 0;
}
if ($count > 1) {
my $titleIndex = VO::Service::SIAP::getUCDCol("title", $ucds);
if (!defined($titleIndex) || $titleIndex < 0) {
return 0;
}
if ($$data[$titleIndex] ne $resTitle) {
return 0;
}
}
return 1;
}
;
# Is there more than one FITS image returned? If so we need
# to keep track of the state and make this whole page a query form.
if ($count == 1 && $fitsCount > 1) {
$singlet = 0;
}
if ($count > 1 && $fitsCount > 1) {
my $hits = $$ids{$resTitle};
if (defined($hits) && ref($hits) && scalar(@$hits) > 1) {
$singlet = 0;
}
}
$colPrefix = sub {
my $content;
if ($singlet) {
$content = " ";
} else {
$content = "Row-Select ";
}
my ($self, $fields, $col) = @_;
$self->emit("
$content
");
}
;
$ucdPrefix = sub {
my ($self, $fields, $col) = @_;
$self->emit("
(Links)
");
}
;
$rowPrefix = sub {
my ($self, $data, $ucds, $row, $col) = @_;
# Note that row is the index of printed rows, not
# the original row in the table...
my $links;
my $img = VO::Service::SIAP::getUCDCol("url", $ucds);
my $format = VO::Service::SIAP::getUCDCol("format", $ucds);
if (defined($img)) {
my $type = "FITS";
if ($fitsCount == 0 && $qlCount == 0) {
$type = "File";
} elsif ($fitsCount == 0) {
$type = "Quicklook";
}
my $fimg = $$data[$img];
$fimg = trim($fimg);
my $xfimg= $cache->getAndCache($fimg, "$tag.".($row+1), ".fits");
$links = "$type";
if ($fitsCount > 0) {
my $qlc = 0;
if ($singlet && $qlSinglet) {
$links .= " / QL";
$qlc = 1;
} elsif ($qlCount > 0) {
my $iql = $$ql[$row];
if (defined($iql)) {
my $iurl = $$urls[$iql];
my $form = $$formats[$iql];
my $suffix = ".gif";
if ($form =~ /jpeg/i) {
$suffix = ".jpg";
}
$iurl = trim($iurl);
$iurl = $cache->getAndCache($iurl, "$tag.".($row+1), $suffix);
$links .= " / QL";
# Indicate we have both the FITS and QL data.
$$data[$format] = "$$data[$format], $$formats[$iql]";
$qlc = 1;
}
}
# If we haven't gotten a quicklook image yet
# generate one from the FITS file.
if ($qlc == 0) {
my $qlimg;
if ($xfimg =~ /cacheTee/) {
$qlimg = $xfimg ."&gif=1";
} else {
$xfimg = $filePrefix . substr($xfimg, length($urlPrefix));
$qlimg = "$VO::cgiBase/datascope/ql.pl?file=$xfimg";
}
$links .= " / QL";
}
}
if (!$singlet) {
my $str = "
");
};
}
}
if (!$singlet) {
my $ra = $cgi->param("ra");
my $dec = $cgi->param("dec");
my $position = $cgi->param("position");
my $size = $cgi->param("size");
my $state = $state->toString;
my $refresh = $cgi->param("refresh");
my $criteria = $cgi->param("criteria");
my $requestID = $cgi->param("requestID");
print <
Use this button to return to the summary page after
browsing and selecting data. Your selections on
this form will be remembered.
Use the checkboxes to make selections for further analysis
or download.
EOT
# Remember the criterion selection parameters that we need to propogate.
my @params = $cgi->param;
foreach my $p (@params) {
if ($p =~ /^c\d+$/) {
print " \n";
}
}
}
my $renderer = VO::Display::VOTableRenderer->new;
if (defined($filter)) {
$renderer->setFilter($filter);
}
if (defined($rowPrefix) || defined($colPrefix) || defined($ucdPrefix)) {
$renderer->prefix($rowPrefix, $colPrefix, $ucdPrefix);
}
$renderer->sexagesimal(1);
$renderer->render($cache->uncache($tag));
if (!$singlet) {
print <
Use this button on the page to return to the summary page. Your selections
on this page will be remembered.
EOT
}
print "