#!/bin/bash
#
# Behera, S. K., J. Luo, S. Masson, S. Rao, S. Gualdi, P. Delecluse, A.
# Navarra and T. Yamagata, 2004 : Paramount Impact of the Indian Ocean
# Dipole on the East African Short Rains: A CGCM Study, J. Climate, In
# press.
#
# donnerait
#
#
#
# Behera S. K.
# J. Luo
# S. Masson
# S. Rao
# S. Gualdi
# P. Delecluse
# A. Navara
# T. Yamagata
#
# 2004
# Paramount Impact of the Indian Ocean Dipole on the East African
# Short Rains: A CGCM Study
# J. Climate
# doi
# In press.
# from
# http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html
# 2007-03-29T16:24:31Z fplod by hand
#
#
#
# example :
# $ ./bibopa.sh -i /Users/smasson/Bibopa/biball.txt -t raw
# $ ./bibopa.sh -i data/mail2007-04-25T08:58:16Z.txt -t mailbody
#
# see also mailtousernemo.sh
#
# original location :
# /usr/home/fplod/incas/bibnemo/src/bibnemomaf/bibopa.sh sur cerbere.locean-ipsl.upmc.fr
#
# update
# ++ gestion des comments
# ++ gestion des id existants (cf à la fin)
# ++ option debug
# smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
# Add journals
# fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
# dernières touches
# fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
# add a filein parameter and an option for mailbody
# comments (line begininig with #) are now possible
# Sebastien Masson avril 2007 creation
#
rmbl () {
echo "$1" | sed -e "s/^ *//" | sed -e "s/ *$//"
}
cleanname () {
echo "$1" | sed -e "s/^ *//" \
-e "s/^ *,//" \
-e "s/^ *;//" \
-e "s/^ *\.//" \
-e "s/ *$//" \
-e "s/, *$//" \
-e "s/; *$//" \
-e "s/\. *$//"
}
#
set -o posix
command=$(basename ${0} .sh)
log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
log=/tmp/${command}.${log_date}
#
# test if xsltproc is available
type xsltproc 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
echo " eee : xsltproc not found"
exit 1
fi
#
usage=" Usage : ${command} -i filein -t type"
#
while [ ! -z "${1}" ] # ++ pb bash
do
case ${1} in
-i) # filein
filein=${2}
shift
;;
-t) # type
type=${2}
shift
;;
*) # other choice
echo "${usage}"
exit 1
;;
esac
shift # next flag
done
#
set -u
#
# check for filein
if [ ! -f ${filein} ]
then
echo "eee : ${filein} not found"
exit 1
fi
#
case ${type} in
raw) # file like data/biball.txt
fileraw=${filein}
;;
mailbody) # file like data/mail2007-04-25T08:58:16Z.txt
fileraw=/tmp/$(basename ${filein}).raw
echo "# from ${filein}" > ${fileraw}
echo "# ${log_date}" >> ${fileraw}
echo "# corrections" >> ${fileraw}
grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
sed -e "s/correction_.*=//">> ${fileraw}
echo "# new references" >> ${fileraw}
awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
#more ${fileraw} # ++ if debug
#read a #++ if debug
;;
*)
echo "eee : type should be raw or mailbody"
exit 1
;;
esac
#
# check for output
fileou=$( basename ${filein} .txt).xml
if [ -f ${fileou} ]
then
echo "eee : ${fileou} already exist"
#exit 1 # ++ if not debug
fi
#
jlist[1]="J. Climate"
jlist[2]="Journal of Climate"
jlist[3]="Ocean Modelling"
jlist[4]="Geophys. Res. Lett."
jlist[5]="J. Geophys. Res."
jlist[6]="Tellus A"
jlist[7]="Tellus B"
jlist[8]="J. Phys. Oceanogr."
jlist[9]="Clim. Dyn."
jlist[10]="Climate Dynamics"
jlist[11]="Dyn. Atmos. Oceans"
jlist[12]="Mon. Wea. Rev."
jlist[13]="Global Biogeochem. Cycles"
jlist[14]="Nonlinear Processes in Geophysics"
jlist[15]="Ocean Science"
jlist[16]="J. Mar. Systems"
jlist[17]="J. Atmos. Sc."
jlist[18]="Proc. Royal Soc."
jlist[19]="Bull. Amer. Meteorol. Soc."
jlist[20]="Ocean Dyn."
jlist[21]="Geophysical Monograph Series"
jlist[22]="Paleoceanography"
jlist[23]="Annales Geophysicae"
jlist[24]="Annals of Geophys."
jlist[25]="Deep Sea Research Part II: Topical Studies in Oceanography"
jlist[26]="Deep Sea Res. II"
jlist[27]="Atmospheric Chemistry and Physics"
jlist[28]="Atmospheric Chemistry and Physics Discussions"
jlist[29]="Earth Plan. Sc. Lett."
jlist[30]="J. Mar. Res."
jlist[31]="PCMDI Report Series"
jlist[32]="J. Mar. Syst."
jlist[33]="Note du Pole de Modelisation"
jlist[34]="Calculateurs Paralleles"
jlist[35]="Note Scientifique du Pole de Modelisation"
jlist[36]="Lecture Notes in Computer Science"
jlist[37]="Prog. Oceanogr."
jlist[38]="Deep Sea Research Part I: Oceanographic Research Papers"
jlist[39]="Deep Sea Res. I"
jlist[40]="IEEE Trans. Geosci. Remote Sensing"
jlist[41]="ECMWF Tech. Memorandum"
jlist[42]="J. Environ. Radioactivity"
jlist[43]="Int. WOCE Newsletter"
jlist[44]="C. R. Acad. Sci. Paris"
jlist[45]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
jlist[46]="In The mathematics of models for climatology and environment"
jlist[47]="Oceanol. Acta"
jlist[48]="The global atmosphere and ocean system"
jlist[49]="NATO Advanced Study Institute"
jlist[50]="WCRP"
jlist[51]="The Courier"
jlist[52]="Elsevier Oceanographic Series"
jlist[53]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
jlist[54]="In Science and engineering on Cray Supercomputers"
jlist[55]="In Modeling the Earth's Climate and its Variability"
jlist[56]="Fish. Oceanogr."
jlist[57]="Q. J. R. Meteor. Soc."
jlist[58]="In High performance computing in the geosciences"
jlist[59]="Int. J. Numer. Meth. in Fluids"
jlist[60]="Lecture notes in Physics"
jlist[61]="J. Meterol. Soc. Japan"
jlist[62]="Journal of Marine Systems"
jlist[63]="Canadian Journal of Fisheries and Aquatic Sciences"
jlist[64]="J. Atmos. Ocean. Tech."
jlist[65]="EOS"
jlist[66]="Nature"
jlist[67]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
jlist[68]="Journal of Atmospheric and Oceanic Technology"
jlist[69]="Lecture Notes in Computational Science Engineering"
jlist[70]="In Greenhouse Gas Control Technologies"
jlist[71]="Chemical Geology"
jlist[72]="Marine Geology"
jlist[73]="Developments in Paleoenvironmental Research"
jlist[74]="Science"
jlist[75]="In Mediterranean Climate Variability"
jlist[76]="Global and Planetary Change"
jlist[77]="Physical Review Letters"
#jlist[]=""
#
#
cat < ${fileou}
$( date -u +"%Y-%m-%dT%H:%M:%SZ" )
EOF
#
# strip comments
fileraw_strict=/tmp/$(basename ${fileraw})_strict
grep -v "^#" ${fileraw} > ${fileraw_strict}
totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
l=1
while [ $l -le $totlines ]
do
# extract one line
line=$( sed -n ${l}p ${fileraw_strict} )
orgline=$( echo $line | sed -e "s/--/- -/g" )
line=$( echo $line | sed -e "s/\</g" -e "s/>/\>/g" )
# before the first :
tmp=${line%%:*}
# before the last ,
auths=${tmp%,*},
# supress and
auths=$( echo "$auths" | sed -e "s/ and //g" )
# after the last ,
year=${tmp##*,}
year=$( rmbl "$year" )
## first author before the first .,
first=${auths%%.,*}.
# its firstname after the last ,
firstfn=${first##*,}
firstfn=$( rmbl "$firstfn" )
# its surname ; before the first ,
firstsn=${first%%,*}
firstsn=$( rmbl "$firstsn" )
## ref id
refid=$( echo $firstsn | tr "[:upper:]" "[:lower:]" | tr -s " " "_" | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )$year
num=$( grep -c "" $fileou )
num=$(( $num + 1 ))
[ $num -le 9 ] && num=0$num
refid=${refid}_$num
cat <> $fileou
${firstsn} ${firstfn}
EOF
## other authors..
previous=${first},
# next authors...
next=${auths##*${previous}}
# while the next author is not empty
while [ "$next" != "" ]
do
# get the first next author; before the first ,
next=${next%%,*}
# its surname ; after the last .
nextsn=${next##*.}
nextsn=$( rmbl "$nextsn" )
# its firstname ; before the last .
nextfn=${next%.*}.
nextfn=$( rmbl "$nextfn" )
#
echo " ${nextsn} ${nextfn} " >> ${fileou}
previous=${next},
next=${auths##*${previous}}
done
echo " " >> $fileou
# end of the line ; after the first :
endline=${line#*:}
## find the journal
j=1
jfound=""
jlistsize=${#jlist[@]}
while [[ $j -le $jlistsize && "${jfound}" == "" ]]
do
ok=$( echo $endline | grep -ci "${jlist[j]} *," )
[ $ok -eq 1 ] && jfound="${jlist[j]}"
j=$(( $j + 1 ))
done
if [ "$jfound" == "" ]
then
echo ERROR Journal not found
echo $endline
exit
fi
## title
# before the first :
title=${endline%%${jfound}*}
title=$( cleanname "$title" )
echo " ${title}" >> $fileou
## end
## end of the line ; after the first ${jfound}
endline=${endline#*${jfound}}
endline=$( cleanname "$endline" )
## doi
endline=$( echo $endline | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
ok=$( echo $endline | grep -ic "doi:" )
if [ $ok -eq 1 ]
then
doi=${endline##*doi:}
echo " ${doi}" >> $fileou
endline=${endline%doi:*}
endline=$( cleanname "$endline" )
else
echo non doi: $line
fi
num=$( echo $endline | tr -dc "," | wc -c )
case $num in
1)
### echo $num: ${endline}
vol=${endline%,*}
vol=$( cleanname "$vol" )
pag=${endline##*,}
pag=$( cleanname "$pag" )
cat <> $fileou
${jfound}
${vol}${pag}
${year}
EOF
;;
2)
vol=${endline%,*}
vol=$( cleanname "$vol" )
iss=${vol##*,}
iss=$( cleanname "$iss" )
vol=${vol%,*}
vol=$( cleanname "$vol" )
pag=${endline##*,}
pag=$( cleanname "$pag" )
cat <> $fileou
${jfound}
${vol}${iss}${pag}
${year}
EOF
;;
*)
echo $num: ${endline}
cat <> $fileou
${jfound}
${year}
${endline}
EOF
;;
esac
cat <> $fileou
EOF
l=$(( $l + 1 ))
done
echo "" >> $fileou
xsltproc \
--output $( basename ${filein} .txt).html \
http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl \
${fileou}
xmlto pdf ${fileou} 2> xml.err
#
# clean
echo "iii : xml.err contains stderr from the following command "
echo "iii : which was done just to check consistence of ${fileou}"
echo "iii : xmlto pdf ${fileou}"
rm -i xml.err
case ${type} in
raw)
echo "iii : ${fileraw_strict} contains a copy of input file without comments"
rm -i ${fileraw_strict}
;;
mailbody)
echo "iii : ${fileraw} contains a copy of input file"
rm -i ${fileraw}
echo "iii : ${fileraw_strict} contains a copy of input file without comments"
rm -i ${fileraw_strict}
;;
esac
#
echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
echo " iii : you can add them in bibrefnemo.xml" #++ filename path
echo " iii : modify date in bibrefnemo.xml" #++ filename path
echo " iii : but please take care of id last part (after underscore) that may"
echo " iii : be in conflict with existing ones" #++ pour s'affranchir de ce souci il faudrait donner en entrée complémentaire le fichier à compléter.
#
exit 0