10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-06-07 22:05:22 +02:00

Compare commits

...

47 Commits

Author SHA1 Message Date
66d3dd5d8e Removed OpenMP because I/O is not thread safe 2023-10-05 15:04:14 +02:00
dba01c4fe0 Added int for dimensions 2023-09-22 16:20:18 +02:00
0520b5e2cf Use (L1) for logicals to avoid bugs between ifort and gfortran 2023-06-28 13:47:39 +02:00
d5805497fa Added ezfio_array_of_array 2022-01-11 10:30:07 +01:00
ed1df9f3c1 Regexp for evaluated commands 2021-06-01 14:50:33 +02:00
ccee52d00c Use irpf90 v2.0.5
Version:2.0.7
2020-12-06 21:18:12 +01:00
3777ff3d95 Merge branch 'master' of gitlab.com:scemama/EZFIO
Version:2.0.6
2020-12-03 18:39:19 +01:00
7560a01faa more robust functions
Version:2.0.5
2020-12-03 18:39:04 +01:00
f7a141dca6 Fixed for MacOS 2020-11-13 17:14:55 +01:00
Anthony Scemama
400dd83599 Merge branch 'master' into 'master'
fix string handling so it works with bytes or str object

See merge request scemama/EZFIO!5
2020-08-03 19:56:22 +00:00
Kevin Gasperich
13a32e3de3 fix string handling so it works with bytes or str object 2020-08-03 13:46:48 -05:00
e2a79a0c53 Fixed character type
Version:2.0.2
2020-05-05 01:31:00 +02:00
ec1956dc99 Update README
Version:2.0.2
2020-02-20 19:13:22 +01:00
7e6be9ab45 Python3.
Version:2.0.0

Version:2.0.1
2020-01-27 20:10:12 +01:00
9cc4b60f79 Python3. Version 2.0
Version:2.0
2020-01-27 11:32:08 +01:00
cfb61939bc Char array as 1D
Version:1.6.1
2019-10-27 23:46:36 +01:00
e27ef1c7f4 Fixed Fortran write character arrays
Version:1.6.0
2019-10-24 21:21:10 +02:00
baa47ab0a9 Faster OCaml I/O
Version:1.5.0

Version:1.5.0
2019-08-21 21:12:37 +02:00
0f4a79c240 make clean keeps ezfio.sh
Version:1.4.1
2019-01-23 00:14:40 +01:00
fa6d40a857 Removed Ninja
Version:1.4.0

Version:1.4.0
2019-01-22 00:29:46 +01:00
744cbac511 iso_c_bindings 2019-01-21 18:01:02 +01:00
6b215092c6 Updated version 2019-01-16 18:03:25 +01:00
6301272b72 Fixed set None 2019-01-16 18:01:07 +01:00
658a9e3132 Fixed ezfio set in bash for strings 2019-01-04 18:16:14 +01:00
93cfb0ec92 Fixed EZFIO.ml 2018-07-27 14:39:32 +02:00
8e20da23d5 Better error message in OCaml 2018-07-10 15:27:43 +02:00
4142dac475 Accelerated write 2018-06-06 00:05:08 +02:00
d96976828b OpenMP string conversion 2018-06-04 19:45:40 +02:00
Anthony Scemama
75d7232b6b
Update ezfio.sh 2018-05-02 19:44:35 +02:00
Anthony Scemama
be34e7a089
Update post-commit 2018-05-02 19:42:52 +02:00
Anthony Scemama
610a1e9e41
Update commit-msg 2018-05-02 19:42:30 +02:00
Anthony Scemama
32c59688b9
Merge pull request #4 from LCPQ/master
Merge LCPQ
2018-05-02 19:42:03 +02:00
Anthony Scemama
54d64397ae
Merge branch 'master' into master 2018-05-02 19:40:44 +02:00
Anthony Scemama
fc447ed41e 8 - 256 2017-07-12 01:49:13 +02:00
Anthony Scemama
c826c47c13 Add hostname in temporary filename
Problem on KNL clusters
2017-07-12 00:18:23 +02:00
Anthony Scemama
ca99587f86 Merge pull request #11 from LCPQ/revert-10-master
Revert "Add hostname in temporary filename (problem on clusters)"
2017-07-12 00:12:04 +02:00
Anthony Scemama
8234a2aea4 Revert "Add hostname in temporary filename (problem on clusters)" 2017-07-12 00:11:34 +02:00
Anthony Scemama
4b4fad1a00 Merge pull request #10 from scemama/master
Add hostname in temporary filename (problem on clusters)
2017-07-11 23:00:28 +02:00
Thomas Applencourt
d93f617d2d Merge pull request #9 from scemama/master
Corrected ninja bugs
2015-06-25 15:05:04 +02:00
Anthony Scemama
997c3750a7 Merge pull request #8 from scemama/master
IRPF90 v1.6.7
2015-06-10 12:22:53 +02:00
Anthony Scemama
9f4bb96427 Merge pull request #7 from scemama/master
IRPF90 version 1.6.6
2015-06-05 18:58:02 +02:00
Anthony Scemama
52bce849bb Merge pull request #6 from scemama/master
Bugs in build with Ninja
2015-06-04 00:41:57 +02:00
Anthony Scemama
1b29de70b0 Merge pull request #5 from scemama/master
Put ezfio.sh back
2015-06-03 23:16:49 +02:00
Anthony Scemama
bf957cdf53 Merge pull request #4 from scemama/master
Forgot config files
2015-06-03 15:01:57 +02:00
Thomas Applencourt
d630421044 Merge pull request #3 from scemama/master
Corrected bug when options have an '='
2015-06-03 09:27:10 +02:00
Anthony Scemama
db5d8597ac Merge pull request #2 from scemama/master
v1.3.0
2015-06-02 16:28:26 +02:00
Anthony Scemama
4fb3b5080b Merge pull request #1 from scemama/master
Import version 1.2
2015-03-25 21:09:54 +01:00
29 changed files with 590 additions and 660 deletions

View File

@ -1,10 +1,13 @@
#!/bin/bash #!/bin/bash
#
# ezfio shell command with completion
#
EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P ) EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
function _ezfio_py() function _ezfio_py()
{ {
python "${EZFIO_ROOT}/Python/ezfio.py" $@ python3 ${EZFIO_ROOT}/Python/ezfio.py "$@"
} }
@ -82,13 +85,13 @@ function _ezfio_unset_verbose()
function _ezfio_set_file() function _ezfio_set_file()
{ {
_require_first_argument $@ || return 1 _require_first_argument "$@" || return 1
if [[ ! -d "$1" ]] if [[ ! -d "$1" ]]
then then
mkdir -p "$1" || return 1 mkdir -p "$1" || return 1
fi fi
export EZFIO_FILE="$1" export EZFIO_FILE=$1
_ezfio_info "Set file ${EZFIO_FILE}" _ezfio_info "Set file ${EZFIO_FILE}"
return 0 return 0
} }
@ -103,8 +106,8 @@ function _ezfio_unset_file()
function _ezfio_has() function _ezfio_has()
{ {
_require_ezfio_file || return 1 _require_ezfio_file || return 1
_require_first_argument $@ || return 1 _require_first_argument "$@" || return 1
if [[ ! -d "${EZFIO_FILE}/${1,,}" ]] if [[ ! -d "${EZFIO_FILE}/${1,,}" ]]
then then
@ -125,12 +128,12 @@ function _ezfio_get()
if [[ -z "$1" ]] if [[ -z "$1" ]]
then then
ls ${EZFIO_FILE} && return 0 || return 1 ls "${EZFIO_FILE}" && return 0 || return 1
fi fi
if [[ -z "$2" ]] if [[ -z "$2" ]]
then then
ls "${EZFIO_FILE}/${1,,}" && return 0 || return 1 ls -- "${EZFIO_FILE}/${1,,}" && return 0 || return 1
fi fi
_ezfio_py get $@ && return 0 || return 1 _ezfio_py get $@ && return 0 || return 1
@ -138,13 +141,13 @@ function _ezfio_get()
function _ezfio_set() function _ezfio_set()
{ {
_require_ezfio_file || return 1 _require_ezfio_file || return 1
_require_first_argument $@ || return 1 _require_first_argument "$@" || return 1
_require_second_argument $@ || return 2 _require_second_argument "$@" || return 2
if [[ -z "$3" ]] if [[ -z $3 ]]
then then
_ezfio_py set $@ || return 1 _ezfio_py set "$@" || return 1
else else
echo "$3" | _ezfio_py set "$1" "$2" || return 1 echo "$3" | _ezfio_py set "$1" "$2" || return 1
fi fi
@ -158,22 +161,22 @@ function ezfio()
case $1 in case $1 in
"has") "has")
shift shift
_ezfio_has $@ _ezfio_has "$@"
;; ;;
"set") "set")
shift shift
_ezfio_set $@ _ezfio_set "$@"
;; ;;
"get") "get")
shift shift
_ezfio_get $@ _ezfio_get "$@"
;; ;;
"set_file") "set_file")
shift shift
_ezfio_set_file $@ _ezfio_set_file "$@"
;; ;;
"unset_file") "unset_file")
@ -212,12 +215,12 @@ _Complete()
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
prev2="${COMP_WORDS[COMP_CWORD-2]}" prev2="${COMP_WORDS[COMP_CWORD-2]}"
if [[ -n ${EZFIO_FILE} && -d ${EZFIO_FILE} ]] if [[ -n "${EZFIO_FILE}" && -d "${EZFIO_FILE}" ]]
then then
case "${prev2}" in case "${prev2}" in
set|has|get) set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE}/${prev} ; ls | sed 's/\.gz//' )" -- $cur ) ) COMPREPLY=( $(compgen -W "$(cd "${EZFIO_FILE}/${prev}" ; ls | sed 's/\.gz//' )" -- $cur ) )
return 0 return 0
;; ;;
esac esac
@ -228,7 +231,7 @@ _Complete()
return 0 return 0
;; ;;
set|has|get) set|has|get)
COMPREPLY=( $(compgen -W "$(cd ${EZFIO_FILE} ; \ls -d */ | sed 's|/||g')" -- $cur ) ) COMPREPLY=( $(compgen -W "$(cd "${EZFIO_FILE}" ; \ls -d */ | sed 's|/||g')" -- $cur ) )
return 0 return 0
;; ;;
*) *)
@ -260,3 +263,4 @@ _Complete()
} }
complete -F _Complete ezfio complete -F _Complete ezfio

View File

View File

@ -1,4 +1,4 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc.,

View File

