#!/bin/bash
#+
#
# .. _bibopa.sh:
#
# .. program:: bibopa.sh
#
# =========
# bibopa.sh
# =========
#
# SYNOPSIS
# ========
#
# .. code-block:: bash
#
#    bibopa.sh -tmpdir tmpdir -i filein -e encoding -ti typein -o order -p project -l lang -to typeout
#
# DESCRIPTION
# ===========
#
# .. option:: -tmpdir   <tmpdir>
# .. option:: -i   <filein>
# .. option:: -ti  <typein>
# .. option:: -e   <encoding>
#
#                   default is encoding="iso-8859-1"
#
# .. option:: -o   <order>
# .. option:: -p   <project>
# .. option:: -l   <lang>
# .. option:: -to  <typeout>
#
# transform a bibliography file in XML/DocBook 5 format
#
# Each entry in the same input file must follows the same order for authors
# except the first one.
#
# With ``fs`` in option :option:`-o order` you will correctly process raw entry with
# firstname and surname in this order for authors except the first one.
#
# If raw entry uses surname and firstname order, you should use ``sf``.
#
# .. parsed-literal::
#
#    Behera, S. K., J. Luo, S. Masson, S. Rao, S. Gualdi, P. Delecluse, A.
#    Navarra and T. Yamagata, 2004 : Paramount Impact of the Indian Ocean
#    Dipole on the East African Short Rains: A CGCM Study, J. Climate, In
#    press.
#
# donnerait
#
# .. parsed-literal::
#
#    <biblioentry xml:id="behara2004">
#    <authorgroup>
#    <author><surname>Behera</surname> <firstname>S. K.</firstname> </author>
#    <author><firstname>J.</firstname> <surname>Luo</surname></author>
#    <author><firstname>S.</firstname> <surname>Masson</surname></author>
#    <author><firstname>S.</firstname> <surname>Rao</surname></author>
#    <author><firstname>S.</firstname> <surname>Gualdi</surname></author>
#    <author><firstname>P.</firstname> <surname>Delecluse</surname></author>
#    <author><firstname>A.</firstname> <surname>Navara</surname></author>
#    <author><firstname>T.</firstname> <surname>Yamagata</surname></author>
#    </authorgroup>
#    <date>2004</date>
#    <title>Paramount Impact of the Indian Ocean Dipole on the East African
#    Short Rains: A CGCM Study</title>
#    <publishername>J. Climate</publishername>
#    <biblioid class="doi">doi</biblioid>
#    <bibliomisc role="pseudoref">In press.</bibliomisc>
#    <bibliomisc role="internalref">from
#    http://www.lodyc.jussieu.fr/~opatlod/NEMO_v1/6_Menu/2_page/index.html
#    2007-03-29T16:24:31Z fplod by hand</bibliomisc>
#    </biblioentry>
#
# .. parsed-literal::
#
#    @book{MetReiCoh2004 ,
#      author    = {Michael Metcalf and
#              John Reid and Malcolm Cohen},
#      title     = {Fortran 95/2003 explained},
#      year      = {2004},
#      publisher = {Oxford University Press},
#      edition   = {Third},
#      ISBN      = {0-19-852693-8},
#      pages = {434}
#    }
#
# donnerait
#
# .. parsed-literal::
#
#    <biblioentry xml:id="MetReiCoh2004">
#    <authorgroup>
#    <author><firstname>Michael</firstname> <surname>Metcalf</surname></author>
#    <author><firstname>John</firstname> <surname>Reid</surname></author>
#    <author><firstname>Malcolm</firstname> <surname>Cohen</surname></author>
#    </authorgroup>
#    <date>2004}</date>
#    <title>Fortran 95/2003 explained</title>
#    <publisher><publishername>Oxford University Press</publishername></publisher>
#    <biblioid class="isbn">0-19-852693-8</biblioid>
#    <pagenums>434</pagenums>
#    <edition>Third</edition>
#
# EXAMPLES
# ========
#
# To transform the NEMO bibliography file written in raw format to XML/DocBook:
#
# .. code-block:: bash
#
#   bibopa.sh -tmpdir /tmp -p birefnemo -i data/biball.txt -ti raw
#
# To transform a bibliography file written mailbody format to XML/DocBook:
#
# .. code-block:: bash
#
#    bibopa.sh -tmpdir /tmp -p bibrefnemo -i data/mail2007-05-10T09:01:56Z -ti mailbody
#
# To transform a bibliography file written in bibtex format in french to XML/DocBook:
#
# .. code-block:: bash
#
#    bibopa.sh -tmpdir /tmp -p polyfortran -i data/petitpolyfp.bib -ti bibtex -l fr
#
# To transform the SUPERBIB demo bibliography file written in raw format to XML/DocBook:
#
# .. code-block:: bash
#
#    bibopa.sh -tmpdir /tmp -p demo1 -i data/bibdemo1.txt -ti raw -l fr
#
# Less official but possible:
#
# To transform the NEMO bibliography file written in raw format to bibtex:
#
# .. code-block:: bash
#
#    bibopa.sh -tmpdir /tmp -p nemo -ti raw -to bib -i bibnemo.txt
#
# SEE ALSO
# ========
#
# :ref:`mailtouser.sh`
#
# TODO
# ====
#
# gestion des comments
#
# gestion des id existants (cf à la fin)
#
# option debug
#
# should use iconv instead of recode
# for portability issue but not found yet the "flat" functionality in
# iconv
# tips 20101006 : iconv: //TRANSLIT feature not documented cf.
# http://www.gnu.org/software/libiconv/documentation/libiconv/iconv_open.3.html
# not already used because non-standard usage
#
# write something in the logfile !
#
# handle fully written firstnames like in:
#
# .. parsed-literal::
#
#    Tsimplis, Michael, Marta Marcos, Jeanne Colin, Samuel Somot, Ananda Pascual, A.G.P. Shaw, 2009 : Sea level variability in the Mediterranean Sea during the 1990s on the basis of two 2d and one 3d model, Journal of Marine Systems, 78, 1, 109-123, doi:10.1016/j.jmarsys.2009.04.003
#
# EVOLUTIONS
# ==========
#
# $Id$
#
# - fplod 20131017T085825Z callisto.locean-ipsl.upmc.fr (Linux)
#
#   * add tmpdir argument
#   * dynamic xmlstarlet vs xml
#   * add journal "Earth and Planetary Sciences, série IIa, Paris,"
#     (nb : diacritics tricks)
#
# - fplod 20130423T143122Z cratos.locean-ipsl.upmc.fr (Linux)
#
#   * add encoding option for input file (too tricky to be implemented see
#     http://stackoverflow.com/questions/805418/how-to-find-encoding-of-a-file-in-unix-via-scripts)
#
# - fplod 20120227
#
#   * xmlstarlet vs xml
#
# - fplod 20101006T113902Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add "Remote Sensing Env."
#   * add "Ocean Sciences"
#   * add "Dynamics of Atmospheres and Oceans"
#   * add "Comptes Rendus Geoscience"
#   * add "Marine Pollution Bulletin"
#   * add "Continental Shelf Research"
#   * add ""Ocean Sci."
#   * add "Environmental Fluid Mechanics"
#   * add "Geochem. Geophys. Geosyst."
#   * add "Journal of Applied Meteorology and Climatology"
#   * add "Monthly Weather Review"
#   * add "High Performance Computing on Vector Systems 2007"
#   * add "High Performance Computing on Vector Systems 2006"
#   * add "High Performance Computing in Science and Engineering '08"
#   * add "Developments in Earth and Environmental Sciences"
#   * add "Oceanography"
#
# - fplod 20101006T100532Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * bug fix (misplaced EOF)
#   * replace -t option by -ti
#   * add -to (typeout) option (by default dbk)
#   * add bibtex production
#
# - fplod 2009-03-13T09:35:42Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add "High Performance Computing in Science and Engineering"
#   * add "Annals of Glaciology"
#   * add "Journal of Physical Oceanography"
#
# - fplod 2009-01-15T10:36:18Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add description of ``-o`` option
#   * add journal "PNAS"
#   * add journal "Lettre PIGB-PMRC"
#
# - fplod 2009-01-14T15:27:48Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add journal "Water Resources Research"
#   * add journal "Climate Research"
#   * add conf "Colloque du GIS « Climat-Environnement-Sociétés »"
#   * add journal "Agricultural and Forest Meteorology"
#   * add conf "VIIth IAHS Scientific Assembly"
#   * add conf "AGU fall Meeting"
#   * add journal "Phil. Trans. Roy. Soc. B"
#   * add journal "Phil. Trans. Roy. Soc. B"
#   * add conf "4th Alexander Von Humboldt International Conference"
#   * add journal/conf "??" (Should not be used too much !)
#   * add journal "Nature Geosciences"
#   * add journal "International Journal of Climatology"
#   * add journal "Journal of Hydrology"
#   * add journal "Revue de l'Énergie"
#   * add journal "Clim. Res."
#   * add journal "Hydrol. Earth Sys. Sci."
#   * add journal "Ambio"
#   * add journal "Theoretical and applied climatology"
#   * add journal "Remote Sensing of Environnement"
#
# - fplod 2008-10-28T11:40:19Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add journal "Progress In Oceanography"
#   * add journal "Climatic Change"
#   * add journal "Ocean Dynamics"
#   * add journal "Phil. Trans. Roy. Soc. A"
#   * add journal "Izvestiya Atmospheric and Oceanic Physics"
#   * add journal "Journal of Hydrometeorology"
#   * add journal "Remote Sensing of Environment"
#   * add journal "Oceanology"
#   * add journal "Water Resour. Res."
#   * add journal "Advances in Atmospheric Sciences"
#   * add journal "Quaternary Science Reviews"
#   * replace "Elsevier Oceanography Series" by "Elsevier Oceanographic Series"
#   * bug fix : unclosed date tag
#   * trouble with flat conversion for id building ...
#   * remove interactivity at then end (allowing redirection of stderr and
#     stdout)
#   * strip blank lines
#   * bug fix : counting nb of occurrences of "," technique ... to be improved
#
# - fplod 2008-09-16T15:19:59Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * comments in reStructuredText
#
# - fplod 2008-05-16T10:33:16Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add parameter -o for firstname/surname order in bibtex file
#
# - fplod 2008-05-15T15:15:04Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * new way of processing bibtex file : external/bibtex2xml.py
#
# - fplod 2008-04-30T07:11:58Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * chgt for dbk5 out
#   * xmlto 0.0.18 does'nt like this docbook release. remove
#   * usage of xml (xmlstarlet) for validation
#   * bug fix
#   * add journal names from demo1
#   * fplod 2008-03-12T16:11:07Z aedon.locean-ipsl.upmc.fr (Darwin)
#   * add -p option (to overide bibrefnemo in file name and id)
#   * add -l option by default en
#
# - fplod 2008-03-11T11:25:27Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * add bibtex entry (not finished)
#
# - fplod 2007-06-20T17:18:02Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * <bibliomisc role="id"> replace by <biblioid class="doi">
#
# - smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
#
#   * Add journals
#
# - fplod 2007-05-10T09:17:09Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * dernières touches
#
# - fplod 2007-04-25T10:59:49Z cerbere.locean-ipsl.upmc.fr (Linux)
#
#   * add a filein parameter and an option for mailbody
#   * comments (line beginning with #) are now possible
#
# - Sebastien Masson avril 2007
#
#   * creation
#
#-

