Bash calls ezfio.py

This commit is contained in:
Anthony Scemama 2015-06-02 12:12:11 +02:00
parent 62e78049c2
commit 3b97748adc
8 changed files with 201 additions and 137 deletions

View File

@ -1,5 +1,13 @@
#!/bin/bash
EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
function _ezfio_py()
{
python ${EZFIO_ROOT}/Python/ezfio.py $@
}
function _ezfio_usage()
{
echo "
@ -78,8 +86,7 @@ function _ezfio_set_file()
if [[ ! -d $1 ]]
then
echo "No such directory: $1"
return 1
mkdir -p $1 || return 1
fi
export EZFIO_FILE=$1
_ezfio_info "Set file ${EZFIO_FILE}"
@ -109,18 +116,7 @@ function _ezfio_has()
return 0
fi
if [[ -f ${EZFIO_FILE}/${1,,}/${2,,} ]]
then
_ezfio_info "EZFIO has $1 / $2"
return 0
elif [[ -f ${EZFIO_FILE}/${1,,}/${2,,}.gz ]]
then
_ezfio_info "EZFIO has $1 / $2"
return 0
else
_ezfio_info "EZFIO doesn't have $1 / $2"
return 1
fi
_ezfio_py has $@ && return 0 || return 1
}
function _ezfio_get()
@ -129,29 +125,15 @@ function _ezfio_get()
if [[ -z $1 ]]
then
ls ${EZFIO_FILE}
return 0
ls ${EZFIO_FILE} && return 0 || return 1
fi
_ezfio_has $@ || return 1
if [[ -z $2 ]]
then
ls ${EZFIO_FILE}/${1,,}
return 0
ls ${EZFIO_FILE}/${1,,} && return 0 || return 1
fi
if [[ -f ${EZFIO_FILE}/${1,,}/${2,,} ]]
then
cat ${EZFIO_FILE}/${1,,}/${2,,}
elif [[ -f ${EZFIO_FILE}/${1,,}/${2,,}.gz ]]
then
zcat ${EZFIO_FILE}/${1,,}/${2,,}.gz
else
_ezfio_info "EZFIO doesn't have $1 / $2"
return 1
fi
return 0
_ezfio_py get $@ && return 0 || return 1
}
function _ezfio_set()
@ -160,15 +142,11 @@ function _ezfio_set()
_require_first_argument $@ || return 1
_require_second_argument $@ || return 2
if [[ ! -d ${EZFIO_FILE}/${1,,} ]]
if [[ -z $3 ]]
then
mkdir -p ${EZFIO_FILE}/${1,,}
fi
if [[ ! -z "$3" ]]
then
echo "$3" > ${EZFIO_FILE}/${1,,}/${2,,}
_ezfio_py set $@ || return 1
else
zcat > ${EZFIO_FILE}/${1,,}/${2,,}.gz
echo $3 | _ezfio_py set $1 $2 || return 1
fi
return 0
}
@ -234,39 +212,51 @@ _Complete()
prev="${COMP_WORDS[COMP_CWORD-1]}"
prev2="${COMP_WORDS[COMP_CWORD-2]}"
case "${prev2}" in
set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE}/${prev} ; ls | sed 's/\.gz//' )" -- $cur ) )
return 0
;;
esac
if [[ -n ${EZFIO_FILE} && -d ${EZFIO_FILE} ]]
then
case "${prev}" in
unset_file|set_verbose|unset_verbose)
COMPREPLY=()
return 0
;;
set_file)
COMPREPLY=( $(compgen -W "$(\ls -d */ | sed 's|/||g')" -- ${cur} ) )
return 0
;;
set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE} ; \ls -d */ | sed 's|/||g')" -- $cur ) )
return 0
;;
*)
if [[ -z ${EZFIO_FILE} ]]
then
COMPREPLY=( $(compgen -W 'set_file \
set_verbose unset_verbose -h' -- $cur ) )
else
case "${prev2}" in
set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE}/${prev} ; ls | sed 's/\.gz//' )" -- $cur ) )
return 0
;;
esac
case "${prev}" in
unset_file|set_verbose|unset_verbose)
COMPREPLY=()
return 0
;;
set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE} ; \ls -d */ | sed 's|/||g')" -- $cur ) )
return 0
;;
*)
COMPREPLY=( $(compgen -W 'has get set unset_file \
set_verbose unset_verbose -h' -- $cur ) )
fi
return 0
;;
esac
return 0
;;
esac
else
case "${prev}" in
set_verbose|unset_verbose)
COMPREPLY=()
return 0
;;
set_file)
COMPREPLY=( $(compgen -W "$(\ls -d */ | sed 's|/||g')" -- ${cur} ) )
return 0
;;
*)
COMPREPLY=( $(compgen -W 'set_file \
set_verbose unset_verbose -h' -- $cur ) )
return 0
;;
esac
fi
}
complete -F _Complete ezfio

