source: trunk/bibopa.sh @ 65

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

some improvemnt but bibopa.sh and superbib01_txt.xsl are still not fully compatible

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