rmbl () {
    echo "${1}" | sed -e "s/^ *//" | sed -e "s/ *$//"
}
cleanname () {
    echo "${1}" | sed -e "s/^ *//" \
    -e "s/^ *,//" \
    -e "s/^ *;//" \
    -e "s/^ *\.//" \
    -e "s/ *$//" \
    -e "s/, *$//" \
    -e "s/; *$//" \
    -e "s/\. *$//"
}
#
system=$(uname)
case "${system}" in
    AIX|IRIX64)
        echo " www : no specific posix checking"
    ;;
    Darwin)
    ;;
    *)
        set -o posix
    ;;
esac
unset system
#
set -u
#
command=$(basename ${0})
log_date=$(date -u +"%Y%m%dT%H%M%SZ")
log=/tmp/$(basename ${command} .sh).log.${log_date}
#
# test if xsltproc is available
tool=xsltproc
type ${tool} 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
    echo " eee : ${tool} not found"
    exit 1
fi
unset status
unset tool
#
# test if xml is available
tool=${xmlcmd}
type ${tool} 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
    echo " eee : ${tool} not found"
    exit 1
fi
unset status
unset tool
#
# test if python is available
tool=python
type ${tool} 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
    echo " eee : ${tool} not found"
    exit 1
fi
unset status
unset tool
#
# test if recode is available
tool=recode
type ${tool} 1> /dev/null 2>&1
status=${?}
if [ ${status} -ne 0 ]
then
    echo " eee : ${tool} not found"
    exit 1
