#!/bin/bash

#./BuildAnalyze  ABC_bc.dat
#
# Assumes following files are present
# ABC_bc.dat ... list of bibcodes & citations for author "ABC"
# ref_authors.dat ... list of authors of reference papers
# cite_authors.dat ... list of authors of citatation papers
# ABC_coauthors.dat ... list of co-authors of author
#
# output files:
# ABC_coauthors_hist.dat
# ABC_ref_hist.dat
# ABC_cite_hist.dat
# ABC_Table.tex


n=30;	#length of table

  if [[ -z $1 ]]; then
    echo "exit: need file listing bibcodes, no. of citations"
    exit -1
  fi

inauthor=$1
outf=${infile%#*}

./HistogramAuthors ${out}_couauthors > ${outf}_coauthors_hist.dat
cat ref_authors.dat | sed '/^#/d' > a
./HistogramAuthors a > ${outf}_ref_hist.dat
cat cite_authors.dat | sed '/^#/d' > a
./HistogramAuthors a > ${outf}_cite_hist.dat

outfile=${outf}_Table.tex
echo -e "\\\begin{table}[hbtp]" > $outfile
echo -e "\\\begin{tabular}{lll}" >> $outfile 
echo -e "\\\hline\\\\\ " >> $outfile 
echo -e "Co-Authors & Prosperity & Co-Prosperity \\\\\ " >> $outfile
echo -e "\\\hline\\\\\ " >> $outfile 
paste -d"&" <(head -$n ${outf}_coauthors_hist.dat) \
            <(head -$n ${outf}_cite_hist.dat)      \
            <(head -$n ${outf}_ref_hist.dat) |     \
      sed 's/$/\\\cr/' >> $outfile 
echo -e "\\hline" >> $outfile 
echo -e "\\\end{tabular}" >> $outfile 
echo -e "\\\end{table}" >> $outfile 

