#!/usr/bin/perl use strict; # General modules use Time::localtime; use DateTime; use File::Spec; use Getopt::Long; use Carp; use Data::Dumper; use Net::Domain qw(hostname hostdomain); use LWP::UserAgent; # Astronomy modules use Astro::ADS::Query; # O P T I O N S H A N D L I N G -------------------------------------------- my ( %opt ); my $status = GetOptions("year=s" => \$opt{"year"}, "start=s" => \$opt{"start"}, "end=s" => \$opt{"end"}, "author=s" => \$opt{"author"} ); my $dt = DateTime->now(); $opt{"year"} = $dt->year() unless defined $opt{"year"}; my $start = $opt{start} if defined $opt{start}; my $end = $opt{end} if defined $opt{end}; $start = $opt{year} unless defined $start; $end = $opt{year} unless defined $end; $end = $start if $start > $end; # Q U E R Y A D S --------------------------------------------------------- # list of authors my @names; my ( %refereed, %other ); my ( %refereed_added, %other_added ); # add the extra author on if there is one if( defined $opt{"author"} ) { push @names, $opt{"author"}; } #print "# " . ctime() . "\n#\n"; #print "# author = $opt{author}\n"; #print "# range = $start to $end\n#\n"; foreach my $year ( $start ... $end ) { #print "# year = $year\n"; my $papers = new Astro::ADS::Query( Authors => \@names, StartMonth => '01', StartYear => $year, EndMonth => '12', EndYear => $year, Journal => 'REFEREED' ); my $articles = new Astro::ADS::Query( Authors => \@names, StartMonth => '01', StartYear => $year, EndMonth => '12', EndYear => $year, Journal => 'OTHER' ); # Query the ADS #print "# Connecting to the ADS\n"; my $refereed_papers = $papers->querydb(); my $refereed_count = $refereed_papers->sizeof(); if( $opt{author} eq "Bate, Matthew" && $year == 1992 ) { $refereed_added{$year} = 1; #print "# Retrieved $refereed_count + 1 refereed paper\n"; } else { #print "# Retrieved $refereed_count refereed papers\n"; } # Query the ADS #print "# Connecting to the ADS\n"; my $other_papers = $articles->querydb(); my $other_count = $other_papers->sizeof(); if( $opt{author} eq "Allan, Alasdair" && $year == 2000 ) { $other_added{$year} = 3; #print "# Retrieved $other_count + 3 other papers\n#\n"; } else { #print "# Retrieved $other_count other papers\n#\n"; } $refereed{$year} = $refereed_papers; $other{$year} = $other_papers; } # P U B L I C A T I O N S ----------------------------------------------------- my @objects; for ( my $year = $end; $year>=$start; $year-- ) { #print "#\n# Building data for $year\n"; my $refereed_papers = $refereed{$year}; my $refereed_count = $refereed_papers->sizeof(); my $refereed_total = $refereed_count + $refereed_added{$year}; my $other_papers = $other{$year}; my $other_count = $other_papers->sizeof(); my $other_total = $other_count + $other_added{$year}; if ( $refereed_total == 0 && $other_total == 0 ) { #print "# No publications in $year\n"; next; } elsif ( $refereed_total == 0 && $other_total != 0 ) { #print "# $other_total other publications\n"; } elsif ( $refereed_total !=0 && $other_total == 0 ) { #print "# $refereed_total refereed papers\n"; } else { #print "# $refereed_total refereed, $other_total other papers\n"; } # REFEREED PUBLICATIONS ==================================================== unless ( $refereed_total == 0 ) { foreach my $i ( 0 ... $refereed_count - 1 ) { # grab paper my $paper = $refereed_papers->paperbyindex( $i ); push @objects, query_simbad( $paper, $year ); } # loop around refereed papers } # if( ) no papers # OTHER PUBLICATIONS ======================================================= unless ( $other_total == 0 ) { foreach my $i ( 0 ... $other_count - 1 ) { # grab paper my $paper = $other_papers->paperbyindex( $i ); push @objects, query_simbad( $paper, $year ); } # loop around other papers } # if( ) no papers } # end of loop from $start to $end #print "# sizeof() \@objects is " . scalar( @objects ) . "\n"; # L O O P A R O U N D O B J E C T S -------------------------------------- my $kml = ''."\n". ''."\n". ' '.$opt{author}.''."\n". ' '."\n". ' '."\n"; foreach my $o ( 0 ... $#objects ) { my %hash = %{$objects[$o]}; #print "#\n# $hash{name} (from $hash{year})\n"; #print "# RA = $hash{ra}, Dec = $hash{dec}\n"; my $long = $hash{ra} - 180 if defined $hash{ra}; $kml = $kml . ' '."\n". ' #myBalloonStyle'."\n". ' '.$hash{name}.''."\n". " \n". ' '."\n". ' '.$long.','.$hash{dec}.',0'."\n". ' '."\n". ' '."\n" if defined $hash{ra}; } $kml = $kml . ' '."\n". ''."\n"; print $kml; exit; sub query_simbad { my $paper = shift; my $year = shift; my @obj; my $simbad = "http://simbad.u-strasbg.fr/simbad/sim-script?submit=submit+script&script=format+object+%22%25-20IDLIST%281%29+%7C+%25-27COO%28d%3B+A%2CD%29+%7C+%25-15OTYPE%28S%29+%7C+%25-10SP%28S%29+%7C+%25FLUXLIST%28U%2CB%2CV%2CR%2CI%29%5B%25*%28F%29+%5D%22%0D%0Aquery+bibobj+"; my $url = $paper->url(); my $title = $paper->title(); my @authors = $paper->authors(); my $journal = $paper->journal(); my @inst = $paper->affil(); my $bibcode = $paper->bibcode(); my @links = $paper->links(); ##print "# Paper $i\n"; foreach my $j ( 0 ... $#links ) { if ( $links[$j] eq "SIMBAD" ) { #print "# Paper has a link to SIMBAD\n"; my $simbad_url = $simbad . $bibcode; my $lwp = new LWP::UserAgent( timeout => 15 ); $lwp->env_proxy(); $lwp->agent( "eSTAR ADS KML Mashup /0.1 (".hostname().")" ); my $request = new HTTP::Request(GET => $simbad_url ); #$request->authorization_basic('aa', 'wibble'); my $reply; eval { $reply = $lwp->request( $request ) }; if ( $@ ) { #print "# Error: $@\n"; next; } unless ( ${$reply}{"_rc"} eq 200 ) { #print "# Error (${$reply}{_rc}): ${$reply}{_msg}\n"; next; } my $list = ${$reply}{_content}; unless ( $list =~ "::error::" ) { my @lines = split "\n", $list; my $not_there_yet = 1; my $k = 0; while ( $not_there_yet ) { unless ( $lines[$k] =~ "::data::" ) { $k = $k + 1; } else { $not_there_yet = 0; } } foreach my $m ( $k+2 ... $#lines ) { $lines[$m] =~ s/\|\s+/\|/g; $lines[$m] =~ s/\s+\|/\|/g; ##print "# $lines[$m]\n"; my @object = split /\|/, $lines[$m]; #print Dumper( @object ); my %hash; $hash{year} = $year; $hash{name} = $object[0]; $hash{name} =~ s/\s{2,}/ /g; $hash{name} =~ s/NAME\s+//g; ( $hash{ra}, $hash{dec} ) = split ",", $object[1]; $hash{ra} =~ s/^0{1,2}//; $hash{ra} = undef if $hash{ra} =~ "No Coord."; $hash{dec} =~ s/\+//; $hash{dec} =~ s/^0{1,2}//; $hash{dec} = "0" . $hash{dec} if $hash{dec} =~ m/^\.\d+/; $hash{dec} =~ s/^-0/-/; $hash{bibcode} = $bibcode; $hash{title} = $title; $hash{journal} = $journal; my $content = "

$title, \n"; foreach my $j ( 0 ... $#authors ) { my ( $last, $first ) = split ",", $authors[$j]; my $bold; foreach my $k ( 0 ... $#names ) { my ( $surname, $firstname) = split ",", $names[$k]; $bold = 1 if ($last eq $surname) && #lc($inst[$j]) =~ "exeter" && (uc(substr($first,0,1)) eq uc(substr($firstname,0,1))); } if ( $bold ) { $content = $content . "$authors[$j]; \n"; } else { $content = $content . "$authors[$j]; \n"; } } $content = $content . "$journal

"; $hash{description} = $content; my $flag = 0; foreach my $z ( 0 ... $#objects ) { my %tmp = %{$objects[$z]}; #print "# z = $z, name = $tmp{name}, $hash{name}\n"; if ( $tmp{name} eq $hash{name} && $tmp{bibcode} eq $hash{bibcode} ) { #print "# discarding duplicate\n"; $flag = 1; last; } } push @obj, \%hash unless $flag == 1; } my $num = $#lines + 1 - ( $k+2 ); #print "# " . $num . " objects found\n"; } else { #print "# SIMBAD query returned an error\n"; } last; } } return @obj; }