fi
unset status
unset tool
#
usage=" Usage : ${command} -tmpdir tmpdir -i filein -ti typein -e encoding -o order -p project -l lang -to typeout"
#
# default
lang=en
# fs mean "firstname surname"
order="fs"
typeout="dbk"
encoding="iso-8859-1"
tmpdir="/tmp"
#
minargcount=8
#echo " narg ${#}"
if [ ${#} -lt ${minargcount} ]
then
    echo "eee : not enough arguments"
    echo "${usage}"
    exit 1
fi
unset minargcount
#
while [ ${#} -gt 0 ]
do
    case ${1} in
        -tmpdir)
            tmpdir=${2}
            shift
        ;;
        -i)
            filein=${2}
            shift
        ;;
        -ti)
            typein=${2}
            shift
        ;;
        -e)
            encoding=${2}
            shift
        ;;
        -to)
            typeout=${2}
            shift
        ;;
        -o)
            # order of firstname surname in bibtex file
            order=${2}
            shift
        ;;
        -p)
            project=${2}
            shift
        ;;
        -l)
            lang=${2}
            shift
        ;;
        -h)
            echo "${usage}"
            exit 0
        ;;
        *)
            # other choice
            echo "eee : unknown option ${1}"
            echo "${usage}"
            exit 1
        ;;
    esac
    # next flag
    shift
done
unset usage
#
# check for filein
if [ ! -f ${filein} ]
then
    echo "eee : ${filein} not found"
    exit 1
fi
#
case ${typeout} in
    dbk)
        fileou=$( basename ${filein} .txt).xml
    ;;
    bibtex)
        fileou=$( basename ${filein} .txt).bib
    ;;
    *)
        echo "eee : typeout should be dbk or bibtex"
        exit 1
    ;;
esac
#
# check for output
case ${typein} in
    raw)
        # file like data/biball.txt
        fileraw=${filein}
    ;;
    mailbody)
        # file like data/mail2007-04-25T08:58:16Z.txt
        fileraw=${tmpdir}/$(basename ${filein}).raw
        echo "# from ${filein}" > ${fileraw}
        echo "# ${log_date}" >> ${fileraw}
        echo "# corrections" >> ${fileraw}
        grep "correction_.*=" ${filein} | grep -v "correction_.*=$" | \
        sed -e "s/correction_.*=//">> ${fileraw}
        echo "# new references" >> ${fileraw}
        awk "/newreferences=/,/comments=/" ${filein} | sed -e "s/newreferences=//" -e "/comments=/d" >> ${fileraw}
        #more ${fileraw} # ++ if debug
        #read a #++ if debug
    ;;
    bibtex)
        # file like data/petitpoly.bib
        fileraw=${tmpdir}/$(basename ${filein}).raw
        awk -f ${PROJECT}/join_endcomma.awk ${filein} > ${fileraw}
    ;;
    *)
        echo "eee : typein should be raw, mailbody or bibtex"
        exit 1
    ;;
esac
#
# check for output
if [ -f ${fileou} ]
then
    echo "eee : ${fileou} already exist"
    exit 1
