#!/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".
'
$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; }