"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/c2btools/med2bib" (12 Feb 2021, 2617 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 #-------------------------------------------------------------------------------
    3 # med2bib  --  Script to convert PUBMED format to BibTeX
    4 # cb2Bib Tools
    5 #
    6 # Copyright (C) 2009 by Filippo Rusconi
    7 # rusconi@mnhn.fr
    8 #
    9 # Based on previous work by
   10 # Pere Constans
   11 # constans@molspaces.com
   12 #
   13 # See LICENSE file that comes with this distribution
   14 #
   15 # Usage: med2bib input_med output_bib
   16 #-------------------------------------------------------------------------------
   17 # Using med2xml and xml2bib utilities from:
   18 # http://bibutils.refbase.org/
   19 #-------------------------------------------------------------------------------
   20 
   21 #-------------------------------------------------------------------------------
   22 # Init variables
   23 #-------------------------------------------------------------------------------
   24 # Modify accordingly
   25 #med2xml=/usr/local/bin/med2xml
   26 #xml2bib=/usr/local/bin/xml2bib
   27 med2xml=med2xml
   28 xml2bib=xml2bib
   29 med2xml_flags="-u"
   30 xml2bib_flags="-sd -b"
   31 #-------------------------------------------------------------------------------
   32 
   33 # Immediately check that the needed programs are there:
   34 "${med2xml}" --version > /dev/null 2>&1
   35 
   36 if [ "$?" != "0" ]
   37 then
   38     echo "Program med2xml (suite bibutils) is required."
   39     echo "Set it in your path, and/or modify $0 accordingly."
   40     echo "Ending processing."
   41     exit 1
   42 fi
   43 
   44 "${xml2bib}" --version > /dev/null 2>&1
   45 
   46 if [ "$?" != "0" ]
   47 then
   48     echo "Program xml2bib (suite bibutils) is required."
   49     echo "Set it in your path, and/or modify $0 accordingly."
   50     echo "Ending processing."
   51     exit 1
   52 fi
   53 
   54 # Make sure we trap errors (we put that after the tests above because
   55 # we need the tests to fail, in case, without exiting immediately).
   56 set -e
   57 
   58 # Getting filenames from command line
   59 echo "cb2Bib Tools: Script to convert PUBMED-XML format to BibTeX"
   60 echo ""
   61 echo "It uses external package bibutils from"
   62 echo "http://bibutils.refbase.org/"
   63 echo ""
   64 if test "$#" != 2; then
   65     cat <<EOF
   66 Usage: $0 input_med output_bib
   67 EOF
   68     exit 2
   69 fi
   70 
   71 # Create temporary directory
   72 # Note that we use the mktemp utility that ensures that
   73 # we do not overwrite any preexisting directory
   74 tmp_dir=$(mktemp -d --tmpdir c2b_tools_tmp.XXXXXXXX)
   75 
   76 # Setting files
   77 med="$1"
   78 bib="$2"
   79 work_dir="$PWD"
   80 
   81 # Preparing temporary files
   82 cp "$med" "${tmp_dir}"/c2b_tmp.med
   83 cp "$med" "${tmp_dir}"/c2b_tmp.bib
   84 
   85 # bibutils procedure
   86 cd "${tmp_dir}"
   87 "${med2xml}" $med2xml_flags c2b_tmp.med > c2b_tmp.xml
   88 "${xml2bib}" $xml2bib_flags c2b_tmp.xml | sed 's%^ISSUE=%NUMBER=%g' > c2b_tmp.bib
   89 
   90 # Clean up
   91 cd "${work_dir}"
   92 cp "${tmp_dir}"/c2b_tmp.bib "$bib"
   93 rm -rf "${tmp_dir}"
   94 echo ""
   95 echo "$0 ended."