fi
#
ij=1
jlist[${ij}]="J. Climate"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Climate"
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Modelling"
ij=$(( ${ij} + 1))
jlist[${ij}]="Geophys. Res. Lett."
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Geophys. Res."
ij=$(( ${ij} + 1))
jlist[${ij}]="Tellus A"
ij=$(( ${ij} + 1))
jlist[${ij}]="Tellus B"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Phys. Oceanogr."
ij=$(( ${ij} + 1))
jlist[${ij}]="Clim. Dyn."
ij=$(( ${ij} + 1))
jlist[${ij}]="Clim. Res."
ij=$(( ${ij} + 1))
jlist[${ij}]="Climate Dynamics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Dynamics of Atmospheres and Oceans"
ij=$(( ${ij} + 1))
jlist[${ij}]="Dyn. Atmos. Oceans"
ij=$(( ${ij} + 1))
jlist[${ij}]="Mon. Wea. Rev."
ij=$(( ${ij} + 1))
jlist[${ij}]="Monthly Weather Review"
ij=$(( ${ij} + 1))
jlist[${ij}]="Global Biogeochem. Cycles"
ij=$(( ${ij} + 1))
jlist[${ij}]="Nonlinear Processes in Geophysics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Sci."
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Science"
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Sciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Mar. Systems"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Atmos. Sc."
ij=$(( ${ij} + 1))
jlist[${ij}]="Proc. Royal Soc."
ij=$(( ${ij} + 1))
jlist[${ij}]="Bull. Amer. Meteorol. Soc."
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Dyn."
ij=$(( ${ij} + 1))
jlist[${ij}]="Geophysical Monograph Series, Earth's Climate: The Ocean-Atmosphere Interaction"
ij=$(( ${ij} + 1))
jlist[${ij}]="Paleoceanography"
ij=$(( ${ij} + 1))
jlist[${ij}]="Annales Geophysicae"
ij=$(( ${ij} + 1))
jlist[${ij}]="Annals of Geophys."
ij=$(( ${ij} + 1))
jlist[${ij}]="Deep Sea Research Part II: Topical Studies in Oceanography"
ij=$(( ${ij} + 1))
jlist[${ij}]="Deep Sea Res. II"
ij=$(( ${ij} + 1))
jlist[${ij}]="Atmospheric Chemistry and Physics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Atmospheric Chemistry and Physics Discussions"
ij=$(( ${ij} + 1))
jlist[${ij}]="Earth Plan. Sc. Lett."
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Mar. Res."
ij=$(( ${ij} + 1))
jlist[${ij}]="PCMDI Report Series"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Mar. Syst."
ij=$(( ${ij} + 1))
jlist[${ij}]="Note du Pôle de Modélisation"
ij=$(( ${ij} + 1))
jlist[${ij}]="Calculateurs Parallèles"
ij=$(( ${ij} + 1))
jlist[${ij}]="Note Scientifique du Pôle de Modélisation"
ij=$(( ${ij} + 1))
jlist[${ij}]="Lecture Notes in Computer Science"
ij=$(( ${ij} + 1))
jlist[${ij}]="Prog. Oceanogr."
ij=$(( ${ij} + 1))
jlist[${ij}]="Deep Sea Research Part I: Oceanographic Research Papers"
ij=$(( ${ij} + 1))
jlist[${ij}]="Deep Sea Res. I"
ij=$(( ${ij} + 1))
jlist[${ij}]="IEEE Trans. Geosci. Remote Sensing"
ij=$(( ${ij} + 1))
jlist[${ij}]="ECMWF Tech. Memorandum"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Environ. Radioactivity"
ij=$(( ${ij} + 1))
jlist[${ij}]="Int. WOCE Newsletter"
ij=$(( ${ij} + 1))
jlist[${ij}]="C. R. Acad. Sci. Paris"
ij=$(( ${ij} + 1))
jlist[${ij}]="C. R. Acad. Sci. Paris, Earth and Planetary Sciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="In The mathematics of models for climatology and environment"
ij=$(( ${ij} + 1))
jlist[${ij}]="Oceanol. Acta"
ij=$(( ${ij} + 1))
jlist[${ij}]="The global atmosphere and ocean system"
ij=$(( ${ij} + 1))
jlist[${ij}]="NATO Advanced Study Institute"
ij=$(( ${ij} + 1))
jlist[${ij}]="WCRP"
ij=$(( ${ij} + 1))
jlist[${ij}]="The Courier"
ij=$(( ${ij} + 1))
jlist[${ij}]="Elsevier Oceanography Series"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Conference Proceedings of the 1988 International Conference on Supercomputing"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Science and engineering on Cray Supercomputers"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Modeling the Earth's Climate and its Variability"
ij=$(( ${ij} + 1))
jlist[${ij}]="Fish. Oceanogr."
ij=$(( ${ij} + 1))
jlist[${ij}]="Q. J. R. Meteor. Soc."
ij=$(( ${ij} + 1))
jlist[${ij}]="In High performance computing in the geosciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="Int. J. Numer. Meth. in Fluids"
ij=$(( ${ij} + 1))
jlist[${ij}]="Lecture notes in Physics"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Meteorol. Soc. Japan"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Marine Systems"
ij=$(( ${ij} + 1))
jlist[${ij}]="Canadian Journal of Fisheries and Aquatic Sciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Atmos. Ocean. Tech."
ij=$(( ${ij} + 1))
jlist[${ij}]="EOS"
ij=$(( ${ij} + 1))
jlist[${ij}]="Nature"
ij=$(( ${ij} + 1))
jlist[${ij}]="Nature Geosciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="Physics and Chemistry of the Earth, Part B: Hydrology, Oceans and Atmosphere"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Atmospheric and Oceanic Technology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Lecture Notes in Computational Science Engineering"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Greenhouse Gas Control Technologies"
ij=$(( ${ij} + 1))
jlist[${ij}]="Chemical Geology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Marine Geology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Developments in Paleoenvironmental Research"
ij=$(( ${ij} + 1))
jlist[${ij}]=" Developments in Earth and Environmental Sciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="Science"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Mediterranean Climate Variability"
ij=$(( ${ij} + 1))
jlist[${ij}]="Global and Planetary Change"
ij=$(( ${ij} + 1))
jlist[${ij}]="Physical Review Letters"
ij=$(( ${ij} + 1))
jlist[${ij}]="Progress In Oceanography"
ij=$(( ${ij} + 1))
jlist[${ij}]="Climatic Change"
ij=$(( ${ij} + 1))
jlist[${ij}]="Ocean Dynamics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Phil. Trans. Roy. Soc. A"
ij=$(( ${ij} + 1))
jlist[${ij}]="Phil. Trans. Roy. Soc. B"
ij=$(( ${ij} + 1))
jlist[${ij}]="Izvestiya Atmospheric and Oceanic Physics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Hydrometeorology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Hydrology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Remote Sensing of Environment"
ij=$(( ${ij} + 1))
jlist[${ij}]="Remote Sensing Env."
ij=$(( ${ij} + 1))
jlist[${ij}]="Oceanology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Water Resour. Res."
ij=$(( ${ij} + 1))
jlist[${ij}]="Water Resources Research"
ij=$(( ${ij} + 1))
jlist[${ij}]="Advances in Atmospheric Sciences"
ij=$(( ${ij} + 1))
jlist[${ij}]="Quaternary Science Reviews"
ij=$(( ${ij} + 1))
jlist[${ij}]="AGU monograph Ocean Circulation Mechanisms and Impacts"
ij=$(( ${ij} + 1))
jlist[${ij}]="Climate Research"
ij=$(( ${ij} + 1))
jlist[${ij}]="Colloque du GIS « Climat-Environnement-Sociétés »"
ij=$(( ${ij} + 1))
jlist[${ij}]="Agricultural and Forest Meteorology"
ij=$(( ${ij} + 1))
jlist[${ij}]="VIIth IAHS Scientific Assembly"
ij=$(( ${ij} + 1))
jlist[${ij}]="AGU fall Meeting"
ij=$(( ${ij} + 1))
jlist[${ij}]="4th Alexander Von Humboldt International Conference"
ij=$(( ${ij} + 1))
jlist[${ij}]="International Journal of Climatology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Revue de l'Énergie"
ij=$(( ${ij} + 1))
jlist[${ij}]="Hydrol. Earth Sys. Sci."
ij=$(( ${ij} + 1))
jlist[${ij}]="Ambio"
ij=$(( ${ij} + 1))
jlist[${ij}]="Theoretical and applied climatology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Remote Sensing of Environnement"
ij=$(( ${ij} + 1))
jlist[${ij}]="PNAS"
ij=$(( ${ij} + 1))
jlist[${ij}]="Lettre PIGB-PMRC"
ij=$(( ${ij} + 1))
jlist[${ij}]="High Performance Computing in Science and Engineering"
ij=$(( ${ij} + 1))
jlist[${ij}]="High Performance Computing in Science and Engineering '08"
ij=$(( ${ij} + 1))
jlist[${ij}]="High Performance Computing on Vector Systems 2006"
ij=$(( ${ij} + 1))
jlist[${ij}]="High Performance Computing on Vector Systems 2007"
ij=$(( ${ij} + 1))
jlist[${ij}]="Annals of Glaciology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Oceanography"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Physical Oceanography"
ij=$(( ${ij} + 1))
jlist[${ij}]="In Deep convection and deep water formation in the oceans"
ij=$(( ${ij} + 1))
jlist[${ij}]="Journal of Applied Meteorology and Climatology"
ij=$(( ${ij} + 1))
jlist[${ij}]="Geochem. Geophys. Geosyst."
ij=$(( ${ij} + 1))
jlist[${ij}]="Environmental Fluid Mechanics"
ij=$(( ${ij} + 1))
jlist[${ij}]="Continental Shelf Research"
ij=$(( ${ij} + 1))
jlist[${ij}]="Marine Pollution Bulletin"
ij=$(( ${ij} + 1))
jlist[${ij}]="Comptes Rendus Geosciences"
ij=$(( ${ij} + 1))
#jlist[${ij}]="Earth and Planetary Sciences, série IIa, Paris"
jlist[${ij}]="Earth and Planetary Sciences, sÃ©rie IIa, Paris"
ij=$(( ${ij} + 1))
jlist[${ij}]="??"
#
# following Journal name are fake ones for demo1 : references extracted from
# Cantratrix Sopronica L. written by Georges Perec
#find in http://www-rocq.inria.fr/who/Marc.Thiriet/PsFil/Biblio/cantatrix.ps
ij=$(( ${ij} + 1))
jlist[${ij}]="Res. Proc. neurophysiol. Fanatic Soc."
ij=$(( ${ij} + 1))
jlist[${ij}]="New Records Ass. J."
ij=$(( ${ij} + 1))
jlist[${ij}]="Am. J. Allegrol."
ij=$(( ${ij} + 1))
jlist[${ij}]="J. Neurochem. Neurocytol. Enzymol."
ij=$(( ${ij} + 1))
jlist[${ij}]="Hammersmith J."
ij=$(( ${ij} + 1))
jlist[${ij}]="Nasa Rept."
ij=$(( ${ij} + 1))
jlist[${ij}]="C.r. Assoc. Conc. Lam."
ij=$(( ${ij} + 1))
jlist[${ij}]="Gaz. med. franco-rus."
ij=$(( ${ij} + 1))
jlist[${ij}]="Amer. J. music. Deficiency"
#
# strip comments and blank lines
fileraw_strict=${tmpdir}/$(basename ${fileraw})_strict
grep -v "^#" ${fileraw} | grep -v "^%" | sed "/^$/d" > ${fileraw_strict}
# following line is not compatible with XML header ++
if [ "${encoding}" = "iso-8859-1" ]
then
    # convert ot UTF-8 to please bibtex2xml
    iconv -f ISO-8859-1 -t UTF-8 ${fileraw_strict} > ${fileraw_strict}2
    mv ${fileraw_strict}2 ${fileraw_strict}
