#!/bin/csh
# file: acarxiv
# init: around 2010? as getastroph
# last: Oct 26 2019  Rob Rutten  Deil
# site: ~/rr/bin 
# note: usage: acarxiv 0711.2166 [vitas] or 2007arXiv0711.2166V [vitas]

# help response if no input params
if ($#argv == 0) then 
  echo === acarxiv arXiv code or ADS altcode for arXiv
  echo === optional second parameter: store folder name .../lit/perauthor
  echo === example: 0711.2166  \[vitas\]  
  echo === example: 2007arXiv0711.2166V  \[vitas\]
  exit
endif

# search string > /tmp file
echo ${1} > /tmp/arxiv1

# strip if ADS string
sed -i 's/....arXiv//' /tmp/arxiv1
cut -c1-9 /tmp/arxiv1 > /tmp/arxiv2

# get the arXiv preprublication
curl "https://arxiv.org/pdf/`cat /tmp/arxiv2`.pdf" > /tmp/arxiv.pdf

# store if asked, open in acrobat
if ($#argv == 2) then
    mkdir -p  ~/rr/lit/perauthor/$2
    cp /tmp/arxiv.pdf ~/rr/lit/perauthor/$2/${1}.pdf
    ac ~/rr/lit/perauthor/$2/${1}.pdf
  else
    ac /tmp/arxiv.pdf
endif  
