DB=jeter.sqlite
PROXY=" -Dhttp.proxyHost=cache.ha.univ-nantes.fr  -Dhttp.proxyPort=3128 "
javac Biostar54473.java

if [ ! -f ${DB} ]
then
	rm -f ${DB}
	curl -s "ftp://ftp.ncbi.nih.gov/pubmed/J_Sequence.txt" |
	tr -d '\r' |
	awk -F ': ' '/^JournalTitle/ {t=$2;next;} /^NlmId/ {i=$2;next} /^ISSN \(Print\)/ {p=$2;next; } /^\-\-/ {if(length(t)>0) printf("%s\t%s\t%s\n",t,i,p);next;} {next;}' > jeter.txt

	rm -f jeter.sql

	echo  "create table journal(title text,nlmId int,issn text);\n.separator \"	\"\n.import jeter.txt journal\ndelete from journal where issn=''; alter table journal add column ai double; alter table journal add column ef double; alter table journal add column days double; alter table journal add column daysstddev double;alter table journal add column articlecount int;" |sqlite3  ${DB}
fi


echo "select issn from journal where ef is null ;" | sqlite3  ${DB} |while read L
do
	echo $L
	curl -s "http://www.eigenfactor.org/rankings.php?search=${L}&searchby=issn&orderby=year" |
	xsltproc --html --stringparam issn ${L} eigenfactor2sqlite.xsl  - 2> /dev/null >> jeter.sql
	
done

if [  -f jeter.sql ]
then
	cat jeter.sql |sqlite3  ${DB}
fi

rm -f jeter.sql
echo "select issn from journal where articlecount is null order by title;" | sqlite3  ${DB} | while read L
do


	java ${PROXY} -jar ${HOME}/src/jsandbox/dist/pubmeddump.jar "(\"2000\"[Date - Publication] : \"3000\"[Date - Publication]) and \"$L\"" |
	java ${PROXY} Biostar54473 $L >> jeter.sql
done

if [  -f jeter.sql ]
then
	cat jeter.sql |sqlite3  ${DB}
fi

sqlite3 -header --csv  ${DB} 'select * from journal order by title' > journal.impact2daysaccepted.csv 

Rscript - <<EOF
T<-read.csv("journal.impact2daysaccepted.csv",header=T)
png(filename="journal.impact2daysaccepted.png")
plot(T\$days,T\$ef,main='log(eigenfactor)=f(day(accepted-submitted))',xlab='days',ylab='log(eigenfactor)',xlim=c(0,500),log="y");

dev.off()
EOF

