#!/bin/csh
# file: ads-name-abs = get ADS abstracts per author
# init: Oct  3 2019  Rob Rutten  Deil
# last: Oct 21 2020  Rob Rutten  Deil
# note: 1 parameter = ADS search name (eg: rutten-rob)
#       all /tmp variables have $1 to make them unique in parallel runs
#       but that shouldn't happen anyhow

# check parameters
if ($#argv == 0) then 
  echo === usage: ads-name-ads adsname without quotes
  echo === example: ads-name-ads rutten-rob
  exit
endif

# do this work in /tmp
cd /tmp

# # get ADS search string for this name per namestring + solarstring
# cat ~/rr/www/bibfiles/ads/namestrings/$1  > namestring
# cat namestring ~/rr/www/bibfiles/ads/solarstring | urlencode > $1adsurl

# get ADS search string for this name per database+namestring
printf "database: astronomy " > basestring
cat basestring ~/rr/www/bibfiles/ads/namestrings/$1 | urlencode > $1adsurl

#  get file with ADS output for this search string
curl -H "Authorization: Bearer hahahahahahaha"  "https://api.adsabs.harvard.edu/v1/search/query?q="`cat $1adsurl`"&fl=abstract,title,author,bibcode,alternate_bibcode&rows=1999&sort=pubdate+desc" > $1muck1

# open file to write in, add header on top
printf "Author name code: " > $1.txt
printf $1'\n' >> $1.txt
printf "ADS astronomy entries on " >> $1.txt
date +%Y-%m-%d >> $1.txt 
cat ~/rr/www/bibfiles/ads/namestrings/$1 >> $1.txt

echo '------------------------------------------------------------------------  ' >> $1.txt
echo "" >> $1.txt

# extract with Icarus routine
ads-distill-icarus $1muck1 >> $1.txt

# write result
mv /tmp/$1.txt ~/rr/www/bibfiles/ads/abs/$1.txt

# clean /tmp 
rm -f /tmp/*$1*

# back to calling dir
back
