source: trunk/bibopa.sh @ 2

Last change on this file since 2 was 2, checked in by smasson, 15 years ago

initial import

File size: 12.2 KB
Line 
1#!/bin/bash
2#
3#    Behera, S. K., J. Luo, S. Masson, S. Rao, S. Gualdi, P. Delecluse, A.
4#    Navarra and T. Yamagata, 2004 : Paramount Impact of the Indian Ocean
5#    Dipole on the East African Short Rains: A CGCM Study, J. Climate, In
6#    press.
7#   
8#    donnerait
9#   
10#    <biblioentry id="behara2004">
11#    <authorgroup>
12#    <author><surname>Behera</surname> <firstname>S. K.</firstname> </author>
13#    <author><firstname>J.</firstname> <surname>Luo</surname></author>
14#    <author><firstname>S.</firstname> <surname>Masson</surname></author>
15#    <author><firstname>S.</firstname> <surname>Rao</surname></author>
16#    <author><firstname>S.</firstname> <surname>Gualdi</surname></author>
17#    <author><firstname>P.</firstname> <surname>Delecluse</surname></author>
18#    <author><firstname>A.</firstname> <surname>Navara</surname></author>
19#    <author><firstname>T.</firstname> <surname>Yamagata</surname></author>
20#    </authorgroup>
21#    <date>2004</date>
22#    <title>Paramount Impact of the Indian Ocean Dipole on the East African
23#    Short Rains: A CGCM Study</title>
24#    <publishername>J. Climate</publishername>
25#    <bibliomisc role="doi">doi</bibliomisc>
26#    <bibliomisc role="pseudoref">In press.</bibliomisc>
27#    <bibliomisc role="internalref">from
28#    http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html
29#    2007-03-29T16:24:31Z fplod by hand</bibliomisc>
30#    </biblioentry>
31#   
32#
33# example :
34# $ ./bibopa.sh -i /Users/smasson/Bibopa/biball.txt -t raw
35# $ ./bibopa.sh -i data/mail2007-04-25T08:58:16Z.txt -t mailbody
36#
37# see also mailtousernemo.sh
38#
39# original location :
40# /usr/home/fplod/incas/bibnemo/src/bibnemomaf/bibopa.sh sur cerbere.locean-ipsl.upmc.fr
41#
42# update
43# ++ gestion des comments
44# ++ gestion des id existants (cf à la fin)
45# ++ option debug
46# fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
47# dernières touches
48# fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
49# add a filein parameter and an option for mailbody
50# comments  (line begininig with #) are now possible
51# Sebastien Masson avril 2007 creation
52#
53
54rmbl () {
55    echo "$1" | sed -e "s/^ *//" | sed -e "s/ *$//"
56}
57cleanname () {
58    echo "$1" | sed -e "s/^ *//" \
59        -e "s/^ *,//" \
60        -e "s/^ *;//" \
61        -e "s/^ *\.//" \
62        -e "s/ *$//" \
63        -e "s/, *$//" \
64        -e "s/; *$//" \
65        -e "s/\. *$//"
66}
67#
68set -o posix
69command=$(basename ${0} .sh)
70log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
71log=/tmp/${command}.${log_date}
72#
73# test if xsltproc is available
74type xsltproc 1> /dev/null 2>&1
75status=${?}
76if [ ${status} -ne 0 ]
77then
78 echo " eee : xsltproc not found"
79 exit 1
80fi
81#
82usage=" Usage : ${command} -i filein -t type"
83#
84while [ ! -z "${1}" ] # ++ pb bash
85do
86 case ${1} in
87 -i) # filein
88  filein=${2}
89  shift
90 ;;
91 -t) # type
92  type=${2}
93  shift
94 ;;
95 *) # other choice
96  echo "${usage}"
97  exit 1
98 ;;
99 esac
100 shift # next flag
101done
102#
103set -u
104#
105# check for filein
106if [ ! -f ${filein} ]
107then
108  echo "eee : ${filein} not found"
109  exit 1
110fi
111#
112case ${type} in
113raw) # file like data/biball.txt
114 fileraw=${filein}
115;;
116mailbody) # file like data/mail2007-04-25T08:58:16Z.txt
117 fileraw=/tmp/$(basename ${filein}).raw
118 echo "# from ${filein}" > ${fileraw}
119 echo "# ${log_date}" >> ${fileraw}
120 echo "# corrections" >> ${fileraw}
121 grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
122 sed -e "s/correction_.*=//">> ${fileraw}
123 echo "# new references" >> ${fileraw}
124 awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
125 #more ${fileraw} # ++ if debug
126 #read a #++ if debug
127;;
128*) 
129   echo "eee : type should be raw or mailbody"
130   exit 1
131;;
132esac
133#
134# check for output
135fileou=$( basename ${filein} .txt).xml
136if [ -f ${fileou} ]
137then
138   echo "eee : ${fileou} already exist"
139   #exit 1 # ++ if not debug
140fi
141#
142jlist[1]="J. Climate"
143jlist[2]="Journal of Climate"
144jlist[3]="Ocean Modelling"
145jlist[4]="Geophys. Res. Lett."
146jlist[5]="J. Geophys. Res."
147jlist[6]="Tellus A"
148jlist[7]="Tellus B"
149jlist[8]="J. Phys. Oceanogr."
150jlist[9]="Clim. Dyn."
151jlist[10]="Climate Dynamics"
152jlist[11]="Dyn. Atmos. Oceans"
153jlist[12]="Mon. Wea. Rev."
154jlist[13]="Global Biogeochem. Cycles"
155jlist[14]="Nonlinear Processes in Geophysics"
156jlist[15]="Ocean Science"
157jlist[16]="J. Mar. Systems"
158jlist[17]="J. Atmos. Sc."
159jlist[18]="Proc. Royal Soc."
160jlist[19]="Bull. Amer. Meteorol. Soc."
161jlist[20]="Ocean Dyn."
162jlist[21]="Geophysical Monograph Series"
163jlist[22]="Paleoceanography"
164jlist[23]="Annales Geophysicae"
165jlist[24]="Annals of Geophys."
166jlist[25]="Deep Sea Research Part II: Topical Studies in Oceanography"
167jlist[26]="Deep Sea Res. II"
168jlist[27]="Atmospheric Chemistry and Physics"
169jlist[28]="Atmospheric Chemistry and Physics Discussions"
170jlist[29]="Earth Plan. Sc. Lett."
171jlist[30]="J. Mar. Res."
172jlist[31]="PCMDI Report Series"
173jlist[32]="J. Mar. Syst."
174jlist[33]="Note du Pole de Modelisation"
175jlist[34]="Calculateurs Paralleles"
176jlist[35]="Note Scientifique du Pole de Modelisation"
177jlist[36]="Lecture Notes in Computer Science"
178jlist[37]="Prog. Oceanogr."
179jlist[38]="Deep Sea Research Part I: Oceanographic Research Papers"
180jlist[39]="Deep Sea Res. I"
181jlist[40]="IEEE Trans. Geosci. Remote Sensing"
182jlist[41]="ECMWF Tech. Memorandum"
183jlist[42]="J. Environ. Radioactivity"
184jlist[43]="Int. WOCE Newsletter"
185jlist[44]="C. R. Acad. Sci. Paris"
186jlist[45]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
187jlist[46]="In The mathematics of models for climatology and environment"
188jlist[47]="Oceanol. Acta"
189jlist[48]="The global atmosphere and ocean system"
190jlist[49]="NATO Advanced Study Institute"
191jlist[50]="WCRP"
192jlist[51]="The Courier"
193jlist[52]="Elsevier Oceanographic Series"
194jlist[53]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
195jlist[54]="In Science and engineering on Cray Supercomputers"
196jlist[55]="In Modeling the Earth's Climate and its Variability"
197jlist[56]="Fish. Oceanogr."
198jlist[57]="Q. J. R. Meteor. Soc."
199jlist[58]="In High performance computing in the geosciences"
200jlist[59]="Int. J. Numer. Meth. in Fluids"
201jlist[60]="Lecture notes in Physics"
202jlist[61]="J. Meterol. Soc. Japan"
203jlist[62]="Journal of Marine Systems"
204jlist[63]="Canadian Journal of Fisheries and Aquatic Sciences"
205jlist[64]="J. Atmos. Ocean. Tech."
206jlist[65]="EOS"
207jlist[66]="Nature"
208jlist[67]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
209jlist[68]="Journal of Atmospheric and Oceanic Technology"
210jlist[69]="Lecture Notes in Computational Science Engineering"
211jlist[70]="In Greenhouse Gas Control Technologies"
212jlist[71]="Chemical Geology"
213jlist[72]="Marine Geology"
214jlist[73]="Developments in Paleoenvironmental Research"
215jlist[74]="Science"
216jlist[75]="In Mediterranean Climate Variability"
217#jlist[]=""
218#
219#
220    cat <<EOF > ${fileou}
221<?xml version='1.0' encoding='ISO-8859-1'?>
222<!DOCTYPE bibliography PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
223 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
224<bibliography id="bibrefnemo" lang="en">
225<bibliographyinfo>
226<date>$( date -u +"%Y-%m-%dT%H:%M:%SZ" )</date>
227</bibliographyinfo>
228EOF
229#
230# strip comments
231fileraw_strict=/tmp/$(basename ${fileraw})_strict
232grep -v "^#" ${fileraw} > ${fileraw_strict}
233totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
234l=1
235while [ $l -le $totlines  ]
236do
237# extract one line
238
239  line=$( sed -n ${l}p ${fileraw_strict} )
240  orgline=$( echo $line | sed -e "s/--/- -/g" )
241  line=$( echo $line | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" )
242# before the first :
243  tmp=${line%%:*}
244# before the last ,
245  auths=${tmp%,*},
246# supress and
247  auths=$( echo "$auths" | sed -e "s/ and //g" )
248# after the last ,
249  year=${tmp##*,}
250  year=$( rmbl "$year" )
251## first author before the first .,
252  first=${auths%%.,*}.
253# its firstname after the last ,
254  firstfn=${first##*,}
255  firstfn=$( rmbl "$firstfn" )
256# its surname ; before the first ,
257  firstsn=${first%%,*}
258  firstsn=$( rmbl "$firstsn" )
259## ref id
260  refid=$( echo $firstsn | tr "[:upper:]" "[:lower:]" | tr -s " " "_"  | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )$year
261  num=$( grep -c "<biblioentry id=\"${refid}_[0-9][0-9]\">" $fileou )
262  num=$(( $num + 1 ))
263  [ $num -le 9 ] && num=0$num 
264  refid=${refid}_$num
265 
266          cat <<EOF >> $fileou
267<biblioentry id="${refid}">
268  <!-- date
269  $( date -u +"%Y-%m-%dT%H:%M:%SZ" )
270  -->
271  <!-- original text
272  $orgline
273  -->
274  <authorgroup>
275    <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author>
276EOF
277 
278## other authors..
279  previous=${first},
280# next authors...
281  next=${auths##*${previous}}
282# while the next author is not empty
283  while [  "$next" != "" ]
284    do
285# get the first next author; before the first ,
286    next=${next%%,*}
287# its surname ; after the last .
288    nextsn=${next##*.}
289    nextsn=$( rmbl "$nextsn" )
290# its firstname ; before the last .
291    nextfn=${next%.*}.
292    nextfn=$( rmbl "$nextfn" )
293#
294    echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou}
295    previous=${next},
296    next=${auths##*${previous}}
297   
298  done
299  echo "  </authorgroup>"  >> $fileou
300 
301# end of the line ; after the first :
302  endline=${line#*:}
303 
304## find the journal
305  j=1
306  jfound=""
307  jlistsize=${#jlist[@]}
308  while [[ $j -le $jlistsize && "${jfound}" == "" ]]
309    do
310    ok=$( echo $endline | grep -ci "${jlist[j]} *," ) 
311    [ $ok -eq 1 ] && jfound="${jlist[j]}"
312    j=$(( $j + 1 ))
313  done
314  if [ "$jfound" == "" ]
315      then
316      echo ERROR Journal not found
317      echo $endline
318      exit
319  fi
320## title
321# before the first :
322  title=${endline%%${jfound}*}
323  title=$( cleanname "$title" )
324  echo "  <title>${title}</title>" >> $fileou
325## end
326## end of the line ; after the first ${jfound}
327  endline=${endline#*${jfound}}
328  endline=$( cleanname "$endline" )
329## doi
330  endline=$( echo $endline | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
331  ok=$( echo $endline | grep -ic "doi:" )
332  if [ $ok -eq 1 ]
333      then
334      doi=${endline##*doi:}
335      echo "  <bibliomisc role=\"doi\">${doi}</bibliomisc>" >> $fileou
336      endline=${endline%doi:*}
337      endline=$( cleanname "$endline" )
338  else
339      echo non doi: $line
340  fi
341  num=$( echo $endline |  tr -dc "," | wc -c )
342  case $num in
343      1) 
344### echo $num: ${endline}
345          vol=${endline%,*}
346          vol=$( cleanname "$vol" )
347          pag=${endline##*,} 
348          pag=$( cleanname "$pag" )
349          cat <<EOF >> $fileou
350  <biblioset relation="journal">
351    <title>${jfound}</title>
352    <volumenum>${vol}</volumenum><pagenums>${pag}</pagenums>
353    <pubdate>${year}</pubdate>
354  </biblioset>
355EOF
356      ;;
357      2) 
358          vol=${endline%,*}
359          vol=$( cleanname "$vol" )
360          iss=${vol##*,} 
361          iss=$( cleanname "$iss" )
362          vol=${vol%,*}
363          vol=$( cleanname "$vol" )
364          pag=${endline##*,} 
365          pag=$( cleanname "$pag" )
366          cat <<EOF >> $fileou
367  <biblioset role="journal">
368    <title>${jfound}</title>
369    <volumenum>${vol}</volumenum><issuenum>${iss}</issuenum><pagenums>${pag}</pagenums>
370    <pubdate>${year}</pubdate>
371  </biblioset>
372EOF
373      ;;
374      *)
375echo $num: ${endline}
376          cat <<EOF >> $fileou
377  <biblioset role="journal">
378    <title>${jfound}</title>
379    <pubdate>${year}</pubdate>
380    <bibliomisc>${endline}</bibliomisc>
381  </biblioset>
382EOF
383      ;;
384  esac
385 
386          cat <<EOF >> $fileou
387</biblioentry>
388 
389EOF
390
391
392
393
394 
395  l=$(( $l + 1 ))
396 
397done
398echo "</bibliography>" >> $fileou
399
400xsltproc \
401--output $( basename ${filein} .txt).html \
402http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl \
403${fileou}
404
405xmlto pdf ${fileou} 2> xml.err
406#
407# clean
408echo "iii : xml.err contains stderr from the following command "
409echo "iii : which was done just to check consistence of ${fileou}" 
410echo "iii : xmlto pdf ${fileou}"
411rm -i xml.err
412case ${type} in
413raw) 
414 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
415 rm -i ${fileraw_strict}
416;;
417mailbody)
418 echo "iii : ${fileraw} contains a copy of input file"
419 rm -i ${fileraw}
420 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
421 rm -i ${fileraw_strict}
422;;
423esac
424#
425echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
426echo " iii : you can add them in bibrefnemo.xml" #++ filename path
427echo " iii : modify date in bibrefnemo.xml" #++ filename path
428echo " iii : but please take care of id last part (after underscore) that may"
429echo " 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.
430#
431exit 0
Note: See TracBrowser for help on using the repository browser.