View File

@ -19,8 +19,8 @@ The following packages are needed:
* `IRPF90 <http://irpf90.ups-tlse.fr>`_
* `Python <http://www.python.org>`_
* `GNU make <http://www.python.org>`_ or `Ninja <http://github.com/martine/ninja>`_
The latest version can be downloaded `here <http://qmcchem.ups-tlse.fr/files/scemama/EZFIO.latest.tar.gz>`_.
Tutorial
========
@ -39,15 +39,9 @@ Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file
$ ls
EZFIO/
Get into the ``EZFIO`` directory and set up your compiling options:
.. code-block:: bash
$ cp make.config.example make.config
$ vim make.config
Now, configure the library to produce the desired suboutines. Get into
the ``config`` directory and create a new file ``test.config``
Get into the ``EZFIO`` directory and configure the library to produce the
desired suboutines. Get into the ``config`` directory and create a new file
``test.config``
containing::
molecule
@ -79,19 +73,27 @@ simple operation is written after an = symbol (as for ``mass`` in the
Once your configuration file is ready, run ``make`` and your library
will be built.
Building the library
--------------------
Now, go back to the EZFIO root directory, and run:
Now, go back to the EZFIO root directory. To build with GNU make, run:
.. code-block:: bash
$ make
The ``lib`` directory now contains the shared library
(``libezfio.so``), the static library (``libezfio.a``), and a static
Or you can use Ninja to build the library:
.. code-block:: bash
$ ninja
The ``lib`` directory now contains the static library ``libezfio.a``, and a static
library for use under the IRPF90 environment (``libezfio_irp.a``).
The ``Python`` directory contains the Python module for the use of the library in Python.
The ``Python``, ``Ocaml`` and ``Bash`` directories contain the binding for these languages.
Using the produced library
--------------------------
@ -220,7 +222,7 @@ Create a file named ``create_input.py`` with:
ezfio.molecule_mass = mass
ezfio.molecule_coord = coord
# Check that the total charge and mass is correct:
# Check that the total mass is correct:
print ezfio.properties_mass # Should give 18.
Execute the script:
@ -236,10 +238,10 @@ The printed mass is correct, and a new directory (``Water``) was created with ou
$ ls Water/*
Water/ezfio:
creation
creation library user
Water/molecule:
charge.gz coord.gz mass.gz num_atoms
coord.gz mass.gz num_atoms
In Fortran
----------
@ -307,6 +309,20 @@ the EZFIO file.
end
Compile the fortran program and link it the ``libezfio.a`` library, and run the
executable.
.. code-block:: bash
$ gfortran test.f90 EZFIO/lib/libezfio.a -o test.x
$ ./test.x
Data in the EZFIO file:
16.0000000 0.00000000 0.222396001 0.00000000
1.00000000 1.43649399 -0.889660001 0.00000000
1.00000000 -1.43649399 -0.889660001 0.00000000
A new directory (``properties``) was created with the center_of_mass
file:
@ -317,25 +333,64 @@ file:
creation
Water/molecule:
charge.gz coord.gz mass.gz num_atoms
coord.gz mass.gz num_atoms
Water/properties:
center_of_mass.gz
Compile and run the program using:
Using Bash
----------
To use EZFIO in Bash, you need to source the ``ezfio.sh`` file:
.. code-block:: bash
$ $FC -o test test.F90 EZFIO/lib/libezfio.a
$ ./test
$ source EZFIO/Bash/ezfio.sh
where ``$FC`` is your fortran compiler, and ``test.F90`` is the file
containing the test example. If you don't have the EZFIO static
library, you can use the shared library as:
The usage of the ``ezfio`` bash command is::
ezfio set_file EZFIO_DIRECTORY
ezfio unset_file
ezfio has DIRECTORY ITEM
ezfio get DIRECTORY ITEM
ezfio set DIRECTORY ITEM VALUE : Scalar values
ezfio set DIRECTORY ITEM : Array values read from stdin
ezfio set_verbose
ezfio unset_verbose
Here is the same script as the Python script, but using Bash (``create_input.sh``):
.. code-block:: bash
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/EZFIO/lib
$ $FC -o test -L./EZFIO/lib -lezfio
#!/bin/bash
source EZFIO/Bash/ezfio.sh
# Select the EZFIO file
ezfio set_file Water
# Set the number of atoms
ezfio set molecule num_atoms 3
# Create the mass array
mass="[16.0, 1.0, 1.0]"
echo $mass | ezfio set molecule mass
# Create the coordinates
cat << EOF | ezfio set molecule coord
[
[ 0.000000, 0.222396, 0.0],
[ 1.436494, -0.889660, 0.0],
[-1.436494, -0.889660, 0.0]
]
EOF
# Check that the total mass is correct:
ezfio get properties mass # Should print 18.

View File

@ -52,18 +52,18 @@ def create_build_ninja():
d["irpf90_files"] = [ "src/{0}".format(x) for x in
"""
IRPF90_temp/build.ninja irpf90.make irpf90_entities
tags
tags libezfio_groups-gen.py libezfio_util-gen.py
""".split() ] + \
"""
Python/ezfio.py Ocaml/ezfio.ml Bash/ezfio.sh
Python/ezfio.py Ocaml/ezfio.ml
""".split()
d["irpf90_sources"] = [ "src/{0}".format(x) for x in
"""
libezfio_error.irp.f create_ocaml.py groups_templates.py
libezfio_file.irp.f create_python.py libezfio_groups-gen.py
libezfio_groups.irp.f ezfio-head.py libezfio_util-gen.py
libezfio_util.irp.f ezfio-tail.py read_config.py run.irp.f
libezfio_file.irp.f create_python.py
libezfio_groups.irp.f ezfio-head.py
libezfio_util.irp.f ezfio-tail.py read_config.py
f_types.py test.py create_bash.py groups.py
""".split() ] + [ "make.config" ]
@ -93,7 +93,7 @@ rule build_libezfio_a
description = Building libezfio.a
rule build_libezfio_irp_a
command = cp lib/libezfio.a lib/libezfio_irp.a ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o ; {RANLIB} lib/libezfio_irp.a
command = cp lib/libezfio.a lib/libezfio_irp.a ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o > /dev/null ; {RANLIB} lib/libezfio_irp.a
description = Building libezfio_irp.a

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#

View File

@ -24,3 +24,52 @@
ezfio = ezfio_obj()
def main():
import pprint
import sys
import os
try:
EZFIO_FILE = os.environ["EZFIO_FILE"]
except KeyError:
print "EZFIO_FILE not defined"
return 1
ezfio.set_file(EZFIO_FILE)
command = '_'.join(sys.argv[1:]).lower()
try:
f = getattr(ezfio,command)
except AttributeError:
print "{0} not found".format(command)
return 1
if command.startswith('has'):
if f(): return 0
else : return 1
elif command.startswith('get'):
result = f()
pprint.pprint( result, width=60, depth=3, indent=4 )
return 0
elif command.startswith('set'):
try:
data = eval(sys.stdin.read())
except:
print "Syntax Error"
return 1
f(data)
return 0
else:
return 1
if __name__ == '__main__':
rc = main()
sys.exit(rc)

View File

@ -144,10 +144,3 @@ for group in groups.keys():
print >>file_py, attributes_arr_py%d
file_py.close()
import create_ocaml
create_ocaml.run()
import create_python
create_python.run()

View File

@ -354,6 +354,13 @@ print >>file_py, """
"""%cwd
file_py.close()
import create_ocaml
create_ocaml.run()
import create_python
create_python.run()
END_SHELL
BEGIN_PROVIDER [ integer, libezfio_buffer_rank ]

View File

@ -1,31 +0,0 @@
! EZFIO is an automatic generator of I/O libraries
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along
! with this program; if not, write to the Free Software Foundation, Inc.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
! Anthony Scemama
! LCPQ - IRSAMC - CNRS
! Universite Paul Sabatier
! 118, route de Narbonne
! 31062 Toulouse Cedex 4
! scemama@irsamc.ups-tlse.fr
program run
BEGIN_DOC
! Test run
END_DOC
! Leave this empty
end