#!/bin/csh
# file: getads = download bibcode-specified paper from ADS via remote server
# last: Oct 26 2019  Rob Rutten  Deil = post copy not specifying login@server
# note: usage: getads "1991A&A...252..203R"
#       opens pdf in Acrobat with copy in laptop /tmp and server /tmp 
#       A&A needs quotes and changes into A+A

if ($#argv == 0) then 
  echo === usage: getads "1991A&A...252..203R" 
  echo === opens pdf in Acrobat with copy in /tmp, or opens ADS page
  echo === A\&A changes into A+A in the file name
  exit
endif

# convert & into %26
setenv BIBCODE `echo ${1} | sed -e "s|\&|\%26|"`

# get pdf into remote server /tmp
setenv RSYNC_RSH ssh
ssh <my login at remote server> "~/rr/bin/adscode2tmp ${BIBCODE}"

# convert %26 into +
setenv FILECODE `echo ${BIBCODE} | sed -e "s|\%26|\+|"`

# copy remote server pdf to local /tmp in my laptop
rsync -z <my login at remote server>:/tmp/${FILECODE}.pdf /tmp

# if size zero then open ADS page
if (-z /tmp/${FILECODE}.pdf) then
      # open "new" ADS abstract page for clicking ArXiv/publisher pdf
      chrome http://ui.adsabs.harvard.edu/abs/${1}/abstract &
endif 