fi
case ${typein} in
    bibtex)
        fileou_bibtexml=${tmpdir}/$(basename ${fileraw})_bibtexml
        python ${PROJECT}/external/bibtex2xml.py ${fileraw_strict} > ${fileou_bibtexml}
        xsltproc --output ${fileou} \
        --param lang "'${lang}'" \
        --param project "'${project}'" \
        --param makedate "'${log_date}'" \
        --param order "'${order}'" \
        ${PROJECT}/bibtexml2dbk.xsl ${fileou_bibtexml}
read a
head ${fileou}
        #++rm ${fileou_bibtexml}
    ;;
    *)
        case ${typeout} in
            dbk)
                cat <<EOF > ${fileou}
<?xml version='1.0' encoding='ISO-8859-1'?>
<bibliography
version="5.0"
xmlns="http://docbook.org/ns/docbook"
xml:id="bib${project}ref"
xml:lang="${lang}">

<info>
    <date>${log_date}</date>
</info>
EOF
            ;;
            bibtex)
                cat <<EOF > ${fileou}

@PREAMBLE{"bibliography of ${project}"}"

% ${log_date}

EOF
            ;;
        esac
        totlines=$( wc -l ${fileraw_strict} | awk '{print $1}' )
        l=1
        while [ ${l} -le ${totlines} ]
        do
            #echo "line: ${l}"
            # extract one line
            line=$( sed -n ${l}p ${fileraw_strict} )
            orgline=$( echo ${line} | sed -e "s/--/- -/g" )
            line=$( echo ${line} | sed -e "s/</\&lt;/g" -e "s/>/\&gt;/g" )
            # parsing non bibtex line
            bibtex=0
            # before the first :
            tmp=${line%%:*}
            # before the last ,
            auths=${tmp%,*},
            # replace " and " by ","
            auths=$( echo "${auths}" | sed -e "s/ and /,/g" )
            # replace " et " by ","
            auths=$( echo "${auths}" | sed -e "s/ et /,/g" )
            # after the last ,
            year=${tmp##*,}
            year=$( rmbl "${year}" )
            ## first author before the first .,
            first=${auths%%.,*}.
            # its firstname after the last ,
            firstfn=${first##*,}
            firstfn=$( rmbl "${firstfn}" )
            # its surname ; before the first ,
            firstsn=${first%%,*}
            firstsn=$( rmbl "${firstsn}" )
            ## ref id
            firstsn_flat=$( echo "${firstsn}" | recode -d -f ISO-8859-15..flat )
            # echo "firstsn : ${firstsn}" # ++ debug
            # echo "firstsn_flat : ${firstsn_flat}" #++ debug
            # test if no encoding problem after ISO-8859-15 to flat conversion
            firstsn_test1=$(echo "${firstsn_flat}" | tr -d "[:alpha:]" | tr -d " " | tr -d "'" | tr -d "-" | tr -d ".")
            # echo "firstsn_test1 : ${firstsn_test1}" # ++ debug
            if [ ! -z "${firstsn_test1}" ]
            then
                echo "www : pb on ISO-8859-15 to flat conversion"
                echo "www : on ${firstsn}"
                echo "www : trying UTF-8 to flat conversion ..."
                firstsn_flat=$( echo "${firstsn}" | recode -d -f UTF-8..flat )
                # test if no encoding problem after UTF-8 to flat conversion
                firstsn_test2=$(echo "${firstsn_flat}" | tr -d "[:alpha:]" | tr -d " " | tr -d "'")
                #echo "firstsn_test2 : A${firstsn_test2}A" # ++ debug
                if [ ! -z "${firstsn_test2}" ]
                then
                    echo "eee : pb on flat conversion of ${firstsn}"
                    exit 1
                fi
            fi
            firstsn_lower=$( echo "${firstsn_flat}" | tr "[:upper:]" "[:lower:]")
            firstsn_nopunct=$( echo "${firstsn_lower}" | tr -s " " "_"  | tr -s "'" "_")
            refid="${firstsn_nopunct}${year}"
            unset firstsn_lower
            unset firstsn_flat
            unset firstsn_test1
            unset firstsn_test2
            # look for id of biblio entry to produce a unique one
            case ${typeout} in
                dbk)
                    num=$( grep -c "<biblioentry xml:id=\"${refid}_[0-9][0-9]\">" ${fileou} )
                ;;
                bibtex)
                    num=$( grep -c "@.*{${refid}_[0-9][0-9]," ${fileou} )
                ;;
            esac
            num=$(( ${num} + 1 ))
            [ ${num} -le 9 ] && num=0${num}
            refid=${refid}_${num}
            hasauthor=1
            case ${typeout} in
                dbk)
                    cat <<EOF >> ${fileou}
