source: trunk/bibopa.sh @ 93

Last change on this file since 93 was 93, checked in by pinsard, 15 years ago

remove most of wiki pages

  • Property svn:keywords set to Id
File size: 30.5 KB
Line 
1#!/bin/bash
2#+
3#
4# NAME
5# ====
6#
7# bibopa.sh - transform a bibliography file in DocBook 5 format
8#
9# SYNOPSIS
10# ========
11#
12# ::
13#
14#  $ bibopa.sh -i filein -t type -o order -p project -l lang
15#
16#
17# DESCRIPTION
18# ===========
19#
20#
21# Each entry in the same input file must follows the same order for authors
22# except the first one.
23#
24# With ``fs`` in option order you will correctly process raw entry with
25# firstname and surname in this order for authors except the first one.
26#
27# If raw entry uses surname and firstname order, you should use ``sf``.
28#
29# ::
30#
31#    Behera, S. K., J. Luo, S. Masson, S. Rao, S. Gualdi, P. Delecluse, A.
32#    Navarra and T. Yamagata, 2004 : Paramount Impact of the Indian Ocean
33#    Dipole on the East African Short Rains: A CGCM Study, J. Climate, In
34#    press.
35#
36#
37# donnerait
38#
39# ::
40#
41#    <biblioentry xml:id="behara2004">
42#    <authorgroup>
43#    <author><surname>Behera</surname> <firstname>S. K.</firstname> </author>
44#    <author><firstname>J.</firstname> <surname>Luo</surname></author>
45#    <author><firstname>S.</firstname> <surname>Masson</surname></author>
46#    <author><firstname>S.</firstname> <surname>Rao</surname></author>
47#    <author><firstname>S.</firstname> <surname>Gualdi</surname></author>
48#    <author><firstname>P.</firstname> <surname>Delecluse</surname></author>
49#    <author><firstname>A.</firstname> <surname>Navara</surname></author>
50#    <author><firstname>T.</firstname> <surname>Yamagata</surname></author>
51#    </authorgroup>
52#    <date>2004</date>
53#    <title>Paramount Impact of the Indian Ocean Dipole on the East African
54#    Short Rains: A CGCM Study</title>
55#    <publishername>J. Climate</publishername>
56#    <biblioid class="doi">doi</biblioid>
57#    <bibliomisc role="pseudoref">In press.</bibliomisc>
58#    <bibliomisc role="internalref">from
59#    http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html
60#    2007-03-29T16:24:31Z fplod by hand</bibliomisc>
61#    </biblioentry>
62#
63#
64# ::
65#
66#   @book{MetReiCoh2004 ,
67#      author    = {Michael Metcalf and
68#              John Reid and Malcolm Cohen},
69#      title     = {Fortran 95/2003 explained},
70#      year      = {2004},
71#      publisher = {Oxford University Press},
72#      edition   = {Third},
73#      ISBN      = {0-19-852693-8},
74#      pages = {434}
75#   }
76#
77#
78# donnerait
79#
80# ::
81#
82#    <biblioentry xml:id="MetReiCoh2004">
83#    <authorgroup>
84#    <author><firstname>Michael</firstname> <surname>Metcalf</surname></author>
85#    <author><firstname>John</firstname> <surname>Reid</surname></author>
86#    <author><firstname>Malcolm</firstname> <surname>Cohen</surname></author>
87#    </authorgroup>
88#    <date>2004}</date>
89#    <title>Fortran 95/2003 explained</title>
90#    <publisher><publishername>Oxford University Press</publishername></publisher>
91#    <biblioid class="isbn">0-19-852693-8</biblioid>
92#    <pagenums>434</pagenums>
93#    <edition>Third</edition>
94#
95#
96# EXAMPLES
97# ========
98#
99# To transform the NEMO bibliography file in raw format:
100#
101# ::
102#
103#  $ ./bibopa.sh -p birefnemo -i data/biball.txt -t raw
104#
105#
106# To transform a bibliography file in mailbody format:
107#
108# ::
109#
110#  $ ./bibopa.sh -p bibrefnemo -i data/mail2007-05-10T09:01:56Z -t mailbody
111#
112#
113# To transform a bibliography file in bibtex format in french:
114#
115# ::
116#
117#  $ ./bibopa.sh -p polyfortran -i data/petitpolyfp.bib -t bibtex -l fr
118#
119#
120# To transform the SUPERBIB demo bibliography file in raw format:
121#
122# ::
123#
124#  $ ./bibopa.sh -p demo1 -i data/bibdemo1.txt -t raw -l fr
125#
126#
127# SEE ALSO
128# ========
129#
130# mailtouser.sh_
131#
132# .. _mailtouser.sh : mailtouser.sh.html
133#
134# FILES
135# =====
136#
137# original location
138# ~~~~~~~~~~~~~~~~~
139#
140# /usr/home/fplod/incas/bibnemo/src/bibnemomaf/bibopa.sh sur cerbere.locean-ipsl.upmc.fr
141#
142#
143# TODO
144# ====
145#
146# gestion des comments
147#
148# gestion des id existants (cf à la fin)
149#
150# option debug
151#
152# should use iconv instead of recode
153# for portability issue but not found yet the "flat" fonctionnality in
154# iconv
155#
156# write something in the logfile !
157#
158# EVOLUTIONS
159# ==========
160#
161#
162#
163# $Id$
164#
165# - fplod 2009-03-13T09:35:42Z aedon.locean-ipsl.upmc.fr (Darwin)
166#
167#   * add "High Performance Computing in Science and Engineering"
168#   * add "Annals of Glaciology"
169#   * add "Journal of Physical Oceanography"
170#
171# - fplod 2009-01-15T10:36:18Z aedon.locean-ipsl.upmc.fr (Darwin)
172#
173#   * add description of ``-o`` option
174#   * add journal "PNAS"
175#   * add journal "Lettre PIGB-PMRC"
176#
177# - fplod 2009-01-14T15:27:48Z aedon.locean-ipsl.upmc.fr (Darwin)
178#
179#   * add journal "Water Resources Research"
180#   * add journal "Climate Research"
181#   * add conf "Colloque du GIS « Climat-Environnement-Sociétés »"
182#   * add journal "Agricultural and Forest Meteorology"
183#   * add conf "VIIth IAHS Scientific Assembly"
184#   * add conf "AGU fall Meeting"
185#   * add journal "Phil. Trans. Roy. Soc. B"
186#   * add journal "Phil. Trans. Roy. Soc. B"
187#   * add conf "4th Alexander Von Humboldt International Conference"
188#   * add journal/conf "??" (Should not be used too much !)
189#   * add journal "Nature Geosciences"
190#   * add journal "International Journal of Climatology"
191#   * add journal "Journal of Hydrology"
192#   * add journal "Revue de l'Énergie"
193#   * add journal "Clim. Res."
194#   * add journal "Hydrol. Earth Sys. Sci."
195#   * add journal "Ambio"
196#   * add journal "Theoretical and applied climatology"
197#   * add journal "Remote Sensing of Environnement"
198#
199# - fplod 2008-10-28T11:40:19Z aedon.locean-ipsl.upmc.fr (Darwin)
200#
201#   * add journal "Progress In Oceanography"
202#   * add journal "Climatic Change"
203#   * add journal "Ocean Dynamics"
204#   * add journal "Phil. Trans. Roy. Soc. A"
205#   * add journal "Izvestiya Atmospheric and Oceanic Physics"
206#   * add journal "Journal of Hydrometeorology"
207#   * add journal "Remote Sensing of Environment"
208#   * add journal "Oceanology"
209#   * add journal "Water Resour. Res."
210#   * add journal "Advances in Atmospheric Sciences"
211#   * add journal "Quaternary Science Reviews"
212#   * replace "Elsevier Oceanography Series" by "Elsevier Oceanographic Series"
213#   * bug fix : unclosed date tag
214#   * trouble with flat conversion for id building ...
215#   * remove interactivity at then end (allowing redirection of stderr and
216#     stdout)
217#   * strip blank lines
218#   * bug fix : counting nb of occurences of "," technique ... to be improved
219#
220# - fplod 2008-09-16T15:19:59Z aedon.locean-ipsl.upmc.fr (Darwin)
221#
222#   * comments in ReStructured Text
223#
224# - fplod 2008-05-16T10:33:16Z aedon.locean-ipsl.upmc.fr (Darwin)
225#
226#   * add parameter -o for firstname/surname order in bibtex file
227#
228# - fplod 2008-05-15T15:15:04Z aedon.locean-ipsl.upmc.fr (Darwin)
229#
230#   * new way of processing bibtex file : external/bibtex2xml.py
231#
232# - fplod 2008-04-30T07:11:58Z aedon.locean-ipsl.upmc.fr (Darwin)
233#
234#   * chgt for dbk5 out
235#   * xmlto 0.0.18 does'nt like this docbook release. remove
236#   * usage of xml (xmlstarlet) for validation
237#   * bug fix
238#   * add journal names from demo1
239#   * fplod 2008-03-12T16:11:07Z aedon.locean-ipsl.upmc.fr (Darwin)
240#   * add -p option (to overide bibrefnemo in file name and id)
241#   * add -l option by default en
242#
243# - fplod 2008-03-11T11:25:27Z aedon.locean-ipsl.upmc.fr (Darwin)
244#
245#   * add bibtex entry (not finished)
246#
247# - fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin)
248#
249#   * <bibliomisc role="id"> replace by <biblioid class="doi">
250#
251# - smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
252#
253#   * Add journals
254#
255# - fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
256#
257#   * dernières touches
258#
259# - fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
260#
261#   * add a filein parameter and an option for mailbody
262#   * comments (line begininig with #) are now possible
263#
264# - Sebastien Masson avril 2007
265#
266#   * creation
267#
268#-
269
270rmbl () {
271    echo "${1}" | sed -e "s/^ *//" | sed -e "s/ *$//"
272}
273cleanname () {
274    echo "${1}" | sed -e "s/^ *//" \
275        -e "s/^ *,//" \
276        -e "s/^ *;//" \
277        -e "s/^ *\.//" \
278        -e "s/ *$//" \
279        -e "s/, *$//" \
280        -e "s/; *$//" \
281        -e "s/\. *$//"
282}
283#
284system=$(uname)
285case "${system}" in
286 AIX|IRIX64)
287  echo " www : no specific posix checking"
288 ;;
289 *)
290  set -o posix
291 ;;
292esac
293command=$(basename ${0})
294log_date=$(date -u +"%Y%m%dT%H%M%SZ")
295log=/tmp/$(basename ${command} .sh).log.${log_date}
296#
297# test if xsltproc is available
298tool=xsltproc
299type ${tool} 1> /dev/null 2>&1
300status=${?}
301if [ ${status} -ne 0 ]
302then
303 echo " eee : ${tool} not found"
304 exit 1
305fi
306unset status
307unset tool
308#
309# test if xml is available
310tool=xml
311type ${tool} 1> /dev/null 2>&1
312status=${?}
313if [ ${status} -ne 0 ]
314then
315 echo " eee : ${tool} not found"
316 exit 1
317fi
318unset status
319unset tool
320#
321# test if python is available
322tool=python
323type ${tool} 1> /dev/null 2>&1
324status=${?}
325if [ ${status} -ne 0 ]
326then
327 echo " eee : ${tool} not found"
328 exit 1
329fi
330unset status
331unset tool
332#
333# test if recode is available
334tool=recode
335type ${tool} 1> /dev/null 2>&1
336status=${?}
337if [ ${status} -ne 0 ]
338then
339 echo " eee : ${tool} not found"
340 exit 1
341fi
342unset status
343unset tool
344#
345usage=" Usage : ${command} -i filein -t type -o order -p project -l lang"
346#
347# default
348lang=en
349order="fs" # firstname surname
350#
351minargcount=6
352#echo " narg ${#}"
353if [ ${#} -lt ${minargcount} ]
354then
355   echo "eee : not enought arguments"
356   echo "${usage}"
357   exit 1
358fi
359unset minargcount
360#
361while [ ! -z "${1}" ]
362do
363 case ${1} in
364 -i) # filein
365  filein=${2}
366  shift
367 ;;
368 -t) # type
369  type=${2}
370  shift
371 ;;
372 -o) # order of firstname surname in bibtex file
373  order=${2}
374  shift
375 ;;
376 -p)
377  project=${2}
378  shift
379 ;;
380 -l)
381  lang=${2}
382  shift
383 ;;
384 -h)
385  echo "${usage}"
386  exit 0
387 ;;
388 *) # other choice
389  echo "${usage}"
390  exit 1
391 ;;
392 esac
393 shift # next flag
394done
395unset usage
396#
397set -u
398#
399# check for filein
400if [ ! -f ${filein} ]
401then
402   echo "eee : ${filein} not found"
403   exit 1
404fi
405#
406case ${type} in
407raw) # file like data/biball.txt
408 fileraw=${filein}
409 fileou=$( basename ${filein} .txt).xml
410;;
411mailbody) # file like data/mail2007-04-25T08:58:16Z.txt
412 fileraw=/tmp/$(basename ${filein}).raw
413 fileou=$( basename ${filein} .txt).xml
414 echo "# from ${filein}" > ${fileraw}
415 echo "# ${log_date}" >> ${fileraw}
416 echo "# corrections" >> ${fileraw}
417 grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
418 sed -e "s/correction_.*=//">> ${fileraw}
419 echo "# new references" >> ${fileraw}
420 awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
421 #more ${fileraw} # ++ if debug
422 #read a #++ if debug
423;;
424bibtex) # file like data/petitpoly.bib
425 fileraw=/tmp/$(basename ${filein}).raw
426 awk -f join_endcomma.awk ${filein} > ${fileraw}
427 fileou=$( basename ${filein} .bib).xml
428;;
429*)
430   echo "eee : type should be raw, mailbody or bibtex"
431   exit 1
432;;
433esac
434#
435# check for output
436if [ -f ${fileou} ]
437then
438   echo "eee : ${fileou} already exist"
439   exit 1
440fi
441#
442ij=1
443jlist[${ij}]="J. Climate"
444ij=$(( ${ij} + 1))
445jlist[${ij}]="Journal of Climate"
446ij=$(( ${ij} + 1))
447jlist[${ij}]="Ocean Modelling"
448ij=$(( ${ij} + 1))
449jlist[${ij}]="Geophys. Res. Lett."
450ij=$(( ${ij} + 1))
451jlist[${ij}]="J. Geophys. Res."
452ij=$(( ${ij} + 1))
453jlist[${ij}]="Tellus A"
454ij=$(( ${ij} + 1))
455jlist[${ij}]="Tellus B"
456ij=$(( ${ij} + 1))
457jlist[${ij}]="J. Phys. Oceanogr."
458ij=$(( ${ij} + 1))
459jlist[${ij}]="Clim. Dyn."
460ij=$(( ${ij} + 1))
461jlist[${ij}]="Clim. Res."
462ij=$(( ${ij} + 1))
463jlist[${ij}]="Climate Dynamics"
464ij=$(( ${ij} + 1))
465jlist[${ij}]="Dyn. Atmos. Oceans"
466ij=$(( ${ij} + 1))
467jlist[${ij}]="Mon. Wea. Rev."
468ij=$(( ${ij} + 1))
469jlist[${ij}]="Global Biogeochem. Cycles"
470ij=$(( ${ij} + 1))
471jlist[${ij}]="Nonlinear Processes in Geophysics"
472ij=$(( ${ij} + 1))
473jlist[${ij}]="Ocean Science"
474ij=$(( ${ij} + 1))
475jlist[${ij}]="J. Mar. Systems"
476ij=$(( ${ij} + 1))
477jlist[${ij}]="J. Atmos. Sc."
478ij=$(( ${ij} + 1))
479jlist[${ij}]="Proc. Royal Soc."
480ij=$(( ${ij} + 1))
481jlist[${ij}]="Bull. Amer. Meteorol. Soc."
482ij=$(( ${ij} + 1))
483jlist[${ij}]="Ocean Dyn."
484ij=$(( ${ij} + 1))
485jlist[${ij}]="Geophysical Monograph Series, Earth's Climate: The Ocean-Atmosphere Interaction"
486ij=$(( ${ij} + 1))
487jlist[${ij}]="Paleoceanography"
488ij=$(( ${ij} + 1))
489jlist[${ij}]="Annales Geophysicae"
490ij=$(( ${ij} + 1))
491jlist[${ij}]="Annals of Geophys."
492ij=$(( ${ij} + 1))
493jlist[${ij}]="Deep Sea Research Part II: Topical Studies in Oceanography"
494ij=$(( ${ij} + 1))
495jlist[${ij}]="Deep Sea Res. II"
496ij=$(( ${ij} + 1))
497jlist[${ij}]="Atmospheric Chemistry and Physics"
498ij=$(( ${ij} + 1))
499jlist[${ij}]="Atmospheric Chemistry and Physics Discussions"
500ij=$(( ${ij} + 1))
501jlist[${ij}]="Earth Plan. Sc. Lett."
502ij=$(( ${ij} + 1))
503jlist[${ij}]="J. Mar. Res."
504ij=$(( ${ij} + 1))
505jlist[${ij}]="PCMDI Report Series"
506ij=$(( ${ij} + 1))
507jlist[${ij}]="J. Mar. Syst."
508ij=$(( ${ij} + 1))
509jlist[${ij}]="Note du Pole de Modelisation"
510ij=$(( ${ij} + 1))
511jlist[${ij}]="Calculateurs Paralleles"
512ij=$(( ${ij} + 1))
513jlist[${ij}]="Note Scientifique du Pole de Modelisation"
514ij=$(( ${ij} + 1))
515jlist[${ij}]="Lecture Notes in Computer Science"
516ij=$(( ${ij} + 1))
517jlist[${ij}]="Prog. Oceanogr."
518ij=$(( ${ij} + 1))
519jlist[${ij}]="Deep Sea Research Part I: Oceanographic Research Papers"
520ij=$(( ${ij} + 1))
521jlist[${ij}]="Deep Sea Res. I"
522ij=$(( ${ij} + 1))
523jlist[${ij}]="IEEE Trans. Geosci. Remote Sensing"
524ij=$(( ${ij} + 1))
525jlist[${ij}]="ECMWF Tech. Memorandum"
526ij=$(( ${ij} + 1))
527jlist[${ij}]="J. Environ. Radioactivity"
528ij=$(( ${ij} + 1))
529jlist[${ij}]="Int. WOCE Newsletter"
530ij=$(( ${ij} + 1))
531jlist[${ij}]="C. R. Acad. Sci. Paris"
532ij=$(( ${ij} + 1))
533jlist[${ij}]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
534ij=$(( ${ij} + 1))
535jlist[${ij}]="In The mathematics of models for climatology and environment"
536ij=$(( ${ij} + 1))
537jlist[${ij}]="Oceanol. Acta"
538ij=$(( ${ij} + 1))
539jlist[${ij}]="The global atmosphere and ocean system"
540ij=$(( ${ij} + 1))
541jlist[${ij}]="NATO Advanced Study Institute"
542ij=$(( ${ij} + 1))
543jlist[${ij}]="WCRP"
544ij=$(( ${ij} + 1))
545jlist[${ij}]="The Courier"
546ij=$(( ${ij} + 1))
547jlist[${ij}]="Elsevier Oceanography Series"
548ij=$(( ${ij} + 1))
549jlist[${ij}]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
550ij=$(( ${ij} + 1))
551jlist[${ij}]="In Science and engineering on Cray Supercomputers"
552ij=$(( ${ij} + 1))
553jlist[${ij}]="In Modeling the Earth's Climate and its Variability"
554ij=$(( ${ij} + 1))
555jlist[${ij}]="Fish. Oceanogr."
556ij=$(( ${ij} + 1))
557jlist[${ij}]="Q. J. R. Meteor. Soc."
558ij=$(( ${ij} + 1))
559jlist[${ij}]="In High performance computing in the geosciences"
560ij=$(( ${ij} + 1))
561jlist[${ij}]="Int. J. Numer. Meth. in Fluids"
562ij=$(( ${ij} + 1))
563jlist[${ij}]="Lecture notes in Physics"
564ij=$(( ${ij} + 1))
565jlist[${ij}]="J. Meterol. Soc. Japan"
566ij=$(( ${ij} + 1))
567jlist[${ij}]="Journal of Marine Systems"
568ij=$(( ${ij} + 1))
569jlist[${ij}]="Canadian Journal of Fisheries and Aquatic Sciences"
570ij=$(( ${ij} + 1))
571jlist[${ij}]="J. Atmos. Ocean. Tech."
572ij=$(( ${ij} + 1))
573jlist[${ij}]="EOS"
574ij=$(( ${ij} + 1))
575jlist[${ij}]="Nature"
576ij=$(( ${ij} + 1))
577jlist[${ij}]="Nature Geosciences"
578ij=$(( ${ij} + 1))
579jlist[${ij}]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
580ij=$(( ${ij} + 1))
581jlist[${ij}]="Journal of Atmospheric and Oceanic Technology"
582ij=$(( ${ij} + 1))
583jlist[${ij}]="Lecture Notes in Computational Science Engineering"
584ij=$(( ${ij} + 1))
585jlist[${ij}]="In Greenhouse Gas Control Technologies"
586ij=$(( ${ij} + 1))
587jlist[${ij}]="Chemical Geology"
588ij=$(( ${ij} + 1))
589jlist[${ij}]="Marine Geology"
590ij=$(( ${ij} + 1))
591jlist[${ij}]="Developments in Paleoenvironmental Research"
592ij=$(( ${ij} + 1))
593jlist[${ij}]="Science"
594ij=$(( ${ij} + 1))
595jlist[${ij}]="In Mediterranean Climate Variability"
596ij=$(( ${ij} + 1))
597jlist[${ij}]="Global and Planetary Change"
598ij=$(( ${ij} + 1))
599jlist[${ij}]="Physical Review Letters"
600ij=$(( ${ij} + 1))
601jlist[${ij}]="Progress In Oceanography"
602ij=$(( ${ij} + 1))
603jlist[${ij}]="Climatic Change"
604ij=$(( ${ij} + 1))
605jlist[${ij}]="Ocean Dynamics"
606ij=$(( ${ij} + 1))
607jlist[${ij}]="Phil. Trans. Roy. Soc. A"
608ij=$(( ${ij} + 1))
609jlist[${ij}]="Phil. Trans. Roy. Soc. B"
610ij=$(( ${ij} + 1))
611jlist[${ij}]="Izvestiya Atmospheric and Oceanic Physics"
612ij=$(( ${ij} + 1))
613jlist[${ij}]="Journal of Hydrometeorology"
614ij=$(( ${ij} + 1))
615jlist[${ij}]="Journal of Hydrology"
616ij=$(( ${ij} + 1))
617jlist[${ij}]="Remote Sensing of Environment"
618ij=$(( ${ij} + 1))
619jlist[${ij}]="Oceanology"
620ij=$(( ${ij} + 1))
621jlist[${ij}]="Water Resour. Res."
622ij=$(( ${ij} + 1))
623jlist[${ij}]="Water Resources Research"
624ij=$(( ${ij} + 1))
625jlist[${ij}]="Advances in Atmospheric Sciences"
626ij=$(( ${ij} + 1))
627jlist[${ij}]="Quaternary Science Reviews"
628ij=$(( ${ij} + 1))
629jlist[${ij}]="AGU monograph Ocean Circulation Mechanisms and Impacts"
630ij=$(( ${ij} + 1))
631jlist[${ij}]="Climate Research"
632ij=$(( ${ij} + 1))
633jlist[$ij]="Colloque du GIS « Climat-Environnement-Sociétés »"
634ij=$(( ${ij} + 1))
635jlist[$ij]="Agricultural and Forest Meteorology"
636ij=$(( ${ij} + 1))
637jlist[$ij]="VIIth IAHS Scientific Assembly"
638ij=$(( ${ij} + 1))
639jlist[$ij]="AGU fall Meeting"
640ij=$(( ${ij} + 1))
641jlist[$ij]="4th Alexander Von Humboldt International Conference"
642ij=$(( ${ij} + 1))
643jlist[$ij]="International Journal of Climatology"
644ij=$(( ${ij} + 1))
645jlist[$ij]="Revue de l'Énergie"
646ij=$(( ${ij} + 1))
647jlist[$ij]="Hydrol. Earth Sys. Sci."
648ij=$(( ${ij} + 1))
649jlist[$ij]="Ambio"
650ij=$(( ${ij} + 1))
651jlist[$ij]="Theoretical and applied climatology"
652ij=$(( ${ij} + 1))
653jlist[$ij]="Remote Sensing of Environnement"
654ij=$(( ${ij} + 1))
655jlist[$ij]="PNAS"
656ij=$(( ${ij} + 1))
657jlist[$ij]="Lettre PIGB-PMRC"
658ij=$(( ${ij} + 1))
659jlist[$ij]="High Performance Computing in Science and Engineering"
660ij=$(( ${ij} + 1))
661jlist[$ij]="Annals of Glaciology"
662ij=$(( ${ij} + 1))
663jlist[$ij]="Journal of Physical Oceanography"
664ij=$(( ${ij} + 1))
665jlist[$ij]="??"
666#
667# following Journal name are fake ones for demo1 : references extracted from
668# Cantratrix Sopronica L. written by Georges Perec
669#find in http://www-rocq.inria.fr/who/Marc.Thiriet/PsFil/Biblio/cantatrix.ps
670ij=$(( ${ij} + 1))
671jlist[$ij]="Res. Proc. neurophysiol. Fanatic Soc."
672ij=$(( ${ij} + 1))
673jlist[$ij]="New Records Ass. J."
674ij=$(( ${ij} + 1))
675jlist[$ij]="Am. J. Allegrol."
676ij=$(( ${ij} + 1))
677jlist[$ij]="J. Neurochem. Neurocytol. Enzymol."
678ij=$(( ${ij} + 1))
679jlist[$ij]="Hammersmith J."
680ij=$(( ${ij} + 1))
681jlist[$ij]="Nasa Rept."
682ij=$(( ${ij} + 1))
683jlist[$ij]="C.r. Assoc. Conc. Lam."
684ij=$(( ${ij} + 1))
685jlist[$ij]="Gaz. med. franco-rus."
686ij=$(( ${ij} + 1))
687jlist[$ij]="Amer. J. music. Deciency"
688#
689# strip comments and blank lines
690fileraw_strict=/tmp/$(basename ${fileraw})_strict
691grep -v "^#" ${fileraw} | grep -v "^%" | sed "/^$/d" > ${fileraw_strict}
692# following line is not compatible with XML header ++
693# comments for memory (why did I write this line !?)
694# iconv -f ISO-8859-1 -t UTF-8 ${fileraw_strict} > ${fileraw_strict}2
695# mv ${fileraw_strict}2 ${fileraw_strict}
696case ${type} in
697bibtex)
698 fileou_bibtexml=/tmp/$(basename ${fileraw})_bibtexml
699 python ./external/bibtex2xml.py ${fileraw_strict} > ${fileou_bibtexml}
700#more ${fileou_bibtexml}
701#read a
702 xsltproc --output ${fileou} \
703 --param lang "'${lang}'" \
704 --param project "'${project}'" \
705 --param makedate "'${log_date}'" \
706 --param order "'${order}'" \
707 bibtexml2dbk.xsl ${fileou_bibtexml}
708 rm ${fileou_bibtexml}
709;;
710*)
711    cat <<EOF > ${fileou}
712<?xml version='1.0' encoding='ISO-8859-1'?>
713<bibliography
714version="5.0"
715xmlns="http://docbook.org/ns/docbook"
716xml:id="bib${project}ref"
717xml:lang="${lang}">
718
719<info>
720<date>${log_date}</date>
721</info>
722EOF
723totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
724l=1
725while [ ${l} -le ${totlines}  ]
726do
727# extract one line
728  line=$( sed -n ${l}p ${fileraw_strict} )
729  orgline=$( echo ${line} | sed -e "s/--/- -/g" )
730  line=$( echo ${line} | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" )
731     # parsing non bibtex line
732     bibtex=0
733     # before the first :
734       tmp=${line%%:*}
735     # before the last ,
736       auths=${tmp%,*},
737     # replace " and " by ","
738       auths=$( echo "${auths}" | sed -e "s/ and /,/g" )
739     # replace " et " by ","
740       auths=$( echo "${auths}" | sed -e "s/ et /,/g" )
741     # after the last ,
742       year=${tmp##*,}
743       year=$( rmbl "${year}" )
744     ## first author before the first .,
745       first=${auths%%.,*}.
746     # its firstname after the last ,
747       firstfn=${first##*,}
748       firstfn=$( rmbl "${firstfn}" )
749     # its surname ; before the first ,
750       firstsn=${first%%,*}
751       firstsn=$( rmbl "${firstsn}" )
752     ## ref id
753       firstsn_flat=$( echo "${firstsn}" | recode -d -f ISO-8859-15..flat )
754       # echo "firstsn : ${firstsn}" # ++ debug
755       # echo "firstsn_flat : ${firstsn_flat}" #++ debug
756       # test if no encoding problem after ISO-8859-15 to flat conversion
757       firstsn_test1=$(echo "${firstsn_flat}" | tr -d "[:alpha:]" | tr -d " " | tr -d "'" | tr -d "-")
758       #echo "firstsn_test1 : ${firstsn_test1}" # ++ debug
759       if [ ! -z "${firstsn_test1}" ]
760       then
761        echo "www : pb on ISO-8859-15 to flat conversion"
762        echo "www : on ${firstsn}"
763        echo "www : trying UTF-8 to flat conversion ..."
764        firstsn_flat=$( echo "${firstsn}" | recode -d -f UTF-8..flat )
765        # test if no encoding problem after UTF-8 to flat conversion
766        firstsn_test2=$(echo "${firstsn_flat}" | tr -d "[:alpha:]" | tr -d " " | tr -d "'")
767        #echo "firstsn_test2 : A${firstsn_test2}A" # ++ debug
768        if [ ! -z "${firstsn_test2}" ]
769        then
770         echo "eee : pb on flat conversion of ${firstsn}"
771         exit 1
772        fi
773       fi
774       firstsn_lower=$( echo "${firstsn_flat}" | tr "[:upper:]" "[:lower:]")
775       firstsn_nopunct=$( echo "${firstsn_lower}" | tr -s " " "_"  | tr -s "'" "_")
776       refid="${firstsn_nopunct}${year}"
777       unset firstsn_lower
778       unset firstsn_flat
779       unset firstsn_test1
780       unset firstsn_test2
781       num=$( grep -c "<biblioentry xml:id=\"${refid}_[0-9][0-9]\">" ${fileou} )
782       num=$(( ${num} + 1 ))
783       [ ${num} -le 9 ] && num=0${num}
784       refid=${refid}_${num}
785       hasauthor=1
786
787          cat <<EOF >> ${fileou}
788<biblioentry xml:id="${refid}">
789  <!-- date
790  $( date -u +"%Y%m%dT%H%M%SZ" )
791  -->
792  <!-- original text
793  ${orgline}
794  -->
795EOF
796      if [ ${hasauthor} -eq 1 ]
797      then
798          cat <<EOF >> ${fileou}
799  <authorgroup>
800    <author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author>
801EOF
802
803## other authors..
804  if [ ${bibtex} -eq 0 ]
805  then
806   previous=${first},
807   # next authors...
808   next=${auths##*${previous}}
809  fi
810  if [ ${bibtex} -eq 1 ]
811  then
812   previous=${first}"and "
813   # next authors...
814   #echo "auths ${auths}"
815   next=${auths##*${previous}}
816   if [ "${next}and " = "${previous}" ]
817   then
818     next=""
819   fi
820  fi
821  #echo "previous ${previous}"
822  #echo "next ${next}"
823# while the next author is not empty
824  while [  "${next}" != "" ]
825    do
826      if [ ${bibtex} -eq 0 ]
827      then
828         # get the first next author; before the first ,
829         next=${next%%,*}
830         # its surname ; after the last .
831         nextsn=${next##*.}
832         nextsn=$( rmbl "${nextsn}" )
833         # its firstname ; before the last .
834         nextfn=${next%.*}.
835         nextfn=$( rmbl "${nextfn}" )
836       fi
837      if [ ${bibtex} -eq 1 ]
838      then
839         # get the first next author; before the first "and"
840         next=${next%%and *}
841         # its surname after the last " "  ++ pas vrai double nom et pb blanc dans la syntaxe
842         # nextsn=${next##* } . ok en interactif . pas ok en script
843         nextsn=$( echo ${next}  | awk '{print $2}')
844         #echo "nextsn $nextsn"
845         # its nextname before the first " "
846         nextfn=${next%% *}
847      fi
848#
849    echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou}
850    #echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>"  #++debug
851    if [ ${bibtex} -eq 0 ]
852    then
853      previous=${next},
854      next=${auths##*${previous}}
855    fi
856    if [ ${bibtex} -eq 1 ]
857    then
858      previous=${next}"and "
859      next=${auths##*${previous}}
860    fi
861  done
862  echo "  </authorgroup>"  >> ${fileou}
863  fi
864
865# end of the line ; after the first :
866  endline=${line#*:}
867## find the journal
868  j=1
869  jfound=""
870  jlistsize=${#jlist[@]}
871  while [[ ${j} -le ${jlistsize} && "${jfound}" == "" ]]
872    do
873    ok=$( echo ${endline} | grep -ci "${jlist[j]} *," )
874    [ ${ok} -eq 1 ] && jfound="${jlist[j]}"
875    j=$(( ${j} + 1 ))
876  done
877  unset ok
878  if [ "${jfound}" == "" ]
879      then
880      echo "eee: Journal not found "
881      echo "${endline}"
882      # uncomment next line for debug
883      # set # ++ debug
884      exit 1
885#+++ following lines are not yet validate
886      # it might be a book, a manual, a conference, etc. ++
887      echo "  <title>${title}</title>" >> ${fileou}
888          cat <<EOF >> ${fileou}
889  <biblioset relation="nojournal">
890    <title>${title}</title>
891    <pagenums>${pag}</pagenums>
892    <pubdate>${year}</pubdate>
893  </biblioset>
894EOF
895          cat <<EOF >> ${fileou}
896</biblioentry>
897
898EOF
899  fi # end of if jfound empty (ie not an article)
900  if [ "${jfound}" != "" ]
901  then
902## title
903# before the first :
904  title=${endline%%${jfound}*}
905  title=$( cleanname "${title}" )
906  echo "  <title>${title}</title>" >> ${fileou}
907## end
908## end of the line ; after the first ${jfound}
909  endline=${endline#*${jfound}}
910  endline=$( cleanname "${endline}" )
911## doi
912  endline=$( echo ${endline} | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
913  #echo "endline for doi ${endline}"
914  ok=$( echo ${endline} | grep -ic "doi:" )
915  if [ ${ok} -eq 1 ]
916  then
917      doi=${endline##*doi:}
918      #echo "doi : $doi"
919      echo "  <biblioid class=\"doi\">${doi}</biblioid>" >> ${fileou}
920      unset doi
921      endline=${endline%doi:*}
922      endline=$( cleanname "${endline}" )
923  else
924      echo "non doi: ${line}"
925      echo ""
926  fi
927  num=$( echo "${endline}" |  tr -dc "," | wc -c | tr -d " ")
928  case "${num}" in
929      0)
930### echo ${num}: ${endline}
931          cat <<EOF >> ${fileou}
932  <biblioset relation="journal">
933    <title>${jfound}</title>
934    <pubdate>${year}</pubdate>
935    <bibliomisc>${endline}</bibliomisc>
936  </biblioset>
937EOF
938          unset jfound
939          unset year
940      ;;
941
942      1)
943### echo ${num}: ${endline}
944          vol=${endline%,*}
945          vol=$( cleanname "${vol}" )
946          pag=${endline##*,}
947          pag=$( cleanname "${pag}" )
948          cat <<EOF >> ${fileou}
949  <biblioset relation="journal">
950    <title>${jfound}</title>
951    <volumenum>${vol}</volumenum><pagenums>${pag}</pagenums>
952    <pubdate>${year}</pubdate>
953  </biblioset>
954EOF
955          unset vol
956          unset pag
957          unset jfound
958          unset year
959      ;;
960      2)
961          vol=${endline%,*}
962          vol=$( cleanname "${vol}" )
963          iss=${vol##*,}
964          iss=$( cleanname "${iss}" )
965          vol=${vol%,*}
966          vol=$( cleanname "${vol}" )
967          pag=${endline##*,}
968          pag=$( cleanname "${pag}" )
969          cat <<EOF >> ${fileou}
970  <biblioset relation="journal">
971    <title>${jfound}</title>
972    <volumenum>${vol}</volumenum><issuenum>${iss}</issuenum><pagenums>${pag}</pagenums>
973    <pubdate>${year}</pubdate>
974  </biblioset>
975EOF
976          unset vol
977          unset pag
978          unset jfound
979          unset year
980          unset iss
981      ;;
982      6)
983          conftitle=${endline%%,*}
984          endline=${endline#*,}
985          confdates=${endline%%,*} # day(s) month
986          endline=${endline#*,}
987          confdates="${confdates}, ${endline%%,*}" # day(s) month and year
988          confdates=$( cleanname "${confdates}" )
989          endline=${endline#*,}
990          confaddress=${endline%%,*} # Town
991          endline=${endline#*,}
992          confaddress="${confaddress}, ${endline%%,*}" # Town and country
993          confaddress=$( cleanname "${confaddress}" )
994          endline=${endline#*,}
995          publishername=${endline%%,*}
996          publishername=$( cleanname "${publishername}" )
997          endline=${endline#*,}
998          pag=${endline##*,}
999          pag=$( cleanname "${pag}" )
1000#set
1001#read a
1002          cat <<EOF >> ${fileou}
1003<biblioset relation="conference">
1004 <title>${jfound}</title>
1005 <pubdate>${year}</pubdate>
1006 <publisher><publishername>${publishername}</publishername></publisher>
1007 <pagenums>${pag}</pagenums>
1008 <confgroup>
1009  <conftitle>${conftitle}</conftitle>
1010  <confdates>${confdates}</confdates>
1011  <address>${confaddress}</address>
1012 </confgroup>
1013</biblioset>
1014EOF
1015      unset confaddress
1016      unset conftitle
1017      unset confdates
1018      unset pag
1019      unset publishername
1020      unset year
1021      unset jfound
1022      ;;
1023      10)
1024          publishername=${endline%%Editors,*}
1025          publishername="${publishername} Editors"
1026          publishername=$( cleanname "${publishername}" )
1027          endline=${endline#*Editors,}
1028          vol=${endline%%,*}
1029          vol=$( cleanname "${vol}" )
1030          endline=${endline#*,}
1031          pag=${endline%%,*}
1032          pag=$( cleanname "${pag}" )
1033          endline=${endline#*,}
1034          isbn=${endline%%,*}
1035          isbn=$(echo ${isbn} | sed -e "s/ISBN ://")
1036          isbn=$( cleanname "${isbn}" )
1037          endline=${endline#*,}
1038          agu=${endline%%,*}
1039          agu=$(echo ${agu} | sed -e "s/AGU ://")
1040          agu=$( cleanname "${agu}" )
1041
1042          endline=${endline#*${agu}}
1043          endline=$( cleanname "${endline}" )
1044          endline=$( cleanname "${endline}" )
1045
1046          cat <<EOF >> ${fileou}
1047  <biblioid class="isbn">${isbn}</biblioid>
1048  <biblioid class="other" otherclass="AGU">${agu}</biblioid>
1049  <biblioset relation="journal">
1050    <title>${jfound}</title>
1051    <pubdate>${year}</pubdate>
1052    <publisher><publishername>${publishername}</publishername></publisher>
1053    <volumenum>${vol}</volumenum>
1054    <pagenums>${pag}</pagenums>
1055    <bibliomisc>${endline}</bibliomisc>
1056  </biblioset>
1057EOF
1058      unset isbn
1059      unset agu
1060      unset pag
1061      unset publishername
1062      unset year
1063      unset jfound
1064      unset vol
1065
1066      ;;
1067      *)
1068#echo "${num}: ${endline}" # ++debug
1069#set # ++ debug
1070#exit 1 #++ debug
1071          cat <<EOF >> ${fileou}
1072  <biblioset relation="journal">
1073    <title>${jfound}</title>
1074    <pubdate>${year}</pubdate>
1075    <bibliomisc>${endline}</bibliomisc>
1076  </biblioset>
1077EOF
1078      ;;
1079  esac
1080
1081          cat <<EOF >> ${fileou}
1082</biblioentry>
1083
1084EOF
1085  fi # end of if jfound not empty
1086  unset title
1087  unset vol
1088  unset year
1089  unset pag
1090  l=$(( ${l} + 1 ))
1091
1092done
1093unset totlines
1094unset l
1095echo "</bibliography>" >> ${fileou}
1096;;
1097esac # end of case bibtex vs other for processing
1098
1099xml val --err \
1100        --xsd http://www.docbook.org/xml/5.0/xsd/docbook.xsd \
1101        ${fileou} 1> xmlstarlet.log 2>&1
1102
1103# clean
1104echo "iii : xslstarlet.log contains sdtout and stderr from xml command on ${fileou}"
1105echo "iii : which was done just to check consistence of ${fileou}"
1106more xmlstarlet.log
1107#
1108case ${type} in
1109raw)
1110 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
1111;;
1112mailbody)
1113 echo "iii : ${fileraw} contains a copy of input file"
1114 echo "iii : ${fileraw_strict} contains a copy of input file without comments"
1115;;
1116esac
1117#
1118echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
1119echo " iii : you can add them in ${fileou}" #++ filename path
1120echo " iii : modify date in ${fileou}" #++ filename path
1121echo " iii : but please take care of id last part (after underscore) that may"
1122echo " 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.
1123#
1124exit 0
Note: See TracBrowser for help on using the repository browser.