@ -28,28 +28,24 @@ include make.config
.PHONY: default clean veryclean archive .PHONY: default clean veryclean archive
default: make.config default: make.config
cd src $(MAKE) cd src && $(MAKE)
clean: clean:
- bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*" - bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*"
- bash -c "[[ -f Python/ezfio.py ]] && rm $$PWD/Python/*" - bash -c "[[ -f Python/ezfio.py ]] && rm $$PWD/Python/*"
- bash -c "[[ -f Ocaml/ezfio.ml ]] && rm $$PWD/Ocaml/*" - bash -c "[[ -f Ocaml/ezfio.ml ]] && rm $$PWD/Ocaml/*"
- bash -c "[[ -f Bash/ezfio.sh ]] && rm $$PWD/Bash/*"
- $(MAKE) -C $$PWD/src veryclean - $(MAKE) -C $$PWD/src veryclean
archive: distclean archive: veryclean
git archive --format=tar HEAD > EZFIO.$(VERSION).tar git archive --format=tar HEAD > EZFIO.$(VERSION).tar
mkdir EZFIO ; cd EZFIO ; tar -xvf ../EZFIO.$(VERSION).tar mkdir EZFIO ; cd EZFIO ; tar -xvf ../EZFIO.$(VERSION).tar
rm EZFIO.$(VERSION).tar rm EZFIO.$(VERSION).tar
tar -zcvf EZFIO.$(VERSION).tar.gz EZFIO tar -zcvf EZFIO.$(VERSION).tar.gz EZFIO
rm -rf EZFIO rm -rf EZFIO
make.config:
./configure.py
veryclean: veryclean:
$(MAKE) -C src veryclean $(MAKE) -C src veryclean
rm -f make.config
rm -f Ocaml/ezfio.ml rm -f Ocaml/ezfio.ml
rm -f Python/ezfio.py rm -f Python/ezfio.py
rm -f lib/{libezfio.a,libezfio_irp.a} rm -f lib/{libezfio.a,libezfio_irp.a}

View File

@ -4,13 +4,15 @@ EZFIO
EZFIO is the Easy Fortran I/O library generator. It generates EZFIO is the Easy Fortran I/O library generator. It generates
automatically an I/O library from a simple configuration file. The automatically an I/O library from a simple configuration file. The
produced library contains Fortran subroutines to read/write the data produced library contains Fortran subroutines to read/write the data
from/to disk, and to check if the data exists. from/to disk, and to check if the data exists. A Python and an Ocaml API
A Python and an Ocaml API are also provided. are also provided.
With EZFIO, the data is organized in a file system inside a main With EZFIO, the data is organized in a file system inside a main
directory. This main directory contains subdirectories, which contain directory. This main directory contains subdirectories, which contain
files. Each file corresponds to a data. For atomic data the file is a 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. plain text file, and for array data the file is a gzipped text file.
Starting with version 2.0, EZFIO produces Python3 files.
Download Download
======== ========
@ -19,7 +21,8 @@ The following packages are needed:
* `IRPF90 <http://irpf90.ups-tlse.fr>`_ * `IRPF90 <http://irpf90.ups-tlse.fr>`_
* `Python <http://www.python.org>`_ * `Python <http://www.python.org>`_
* `GNU make <http://www.python.org>`_ or `Ninja <http://github.com/martine/ninja>`_ * `GNU make <https://www.gnu.org/software/make>`_
* `Zlib <https://www.zlib.net>`_
Tutorial Tutorial
@ -32,7 +35,8 @@ the 3D space.
Preparation of the library Preparation of the library
-------------------------- --------------------------
Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file in this directory. This directory now contains: Create an empty directory for your project and unpack the
``EZFIO.tar.gz`` file in this directory. This directory now contains:
.. code-block:: bash .. code-block:: bash
@ -40,9 +44,8 @@ Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file
EZFIO/ EZFIO/
Get into the ``EZFIO`` directory and configure the library to produce the Get into the ``EZFIO`` directory and configure the library to produce the
desired suboutines. Get into the ``config`` directory and create a new file desired suboutines. Get into the ``config`` directory and create a new
``test.config`` file ``test.config`` containing::
containing::
molecule molecule
num_atoms integer num_atoms integer
@ -56,14 +59,13 @@ containing::
In this example, ``molecule`` and ``properties`` are containers of data. In this example, ``molecule`` and ``properties`` are containers of data.
Those are defined in the config file by their name at the beginning of a Those are defined in the config file by their name at the beginning of a
new line. new line. Each data contained inside a container is characterized by a
Each data contained inside a container is characterized by a triplet triplet (name,type,dimension), preceded by at least one white space at
(name,type,dimension), preceded by at least one white space at the the beginning of the line.
beginning of the line.
If the dimension of an array is a data, the name of the data can be used If the dimension of an array is a data, the name of the data can be
as ``<container>_<data>`` in the definition of the dimension. For used as ``<container>_<data>`` in the definition of the dimension.
example, the dimension (``molecule_num_atoms``) uses the data For example, the dimension (``molecule_num_atoms``) uses the data
``num_atoms`` of container ``molecule``. ``num_atoms`` of container ``molecule``.
Data can also be the result of a simple operation. In that case, the Data can also be the result of a simple operation. In that case, the
@ -83,16 +85,10 @@ Now, go back to the EZFIO root directory. To build with GNU make, run:
$ make $ make
Or you can use Ninja to build the library: The ``lib`` directory now contains the static library ``libezfio.a``,
and a static library for use under the IRPF90 environment
.. code-block:: bash (``libezfio_irp.a``). The ``Python``, ``Ocaml`` and ``Bash`` directories
contain the binding for these languages.
$ 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``, ``Ocaml`` and ``Bash`` directories contain the binding for these languages.
Using the produced library Using the produced library
@ -186,7 +182,7 @@ Create a file named ``create_input.py`` with:
.. code-block:: python .. code-block:: python
#!/usr/bin/python2 #!/usr/bin/python3
import sys import sys
EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory
@ -201,17 +197,17 @@ Create a file named ``create_input.py`` with:
Molecule = [] Molecule = []
for line in input.splitlines(): for line in input.splitlines():
new_list = map(eval,line.split()) new_list = list(map(eval,line.split()))
Molecule.append(new_list) Molecule.append(new_list)
# Create the mass array # Create the mass array
mass = map( lambda x: x[0], Molecule ) mass = [ x[0] for x in Molecule ]
# print mass # print(mass)
# [16.0, 1.0, 1.0] # [16.0, 1.0, 1.0]
# Create the coord array # Create the coord array
coord = map( lambda x: (x[1], x[2], x[3]), Molecule ) coord = [ (x[1], x[2], x[3]) for x in Molecule ]
# print coord # print(coord)
# [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)] # [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)]
# Select the EZFIO file # Select the EZFIO file
@ -223,16 +219,17 @@ Create a file named ``create_input.py`` with:
ezfio.molecule_coord = coord ezfio.molecule_coord = coord
# Check that the total mass is correct: # Check that the total mass is correct:
print ezfio.properties_mass # Should give 18. print(ezfio.properties_mass) # Should give 18.
Execute the script: Execute the script:
.. code-block:: bash .. code-block:: bash
$ python2 create_input.py $ python3 create_input.py
18.0 18.0
The printed mass is correct, and a new directory (``Water``) was created with our data: The printed mass is correct, and a new directory (``Water``) was created
with our data:
.. code-block:: bash .. code-block:: bash
@ -309,12 +306,12 @@ the EZFIO file.
end end
Compile the fortran program and link it the ``libezfio.a`` library, and run the Compile the fortran program and link it the ``libezfio.a`` library and
executable. ``zlib``, and run the executable.
.. code-block:: bash .. code-block:: bash
$ gfortran test.f90 EZFIO/lib/libezfio.a -o test.x $ gfortran test.f90 EZFIO/lib/libezfio.a -lz -o test.x
$ ./test.x $ ./test.x
Data in the EZFIO file: Data in the EZFIO file:
16.0000000 0.00000000 0.222396001 0.00000000 16.0000000 0.00000000 0.222396001 0.00000000
@ -362,13 +359,14 @@ The usage of the ``ezfio`` bash command is::
ezfio unset_verbose ezfio unset_verbose
Here is the same script as the Python script, but using Bash (``create_input.sh``): Here is the same script as the Python script, but using Bash
(``create_input.sh``):
.. code-block:: bash .. code-block:: bash
#!/bin/bash #!/bin/bash
source EZFIO/Bash/ezfio.sh source EZFIO/Bash/ezfio.sh # Put correct path here
# Select the EZFIO file # Select the EZFIO file
ezfio set_file Water ezfio set_file Water

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
import sys import sys
import os import os
sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path
import cPickle as pickle import pickle as pickle
import zlib import zlib
from ezfio import ezfio_obj, ezfio from ezfio import ezfio_obj, ezfio
@ -20,7 +20,7 @@ def main():
sys.argv.remove("-v") sys.argv.remove("-v")
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "syntax: %s <EZFIO_Filename>"%(sys.argv[0]) print(("syntax: %s <EZFIO_Filename>"%(sys.argv[0])))
sys.exit(1) sys.exit(1)
ezfio_filename = sys.argv[1] ezfio_filename = sys.argv[1]
while ezfio_filename[-1] == "/": while ezfio_filename[-1] == "/":
@ -28,21 +28,19 @@ def main():
ezfio.set_filename(ezfio_filename) ezfio.set_filename(ezfio_filename)
get_functions = filter( get_functions = [x for x in list(ezfio_obj.__dict__.keys()) if x.startswith("has_")]
lambda x: x.startswith("has_"),
ezfio_obj.__dict__.keys() )
d = {} d = {}
for f in get_functions: for f in get_functions:
f_name = f[4:] f_name = f[4:]
try: try:
exec """d['%s'] = ezfio.%s"""%(f_name,f_name) exec("""d['%s'] = ezfio.%s"""%(f_name,f_name))
except IOError: except:
if do_verbose: if do_verbose:
print "%-40s [%5s]"%(f_name, "Empty") print(("%-40s [%5s]"%(f_name, "Empty")))
else: else:
if do_verbose: if do_verbose:
print "%-40s [%5s]"%(f_name, " OK ") print(("%-40s [%5s]"%(f_name, " OK ")))
dump = zlib.compress(pickle.dumps(d)) dump = zlib.compress(pickle.dumps(d))
file = open(ezfio_filename+".ezar","w") file = open(ezfio_filename+".ezar","w")

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
import sys import sys
import os import os
sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path
import cPickle as pickle import pickle as pickle
import zlib import zlib
from ezfio import ezfio_obj, ezfio from ezfio import ezfio_obj, ezfio
@ -15,7 +15,7 @@ ezfio.error = f
def main(): def main():
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "syntax: %s <EZFIO_Archive.ezar>"%(sys.argv[0]) print(("syntax: %s <EZFIO_Archive.ezar>"%(sys.argv[0])))
sys.exit(1) sys.exit(1)
ezfio_filename = sys.argv[1].split(".ezar")[0] ezfio_filename = sys.argv[1].split(".ezar")[0]
@ -27,7 +27,7 @@ def main():
d = pickle.loads(zlib.decompress(dump)) d = pickle.loads(zlib.decompress(dump))
set_functions = d.keys() set_functions = list(d.keys())
nerrors_old = len(d)+1 nerrors_old = len(d)+1
nerrors = nerrors_old+1 nerrors = nerrors_old+1
@ -37,15 +37,15 @@ def main():
failed = [] failed = []
for f_name in set_functions: for f_name in set_functions:
try: try:
exec """ezfio.%s = d['%s']"""%(f_name,f_name) exec("""ezfio.%s = d['%s']"""%(f_name,f_name))
except: except:
nerrors += 1 nerrors += 1
failed.append(f_name) failed.append(f_name)
if nerrors != 0: if nerrors != 0:
print "Unarchive failed:" print("Unarchive failed:")
for i in failed: for i in failed:
print i print(i)
sys.exit(1) sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,31 +0,0 @@
include version
rule build_generated_ninja
command = python2 configure.py
description = Creating generated.ninja
rule run_ninja
command = bash -c 'source .make.config.sh ; $$NINJA -f $in'
description = Building Fortran library
pool = console
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 clean_all
command = bash -c 'source .make.config.sh ; bash -c "$$NINJA -f $in -t clean ; $$NINJA -t clean" ; rm -rf src/IRPF90_{temp,man} src/*.pyc'
description = Cleaning directory
build make.config .make.config.sh generated.ninja impossible_target: build_generated_ninja
build all: run_ninja generated.ninja
default all
build EZFIO.${VERSION}.tar.gz: build_archive
build archive: phony EZFIO.${VERSION}.tar.gz
build clean: clean_all generated.ninja