<biblioentry xml:id="${refid}">
<!-- date $( date -u +"%Y%m%dT%H%M%SZ" ) -->
<!-- original text
${orgline}
-->
EOF
                ;;
                bibtex)
                    cat <<EOF >> ${fileou}
%
% date $( date -u +"%Y%m%dT%H%M%SZ" )
% original text :
% ${orgline}
%
@article{${refid},
EOF
                ;;
            esac
            if [ ${hasauthor} -eq 1 ]
            then
                case ${typeout} in
                    dbk)
                        cat <<EOF >> ${fileou}
<authorgroup>
<author> <personname> <surname>${firstsn}</surname> <firstname>${firstfn}</firstname> </personname> </author>
EOF
                    ;;
                    bibtex)
                        cat <<EOF >> ${fileou}
author = {${firstsn}, ${firstfn}},
EOF
                    ;;
                esac
                ## other authors..
                if [ ${bibtex} -eq 0 ]
                then
                    previous=${first},
                    # next authors...
                    next=${auths##*${previous}}
                fi
                if [ ${bibtex} -eq 1 ]
                then
                    previous=${first}"and "
                    # next authors...
                    #echo "auths ${auths}"
                    next=${auths##*${previous}}
                    if [ "${next}and " = "${previous}" ]
                    then
                        next=""
                    fi
                fi
                #echo "previous ${previous}"
                #echo "next ${next}"
                # while the next author is not empty
                while [  "${next}" != "" ]
                do
                    if [ ${bibtex} -eq 0 ]
                    then
                        # get the first next author; before the first ,
                        next=${next%%,*}
                        # its surname ; after the last .
                        nextsn=${next##*.}
                        nextsn=$( rmbl "${nextsn}" )
                        # its firstname ; before the last .
                        nextfn=${next%.*}.
                        nextfn=$( rmbl "${nextfn}" )
                    fi
                    if [ ${bibtex} -eq 1 ]
                    then
                        # get the first next author; before the first "and"
                        next=${next%%and *}
                        # its surname after the last " "
                        # ++ pas vrai double nom et pb blanc dans la syntaxe
                        # nextsn=${next##* } .
                        # ok en interactif . pas ok en script
                        nextsn=$( echo ${next}  | awk '{print $2}')
                        #echo "nextsn ${nextsn}"
                        # its nextname before the first " "
                        nextfn=${next%% *}
                    fi
                    #
                    case ${typeout} in
                        dbk)
                            echo "    <author> <personname> <surname>${nextsn}</surname> <firstname>${nextfn}</firstname> </personname> </author>" >> ${fileou}
                        ;;
                        bibtex)
                            echo "author = {${nextsn}, ${nextfn}}," >> ${fileou}
                        ;;
                    esac
                    if [ ${bibtex} -eq 0 ]
                    then
                        previous=${next},
                        next=${auths##*${previous}}
                    fi
                    if [ ${bibtex} -eq 1 ]
                    then
                        previous=${next}"and "
                        next=${auths##*${previous}}
                    fi
                done
                case ${typeout} in
                    dbk)
                        echo "  </authorgroup>"  >> ${fileou}
                    ;;
                esac
            fi
            # end of the line ; after the first :
            endline=${line#*:}
            ## find the journal
            j=1
            jfound=""
            jlistsize=${#jlist[@]}
            while [[ ${j} -le ${jlistsize} && "${jfound}" = "" ]]
            do
                ok=$( echo ${endline} | grep -ci "${jlist[j]} *," )
                [ ${ok} -eq 1 ] && jfound="${jlist[j]}"
                j=$(( ${j} + 1 ))
            done
            unset ok
            if [ "${jfound}" = "" ]
            then
                echo "eee: Journal not found "
                echo "${endline}"
                # uncomment next line for debug
                # set # ++ debug
                exit 1
                #+++ following lines are not yet validate
                # it might be a book, a manual, a conference, etc. ++
                case ${typeout} in
                    dbk)
                        echo "  <title>${title}</title>" >> ${fileou}
                        cat <<EOF >> ${fileou}
<biblioset relation="nojournal">
<title>${title}</title>
<pagenums>${pag}</pagenums>
<pubdate>${year}</pubdate>
</biblioset>
</biblioentry>
EOF
                    ;;
                    bibtex)
                        echo "title = {${title}}," >> ${fileou}
                        echo "pages = {${pag}}," >> ${fileou}
                        echo "year = {${year}}" >> ${fileou}
                        echo "}" >> ${fileou}
                    ;;
                esac
                # end of if jfound empty (ie not an article)
            fi
            if [ "${jfound}" != "" ]
            then
                ## title
                # before the first :
                title=${endline%%${jfound}*}
                title=$( cleanname "${title}" )
                case ${typeout} in
                    dbk)
                        echo "  <title>${title}</title>" >> ${fileou}
                    ;;
                    bibtex)
                        echo "title = {${title}}," >> ${fileou}
                    ;;
                esac
                ## end
                ## end of the line ; after the first ${jfound}
                endline=${endline#*${jfound}}
                endline=$( cleanname "${endline}" )
                ## doi
                endline=$( echo ${endline} | sed -e "s/[dD][oO][iI] *\t* *: *\t* */doi:/" )
                #echo "endline for doi ${endline}"
                ok=$( echo ${endline} | grep -ic "doi:" )
                if [ ${ok} -eq 1 ]
                then
                    doi=${endline##*doi:}
                    #echo "doi : ${doi}"
                    case ${typeout} in
                        dbk)
                            echo "  <biblioid class=\"doi\">${doi}</biblioid>" >> ${fileou}
                        ;;
                        bibtex)
                            echo "doi={${doi}}," >> ${fileou}
                        ;;
                    esac
                    unset doi
                    endline=${endline%doi:*}
                    endline=$( cleanname "${endline}" )
                else
                    echo "non doi: ${line}"
                    echo ""
                fi
                num=$( echo "${endline}" |  tr -dc "," | wc -c | tr -d " ")
                case "${num}" in
                    0)
                        ## echo ${num}: ${endline}
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioset relation="journal">
<title>${jfound}</title>
<pubdate>${year}</pubdate>
<bibliomisc>${endline}</bibliomisc>
</biblioset>
EOF
                            ;;
                            bibtex)
                                cat <<EOF >> ${fileou}
