#!/bin/csh
# file: acads = open paper either in laptop or via getads
# init: don't remember, late 1990s?
# last: Jan 12 2020  Rob Rutten  Deil

# help response if no input params
if ($#argv == 0) then 
  echo === acads adsbibcode + optional authorname for storage
  echo === for A\&A paper add quotation marks around adsbibcode
  echo === example: acads 1981ApJS...45..635V
  echo ===          acads 1981ApJS...45..635V avrett
  exit
endif

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

setenv PAPEREXISTS `locate -c -n 1 ${FILECODE}.pdf`
if $PAPEREXISTS then
    setenv PAPER `locate -n 1 ${FILECODE}.pdf`
    if ($#argv == 2) then
      mkdir -p  ~/rr/lit/perauthor/$2
      cp $PAPER ~/rr/lit/perauthor/$2/.
    endif  
    ac $PAPER
  else
    /home/rutten/bin/getads ${1}
    if ($#argv == 2) then
        mkdir -p  ~/rr/lit/perauthor/$2
        cp /tmp/$FILECODE.pdf ~/rr/lit/perauthor/$2/.
        ac ~/rr/lit/perauthor/$2/$FILECODE.pdf
      else
        ac /tmp/$FILECODE.pdf
     endif  
endif

## ac above opens linux acroread pdf viewer in this workspace by calling:
##  acroread -geometry 1400x800+00+00 -openInNewInstance /a "view=Fit & pagemode=none & scrollbar=0 & toolbar=0" $1 > ~/troep &
