source: trunk/bibopa.sh @ 31

Last change on this file since 31 was 31, checked in by pinsard, 16 years ago

remove nemo in elements names and filenames

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