View File

@ -1,145 +0,0 @@
#!/usr/bin/env python2
import os,sys
def write_if_different(filename,s):
try:
with open(filename, "r") as f:
ref = f.read()
except:
ref = ""
if ref == s:
return
else:
with open(filename, "w") as f:
f.write(s)
with open("version",'r') as f:
version = f.read().strip().rsplit('=')[1]
d_default = {
"VERSION" : version,
"IRPF90" : 'irpf90',
"FC" : 'gfortran -g -ffree-line-length-none -fPIC',
"FCFLAGS" : '-O2',
"RANLIB" : 'ranlib',
"AR" : 'ar',
"BUILD_SYSTEM" : 'make',
"NINJA" : 'ninja',
}
CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty'])
def create_make_config():
try:
d = read_make_config()
except:
d = {}
fmt = { "make.config" :'{0}={1}\n' ,
".make.config.sh": 'export {0}="{1}"\n' }
for var,default in d_default.iteritems():
if var not in d:
try:
cur = os.environ[var]
except KeyError:
cur = default
d[var]=cur
for filename in fmt:
out = ""
for var,default in d_default.iteritems():
cur = d[var]
out += fmt[filename].format(var,cur)
write_if_different(filename,out)
return d
def read_make_config():
result = {}
with open("make.config",'r') as f:
for line in f.readlines():
try:
key, value = line.strip().split('=',1)
except:
print "Error in make.config:"
print line
sys.exit(1)
result[key] = value
return result
def create_build_ninja():
d=create_make_config()
d["irpf90_files"] = [ "src/{0}".format(x) for x in
"""
IRPF90_temp/build.ninja irpf90.make irpf90_entities
tags libezfio_groups-gen.py libezfio_util-gen.py
""".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.irp.f ezfio-head.py
libezfio_util.irp.f ezfio-tail.py read_config.py
f_types.py test.py groups.py
""".split() ] + [ "make.config" ]
d["irpf90_files"] = ' '.join(d["irpf90_files"])
d["irpf90_sources"] = ' '.join(d["irpf90_sources"])
template = """
rule compile_irpf90
command = bash -c 'source .make.config.sh ; cd src ; {IRPF90} --ninja'
description = Compiling IRPF90
rule build_irpf90_a
command = {NINJA} -C src/IRPF90_temp && touch $out
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 ; {RANLIB} lib/libezfio_irp.a
description = Building libezfio_irp.a
rule build_python
command = cd src ; python2 create_python.py
description = Building Python module
rule build_ocaml
command = cd src ; python2 create_ocaml.py
description = Building Ocaml module
build {irpf90_files}: compile_irpf90 | {irpf90_sources} {CONFIG_FILES}
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
build Python/ezfio.py: build_python | lib/libezfio.a
build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a
"""
d["CONFIG_FILES"] = CONFIG_FILES
write_if_different('generated.ninja',template.format(**d))
if __name__ == '__main__':
create_build_ninja()

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
import os,sys import os,sys
ROOT = os.path.dirname(__file__)+'/../../' ROOT = os.path.dirname(__file__)+'/../../'
@ -6,7 +6,7 @@ file = open(ROOT+'version','r')
lines = file.readlines() lines = file.readlines()
file.close() file.close()
file = open(sys.argv[1],'a') file = open(sys.argv[1],'a')
print >>file, 'Version:'+lines[0].split('=')[1] print('Version:'+lines[0].split('=')[1], file=file)
file.close() file.close()

View File

@ -5,6 +5,6 @@ cd ../.git/hooks/
for i in commit-msg post-commit for i in commit-msg post-commit
do do
rm $i rm --force -- $i
ln -s $OLD_DIR/$i $PWD/$i ln -s $OLD_DIR/$i $PWD/$i
done done

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
import os import os
ROOT = os.path.dirname(__file__)+'/../../' ROOT = os.path.dirname(__file__)+'/../../'
@ -6,7 +6,7 @@ ROOT = os.path.dirname(__file__)+'/../../'
file = open(ROOT+'version','r') ; file = open(ROOT+'version','r') ;
lines = file.readlines() ; lines = file.readlines() ;
file.close() ; file.close() ;
v = map(int,lines[0].split('=')[1].split('.')); v = list(map(int,lines[0].split('=')[1].split('.')));
v[2] += 1 v[2] += 1
lines[0] = "VERSION=%d.%d.%d\n"%tuple(v) lines[0] = "VERSION=%d.%d.%d\n"%tuple(v)

9
make.config Normal file
View File

@ -0,0 +1,9 @@
VERSION ?= 2.0.7
RANLIB ?= ranlib
IRPF90 ?= irpf90
CC ?= gcc
FC ?= gfortran -g -ffree-line-length-none -fPIC
FCFLAGS ?= -fPIC
ARCHIVE ?= ar crs
RANLIB ?= ranlib
PYTHON ?= python3

View File

@ -1,71 +1,68 @@
.EXPORT_ALL_VARIABLES: # 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
DEFAULT_TARGET: all
include ../make.config include ../make.config
export
# Dark magic below modify with caution! include irpf90.make
# "You are Not Expected to Understand This"
# .
# /^\ .
# /\ "V",
# /__\ I O o
# //..\\ I .
# \].`[/ I
# /l\/j\ (] . O
# /. ~~ ,\/I .
# \\L__j^\/I o
# \/--v} I o .
# | | I _________
# | | I c(` ')o
# | l I \. ,/
# _/j L l\_! _//^---^\\_
irpf90.make: $(wildcard *.irp.f) ../config/* IRPF90_temp/system.o IRPF90_temp/system_f.o
$(IRPF90)
ifeq ($(BUILD_SYSTEM),ninja) include ../version
BUILD_FILE=IRPF90_temp/build.ninja
IRPF90FLAGS += -j
else ifeq ($(BUILD_SYSTEM),make)
BUILD_FILE=IRPF90_temp/build.make
BUILD_SYSTEM += -j
else
DUMMY:
$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')
endif
define run_and_touch
$(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)
endef
export PYTHONPATH:=$(CURDIR):$(PYTHONPATH)
.PHONY: static all .PHONY: static all
all: static ../Python/ezfio.py ../Ocaml/ezfio.ml all: static ../Python/ezfio.py ../Ocaml/ezfio.ml
static: ../lib/libezfio.a ../lib/libezfio_irp.a static: ../lib/libezfio.a ../lib/libezfio_irp.a
IRPF90_temp/system.o: system.c
mkdir -p IRPF90_temp/
$(CC) -c system.c -o IRPF90_temp/system.o
IRPF90_temp/system_f.o: system_f.f90
mkdir -p IRPF90_temp/
$(FC) -c system_f.f90 -o IRPF90_temp/system_f.o && cp system.mod IRPF90_temp/
../lib/libezfio.a: IRPF90_temp/irpf90.a ../lib/libezfio.a: IRPF90_temp/irpf90.a
rm -f ../lib/libezfio.a rm -f ../lib/libezfio.a
cp IRPF90_temp/irpf90.a ../lib/libezfio.a $(ARCHIVE) ../lib/libezfio.a IRPF90_temp/system_f.o IRPF90_temp/system.o $(OBJ1)
$(RANLIB) ../lib/libezfio.a $(RANLIB) ../lib/libezfio.a
#No more irp_stack
../lib/libezfio_irp.a: ../lib/libezfio.a ../lib/libezfio_irp.a: ../lib/libezfio.a
cp ../lib/libezfio.a ../lib/libezfio_irp.a rm -f ../lib/libezfio_irp.a
$(ARCHIVE) ../lib/libezfio_irp.a IRPF90_temp/system_f.o IRPF90_temp/system.o $(filter-out IRPF90_temp/irp_stack.irp.o, $(OBJ1) )
$(RANLIB) ../lib/libezfio_irp.a
../Python/ezfio.py: ../lib/libezfio.a ../Python/ezfio.py: ../lib/libezfio.a
python2 create_python.py $(PYTHON) create_python.py
../Ocaml/ezfio.ml: ../lib/libezfio.a ../Ocaml/ezfio.ml: ../lib/libezfio.a
python2 create_ocaml.py $(PYTHON) create_ocaml.py
IRPF90_temp/irpf90.a: $(BUILD_FILE)
$(call run_and_touch, $<, $@)
$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print) ../config/*
$(IRPF90) $(IRPF90FLAGS)
clean:
rm -f -- $(BUILD_FILE) $(shell find IRPF90_temp -type f \( -name "*.o" -o -name "*.mod" -name "*.a" \) -delete;)
rm -f ../lib/libezfio.a ../lib/libezfio_irp.a
veryclean: clean
rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -46,7 +46,7 @@ def run():
for group in groups.keys(): for group in groups.keys():
for var,type,dims,command in groups[group]: for var,type,dims,command in groups[group]:
if command is not "": if command != "":
continue continue
dims_py = str(dims) dims_py = str(dims)
for g in groups.keys(): for g in groups.keys():

View File

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

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -25,10 +25,11 @@
import os, sys import os, sys
import time import time
import cStringIO as StringIO import io as StringIO
from gzip import GzipFile from gzip import GzipFile
import tempfile import tempfile
import threading import threading
from functools import reduce
def version(x): def version(x):
b = [int(i) for i in x.split('.')] b = [int(i) for i in x.split('.')]
@ -40,7 +41,7 @@ def size(x):
def flatten(l): def flatten(l):
res = [] res = []
for i in l: for i in l:
if hasattr(i, "__iter__") and not isinstance(i, basestring): if hasattr(i, "__iter__") and not isinstance(i, str):
res.extend(flatten(i)) res.extend(flatten(i))
else: else:
res.append(i) res.append(i)
@ -101,7 +102,7 @@ def get_conv(type):
else: else:
raise TypeError raise TypeError
elif type == "ch": elif type == "ch":
conv = lambda x: x.strip() conv = lambda x: x.decode('utf-8').strip() if isinstance(x,bytes) else x.strip()
else: else:
raise TypeError raise TypeError
return conv return conv
@ -149,18 +150,18 @@ class ezfio_obj(object):
except OSError: except OSError:
pass pass
file = open(path.strip()+'/.version','w') file = open(path.strip()+'/.version','w')
print >>file,self.version print(self.version, file=file)
file.close() file.close()
def error(self,where,txt): def error(self,where,txt):
print '------------------------------------------------------------' print('------------------------------------------------------------')
print 'EZFIO File : '+self.filename print('EZFIO File : '+self.filename)
print 'EZFIO Error in : '+where.strip() print('EZFIO Error in : '+where.strip())
print '------------------------------------------------------------' print('------------------------------------------------------------')
print '' print('')
print txt.strip() print(txt.strip())
print '' print('')
print '------------------------------------------------------------' print('------------------------------------------------------------')
raise IOError raise IOError
def get_filename(self): def get_filename(self):
@ -233,7 +234,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
indices = [] indices = []
values = [] values = []
for i in xrange(isize): for i in range(isize):
try: try:
line = self.file.readline().split() line = self.file.readline().split()
except: except:
@ -250,7 +251,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
if self.buffer_rank == -1: if self.buffer_rank == -1:
self.error('write_buffer','No buffered file is open.') self.error('write_buffer','No buffered file is open.')
for i in xrange(isize): for i in range(isize):
for j in indices[i]: for j in indices[i]:
self.file.write("%4d "%(j,)) self.file.write("%4d "%(j,))
self.file.write("%24.15e\n"%(values[i],)) self.file.write("%24.15e\n"%(values[i],))

View File

@ -32,7 +32,7 @@ def main():
try: try:
EZFIO_FILE = os.environ["EZFIO_FILE"] EZFIO_FILE = os.environ["EZFIO_FILE"]
except KeyError: except KeyError:
print "EZFIO_FILE not defined" print("EZFIO_FILE not defined")
return 1 return 1
ezfio.set_file(EZFIO_FILE) ezfio.set_file(EZFIO_FILE)
@ -42,7 +42,7 @@ def main():
try: try:
f = getattr(ezfio,command) f = getattr(ezfio,command)
except AttributeError: except AttributeError:
print "{0} not found".format(command) print("{0} not found".format(command))
return 1 return 1
if command.startswith('has'): if command.startswith('has'):
@ -55,11 +55,22 @@ def main():
return 0 return 0
elif command.startswith('set'): elif command.startswith('set'):
text = sys.stdin.read()
true = True
false = False
TRUE = True
FALSE = False
T = True
F = False
try: try:
data = eval(sys.stdin.read()) data = eval(text)
except NameError:
data = text
except: except:
print "Syntax Error" print("Syntax Error")
return 1 return 1
if data is None:
data = "None"
f(data) f(data)
return 0 return 0

View File

@ -1,26 +1,26 @@
(* (*
EZFIO is an automatic generator of I/O libraries EZFIO is an automatic generator of I/O libraries
Copyright (C) 2009 Anthony SCEMAMA, CNRS Copyright (C) 2009 Anthony SCEMAMA, CNRS
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along 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., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Anthony Scemama Anthony Scemama
LCPQ - IRSAMC - CNRS LCPQ - IRSAMC - CNRS
Universite Paul Sabatier Universite Paul Sabatier
118, route de Narbonne 118, route de Narbonne
31062 Toulouse Cedex 4 31062 Toulouse Cedex 4
scemama@irsamc.ups-tlse.fr scemama@irsamc.ups-tlse.fr
*) *)
@ -31,39 +31,39 @@ Exceptions
========== ==========
*) *)
exception Read_only of string;; exception Read_only of string
(* (*
State variables State variables
=============== ===============
*) *)
let read_only = ref false;; let read_only = ref false
let ezfio_filename = ref "EZFIO_File";; let ezfio_filename = ref "EZFIO_File"
(* (*
Helper functions Helper functions
================= =================
*) *)
let check_readonly = let check_readonly =
if !read_only then if !read_only then
raise (Read_only "Read only attribute is set"); raise (Read_only "Read only attribute is set")
;;
let exists path = let exists path =
let filename = path^"/.version" in let filename = Filename.concat path ".version" in
Sys.file_exists filename Sys.file_exists filename
;;
let has group name = let has group name =
let dirname = !ezfio_filename ^ "/" ^ group in let dirname = Filename.concat !ezfio_filename group in
if (exists dirname) then if (exists dirname) then
(Sys.file_exists (dirname ^ "/" ^ name) ) Sys.file_exists @@ Filename.concat dirname name
else else
false false
;;
let has_array group name = has group (name^".gz");;
let has_array group name = has group (name^".gz")
let mkdir path = let mkdir path =
check_readonly; check_readonly;
@ -72,99 +72,59 @@ let mkdir path =
Unix.mkdir path 0o777; Unix.mkdir path 0o777;
let out_channel = open_out (path^"/.version") in let out_channel = open_out (path^"/.version") in
Printf.fprintf out_channel "%s\n" version ; Printf.fprintf out_channel "%s\n" version ;
close_out out_channel; close_out out_channel
;;
let create_group group = let create_group group =
let dirname = !ezfio_filename ^ "/" ^ group in let dirname = Filename.concat !ezfio_filename group in
if not (exists dirname) then if not (exists dirname) then
mkdir dirname; mkdir dirname
;;
let split line s =
let rec do_work lst word = function
| 0 -> word::lst
| i ->
begin
match line.[i-1] with
| a when a == s ->
if word <> "" then
do_work (word::lst) "" (i-1)
else
do_work lst "" (i-1)
| a -> do_work lst ( (Char.escaped a)^word) (i-1)
end
in do_work [] "" (String.length line)
;;
let ltrim s =
let rec do_work s l =
match s.[0] with
| '\n'
| ' ' -> do_work (String.sub s 1 (l-1)) (l-1)
| _ -> s
in
let l = String.length s in
if (l > 0) then do_work s l
else s
;;
let rtrim s = let maxval l =
let rec do_work s l =
let newl = l-1 in
match s.[newl] with
| '\n'
| ' ' -> do_work (String.sub s 0 (newl)) (newl)
| _ -> s
in
let l = String.length s in
if (l > 0) then do_work s l
else s
;;
let trim s = ltrim (rtrim s) ;;
let maxval l =
match l with match l with
| [] -> None | [] -> None
| [a] -> Some a | [a] -> Some a
| hd::tail -> Some (List.fold_left max hd tail) | hd::tail -> Some (List.fold_left max hd tail)
;;
let minval l =
let minval l =
match l with match l with
| [] -> None | [] -> None
| [a] -> Some a | [a] -> Some a
| hd::tail -> Some (List.fold_left min hd tail) | hd::tail -> Some (List.fold_left min hd tail)
;;
let at arr idx = arr.(idx);;
let size (_) = 0;; let at arr idx = arr.(idx)
(*
let size (_) = 0
*)
let n_count_ch (str,_,v) = let n_count_ch (str,_,v) =
let rec do_work accu = function let rec do_work accu = function
| 0 -> accu | 0 -> accu
| i -> | i ->
let newaccu = let newaccu =
if str.[i-1] == v then accu+1 if str.[i-1] == v then accu+1
else accu else accu
in do_work newaccu (i-1) in do_work newaccu (i-1)
in do_work 0 (String.length str) in do_work 0 (String.length str)
;;
let n_count (l,_,v) = let n_count (l,_,v) =
let rec do_work accu = function let rec do_work accu = function
| [] -> accu | [] -> accu
| h::tail -> | h::tail ->
let newaccu = let newaccu =
if h == v then accu+1 if h == v then accu+1
else accu else accu
in do_work newaccu tail in do_work newaccu tail
in do_work 0 l in do_work 0 l
;;
(*
(*
Scalars Scalars
======= =======
*) *)
@ -175,32 +135,32 @@ Read
*) *)
let read_scalar type_conversion group name = let read_scalar type_conversion group name =
let in_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name in let in_filename = Filename.concat !ezfio_filename @@ Filename.concat group name in
let in_channel = open_in in_filename in let in_channel = open_in in_filename in
let trimmed_line = trim (input_line in_channel) in let trimmed_line = String.trim (input_line in_channel) in
let result = type_conversion trimmed_line in let result = type_conversion trimmed_line in
begin begin
close_in in_channel ; close_in in_channel ;
result result
end end
;;
let fortran_bool_of_string = function let fortran_bool_of_string = function
| "T" | "t" -> true | "T" | "t" -> true
| "F" | "f" -> false | "F" | "f" -> false
| x -> raise (Failure ("fortran_bool_of_string should be T or F: "^x)) | x -> raise (Failure ("fortran_bool_of_string should be T or F: "^x))
;;
let fortran_string_of_bool = function let fortran_string_of_bool = function
| true -> "T\n" | true -> "T\n"
| false-> "F\n" | false-> "F\n"
;;
let read_int = read_scalar int_of_string ;;
let read_int64 = read_scalar Int64.of_string ;; let read_int = read_scalar int_of_string
let read_float = read_scalar float_of_string ;; let read_int64 = read_scalar Int64.of_string
let read_string= read_scalar (fun (x:string) -> x);; let read_float = read_scalar float_of_string
let read_bool = read_scalar fortran_bool_of_string;; let read_string= read_scalar (fun (x:string) -> x)
let read_bool = read_scalar fortran_bool_of_string
(* (*
Write Write
@ -208,28 +168,28 @@ Write
*) *)
let print_int out_channel i = Printf.fprintf out_channel "%20d\n" i let print_int out_channel i = Printf.fprintf out_channel "%20d\n" i
and print_int64 out_channel i = Printf.fprintf out_channel "%20Ld\n" i let print_int64 out_channel i = Printf.fprintf out_channel "%20Ld\n" i
and print_float out_channel f = Printf.fprintf out_channel "%24.15e\n" f let print_float out_channel f = Printf.fprintf out_channel "%24.15e\n" f
and print_string out_channel s = Printf.fprintf out_channel "%s\n" s let print_string out_channel s = Printf.fprintf out_channel "%s\n" s
and print_bool out_channel b = Printf.fprintf out_channel "%s\n" (fortran_string_of_bool b);; let print_bool out_channel b = Printf.fprintf out_channel "%s\n" (fortran_string_of_bool b)
let write_scalar print_fun group name s = let write_scalar print_fun group name s =
check_readonly; check_readonly;
create_group group; create_group group;
let out_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name in let out_filename = Filename.concat !ezfio_filename @@ Filename.concat group name in
let out_channel = open_out out_filename in let out_channel = open_out out_filename in
begin begin
print_fun out_channel s; print_fun out_channel s;
close_out out_channel; close_out out_channel
end end
;;
let write_int = write_scalar print_int let write_int = write_scalar print_int
and write_int64 = write_scalar print_int64 let write_int64 = write_scalar print_int64
and write_float = write_scalar print_float let write_float = write_scalar print_float
and write_bool = write_scalar print_bool let write_bool = write_scalar print_bool
and write_string = write_scalar print_string let write_string = write_scalar print_string
;;
@ -239,9 +199,9 @@ Arrays
*) *)
type 'a ezfio_data = type 'a ezfio_data =
| Ezfio_item of 'a array | Ezfio_item of 'a array
| Ezfio_data of ('a ezfio_data) array | Ezfio_data of ('a ezfio_data) array
;;
type 'a ezfio_array = type 'a ezfio_array =
@ -249,14 +209,38 @@ type 'a ezfio_array =
dim : int array; dim : int array;
data : 'a ezfio_data ; data : 'a ezfio_data ;
} }
;;
let ezfio_array_of_array ~rank ~dim ~data =
assert (rank > 0);
let read_1d data nmax =
(Ezfio_item (Array.sub data 0 nmax), Array.sub data nmax ((Array.length data) - nmax))
in
let rec read_nd data = function
| m when m<1 -> raise (Failure "dimension should not be <1")
| 1 -> read_1d data dim.(0)
| m ->
let rec do_work accu data = function
| 0 -> (Array.of_list (List.rev accu), data)
| n ->
let (newlist,rest) = read_nd data (m-1) in
do_work (newlist::accu) rest (n-1)
in
let (data,rest) = do_work [] data dim.(m-1) in
(Ezfio_data data,rest)
in
let (result,_) = read_nd data rank in
{ rank= rank;
dim= dim;
data=result;
}
let ezfio_array_of_list ~rank ~dim ~data = let ezfio_array_of_list ~rank ~dim ~data =
assert (rank > 0); assert (rank > 0);
let read_1d data nmax = let read_1d data nmax =
let rec do_work accu data = function let rec do_work accu data = function
| 0 -> (Array.of_list (List.rev accu), data) | 0 -> (Array.of_list (List.rev accu), data)
| n -> | n ->
begin begin
match data with match data with
| x::rest -> do_work (x::accu) rest (n-1) | x::rest -> do_work (x::accu) rest (n-1)
@ -277,25 +261,25 @@ let ezfio_array_of_list ~rank ~dim ~data =
do_work (newlist::accu) rest (n-1) do_work (newlist::accu) rest (n-1)
in in
let (data,rest) = do_work [] data dim.(m-1) in let (data,rest) = do_work [] data dim.(m-1) in
(Ezfio_data data,rest) (Ezfio_data data,rest)
in in
let (result,_) = read_nd data rank in let (result,_) = read_nd data rank in
{ rank= rank; { rank= rank;
dim= dim; dim= dim;
data=result; data=result;
} }
;;
let ezfio_get_element { rank=r ; dim=d ; data=data } coord = let ezfio_get_element { rank=r ; dim=d ; data=data } coord =
(*assert ((List.length coord) == r);*) (*assert ((List.length coord) == r);*)
let rec do_work buffer = function let rec do_work buffer = function
| [c] -> | [c] ->
begin match buffer with begin match buffer with
| Ezfio_item buffer -> buffer.(c) | Ezfio_item buffer -> buffer.(c)
| Ezfio_data buffer -> raise (Failure "Error in ezfio_get_element") | Ezfio_data buffer -> raise (Failure "Error in ezfio_get_element")
end end
| c::tail -> | c::tail ->
begin match buffer with begin match buffer with
| Ezfio_item buffer -> raise (Failure "Error in ezfio_get_element") | Ezfio_item buffer -> raise (Failure "Error in ezfio_get_element")
| Ezfio_data buffer -> do_work buffer.(c) tail | Ezfio_data buffer -> do_work buffer.(c) tail
@ -303,7 +287,7 @@ let ezfio_get_element { rank=r ; dim=d ; data=data } coord =
| [] -> raise (Failure "Error in ezfio_get_element") | [] -> raise (Failure "Error in ezfio_get_element")
in in
do_work data coord do_work data coord
;;
let flattened_ezfio { rank ; dim ; data } = let flattened_ezfio { rank ; dim ; data } =
@ -327,9 +311,9 @@ let flattened_ezfio { rank ; dim ; data } =
in in
match data with match data with
| Ezfio_item d -> d | Ezfio_item d -> d
| Ezfio_data d -> flatten_n rank d | Ezfio_data d -> flatten_n rank d
;;
(* (*
@ -337,57 +321,47 @@ Read
---- ----
*) *)
let unzipped_filename filename =
if not (Sys.file_exists filename) then
raise (Failure ("file "^filename^" doesn't exist"));
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in
let command = "zcat "^filename^" > "^uz_filename
in
if (Sys.command command) == 0 then
uz_filename
else
begin
Sys.remove uz_filename ;
raise (Failure ("Unable to execute :\n"^command))
end
;;
let read_rank in_channel = let read_rank in_channel =
let trimmed_line = trim (input_line in_channel) in let trimmed_line = String.trim (input_line in_channel) in
int_of_string trimmed_line int_of_string trimmed_line
;;
let read_dimensions in_channel = let read_dimensions in_channel =
let trimmed_line = trim (input_line in_channel) in let line = input_line in_channel in
let list_of_str = split trimmed_line ' ' in let arr_of_str =
Array.of_list (List.map int_of_string list_of_str) String.split_on_char ' ' line
;; |> List.filter (fun x -> x <> "")
|> Array.of_list
in
Array.map int_of_string arr_of_str
let read_array type_conversion group name : 'a ezfio_array = let read_array type_conversion group name : 'a ezfio_array =
let in_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^ ".gz" in let in_filename = (Filename.concat !ezfio_filename @@ Filename.concat group name) ^ ".gz" in
let uz_filename = unzipped_filename in_filename in let in_channel = Unix.open_process_in ("zcat "^in_filename) in
let in_channel = open_in uz_filename in
(* Read rank *) (* Read rank *)
let rank = read_rank in_channel let rank = read_rank in_channel
(* Read dimensions *) (* Read dimensions *)
and dimensions = read_dimensions in_channel and dimensions = read_dimensions in_channel
in in
begin begin
assert (rank == Array.length dimensions) ; assert (rank == Array.length dimensions) ;
(* Read one-dimensional arrays *) (* Read one-dimensional arrays *)
let read_1d nmax = let read_1d nmax =
Ezfio_item (Array.init nmax (fun i-> Ezfio_item (Array.init nmax (fun i->
type_conversion (trim (input_line in_channel))) ) let buffer = String.trim (input_line in_channel) in
try type_conversion buffer with
| Failure s -> failwith (s^": "^buffer)))
in in
(* Read multi-dimensional arrays *) (* Read multi-dimensional arrays *)
let rec read_nd = function let rec read_nd = function
| m when m<1 -> raise (Failure "dimension should not be <1") | m when m<1 -> raise (Failure "dimension should not be <1")
| 1 -> read_1d dimensions.(0) | 1 -> read_1d dimensions.(0)
| m -> | m ->
let rec do_work accu = function let rec do_work accu = function
| 0 -> Array.of_list (List.rev accu) | 0 -> Array.of_list (List.rev accu)
| n -> | n ->
let newlist = read_nd (m-1) in let newlist = read_nd (m-1) in
do_work (newlist::accu) (n-1) do_work (newlist::accu) (n-1)
in in
@ -397,20 +371,20 @@ let read_array type_conversion group name : 'a ezfio_array =
rank = rank ; rank = rank ;
dim = dimensions ; dim = dimensions ;
data = read_nd rank ; data = read_nd rank ;
} }
in in
close_in in_channel ; match Unix.close_process_in in_channel with
Sys.remove uz_filename ; | Unix.WEXITED _ -> result
result; | _ -> failwith ("Failed in reading compressed file "^in_filename)
end end
;;
let read_int_array = read_array int_of_string let read_int_array = read_array int_of_string
and read_int64_array = read_array Int64.of_string let read_int64_array = read_array Int64.of_string
and read_float_array = read_array float_of_string let read_float_array = read_array float_of_string
and read_bool_array = read_array fortran_bool_of_string let read_bool_array = read_array fortran_bool_of_string
and read_string_array = read_array (fun (x:string) -> x) let read_string_array = read_array (fun (x:string) -> x)
;;
(* (*
Write Write
@ -420,32 +394,29 @@ Write
let write_array print_fun group name a = let write_array print_fun group name a =
check_readonly; check_readonly;
create_group group; create_group group;
let out_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^".gz" in let out_filename = (Filename.concat !ezfio_filename @@ Filename.concat group name)^".gz" in
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in let command = "gzip > "^out_filename in
let out_channel = open_out uz_filename in let out_channel = Unix.open_process_out command in
let { rank=rank ; dim=dimensions ; data=data } = a in let { rank=rank ; dim=dimensions ; data=data } = a in
let data = flattened_ezfio a let data = flattened_ezfio a in
in
begin begin
(* Write rank *) (* Write rank *)
Printf.fprintf out_channel "%3d\n" rank; Printf.fprintf out_channel "%3d\n" rank;
(* Write dimensions *) (* Write dimensions *)
Array.iter (Printf.fprintf out_channel "%20d ") dimensions; Array.iter (Printf.fprintf out_channel "%20d ") dimensions;
Printf.fprintf out_channel "\n"; Printf.fprintf out_channel "\n%!";
Array.iter (print_fun out_channel) data; Array.iter (print_fun out_channel) data;
close_out out_channel ; match Unix.close_process_out out_channel with
let command = "gzip -c < "^uz_filename^" > "^out_filename | Unix.WEXITED _ -> ()
in | _ -> failwith ("Failed writing compressed file "^out_filename)
if (Sys.command command == 0) then (Sys.remove uz_filename )
else raise (Failure ("command failed:\n"^command))
end end
;;
let write_int_array = write_array print_int let write_int_array = write_array print_int
and write_int64_array = write_array print_int64 let write_int64_array = write_array print_int64
and write_float_array = write_array print_float let write_float_array = write_array print_float
and write_string_array = write_array print_string let write_string_array = write_array print_string
and write_bool_array = write_array print_bool;; let write_bool_array = write_array print_bool
(* (*
Library routines Library routines
@ -455,7 +426,7 @@ let set_file filename =
if not (exists filename) then if not (exists filename) then
begin begin
mkdir filename; mkdir filename;
mkdir (filename^"/ezfio"); mkdir (Filename.concat filename "ezfio");
let command = Printf.sprintf " let command = Printf.sprintf "
LANG= date > %s/ezfio/creation LANG= date > %s/ezfio/creation
echo $USER > %s/ezfio/user echo $USER > %s/ezfio/user
@ -465,7 +436,7 @@ let set_file filename =
raise (Failure ("Unable to create new ezfio file:\n"^filename)) raise (Failure ("Unable to create new ezfio file:\n"^filename))
end ; end ;
ezfio_filename := filename ezfio_filename := filename
;;
(*$TAIL*) (*$TAIL*)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -34,29 +34,26 @@ file = open("../version","r")
v = file.readline() v = file.readline()
file.close() file.close()
v = v.split('=')[1].strip() v = v.split('=')[1].strip()
print >>file_py, """ print("""
def get_version(self): def get_version(self):
return '%s' return '%s'
version = property(fset=None,fget=get_version) version = property(fset=None,fget=get_version)
"""%(v) """%(v), file=file_py)
file_c = open("../C/ezfio.h","w")
print >>file_c, c_header
import sys import sys
for group in groups.keys(): for group in list(groups.keys()):
print path%{ 'group' : group } print(path%{ 'group' : group })
print >>file_py, path_py%{ 'group' : group } print(path_py%{ 'group' : group }, file=file_py)
for var,type,dims,command in groups[group]: for var,type,dims,command in groups[group]:
command_py = command command_py = command
dims_py = str(dims) dims_py = str(dims)
for g in groups.keys(): for g in list(groups.keys()):
command_py = command_py.replace(g,'self.'+g) command_py = re.sub("(\W)"+g, r"\1self."+g, command_py)
dims_py = dims_py.replace(g,'self.'+g) dims_py = dims_py.replace("(\W)"+g,r'\1self.'+g)
var = var.lower() var = var.lower()
group = group.lower() group = group.lower()
strdims = tuple(map(lambda x: '('+str(x)+')',dims)) strdims = tuple(['('+str(x)+')' for x in dims])
strdims = str(strdims).replace("'","") strdims = str(strdims).replace("'","")
if len(dims) == 1: if len(dims) == 1:
strdims = strdims[:-2]+")" strdims = strdims[:-2]+")"
@ -79,9 +76,8 @@ for group in groups.keys():
'var': var, 'var': var,
'group': group, 'group': group,
'dims': strdims} 'dims': strdims}
print attributes%d print(attributes%d)
print >>file_c, attributes_c%d print(attributes_py%d, file=file_py)
print >>file_py, attributes_py%d
else: else:
d = { 'type': type, d = { 'type': type,
'var': var, 'var': var,
@ -92,16 +88,15 @@ for group in groups.keys():
'expr_py': command_py} 'expr_py': command_py}
buffer = calculated%d buffer = calculated%d
buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer) buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer)
print buffer print(buffer)
print >>file_py, calculated_py%d print(calculated_py%d, file=file_py)
elif type == "buffered": elif type == "buffered":
d = { 'group': group, d = { 'group': group,
'var': var, 'var': var,
'dims_py': dims_py, 'dims_py': dims_py,
'dims': dims } 'dims': dims }
print buffered%d print(buffered%d)
print >>file_c, buffered_c%d print(buffered_py%d, file=file_py)
print >>file_py, buffered_py%d
else: else:
dims_loop = '' dims_loop = ''
copy_loop = '' copy_loop = ''
@ -112,7 +107,7 @@ for group in groups.keys():
declar_loop = declar_loop[:-1] declar_loop = declar_loop[:-1]
for k,d in enumerate(dims): for k,d in enumerate(dims):
dims_loop += " dims("+str(k+1)+") = "+str(d)+"\n" dims_loop += " dims("+str(k+1)+") = "+str(d)+"\n"
dims_loop_py += " dims["+str(k)+"] = "+str(d)+"\n" dims_loop_py += " dims["+str(k)+"] = int("+str(d)+")\n"
for k,d in enumerate(dims): for k,d in enumerate(dims):
copy_loop += k*" "+" do i"+str(k+1)+"=1,"+str(d)+'\n' copy_loop += k*" "+" do i"+str(k+1)+"=1,"+str(d)+'\n'
copy_loop += (k+1)*" "+" %(var)s (" copy_loop += (k+1)*" "+" %(var)s ("
@ -124,7 +119,7 @@ for group in groups.keys():
copy_loop = copy_loop[:-1]%{'var': var,'group': group} + ")\n" copy_loop = copy_loop[:-1]%{'var': var,'group': group} + ")\n"
for k,d in enumerate(dims): for k,d in enumerate(dims):
copy_loop += (len(dims)-k-1)*" "+" enddo\n" copy_loop += (len(dims)-k-1)*" "+" enddo\n"
for g in groups.keys(): for g in list(groups.keys()):
dims_loop_py = dims_loop_py.replace(" "+g,' self.'+g) dims_loop_py = dims_loop_py.replace(" "+g,' self.'+g)
dims_loop_py = dims_loop_py.replace("*"+g,'*self.'+g) dims_loop_py = dims_loop_py.replace("*"+g,'*self.'+g)
dims_loop_py = dims_loop_py.replace("/"+g,'/self.'+g) dims_loop_py = dims_loop_py.replace("/"+g,'/self.'+g)
@ -145,11 +140,7 @@ for group in groups.keys():
'dims_loop_py': dims_loop_py, 'dims_loop_py': dims_loop_py,
'copy_loop': copy_loop, 'copy_loop': copy_loop,
'declar_loop' : declar_loop} 'declar_loop' : declar_loop}
print attributes_arr%d print(attributes_arr%d)
print >>file_py, attributes_arr_py%d print(attributes_arr_py%d, file=file_py)
print >>file_c, attributes_arr_c%d
print >>file_c, c_footer
file_py.close() file_py.close()
file_c.close()

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -58,23 +58,23 @@ BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s ]
END_PROVIDER END_PROVIDER
subroutine ezfio_set_%(group)s_%(var)s(%(var)s) subroutine ezfio_set_%(group)s_%(var)s(v)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Sets the %(group)s/%(var)s attribute ! Sets the %(group)s/%(var)s attribute
END_DOC END_DOC
%(type_set)s :: %(var)s %(type_set)s :: v
call ezfio_write_%(type_short)s(path_%(group)s,'%(var)s',%(var)s) call ezfio_write_%(type_short)s(path_%(group)s,'%(var)s',v)
FREE %(group)s_%(var)s FREE %(group)s_%(var)s
end subroutine end subroutine
subroutine ezfio_get_%(group)s_%(var)s(%(var)s) subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Gets the %(group)s/%(var)s attribute ! Gets the %(group)s/%(var)s attribute
END_DOC END_DOC
%(type)s :: %(var)s %(type)s :: v
%(var)s = %(group)s_%(var)s v = %(group)s_%(var)s
end subroutine end subroutine
subroutine ezfio_has_%(group)s_%(var)s(result) subroutine ezfio_has_%(group)s_%(var)s(result)
@ -111,30 +111,30 @@ BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s, %(dims)s ]
END_PROVIDER END_PROVIDER
subroutine ezfio_set_%(group)s_%(var)s(%(var)s) subroutine ezfio_set_%(group)s_%(var)s(v)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Sets the %(group)s/%(var)s attribute ! Sets the %(group)s/%(var)s attribute
END_DOC END_DOC
%(type_set)s :: %(var)s (*) %(type_set)s :: v (*)
integer :: rank, dim_max, i integer :: rank, dim_max, i
integer :: dims(10) integer :: dims(10)
rank = %(rank)s rank = %(rank)s
character*(1024) :: message character*(1024) :: message
%(dims_loop)s %(dims_loop)s
call ezfio_write_array_%(type_short)s(path_%(group)s,'%(var)s', & call ezfio_write_array_%(type_short)s(path_%(group)s,'%(var)s', &
rank,dims,%(dim_max)s,%(var)s) rank,dims,%(dim_max)s,v)
FREE %(group)s_%(var)s FREE %(group)s_%(var)s
end subroutine end subroutine
subroutine ezfio_get_%(group)s_%(var)s(%(var)s) subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Gets the %(group)s/%(var)s attribute ! Gets the %(group)s/%(var)s attribute
END_DOC END_DOC
%(type)s, intent(out) :: %(var)s (*) %(type)s, intent(out) :: v (*)
character*(1024) :: message character*(1024) :: message
%(var)s(1: %(dim_max)s ) = reshape ( %(group)s_%(var)s, (/ %(dim_max)s /) ) v(1: %(dim_max)s ) = reshape ( %(group)s_%(var)s, (/ %(dim_max)s /) )
end subroutine end subroutine
subroutine ezfio_has_%(group)s_%(var)s(result) subroutine ezfio_has_%(group)s_%(var)s(result)
@ -163,13 +163,13 @@ BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s ]
%(group)s_%(var)s = %(expr)s %(group)s_%(var)s = %(expr)s
END_PROVIDER END_PROVIDER
subroutine ezfio_get_%(group)s_%(var)s(%(var)s) subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Gets the %(group)s/%(var)s attribute ! Gets the %(group)s/%(var)s attribute
END_DOC END_DOC
%(type)s, intent(out) :: %(var)s %(type)s, intent(out) :: v
%(var)s = %(group)s_%(var)s v = %(group)s_%(var)s
end end
subroutine ezfio_free_%(group)s_%(var)s() subroutine ezfio_free_%(group)s_%(var)s()
@ -239,48 +239,38 @@ end
#--------- #---------
attributes_c = """ attributes_c = """
void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s) void ezfio_set_%(group)s_%(var)s(%(type)s %(var)s)
{ {
ezfio_set_%(group)s_%(var)s_(&%(var)s); ezfio_set_%(group)s_%(var)s_(&%(var)s);
} }
void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s)
{
ezfio_get_%(group)s_%(var)s_(%(var)s);
}
int ezfio_has_%(group)s_%(var)s()
{
ezfio_has_%(group)s_%(var)s_();
}
""" """
attributes_arr_c = """ c_header = """
void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s) #ifndef EZFIO_H
{ #define EZFIO_H
ezfio_set_%(group)s_%(var)s_(&%(var)s);
}
void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s)
{
ezfio_get_%(group)s_%(var)s_(%(var)s);
}
int ezfio_has_%(group)s_%(var)s()
{
ezfio_has_%(group)s_%(var)s_();
}
"""
calculated_c = attributes_c
c_header = """#ifndef EZFIO_H\n#define EZFIO_H
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
"""
c_footer = """
#ifdef __cplusplus
}
#endif
#endif
"""
file_h = [c_header]
file_h +=[ """
void ezfio_set_file_(char* filename, long filename_size);
void ezfio_read_buffer_(int* indices,double* values, int* isize);
void ezfio_write_buffer_(int* indices,double* values, int* isize);
"""]
file_c = [ """
typedef struct typedef struct
{ {
@ -292,7 +282,7 @@ void ezfio_set_file(char* filename)
{ {
long len; long len;
len = strlen(filename); len = strlen(filename);
ezfio_set_file_(filename,len); ezfio_set_file_(filename,mlen);
} }
sparse ezfio_read_buffer(int isize) sparse ezfio_read_buffer(int isize)
@ -307,15 +297,7 @@ void ezfio_write_buffer(sparse data, int isize)
ezfio_write_buffer_(data.indices,data.values,&isize); ezfio_write_buffer_(data.indices,data.values,&isize);
} }
""" """ ]
c_footer = """
#ifdef __cplusplus
}
#endif
#endif
"""
@ -363,7 +345,7 @@ attributes_py = """
attributes_arr_py = """ attributes_arr_py = """
def get_%(group)s_%(var)s(self): def get_%(group)s_%(var)s(self):
rank = %(rank)s rank = %(rank)s
dims = range(rank) dims = list(range(rank))
%(dims_loop_py)s %(dims_loop_py)s
dim_max = 1 dim_max = 1
for d in dims: for d in dims:
@ -377,7 +359,7 @@ attributes_arr_py = """
def set_%(group)s_%(var)s(self,%(var)s): def set_%(group)s_%(var)s(self,%(var)s):
rank = %(rank)s rank = %(rank)s
dims = range(rank) dims = list(range(rank))
%(dims_loop_py)s %(dims_loop_py)s
dim_max = 1 dim_max = 1
for d in dims: for d in dims:

View File

@ -128,16 +128,16 @@ logical function exists(path)
character*(*) :: path character*(*) :: path
character*(32) :: V character*(32) :: V
inquire(file=trim(path)//'/.version',exist=exists) inquire(file=trim(path)//'/.version',exist=exists)
! if (exists) then if (exists) then
! open(libezfio_iunit,file=trim(path)//'/.version') open(libezfio_iunit,file=trim(path)//'/.version')
! read(libezfio_iunit,*) V read(libezfio_iunit,*) V
! close(libezfio_iunit) close(libezfio_iunit)
! integer :: char_to_version ! integer :: char_to_version
! if (char_to_version(V) > char_to_version(libezfio_version)) then ! if (char_to_version(V) > char_to_version(libezfio_version)) then
! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//& ! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//&
! ' but the current installed version is '//trim(libezfio_version)//'') ! ' but the current installed version is '//trim(libezfio_version)//'')
! endif ! endif
! endif endif
end function end function
subroutine ezfio_set_file(filename_in) subroutine ezfio_set_file(filename_in)
@ -147,6 +147,9 @@ subroutine ezfio_set_file(filename_in)
END_DOC END_DOC
character*(*) :: filename_in character*(*) :: filename_in
character(8) :: date
character(73) :: time
character(32) :: user
if (filename_in == '') then if (filename_in == '') then
call ezfio_error(irp_here,'EZFIO file name is empty.') call ezfio_error(irp_here,'EZFIO file name is empty.')
@ -157,16 +160,16 @@ subroutine ezfio_set_file(filename_in)
if (.not.exists(libezfio_filename)) then if (.not.exists(libezfio_filename)) then
call ezfio_mkdir(libezfio_filename) call ezfio_mkdir(libezfio_filename)
call ezfio_mkdir(trim(libezfio_filename)//'/ezfio') call ezfio_mkdir(trim(libezfio_filename)//'/ezfio')
call system('LANG= date > '//trim(libezfio_filename)//'/ezfio/creation')
call system('echo $USER > '//trim(libezfio_filename)//'/ezfio/user') ! using keyword arguments
BEGIN_SHELL [ /usr/bin/env python2 ] call date_and_time(DATE=date,TIME=time)
import os open (unit=73, file=trim(libezfio_filename)//'/ezfio/creation', ACTION='WRITE', STATUS='UNKNOWN')
command = "'echo %s > '//trim(libezfio_filename)//'/ezfio/library'" write(73,*) time, ' ', date
cwd = os.getcwd() close(73)
cwd = cwd.split('src')[:-1] open (unit=73, file=trim(libezfio_filename)//'/ezfio/user', ACTION='WRITE', STATUS='UNKNOWN')
cwd = '/'.join(cwd) call getenv('USER',user)
print "call system("+command%cwd+")" write(73,*) user
END_SHELL close(73)
endif endif
TOUCH libezfio_filename TOUCH libezfio_filename
@ -178,9 +181,9 @@ subroutine ezfio_finish()
! Close all open buffers ! Close all open buffers
END_DOC END_DOC
close(libezfio_iunit) close(libezfio_iunit)
BEGIN_SHELL [ /usr/bin/env python2 ] BEGIN_SHELL [ /usr/bin/env python3 ]
import os import os
from zlib import crc32 from zlib import crc32
print ' call irp_finalize_%s'%(str(abs(crc32(os.getcwd())))) print(' call irp_finalize_%s'%(str(abs(crc32(os.getcwd().encode())))))
END_SHELL END_SHELL
end end

View File

@ -22,7 +22,7 @@
! 31062 Toulouse Cedex 4 ! 31062 Toulouse Cedex 4
! scemama@irsamc.ups-tlse.fr ! scemama@irsamc.ups-tlse.fr
BEGIN_SHELL [ /usr/bin/env python2 ] BEGIN_SHELL [ /usr/bin/env python3 ]
import groups import groups
END_SHELL END_SHELL

View File

@ -22,6 +22,7 @@
! 31062 Toulouse Cedex 4 ! 31062 Toulouse Cedex 4
! scemama@irsamc.ups-tlse.fr ! scemama@irsamc.ups-tlse.fr
BEGIN_PROVIDER [ integer, PID ] BEGIN_PROVIDER [ integer, PID ]
&BEGIN_PROVIDER [ character*(256), PID_str ] &BEGIN_PROVIDER [ character*(256), PID_str ]
implicit none implicit none
@ -29,15 +30,12 @@
! Current process ID ! Current process ID
END_DOC END_DOC
integer :: getpid integer :: getpid
character*(240) :: hostname character*(240) :: hostname
PID = getpid() PID = getpid()
write(PID_str,'(I8.8)') PID write(PID_str,'(I8.8)') PID
call HOSTNM(hostname) call HOSTNM(hostname)
write(PID_str,'(A,''.'',I8.8,X)') trim(hostname), PID write(PID_str,'(A,''.'',I8.8,X)') trim(hostname), PID
PID_str = trim(PID_str) PID_str = trim(PID_str)
print *, PID_str
call sleep(1)
END_PROVIDER END_PROVIDER
logical function ezfio_exists(path) logical function ezfio_exists(path)
@ -56,6 +54,7 @@ logical function ezfio_exists(path)
end function end function
subroutine ezfio_mkdir(path) subroutine ezfio_mkdir(path)
use system
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Creates a directory ! Creates a directory
@ -66,7 +65,7 @@ subroutine ezfio_mkdir(path)
call ezfio_error(irp_here,'Read-only file.') call ezfio_error(irp_here,'Read-only file.')
endif endif
if (.not.ezfio_exists(path)) then if (.not.ezfio_exists(path)) then
call system('mkdir '//trim(path)) call mkdir(trim(path)//char(0))
open(unit=libezfio_iunit,file=trim(path)//'/.version') open(unit=libezfio_iunit,file=trim(path)//'/.version')
write(libezfio_iunit,'(A)') libezfio_version write(libezfio_iunit,'(A)') libezfio_version
close(libezfio_iunit) close(libezfio_iunit)
@ -75,6 +74,7 @@ end subroutine
subroutine libezfio_openz(filename,mode,err) subroutine libezfio_openz(filename,mode,err)
use system
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Opens a compressed file ! Opens a compressed file
@ -86,7 +86,7 @@ subroutine libezfio_openz(filename,mode,err)
err=1 err=1
if (mode(1:1) == 'r') then if (mode(1:1) == 'r') then
call system('zcat '//trim(filename)//' > '//trim(fifo)) call zcat(trim(filename)//char(0), trim(fifo)//char(0))
open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='READ') open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='READ')
err=0 err=0
else if (mode(1:1) == 'w') then else if (mode(1:1) == 'w') then
@ -97,7 +97,30 @@ subroutine libezfio_openz(filename,mode,err)
endif endif
end end
subroutine libezfio_reopenz_unformatted(filename,mode,err)
implicit none
BEGIN_DOC
! Opens a compressed file
END_DOC
character*(*) :: filename, mode
character*(1024) :: fifo
integer :: err
fifo = trim(filename)//'.'//trim(PID_str)
err=1
if (mode(1:1) == 'r') then
call ezfio_error(irp_here,'Mode '//trim(mode)//' is not implemented.')
else if (mode(1:1) == 'w') then
close(unit=libezfio_iunit)
open(unit=libezfio_iunit,file=trim(fifo),form='UNFORMATTED',action='WRITE',access='STREAM',position='APPEND')
err=0
else
call ezfio_error(irp_here,'Mode '//trim(mode)//' is not implemented.')
endif
end
subroutine libezfio_closez(filename,mode) subroutine libezfio_closez(filename,mode)
use system
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Closes a compressed file ! Closes a compressed file
@ -107,18 +130,18 @@ subroutine libezfio_closez(filename,mode)
fifo = trim(filename)//'.'//trim(PID_str) fifo = trim(filename)//'.'//trim(PID_str)
if (mode(1:1) == 'w') then if (mode(1:1) == 'w') then
close(unit=libezfio_iunit) close(unit=libezfio_iunit)
call system('gzip -c < '//trim(fifo)//' > '//trim(filename)) call gzip(trim(fifo)//char(0), trim(filename)//char(0))
open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='WRITE') open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='WRITE')
endif endif
close(unit=libezfio_iunit,status='DELETE') close(unit=libezfio_iunit,status='DELETE')
end end
BEGIN_SHELL [ /usr/bin/env python2 ] BEGIN_SHELL [ /usr/bin/env python3 ]
from f_types import format, t_short from f_types import format, t_short
template = """ template_nowrite = """
subroutine ezfio_read_%(type_short)s(dir,fil,dat) subroutine ezfio_read_%(type_short)s(dir,fil,dat)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
@ -153,7 +176,7 @@ subroutine ezfio_write_%(type_short)s(dir,fil,dat)
open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE') open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE')
write(libezfio_iunit,%(fmt)s) dat write(libezfio_iunit,%(fmt)s) dat
close(libezfio_iunit) close(libezfio_iunit)
call system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) ) call rename(trim(l_filename(1)),trim(l_filename(2)) )
end end
subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
@ -168,6 +191,7 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
%(type)s :: dat(dim_max) %(type)s :: dat(dim_max)
integer :: err integer :: err
character*(1024) :: l_filename character*(1024) :: l_filename
character*(32), allocatable :: buffer(:)
l_filename=trim(dir)//'/'//fil//'.gz' l_filename=trim(dir)//'/'//fil//'.gz'
err = 0 err = 0
@ -194,20 +218,21 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
endif endif
enddo enddo
allocate (buffer(dim_max))
read(libezfio_iunit,'(A)') buffer(1:dim_max)
do i=1,dim_max do i=1,dim_max
if (err /= 0) then read(buffer(i),%(fmt)s) dat(i)
call ezfio_error(irp_here,'Error reading data in '//trim(l_filename)//&
'.')
endif
read(libezfio_iunit,%(fmt)s) dat(i)
enddo enddo
deallocate(buffer)
call libezfio_closez(trim(l_filename),'r') call libezfio_closez(trim(l_filename),'r')
return return
else else
call ezfio_error(irp_here,'Attribute '//trim(l_filename)//' is not set') call ezfio_error(irp_here,'Attribute '//trim(l_filename)//' is not set')
endif endif
end end
"""
template_write = """
subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
implicit none implicit none
BEGIN_DOC BEGIN_DOC
@ -219,7 +244,9 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
integer, intent(in) :: dim_max integer, intent(in) :: dim_max
%(type)s, intent(in) :: dat(dim_max) %(type)s, intent(in) :: dat(dim_max)
integer :: err integer :: err
integer :: i
character*(1024) :: l_filename(2) character*(1024) :: l_filename(2)
character*(25), allocatable :: buffer(:)
if (libezfio_read_only) then if (libezfio_read_only) then
call ezfio_error(irp_here,'Read-only file.') call ezfio_error(irp_here,'Read-only file.')
endif endif
@ -231,17 +258,22 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
if (err == 0) then if (err == 0) then
write(libezfio_iunit,'(I3)') rank write(libezfio_iunit,'(I3)') rank
write(libezfio_iunit,'(30(I20,X))') dims(1:rank) write(libezfio_iunit,'(30(I20,X))') dims(1:rank)
close(unit=libezfio_iunit)
integer :: i allocate (buffer(dim_max))
do i=1,dim_max do i=1,dim_max
write(libezfio_iunit,%(fmt)s) dat(i) write(buffer(i)(1:24), %(fmt)s) dat(i)
buffer(i)(25:25) = ACHAR(10)
enddo enddo
call libezfio_reopenz_unformatted(trim(l_filename(1)),'wb',err)
write(libezfio_iunit) buffer
call libezfio_closez(trim(l_filename(1)),'w') call libezfio_closez(trim(l_filename(1)),'w')
deallocate(buffer)
endif endif
call system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) ) call rename(trim(l_filename(1)),trim(l_filename(2)) )
end end
""" """
template_no_logical = """ template_no_logical = """
integer function n_count_%(type_short)s(array,isize,val) integer function n_count_%(type_short)s(array,isize,val)
implicit none implicit none
@ -264,9 +296,11 @@ end function
! Build Python functions ! Build Python functions
""" """
for t in format.keys(): for t in format.keys():
print template%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] } print(template_nowrite%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] })
if not t.startswith("character"):
print(template_write%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] })
if t != "logical": if t != "logical":
print template_no_logical%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] } print(template_no_logical%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] })
template_py = """ template_py = """
def read_%(type_short)s(self,dir,fil): def read_%(type_short)s(self,dir,fil):
@ -293,7 +327,7 @@ template_py = """
l_filename += [ dir.strip()+'/'+fil ] l_filename += [ dir.strip()+'/'+fil ]
dat = conv(dat) dat = conv(dat)
file = open(l_filename[0],'w') file = open(l_filename[0],'w')
print >>file,'%(fmt)s'%%(dat,) print('%(fmt)s'%%(dat,), file=file)
file.close() file.close()
os.rename(l_filename[0],l_filename[1]) os.rename(l_filename[0],l_filename[1])
@ -333,13 +367,13 @@ template_py = """
file.write("\\n") file.write("\\n")
dat = flatten(dat) dat = flatten(dat)
for i in xrange(dim_max): for i in range(dim_max):
file.write("%(fmt)s\\n"%%(dat[i],)) file.write("%(fmt)s\\n"%%(dat[i],))
file.flush() file.flush()
buffer = file.getvalue() buffer = file.getvalue()
file.close() file.close()
file = GzipFile(filename=l_filename[0],mode='wb') file = GzipFile(filename=l_filename[0],mode='wb')
file.write(buffer) file.write(buffer.encode())
file.close() file.close()
os.rename(l_filename[0],l_filename[1]) os.rename(l_filename[0],l_filename[1])
except: except:
@ -349,21 +383,63 @@ template_py = """
file_py = open("libezfio_util-gen.py","w") file_py = open("libezfio_util-gen.py","w")
for t in format.keys(): for t in format.keys():
print >>file_py, template_py%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][1] } print (template_py%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][1] }, file=file_py)
import os import os
command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'" command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'"
cwd = os.getcwd() cwd = os.getcwd()
cwd = cwd.split('src')[:-1] cwd = cwd.split('src')[:-1]
cwd = '/'.join(cwd) cwd = '/'.join(cwd)
print >>file_py, """ print("""
LIBRARY = "%s" LIBRARY = "%s"
"""%cwd """%cwd,file=file_py)
file_py.close() file_py.close()
END_SHELL END_SHELL
subroutine ezfio_write_array_ch(dir,fil,rank,dims,dim_max,dat)
implicit none
BEGIN_DOC
! Writes a string array
END_DOC
character*(*), intent(in) :: dir, fil
integer, intent(in) :: rank
integer, intent(in) :: dims(rank)
integer, intent(in) :: dim_max
character*(*), intent(in) :: dat(dim_max)
integer :: err
integer :: i
character*(1024) :: l_filename(2)
integer :: length
character(len=:), allocatable :: buffer
if (libezfio_read_only) then
call ezfio_error(irp_here,'Read-only file.')
endif
l_filename(1)=trim(dir)//'/.'//fil//trim(PID_str)//'.gz'
l_filename(2)=trim(dir)//'/'//fil//'.gz'
err = 0
call libezfio_openz(trim(l_filename(1)),'wb',err)
if (err == 0) then
write(libezfio_iunit,'(I3)') rank
write(libezfio_iunit,'(30(I20,X))') dims(1:rank)
close(unit=libezfio_iunit)
length = len(dat(1))
allocate( character(len=(length+1)*dim_max) :: buffer )
do i=1,dim_max
write(buffer((i-1)*(length+1)+1:i*(length+1)-1), '(A)') dat(i)
buffer(i*(length+1):i*(length+1)) = ACHAR(10)
enddo
call libezfio_reopenz_unformatted(trim(l_filename(1)),'wb',err)
write(libezfio_iunit) buffer
call libezfio_closez(trim(l_filename(1)),'w')
deallocate(buffer)
endif
call rename(trim(l_filename(1)),trim(l_filename(2)) )
end
BEGIN_PROVIDER [ integer, libezfio_buffer_rank ] BEGIN_PROVIDER [ integer, libezfio_buffer_rank ]
BEGIN_DOC BEGIN_DOC
! Rank of the buffer ready for reading ! Rank of the buffer ready for reading

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -31,7 +31,7 @@ import os, sys
lines = [] lines = []
for filename in [ '../config/'+i for i in os.listdir('../config')]: for filename in [ '../config/'+i for i in os.listdir('../config')]:
file = open(filename,'r') file = open(filename,'r')
lines += map(lambda x: (x,filename), file.readlines()) lines += [(x,filename) for x in file.readlines()]
try: try:
if lines[-1] != '': if lines[-1] != '':
lines.append( ('', filename) ) lines.append( ('', filename) )
@ -51,7 +51,7 @@ for line, filename in lines:
groups[group] = my_list groups[group] = my_list
elif line[0] != ' ': # New group elif line[0] != ' ': # New group
group = line.strip() group = line.strip()
if group in groups.keys(): if group in list(groups.keys()):
my_list = groups[group] my_list = groups[group]
else: else:
my_list = [] my_list = []
@ -76,12 +76,12 @@ for line, filename in lines:
my_list.append(tuple(buffer)) my_list.append(tuple(buffer))
except: except:
import sys, time import sys, time
print >>sys.stderr, '' print('', file=sys.stderr)
print >>sys.stderr, '*'*80 print('*'*80, file=sys.stderr)
print >>sys.stderr, 'Error in EZFIO config file '+filename+' :' print('Error in EZFIO config file '+filename+' :', file=sys.stderr)
print >>sys.stderr, line print(line, file=sys.stderr)
print >>sys.stderr, '*'*80 print('*'*80, file=sys.stderr)
print >>sys.stderr, '' print('', file=sys.stderr)
time.sleep(3) time.sleep(3)
sys.exit(1) sys.exit(1)

