10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-12-21 11:53:33 +01:00

Bash/ezfio.sh

This commit is contained in:
Anthony Scemama 2015-06-02 01:48:43 +02:00
parent c29b6066c8
commit 62e78049c2
8 changed files with 429 additions and 109 deletions

18
.gitignore vendored
View File

@ -1 +1,19 @@
update.sh
Python/ezfio.py
Ocaml/ezfio.ml
Bash/ezfio.sh
.ninja_deps
.ninja_log
generated.ninja
lib/libezfio.a
lib/libezfio_irp.a
make.config
src/IRPF90_man/
src/IRPF90_temp/
src/irpf90.make
src/irpf90_entities
src/libezfio_groups-gen.py
src/libezfio_util-gen.py
src/*.pyc
src/run
src/tags

0
Bash/.empty Normal file
View File

View File

@ -1,4 +1,272 @@
#!/bin/bash
# TODO
function _ezfio_usage()
{
echo "
Usage:
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
"
}
function _require_ezfio_file()
{
if [[ -z ${EZFIO_FILE} ]]
then
echo "EZFIO directory not set: try 'ezfio set_file'"
return 1
fi
if [[ ! -d ${EZFIO_FILE} ]]
then
echo "EZFIO directory not accessible: try 'ezfio set_file'"
return 1
fi
}
function _require_first_argument()
{
if [[ -z $1 ]]
then
_ezfio_usage
echo "Error: First argument not set"
return 1
else
return 0
fi
}
function _require_second_argument()
{
if [[ -z $2 ]]
then
_ezfio_usage
echo "Error: Second argument not set"
return 1
fi
}
function _ezfio_set_verbose()
{
function _ezfio_info()
{
echo "$1"
}
return 0
}
function _ezfio_unset_verbose()
{
function _ezfio_info()
{
:
}
return 0
}
function _ezfio_set_file()
{
_require_first_argument $@ || return 1
if [[ ! -d $1 ]]
then
echo "No such directory: $1"
return 1
fi
export EZFIO_FILE=$1
_ezfio_info "Set file ${EZFIO_FILE}"
return 0
}
function _ezfio_unset_file()
{
_require_ezfio_file || return 1
_ezfio_info "Unset file ${EZFIO_FILE}"
unset EZFIO_FILE
return 0
}
function _ezfio_has()
{
_require_ezfio_file || return 1
_require_first_argument $@ || return 1
if [[ ! -d ${EZFIO_FILE}/${1,,} ]]
then
return 1
fi
if [[ -z $2 ]]
then
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
}
function _ezfio_get()
{
_require_ezfio_file || return 1
if [[ -z $1 ]]
then
ls ${EZFIO_FILE}
return 0
fi
_ezfio_has $@ || return 1
if [[ -z $2 ]]
then
ls ${EZFIO_FILE}/${1,,}
return 0
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
}
function _ezfio_set()
{
_require_ezfio_file || return 1
_require_first_argument $@ || return 1
_require_second_argument $@ || return 2
if [[ ! -d ${EZFIO_FILE}/${1,,} ]]
then
mkdir -p ${EZFIO_FILE}/${1,,}
fi
if [[ ! -z "$3" ]]
then
echo "$3" > ${EZFIO_FILE}/${1,,}/${2,,}
else
zcat > ${EZFIO_FILE}/${1,,}/${2,,}.gz
fi
return 0
}
#---
function ezfio()
{
case $1 in
"has")
shift
_ezfio_has $@
;;
"set")
shift
_ezfio_set $@
;;
"get")
shift
_ezfio_get $@
;;
"set_file")
shift
_ezfio_set_file $@
;;
"unset_file")
shift
_ezfio_unset_file
;;
"set_verbose")
_ezfio_set_verbose
;;
"unset_verbose")
_ezfio_unset_verbose
;;
*)
_ezfio_usage
;;
esac
}
_ezfio_unset_verbose
# Completion
_Complete()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
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
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
COMPREPLY=( $(compgen -W 'has get set unset_file \
set_verbose unset_verbose -h' -- $cur ) )
fi
return 0
;;
esac
}
complete -F _Complete ezfio

View File

@ -31,10 +31,10 @@ default: make.config
$(MAKE) -C $$PWD/src
clean:
- bash -c "[[ -e lib/libezfio.a ]] && rm $$PWD/lib/*"
- bash -c "[[ -e Python/ezfio.py ]] && rm $$PWD/Python/*"
- bash -c "[[ -e Ocaml/ezfio.ml ]] && rm $$PWD/Ocaml/*"
- bash -c "[[ -e Bash/ezfio.sh ]] && rm $$PWD/Bash/*"
- bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*"
- bash -c "[[ -f Python/ezfio.py ]] && rm $$PWD/Python/*"
- bash -c "[[ -f Ocaml/ezfio.ml ]] && rm $$PWD/Ocaml/*"
- bash -c "[[ -f Bash/ezfio.sh ]] && rm $$PWD/Bash/*"
- $(MAKE) -C $$PWD/src veryclean
archive: distclean

86
README
View File

@ -1,86 +0,0 @@
======================================================================
EZFIO
======================================================================
Author: A. Scemama, LCPQ-IRSAMC, CNRS-Universite Paul Sabatier
scemama@irsamc.ups-tlse.fr
== About EZFIO ==
EZFIO is the Easy Fortran I/O library. With EZFIO, your data is organized
in a file system inside a main directory. This main directory contains
subdirectories, which contain files. Each file corresponds to a data. For
atomic data the file is a plain text file, and for array data the file is a
gzipped text file.
== Building a library ==
Your EZFIO library is built according to the definitions given in the
files of the 'config' directory. A configuration file can be, for example:
---
system
title character*(128)
num_elec integer = system_num_alpha + system_num_beta
num_alpha integer
num_beta integer
geometry
num_atom integer
nuc_energy double precision
label character*(32) (geometry_num_atom)
atomic_number integer (geometry_num_atom)
charge double precision (geometry_num_atom)
coord double precision (3,geometry_num_atom)
---
A subdirectory is defined by its name at the beginning of a new line. The
data contained in this subdirectory is defined by the triplet
(name,type,dimension), leaving at least one white space at the beginning of the
line.
If the dimension of an array is a data defined in the file, its name can be
used as <name of the subdirectory>_<name of the data>. For example, the
dimension '(geometry_num_atom)' uses the data 'num_atom' of subdirectory
'geometry'.
A data can also be the result of a simple operation. In that case, the
simple operation is written after an '=' symbol (as for 'num_elec'). In
that case, the data is read_only.
Once your configuration file is ready, run 'make' and your library will be
built.
== Using the library ==
In the following, we will call 'EZFIO file' the main directory containing the
EZFIO data.
Only one EZFIO file can be manipulated at a time. To select a file, use:
character*(64) :: filename
call ezfio_set_file(filename)
To get the name of the current used EZFIO file, use
character*(64) :: filename
call ezfio_get_filename(filename)
For each data, 3 subroutines are created.
<dir> is the name of the subdirectory which contains the data and
<data> is the name of the data.
* subroutine ezfio_has_<dir>_<data> (result)
sets result to .True. if the data exists in the EZFIO file, .False. otherwise.
* subroutine ezfio_set_<dir>_<data> (source)
writes the source data to the EZFIO file.
* subroutine ezfio_get_<dir>_<data> (destination)
reads the data from the EZFIO file to the destination.
For safety, a read-only attribute can be set to the file by
call ezfio_set_read_only(.True.)
or inquired by
logical :: is_read_only
call ezfio_is_read_only(is_read_only)

22
build.ninja Normal file
View File

@ -0,0 +1,22 @@
include version
rule build_generated_ninja
command = python configure.py
description = Creating generated.ninja
generator = 1
rule run_ninja
command = ninja -f $in
rule build_archive
command = git archive --format=tar HEAD > EZFIO.${version}.tar && mkdir -p EZFIO && cd EZFIO && tar -xvf ../EZFIO.${version}.tar && cd .. && rm EZFIO.${version}.tar && tar -zcvf EZFIO.${version}.tar.gz EZFIO && rm -rf EZFIO
description = Building archive
build make.config generated.ninja: build_generated_ninja | configure.py
build all: run_ninja generated.ninja
default all
build EZFIO.${VERSION}.tar.gz: build_archive
build archive: phony EZFIO.${VERSION}.tar.gz

View File

@ -2,21 +2,119 @@
import os
if __name__ == '__main__':
d_default = {
"IRPF90" : 'irpf90',
"FC" : 'gfortran -g -ffree-line-length-none -fPIC',
"FCFLAGS" : '-O2',
"RANLIB" : 'ranlib',
"AR" : 'ar',
"NINJA" : 'ninja'
}
with open("version",'r') as f:
version = f.read().strip().rsplit('=')[1]
with open("make.config",'w') as out:
for var,default in d_default.iteritems():
d_default = {
"VERSION" : version,
"IRPF90" : 'irpf90',
"FC" : 'gfortran -g -ffree-line-length-none -fPIC',
"FCFLAGS" : '-O2',
"RANLIB" : 'ranlib',
"AR" : 'ar',
"NINJA" : 'ninja',
"CONFIG_FILES" :
' '.join([ x for x in os.listdir('config') if x != '.empty'])
}
def create_make_config():
with open("make.config",'w') as out:
for var,default in d_default.iteritems():
try:
cur = os.environ[var]
except KeyError:
cur = default
out.write('{0}={1}\n'.format(var,cur))
def read_make_config():
result = {}
with open("make.config",'r') as f:
for line in f.readlines():
try:
cur = os.environ[var]
except KeyError:
cur = default
out.write("{0} = {1}\n".format(var,cur))
key, value = line.strip().split('=')
except:
print "Error in make.config:"
print line
sys.exit(1)
result[key] = value
return result
def create_build_ninja():
if "make.config" not in os.listdir(os.getcwd()):
create_make_config()
d = read_make_config()
d["irpf90_files"] = [ "src/{0}".format(x) for x in
"""
IRPF90_temp/build.ninja irpf90.make irpf90_entities
tags
""".split() ] + \
"""
Python/ezfio.py Ocaml/ezfio.ml Bash/ezfio.sh
""".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
f_types.py test.py create_bash.py groups.py
""".split() ] + [ "make.config" ]
d["irpf90_files"] = ' '.join(d["irpf90_files"])
d["irpf90_sources"] = ' '.join(d["irpf90_sources"])
template = """
rule build_archive
command = git archive --format=tar HEAD > EZFIO.{VERSION}.tar && mkdir -p EZFIO && cd EZFIO && tar -xvf ../EZFIO.{VERSION}.tar && cd .. && rm EZFIO.{VERSION}.tar && tar -zcvf EZFIO.{VERSION}.tar.gz EZFIO && rm -rf EZFIO
description = Building archive
rule build_make_config
command = python configure.py
description = Creating make.config
rule compile_irpf90
command = cd src ; {IRPF90} --ninja
description = Compiling IRPF90
rule build_irpf90_a
command = {NINJA} -C src/IRPF90_temp
description = Compiling Fortran files
rule build_libezfio_a
command = cp src/IRPF90_temp/irpf90.a lib/libezfio.a ; {RANLIB} lib/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
description = Building libezfio_irp.a
build make.config: build_make_config | configure.py
build {irpf90_files}: compile_irpf90 | {irpf90_sources}
build src/IRPF90_temp/irpf90.a: build_irpf90_a | {irpf90_files}
build lib/libezfio.a: build_libezfio_a | src/IRPF90_temp/irpf90.a
build lib/libezfio_irp.a: build_libezfio_irp_a | lib/libezfio.a
"""
with open('generated.ninja','w') as f:
f.write(template.format(**d))
if __name__ == '__main__':
create_build_ninja()

View File

@ -77,13 +77,13 @@ def run():
'let has_%(group)s_%(var)s () = has_array "%(group)s" "%(var)s" ;;' %(d) ]
file = open('ezfio.ml','r')
file = open('ezfio.sh','r')
template = file.read()
file.close()
template = template.replace("(*$HEAD*)",'\n'.join(head))
template = template.replace("(*$TAIL*)",'\n'.join(tail))
file = open('../Ocaml/ezfio.ml','w')
file = open('../Bash/ezfio-gen.sh','w')
file.write(template)
file.close()