journal = {${jfound}},
year = {${year}},
notes = {${endline}},
EOF
                            ;;
                        esac
                        unset jfound
                        unset year
                    ;;
                    1)
                        ### echo ${num}: ${endline}
                        vol=${endline%,*}
                        vol=$( cleanname "${vol}" )
                        pag=${endline##*,}
                        pag=$( cleanname "${pag}" )
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioset relation="journal">
<title>${jfound}</title>
<volumenum>${vol}</volumenum><pagenums>${pag}</pagenums>
<pubdate>${year}</pubdate>
</biblioset>
EOF
                            ;;
                            bibtex)
                                echo "journal = {${jfound}}," >> ${fileou}
                                echo "volume = {${vol}}," >> ${fileou}
                                echo "pages = {${pag}}," >> ${fileou}
                                echo "year = {${year}}," >> ${fileou}
                            ;;
                        esac
                    ;;
                    bibtex)
                        unset vol
                        unset pag
                        unset jfound
                        unset year
                    ;;
                    2)
                        vol=${endline%,*}
                        vol=$( cleanname "${vol}" )
                        iss=${vol##*,}
                        iss=$( cleanname "${iss}" )
                        vol=${vol%,*}
                        vol=$( cleanname "${vol}" )
                        pag=${endline##*,}
                        pag=$( cleanname "${pag}" )
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioset relation="journal">
<title>${jfound}</title>
<volumenum>${vol}</volumenum><issuenum>${iss}</issuenum><pagenums>${pag}</pagenums>
<pubdate>${year}</pubdate>
</biblioset>
EOF
                           ;;
                           bibtex)
                               echo "journal = {${jfound}}," >> ${fileou}
                               echo "volume = {${vol}}," >> ${fileou}
                               echo "number = {${iss}}," >> ${fileou}
                               echo "pages = {${pag}}," >> ${fileou}
                               echo "year = {${year}}," >> ${fileou}
                           ;;
                        esac
                        unset vol
                        unset pag
                        unset jfound
                        unset year
                        unset iss
                    ;;
                    6)
                        conftitle=${endline%%,*}
                        endline=${endline#*,}
                        # day(s) month
                        confdates=${endline%%,*}
                        endline=${endline#*,}
                        # day(s) month and year
                        confdates="${confdates}, ${endline%%,*}"
                        confdates=$( cleanname "${confdates}" )
                        endline=${endline#*,}
                        # Town
                        confaddress=${endline%%,*}
                        endline=${endline#*,}
                        # Town and country
                        confaddress="${confaddress}, ${endline%%,*}"
                        confaddress=$( cleanname "${confaddress}" )
                        endline=${endline#*,}
                        publishername=${endline%%,*}
                        publishername=$( cleanname "${publishername}" )
                        endline=${endline#*,}
                        pag=${endline##*,}
                        pag=$( cleanname "${pag}" )
                        #set
                        #read a
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioset relation="conference">
 <title>${jfound}</title>
 <pubdate>${year}</pubdate>
 <publisher><publishername>${publishername}</publishername></publisher>
 <pagenums>${pag}</pagenums>
 <confgroup>
  <conftitle>${conftitle}</conftitle>
  <confdates>${confdates}</confdates>
  <address>${confaddress}</address>
 </confgroup>
</biblioset>
EOF
                            ;;
                            bibtex)
                                echo "journal = {${jfound}}," >> ${fileou}
                                echo "year = {${year}}," >> ${fileou}
                                echo "publisher = {${publishername}}," >> ${fileou}
                                echo "booktitle = {${conftitle}}," >> ${fileou}
                                echo "date = {${confdates}}," >> ${fileou}
                                echo "address = {${confaddress}}," >> ${fileou}
                            ;;
                        esac
                        unset confaddress
                        unset conftitle
                        unset confdates
                        unset pag
                        unset publishername
                        unset year
                        unset jfound
                    ;;
                    10)
                        publishername=${endline%%Editors,*}
                        publishername="${publishername} Editors"
                        publishername=$( cleanname "${publishername}" )
                        endline=${endline#*Editors,}
                        vol=${endline%%,*}
                        vol=$( cleanname "${vol}" )
                        endline=${endline#*,}
                        pag=${endline%%,*}
                        pag=$( cleanname "${pag}" )
                        endline=${endline#*,}
                        isbn=${endline%%,*}
                        isbn=$(echo ${isbn} | sed -e "s/ISBN ://")
                        isbn=$( cleanname "${isbn}" )
                        endline=${endline#*,}
                        agu=${endline%%,*}
                        agu=$(echo ${agu} | sed -e "s/AGU ://")
                        agu=$( cleanname "${agu}" )
                        endline=${endline#*${agu}}
                        endline=$( cleanname "${endline}" )
                        endline=$( cleanname "${endline}" )
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioid class="isbn">${isbn}</biblioid>
<biblioid class="other" otherclass="AGU">${agu}</biblioid>
<biblioset relation="journal">
<title>${jfound}</title>
<pubdate>${year}</pubdate>
<publisher><publishername>${publishername}</publishername></publisher>
<volumenum>${vol}</volumenum>
<pagenums>${pag}</pagenums>
<bibliomisc>${endline}</bibliomisc>
</biblioset>
EOF
                            ;;
                            bibtex)
                                echo "isbn= {${isbn}}," >> ${fileou}
                                echo "agu= {${agu}}," >> ${fileou}
                                echo "year = {${year}}," >> ${fileou}
                                echo "journal = {${jfound}}," >> ${fileou}
                                echo "publisher = {${publishername}}," >> ${fileou}
                                echo "volume = {${vol}}," >> ${fileou}
                                echo "pages = {${pag}}," >> ${fileou}
                                echo "notes = {${endline}}," >> ${fileou}
                            ;;
                        esac
                        unset isbn
                        unset agu
                        unset pag
                        unset publishername
                        unset year
                        unset jfound
                        unset vol
                    ;;
                    *)
                        #echo "${num}: ${endline}" # ++debug
                        #set # ++ debug
                        #exit 1 #++ debug
                        case ${typeout} in
                            dbk)
                                cat <<EOF >> ${fileou}
<biblioset relation="journal">
<title>${jfound}</title>
<pubdate>${year}</pubdate>
<bibliomisc>${endline}</bibliomisc>
</biblioset>
EOF
                            ;;
                            bibtex)
                                echo "journal = {${jfound}}," >> ${fileou}
                                echo "year = {${year}}," >> ${fileou}
                                echo "notes = {${endline}}," >> ${fileou}
                            ;;
                        esac
                    ;;
                esac
                case ${typeout} in
                    dbk)
                        echo "</biblioentry>" >> ${fileou}
                    ;;
                    bibtex)
                        echo "}" >> ${fileou}
                    ;;
                esac
                # end of if jfound not empty
            fi
            unset title
            unset vol
            unset year
            unset pag
            l=$(( ${l} + 1 ))
        done
        unset totlines
        unset l
        case ${typeout} in
            dbk)
                echo "</bibliography>" >> ${fileou}
            ;;
        esac
    ;;
    # end of case bibtex vs other for processing
esac

# check conformity of fileou
# if possible
case ${typeout} in
    dbk)
        ${xmlcmd} val --err \
        --xsd http://www.docbook.org/xml/5.0/xsd/docbook.xsd \
        ${fileou} 1> xmlstarlet.log 2>&1
        #
        # clean
        echo " iii : xmlstarlet.log contains sdtout and stderr from ${xmlcmd} command on ${fileou}"
        echo " iii : which was done just to check consistence of ${fileou}"
        more xmlstarlet.log
    ;;
    bibtex)
        echo " iii : no check conformity of bibtex file"
    ;;
esac
#
case ${typein} in
    raw)
        echo " iii : ${fileraw_strict} contains a copy of input file without comments"
    ;;
    mailbody)
        echo " iii : ${fileraw} contains a copy of input file"
        echo " iii : ${fileraw_strict} contains a copy of input file without comments"
    ;;
esac
#
echo " iii : you have a some new or modified bibliographic references in ${fileou} (biblioentry)"
echo " iii : you can add them in ${fileou}" #++ filename path
echo " iii : modify date in ${fileou}" #++ filename path
echo " iii : but please take care of id last part (after underscore) that may"
echo " 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.
#
exit 0