45
src/system.c Normal file
View File

@ -0,0 +1,45 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "zlib.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
void fortran_mkdir(char* filename) {
if (mkdir (filename, S_IRWXU)) {
perror (strerror (errno));
}
}
#define BUFSIZE 16384
void gzip(char* filename, char* output) {
FILE* in = fopen(filename,"r");
gzFile out = gzopen(output,"w");
char buffer[BUFSIZE];
unsigned int size;
while (!feof(in)) {
size = (unsigned int) fread (buffer, sizeof(char), BUFSIZE, in);
gzwrite(out, buffer, size);
}
fclose(in);
gzclose(out);
}
void zcat(char* filename, char* output) {
gzFile in = gzopen(filename,"r");
FILE* out = fopen(output,"w");
char buffer[BUFSIZE];
int size;
while (!gzeof(in)) {
size = gzread (in, buffer, BUFSIZE);
fwrite(buffer, sizeof(char), (size_t) size, out);
}
gzclose(in);
fclose(out);
}

24
src/system_f.f90 Normal file
View File

@ -0,0 +1,24 @@
module system
USE iso_c_binding
INTERFACE
SUBROUTINE mkdir(filename) BIND(C,name="fortran_mkdir")
USE iso_c_binding
CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*)
END SUBROUTINE
SUBROUTINE gzip(filename,output) BIND(C,name="gzip")
USE iso_c_binding
CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*)
CHARACTER(kind=C_CHAR),INTENT(in) :: output(*)
END SUBROUTINE
SUBROUTINE zcat(filename,output) BIND(C,name="zcat")
USE iso_c_binding
CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*)
CHARACTER(kind=C_CHAR),INTENT(in) :: output(*)
END SUBROUTINE
END INTERFACE
end module

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries # EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS # Copyright (C) 2009 Anthony SCEMAMA, CNRS
# #
@ -44,7 +44,7 @@ values = []
isize = 5 isize = 5
EZFIO.open_read_ao_two_int() EZFIO.open_read_ao_two_int()
indices,values = EZFIO.read_buffer(isize) indices,values = EZFIO.read_buffer(isize)
print indices print(indices)
print values print(values)
EZFIO.close_read_ao_two_int() EZFIO.close_read_ao_two_int()

View File

@ -1 +1 @@
VERSION=1.3.2 VERSION=2.0.7