source: trunk/bibopa.sh @ 68

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

basic solution (parameter) to force firstname/surname decomposition of personname

  • Property svn:keywords set to Id
File size: 23.0 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 xml: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</biblioid>
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#   @book{MetReiCoh2004 ,
33#      author    = {Michael Metcalf and
34#              John Reid and Malcolm Cohen},
35#      title     = {Fortran 95/2003 explained},
36#      year      = {2004},
37#      publisher = {Oxford University Press},
38#      edition   = {Third},
39#      ISBN      = {0-19-852693-8},
40#      pages = {434}
41#   }
42# donnerait
43#    <biblioentry xml:id="MetReiCoh2004">
44#    <authorgroup>
45#    <author><firstname>Michael</firstname> <surname>Metcalf</surname></author>
46#    <author><firstname>John</firstname> <surname>Reid</surname></author>
47#    <author><firstname>Malcolm</firstname> <surname>Cohen</surname></author>
48#    </authorgroup>
49#    <date>2004}</date>
50#    <title>Fortran 95/2003 explained</title>
51#    <publisher><publishername>Oxford University Press</publishername></publisher>
52#    <biblioid class="isbn">0-19-852693-8</biblioid>
53#    <pagenums>434</pagenums>
54#    <edition>Third</edition>
55#
56# example :
57# $ ./bibopa.sh -p birefnemo -i data/biball.txt -t raw
58# $ ./bibopa.sh -p bibrefnemo -i data/mail2007-05-10T09:01:56Z -t mailbody
59# $ ./bibopa.sh -p polyfortran -i data/petitpolyfp.bib -t bibtex -l fr
60# $ ./bibopa.sh -p demo1 -i data/bibdemo1.txt -t raw -l fr
61#
62# see also mailtouser.sh
63#
64# original location :
65# /usr/home/fplod/incas/bibnemo/src/bibnemomaf/bibopa.sh sur cerbere.locean-ipsl.upmc.fr
66#
67# update
68# ++ gestion des comments
69# ++ gestion des id existants (cf à la fin)
70# ++ option debug
71# $Id$
72# fplod 2008-05-16T10:33:16Z aedon.locean-ipsl.upmc.fr (Darwin)
73# add parameter -o for firstname/surname order in bibtex file
74# fplod 2008-05-15T15:15:04Z aedon.locean-ipsl.upmc.fr (Darwin)
75# new way of processing bibtex file : external/bibtex2xml.py
76# fplod 2008-04-30T07:11:58Z aedon.locean-ipsl.upmc.fr (Darwin)
77# chgt for dbk5 out
78# xmlto 0.0.18 does'nt like this docbook release. remove
79# usage of xml (xmlstarlet) for validation
80# bug fix
81# add journal names from demo1
82# fplod 2008-03-12T16:11:07Z aedon.locean-ipsl.upmc.fr (Darwin)
83# add -p option (to overide bibrefnemo in file name and id)
84# add -l option by default en
85# fplod 2008-03-11T11:25:27Z aedon.locean-ipsl.upmc.fr (Darwin)
86# add bibtex entry (not finished)++
87# fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin)
88# <bibliomisc role="id"> replace by <biblioid class="doi">
89# smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
90# Add journals
91# fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
92# dernières touches
93# fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
94# add a filein parameter and an option for mailbody
95# comments  (line begininig with #) are now possible
96# Sebastien Masson avril 2007 creation
97#
98
99rmbl () {
100    echo "${1}" | sed -e "s/^ *//" | sed -e "s/ *$//"
101}
102cleanname () {
103    echo "${1}" | sed -e "s/^ *//" \
104        -e "s/^ *,//" \
105        -e "s/^ *;//" \
106        -e "s/^ *\.//" \
107        -e "s/ *$//" \
108        -e "s/, *$//" \
109        -e "s/; *$//" \
110        -e "s/\. *$//"
111}
112#
113set -o posix
114command=$(basename ${0})
115log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
116log=/tmp/${command}.${log_date}
117#
118# test if xsltproc is available
119type xsltproc 1> /dev/null 2>&1
120status=${?}
121if [ ${status} -ne 0 ]
122then
123 echo " eee : xsltproc not found"
124 exit 1
125fi
126unset status
127#
128# test if xml  is available
129type xml 1> /dev/null 2>&1
130status=${?}
131if [ ${status} -ne 0 ]
132then
133 echo " eee : xml not found"
134 exit 1
135fi
136unset status
137#
138# test if python is available
139type python 1> /dev/null 2>&1
140status=${?}
141if [ ${status} -ne 0 ]
142then
143 echo " eee : python not found}"
144 exit 1
145fi
146unset status
147#
148usage=" Usage : ${command} -i filein -t type -o order -p project -l lang"
149#
150# default
151lang=en
152order="fs" # firstname surname
153#
154minargcount=6
155#echo " narg ${#}"
156if [ ${#} -lt ${minargcount} ]
157then
158   echo "eee : not enought arguments"
159   echo "${usage}"
160   exit 1
161fi
162unset minargcount
163#
164while [ ! -z "${1}" ]
165do
166 case ${1} in
167 -i) # filein
168  filein=${2}
169  shift
170 ;;
171 -t) # type
172  type=${2}
173  shift
174 ;;
175 -o) # order of firstname surname in bibtex file
176  order=${2}
177  shift
178 ;;
179 -p)
180  project=${2}
181  shift
182 ;;
183 -l)
184  lang=${2}
185  shift
186 ;;
187 -h)
188  echo "${usage}"
189  exit 0
190 ;;
191 *) # other choice
192  echo "${usage}"
193  exit 1
194 ;;
195 esac
196 shift # next flag
197done
198unset usage
199#
200set -u
201#
202# check for filein
203if [ ! -f ${filein} ]
204then
205   echo "eee : ${filein} not found"
206   exit 1
207fi
208#
209case ${type} in
210raw) # file like data/biball.txt
211 fileraw=${filein}
212 fileou=$( basename ${filein} .txt).xml
213;;
214mailbody) # file like data/mail2007-04-25T08:58:16Z.txt
215 fileraw=/tmp/$(basename ${filein}).raw
216 fileou=$( basename ${filein} .txt).xml
217 echo "# from ${filein}" > ${fileraw}
218 echo "# ${log_date}" >> ${fileraw}
219 echo "# corrections" >> ${fileraw}
220 grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
221 sed -e "s/correction_.*=//">> ${fileraw}
222 echo "# new references" >> ${fileraw}
223 awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
224 #more ${fileraw} # ++ if debug
225 #read a #++ if debug
226;;
227bibtex) # file like data/petitpoly.bib
228 fileraw=/tmp/$(basename ${filein}).raw
229 awk -f join_endcomma.awk ${filein} > ${fileraw}
230 fileou=$( basename ${filein} .bib).xml
231;;
232*)
233   echo "eee : type should be raw, mailbody or bibtex"
234   exit 1
235;;
236esac
237#
238# check for output
239if [ -f ${fileou} ]
240then
241   echo "eee : ${fileou} already exist"
242   exit 1
243fi
244#
245ij=1
246jlist[${ij}]="J. Climate"
247ij=$(( ${ij} + 1))
248jlist[${ij}]="Journal of Climate"
249ij=$(( ${ij} + 1))
250jlist[${ij}]="Ocean Modelling"
251ij=$(( ${ij} + 1))
252jlist[${ij}]="Geophys. Res. Lett."
253ij=$(( ${ij} + 1))
254jlist[${ij}]="J. Geophys. Res."
255ij=$(( ${ij} + 1))
256jlist[${ij}]="Tellus A"
257ij=$(( ${ij} + 1))
258jlist[${ij}]="Tellus B"
259ij=$(( ${ij} + 1))
260jlist[${ij}]="J. Phys. Oceanogr."
261ij=$(( ${ij} + 1))
262jlist[${ij}]="Clim. Dyn."
263ij=$(( ${ij} + 1))
264jlist[${ij}]="Climate Dynamics"
265ij=$(( ${ij} + 1))
266jlist[${ij}]="Dyn. Atmos. Oceans"
267ij=$(( ${ij} + 1))
268jlist[${ij}]="Mon. Wea. Rev."
269ij=$(( ${ij} + 1))
270jlist[${ij}]="Global Biogeochem. Cycles"
271ij=$(( ${ij} + 1))
272jlist[${ij}]="Nonlinear Processes in Geophysics"
273ij=$(( ${ij} + 1))
274jlist[${ij}]="Ocean Science"
275ij=$(( ${ij} + 1))
276jlist[${ij}]="J. Mar. Systems"
277ij=$(( ${ij} + 1))
278jlist[${ij}]="J. Atmos. Sc."
279ij=$(( ${ij} + 1))
280jlist[${ij}]="Proc. Royal Soc."
281ij=$(( ${ij} + 1))
282jlist[${ij}]="Bull. Amer. Meteorol. Soc."
283ij=$(( ${ij} + 1))
284jlist[${ij}]="Ocean Dyn."
285ij=$(( ${ij} + 1))
286jlist[${ij}]="Geophysical Monograph Series, Earth's Climate: The Ocean-Atmosphere Interaction"
287ij=$(( ${ij} + 1))
288jlist[${ij}]="Paleoceanography"
289ij=$(( ${ij} + 1))
290jlist[${ij}]="Annales Geophysicae"
291ij=$(( ${ij} + 1))
292jlist[${ij}]="Annals of Geophys."
293ij=$(( ${ij} + 1))
294jlist[${ij}]="Deep Sea Research Part II: Topical Studies in Oceanography"
295ij=$(( ${ij} + 1))
296jlist[${ij}]="Deep Sea Res. II"
297ij=$(( ${ij} + 1))
298jlist[${ij}]="Atmospheric Chemistry and Physics"
299ij=$(( ${ij} + 1))
300jlist[${ij}]="Atmospheric Chemistry and Physics Discussions"
301ij=$(( ${ij} + 1))
302jlist[${ij}]="Earth Plan. Sc. Lett."
303ij=$(( ${ij} + 1))
304jlist[${ij}]="J. Mar. Res."
305ij=$(( ${ij} + 1))
306jlist[${ij}]="PCMDI Report Series"
307ij=$(( ${ij} + 1))
308jlist[${ij}]="J. Mar. Syst."
309ij=$(( ${ij} + 1))
310jlist[${ij}]="Note du Pole de Modelisation"
311ij=$(( ${ij} + 1))
312jlist[${ij}]="Calculateurs Paralleles"
313ij=$(( ${ij} + 1))
314jlist[${ij}]="Note Scientifique du Pole de Modelisation"
315ij=$(( ${ij} + 1))
316jlist[${ij}]="Lecture Notes in Computer Science"
317ij=$(( ${ij} + 1))
318jlist[${ij}]="Prog. Oceanogr."
319ij=$(( ${ij} + 1))
320jlist[${ij}]="Deep Sea Research Part I: Oceanographic Research Papers"
321ij=$(( ${ij} + 1))
322jlist[${ij}]="Deep Sea Res. I"
323ij=$(( ${ij} + 1))
324jlist[${ij}]="IEEE Trans. Geosci. Remote Sensing"
325ij=$(( ${ij} + 1))
326jlist[${ij}]="ECMWF Tech. Memorandum"
327ij=$(( ${ij} + 1))
328jlist[${ij}]="J. Environ. Radioactivity"
329ij=$(( ${ij} + 1))
330jlist[${ij}]="Int. WOCE Newsletter"
331ij=$(( ${ij} + 1))
332jlist[${ij}]="C. R. Acad. Sci. Paris"
333ij=$(( ${ij} + 1))
334jlist[${ij}]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
335ij=$(( ${ij} + 1))
336jlist[${ij}]="In The mathematics of models for climatology and environment"
337ij=$(( ${ij} + 1))
338jlist[${ij}]="Oceanol. Acta"
339ij=$(( ${ij} + 1))
340jlist[${ij}]="The global atmosphere and ocean system"
341ij=$(( ${ij} + 1))
342jlist[${ij}]="NATO Advanced Study Institute"
343ij=$(( ${ij} + 1))
344jlist[${ij}]="WCRP"
345ij=$(( ${ij} + 1))
346jlist[${ij}]="The Courier"
347ij=$(( ${ij} + 1))
348jlist[${ij}]="Elsevier Oceanographic Series"
349ij=$(( ${ij} + 1))
350jlist[${ij}]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
351ij=$(( ${ij} + 1))
352jlist[${ij}]="In Science and engineering on Cray Supercomputers"
353ij=$(( ${ij} + 1))
354jlist[${ij}]="In Modeling the Earth's Climate and its Variability"
355ij=$(( ${ij} + 1))
356jlist[${ij}]="Fish. Oceanogr."
357ij=$(( ${ij} + 1))
358jlist[${ij}]="Q. J. R. Meteor. Soc."
359ij=$(( ${ij} + 1))
360jlist[${ij}]="In High performance computing in the geosciences"
361ij=$(( ${ij} + 1))
362jlist[${ij}]="Int. J. Numer. Meth. in Fluids"
363ij=$(( ${ij} + 1))
364jlist[${ij}]="Lecture notes in Physics"
365ij=$(( ${ij} + 1))
366jlist[${ij}]="J. Meterol. Soc. Japan"
367ij=$(( ${ij} + 1))
368jlist[${ij}]="Journal of Marine Systems"
369ij=$(( ${ij} + 1))
370jlist[${ij}]="Canadian Journal of Fisheries and Aquatic Sciences"
371ij=$(( ${ij} + 1))
372jlist[${ij}]="J. Atmos. Ocean. Tech."
373ij=$(( ${ij} + 1))
374jlist[${ij}]="EOS"
375ij=$(( ${ij} + 1))
376jlist[${ij}]="Nature"
377ij=$(( ${ij} + 1))
378jlist[${ij}]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
379ij=$(( ${ij} + 1))
380jlist[${ij}]="Journal of Atmospheric and Oceanic Technology"
381ij=$(( ${ij} + 1))
382jlist[${ij}]="Lecture Notes in Computational Science Engineering"
383ij=$(( ${ij} + 1))
384jlist[${ij}]="In Greenhouse Gas Control Technologies"
385ij=$(( ${ij} + 1))
386jlist[${ij}]="Chemical Geology"
387ij=$(( ${ij} + 1))
388jlist[${ij}]="Marine Geology"
389ij=$(( ${ij} + 1))
390jlist[${ij}]="Developments in Paleoenvironmental Research"
391ij=$(( ${ij} + 1))
392jlist[${ij}]="Science"
393ij=$(( ${ij} + 1))
394jlist[${ij}]="In Mediterranean Climate Variability"
395ij=$(( ${ij} + 1))
396jlist[${ij}]="Global and Planetary Change"
397ij=$(( ${ij} + 1))
398jlist[${ij}]="Physical Review Letters"
399#
400# following Journal name are fake ones for demo1 : references extracted from
401# Cantratrix Sopronica L. written by Georges Perec
402#find in http://www-rocq.inria.fr/who/Marc.Thiriet/PsFil/Biblio/cantatrix.ps
403ij=$(( ${ij} + 1))
404jlist[$ij]="Res. Proc. neurophysiol. Fanatic Soc."
405ij=$(( ${ij} + 1))
406jlist[$ij]="New Records Ass. J."
407ij=$(( ${ij} + 1))
408jlist[$ij]="Am. J. Allegrol."
409ij=$(( ${ij} + 1))
410jlist[$ij]="J. Neurochem. Neurocytol. Enzymol."
411ij=$(( ${ij} + 1))
412jlist[$ij]="Hammersmith J."
413ij=$(( ${ij} + 1))
414jlist[$ij]="Nasa Rept."
415ij=$(( ${ij} + 1))
416jlist[$ij]="C.r. Assoc. Conc. Lam."
417ij=$(( ${ij} + 1))
418jlist[$ij]="Gaz. med. franco-rus."
419ij=$(( ${ij} + 1))
420jlist[$ij]="Amer. J. music. Deciency"
421#
422#
423# strip comments
424fileraw_strict=/tmp/$(basename ${fileraw})_strict
425grep -v "^#" ${fileraw} | grep -v "^%" > ${fileraw_strict}
426case ${type} in
427bibtex) 
428 fileou_bibtexml=/tmp/$(basename ${fileraw})_bibtexml
429 python ./external/bibtex2xml.py ${fileraw_strict} > ${fileou_bibtexml}
430 xsltproc --output ${fileou} \
431 --param lang "'${lang}'" \
432 --param project "'${project}'" \
433 --param makedate "'${log_date}'" \
434 --param order "'${order}'" \
435 bibtexml2dbk.xsl ${fileou_bibtexml}
436#++ firstname surname
437 rm ${fileou_bibtexml} 
438;;
439*)
440    cat <<EOF > ${fileou}
441<?xml version='1.0' encoding='ISO-8859-1'?>
442<bibliography
443version="5.0"
444xmlns="http://docbook.org/ns/docbook"
445xml:id="bib${project}ref"
446xml:lang="${lang}">
447
448<info>
449<date>${log_date}<date>
450</info>
451EOF
452totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
453l=1
454while [ ${l} -le ${totlines}  ]
455do
456# extract one line
457  line=$( sed -n ${l}p ${fileraw_strict} )
458  orgline=$( echo ${line} | sed -e "s/--/- -/g" )
459  line=$( echo ${line} | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" )
460     # parsing non bibtex line
461     bibtex=0
462     # before the first :
463       tmp=${line%%:*}
464     # before the last ,
465       auths=${tmp%,*},
466     # replace " and " by ","
467       auths=$( echo "${auths}" | sed -e "s/ and /,/g" )
468     # replace " et " by ","
469       auths=$( echo "${auths}" | sed -e "s/ et /,/g" )
470     # after the last ,
471       year=${tmp##*,}
472       year=$( rmbl "${year}" )
473     ## first author before the first .,
474       first=${auths%%.,*}.
475     # its firstname after the last ,
476       firstfn=${first##*,}
477       firstfn=$( rmbl "${firstfn}" )
478     # its surname ; before the first ,
479       firstsn=${first%%,*}
480       firstsn=$( rmbl "${firstsn}" )
481     ## ref id
482       refid=$( echo ${firstsn} | tr "[:upper:]" "[:lower:]" | tr -s " " "_"  | tr -s "'" "_" | recode -d -f ISO-8859-1..flat )${year}
483       num=$( grep -c "<biblioentry xml:id=\"${refid}_[0-9][0-9]\">" ${fileou} )
484       num=$(( ${num} + 1 ))
485       [ ${num} -le 9 ] && num=0${num}
486       refid=${refid}_${num}
487       hasauthor=1
488
489          cat <<EOF >> ${fileou}
490<biblioentry xml:id="${refid}">
491  <!-- date
492  $( date -u +"%Y-%m-%dT%H:%M:%SZ" )
493  -->
494  <!-- original text
495  ${orgline}
496  -->
497EOF
498      if [ ${hasauthor} -eq 1 ]
499      then
500          cat <<EOF >> ${fileou}
501  <authorgroup>
502    <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author>
503EOF
504
505## other authors..
506  if [ ${bibtex} -eq 0 ]
507  then
508   previous=${first},
509   # next authors...
510   next=${auths##*${previous}}
511  fi
512  if [ ${bibtex} -eq 1 ]
513  then
514   previous=${first}"and "
515   # next authors...
516   #echo "auths ${auths}"
517   next=${auths##*${previous}}
518   if [ "${next}and " = "${previous}" ]
519   then
520     next=""
521   fi
522  fi
523  #echo "previous ${previous}"
524  #echo "next ${next}"
525# while the next author is not empty
526  while [  "${next}" != "" ]
527    do
528      if [ ${bibtex} -eq 0 ]
529      then
530         # get the first next author; before the first ,
531         next=${next%%,*}
532         # its surname ; after the last .
533         nextsn=${next##*.}
534         nextsn=$( rmbl "${nextsn}" )
535         # its firstname ; before the last .
536         nextfn=${next%.*}.
537         nextfn=$( rmbl "${nextfn}" )
538       fi
539      if [ ${bibtex} -eq 1 ]
540      then
541         # get the first next author; before the first "and"
542         next=${next%%and *}
543         # its surname after the last " "  ++ pas vrai double nom et pb blanc dans la syntaxe
544         # nextsn=${next##* } . ok en interactif . pas ok en script
545         nextsn=$( echo ${next}  | awk '{print $2}')
546         #echo "nextsn $nextsn"
547         # its nextname before the first " "
548         nextfn=${next%% *}
549      fi
550#
551    echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou}
552    #echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>"  #++debug
553    if [ ${bibtex} -eq 0 ]
554    then
555      previous=${next},
556      next=${auths##*${previous}}
557    fi
558    if [ ${bibtex} -eq 1 ]
559    then
560      previous=${next}"and "
561      next=${auths##*${previous}}
562    fi
563  done
564  echo "  </authorgroup>"  >> ${fileou}
565  fi
566
567# end of the line ; after the first :
568  endline=${line#*:}
569## find the journal
570  j=1
571  jfound=""
572  jlistsize=${#jlist[@]}
573  while [[ ${j} -le ${jlistsize} && "${jfound}" == "" ]]
574    do
575    ok=$( echo ${endline} | grep -ci "${jlist[j]} *," )
576    [ ${ok} -eq 1 ] && jfound="${jlist[j]}"
577    j=$(( ${j} + 1 ))
578  done
579  unset ok
580  if [ "${jfound}" == "" ]
581      then
582      echo "eee: Journal not found "
583      echo "${endline}"
584      set
585      exit 1
586#+++ following lines are not yet validate
587      # it might be a book, a manual, a conference, etc. ++
588      echo "  <title>${title}</title>" >> ${fileou}
589          cat <<EOF >> ${fileou}
590  <biblioset relation="nojournal">
591    <title>${title}</title>
592    <pagenums>${pag}</pagenums>
593    <pubdate>${year}</pubdate>
594  </biblioset>
595EOF
596          cat <<EOF >> ${fileou}
597</biblioentry>
598
599EOF
600  fi # end of if jfound empty (ie not an article)
601  if [ "${jfound}" != "" ]
602  then
603## title
604# before the first :
605  title=${endline%%${jfound}*}
606  title=$( cleanname "${title}" )
607  echo "  <title>${title}</title>" >> ${fileou}
608## end
609## end of the line ; after the first ${jfound}
610  endline=${endline#*${jfound}}
611  endline=$( cleanname "${endline}" )
612## doi
613  endline=$( echo ${endline} | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
614  ok=$( echo ${endline} | grep -ic "doi:" )
615  if [ ${ok} -eq 1 ]
616      then
617      doi=${endline##*doi:}
618      echo "  <biblioid class=\"doi\">${doi}</biblioid>" >> ${fileou}
619      unset doi
620      endline=${endline%doi:*}
621      endline=$( cleanname "${endline}" )
622  else
623      echo "non doi: ${line}"
624      echo ""
625  fi
626  num=$( echo ${endline} |  tr -dc "," | wc -c )
627  case ${num} in
628      0)
629### echo ${num}: ${endline}
630          cat <<EOF >> ${fileou}
631  <biblioset relation="journal">
632    <title>${jfound}</title>
633    <pubdate>${year}</pubdate>
634    <bibliomisc>${endline}</bibliomisc>
635  </biblioset>
636EOF
637          unset jfound
638          unset year
639      ;;
640
641      1)
642### echo ${num}: ${endline}
643          vol=${endline%,*}
644          vol=$( cleanname "${vol}" )
645          pag=${endline##*,}
646          pag=$( cleanname "${pag}" )
647          cat <<EOF >> ${fileou}
648  <biblioset relation="journal">
649    <title>${jfound}</title>
650    <volumenum>${vol}</volumenum><pagenums>${pag}</pagenums>
651    <pubdate>${year}</pubdate>
652  </biblioset>
653EOF
654          unset vol
655          unset pag
656          unset jfound
657          unset year
658      ;;
659      2)
660          vol=${endline%,*}
661          vol=$( cleanname "${vol}" )
662          iss=${vol##*,}
663          iss=$( cleanname "${iss}" )
664          vol=${vol%,*}
665          vol=$( cleanname "${vol}" )
666          pag=${endline##*,}
667          pag=$( cleanname "${pag}" )
668          cat <<EOF >> ${fileou}
669  <biblioset relation="journal">
670    <title>${jfound}</title>
671    <volumenum>${vol}</volumenum><issuenum>${iss}</issuenum><pagenums>${pag}</pagenums>
672    <pubdate>${year}</pubdate>
673  </biblioset>
674EOF
675          unset vol
676          unset pag
677          unset jfound
678          unset year
679          unset iss
680      ;;
681      6)
682          conftitle=${endline%%,*}
683          endline=${endline#*,}
684          confdates=${endline%%,*} # day(s) month
685          endline=${endline#*,}
686          confdates="${confdates}, ${endline%%,*}" # day(s) month and year
687          confdates=$( cleanname "${confdates}" )
688          endline=${endline#*,}
689          confaddress=${endline%%,*} # Town
690          endline=${endline#*,}
691          confaddress="${confaddress}, ${endline%%,*}" # Town and country
692          confaddress=$( cleanname "${confaddress}" )
693          endline=${endline#*,}
694          publishername=${endline%%,*}
695          publishername=$( cleanname "${publishername}" )
696          endline=${endline#*,}
697          pag=${endline##*,}
698          pag=$( cleanname "${pag}" )
699#set
700#read a
701          cat <<EOF >> ${fileou}
702<biblioset relation="conference">
703 <title>${jfound}</title>
704 <pubdate>${year}</pubdate>
705 <publisher><publishername>${publishername}</publishername></publisher>
706 <pagenums>${pag}</pagenums>
707 <confgroup>
708  <conftitle>${conftitle}</conftitle>
709  <confdates>${confdates}</confdates>
710  <address>${confaddress}</address>
711 </confgroup>
712</biblioset>
713EOF
714      unset confaddress
715      unset conftitle
716      unset confdates
717      unset pag
718      unset publishername
719      unset year
720      unset jfound
721      ;;
722      10)
723          publishername=${endline%%Editors,*}
724          publishername="${publishername} Editors"
725          publishername=$( cleanname "${publishername}" )
726          endline=${endline#*Editors,}
727          vol=${endline%%,*}
728          vol=$( cleanname "${vol}" )
729          endline=${endline#*,}
730          pag=${endline%%,*}
731          pag=$( cleanname "${pag}" )
732          endline=${endline#*,}
733          isbn=${endline%%,*}
734          isbn=$(echo ${isbn} | sed -e "s/ISBN ://")
735          isbn=$( cleanname "${isbn}" )
736          endline=${endline#*,}
737          agu=${endline%%,*}
738          agu=$(echo ${agu} | sed -e "s/AGU ://")
739          agu=$( cleanname "${agu}" )
740
741          endline=${endline#*${agu}}
742          endline=$( cleanname "${endline}" )
743          endline=$( cleanname "${endline}" )
744
745          cat <<EOF >> ${fileou}
746  <biblioid class="isbn">${isbn}</biblioid>
747  <biblioid class="other" otherclass="AGU">${agu}</biblioid>
748  <biblioset relation="journal">
749    <title>${jfound}</title>
750    <pubdate>${year}</pubdate>
751    <publisher><publishername>${publishername}</publishername></publisher>
752    <volumenum>${vol}</volumenum>
753    <pagenums>${pag}</pagenums>
754    <bibliomisc>${endline}</bibliomisc>
755  </biblioset>
756EOF
757      unset isbn
758      unset agu
759      unset pag
760      unset publishername
761      unset year
762      unset jfound
763      unset vol
764
765      ;;
766      *)
767echo ${num}: ${endline} # ++debug
768#set
769#exit 1 #++ debug
770          cat <<EOF >> ${fileou}
771  <biblioset relation="journal">
772    <title>${jfound}</title>
773    <pubdate>${year}</pubdate>
774    <bibliomisc>${endline}</bibliomisc>
775  </biblioset>
776EOF
777      ;;
778  esac
779
780          cat <<EOF >> ${fileou}
781</biblioentry>
782
783EOF
784  fi # end of if jfound not empty
785  unset title
786  unset vol
787  unset year
788  unset pag
789  l=$(( ${l} + 1 ))
790
791done
792unset totlines
793unset l
794echo "</bibliography>" >> ${fileou}
795;;
796esac # end of case bibtex vs other for processing
797
798xml val --err \
799        --xsd http://www.docbook.org/xml/5.0/xsd/docbook.xsd \
800        ${fileou} 1> xmlstarlet.log 2>&1
801
802# clean
803echo "iii : xslstarlet.log contains sdtout and stderr from xml command on ${fileou}"
804echo "iii : which was done just to check consistence of ${fileou}"
805more xmlstarlet.log
806rm -i xmlstarlet.log
807#
808case ${type} in
809raw)
810 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
811 rm -i ${fileraw_strict}
812;;
813mailbody)
814 echo "iii : ${fileraw} contains a copy of input file"
815 rm -i ${fileraw}
816 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
817 rm -i ${fileraw_strict}
818;;
819esac
820#
821echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
822echo " iii : you can add them in ${fileou}" #++ filename path
823echo " iii : modify date in ${fileou}" #++ filename path
824echo " iii : but please take care of id last part (after underscore) that may"
825echo " 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.
826#
827exit 0
Note: See TracBrowser for help on using the repository browser.