Compare commits

...

47 Commits

Author SHA1 Message Date
Anthony Scemama 66d3dd5d8e Removed OpenMP because I/O is not thread safe 2023-10-05 15:04:14 +02:00
Anthony Scemama dba01c4fe0 Added int for dimensions 2023-09-22 16:20:18 +02:00
Anthony Scemama 0520b5e2cf Use (L1) for logicals to avoid bugs between ifort and gfortran 2023-06-28 13:47:39 +02:00
Anthony Scemama d5805497fa Added ezfio_array_of_array 2022-01-11 10:30:07 +01:00
Anthony Scemama ed1df9f3c1 Regexp for evaluated commands 2021-06-01 14:50:33 +02:00
Anthony Scemama ccee52d00c Use irpf90 v2.0.5
Version:2.0.7
2020-12-06 21:18:12 +01:00
Anthony Scemama 3777ff3d95 Merge branch 'master' of gitlab.com:scemama/EZFIO
Version:2.0.6
2020-12-03 18:39:19 +01:00
Anthony Scemama 7560a01faa more robust functions
Version:2.0.5
2020-12-03 18:39:04 +01:00
Pierre-Francois Loos 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
Anthony Scemama e2a79a0c53 Fixed character type
Version:2.0.2
2020-05-05 01:31:00 +02:00
Anthony Scemama ec1956dc99 Update README
Version:2.0.2
2020-02-20 19:13:22 +01:00
Anthony Scemama 7e6be9ab45 Python3.
Version:2.0.0

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

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

Version:1.4.0
2019-01-22 00:29:46 +01:00
Anthony Scemama 744cbac511 iso_c_bindings 2019-01-21 18:01:02 +01:00
Anthony Scemama 6b215092c6 Updated version 2019-01-16 18:03:25 +01:00
Anthony Scemama 6301272b72 Fixed set None 2019-01-16 18:01:07 +01:00
Anthony Scemama 658a9e3132 Fixed ezfio set in bash for strings 2019-01-04 18:16:14 +01:00
Anthony Scemama 93cfb0ec92 Fixed EZFIO.ml 2018-07-27 14:39:32 +02:00
Anthony Scemama 8e20da23d5 Better error message in OCaml 2018-07-10 15:27:43 +02:00
Anthony Scemama 4142dac475 Accelerated write 2018-06-06 00:05:08 +02:00
Anthony Scemama 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
#
# ezfio shell command with completion
#
EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
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()
{
_require_first_argument $@ || return 1
_require_first_argument "$@" || return 1
if [[ ! -d "$1" ]]
then
mkdir -p "$1" || return 1
fi
export EZFIO_FILE="$1"
export EZFIO_FILE=$1
_ezfio_info "Set file ${EZFIO_FILE}"
return 0
}
@ -103,8 +106,8 @@ function _ezfio_unset_file()
function _ezfio_has()
{
_require_ezfio_file || return 1
_require_first_argument $@ || return 1
_require_ezfio_file || return 1
_require_first_argument "$@" || return 1
if [[ ! -d "${EZFIO_FILE}/${1,,}" ]]
then
@ -125,12 +128,12 @@ function _ezfio_get()
if [[ -z "$1" ]]
then
ls ${EZFIO_FILE} && return 0 || return 1
ls "${EZFIO_FILE}" && return 0 || return 1
fi
if [[ -z "$2" ]]
then
ls "${EZFIO_FILE}/${1,,}" && return 0 || return 1
ls -- "${EZFIO_FILE}/${1,,}" && return 0 || return 1
fi
_ezfio_py get $@ && return 0 || return 1
@ -138,13 +141,13 @@ function _ezfio_get()
function _ezfio_set()
{
_require_ezfio_file || return 1
_require_first_argument $@ || return 1
_require_second_argument $@ || return 2
_require_ezfio_file || return 1
_require_first_argument "$@" || return 1
_require_second_argument "$@" || return 2
if [[ -z "$3" ]]
if [[ -z $3 ]]
then
_ezfio_py set $@ || return 1
_ezfio_py set "$@" || return 1
else
echo "$3" | _ezfio_py set "$1" "$2" || return 1
fi
@ -158,22 +161,22 @@ function ezfio()
case $1 in
"has")
shift
_ezfio_has $@
_ezfio_has "$@"
;;
"set")
shift
_ezfio_set $@
_ezfio_set "$@"
;;
"get")
shift
_ezfio_get $@
_ezfio_get "$@"
;;
"set_file")
shift
_ezfio_set_file $@
_ezfio_set_file "$@"
;;
"unset_file")
@ -212,12 +215,12 @@ _Complete()
prev="${COMP_WORDS[COMP_CWORD-1]}"
prev2="${COMP_WORDS[COMP_CWORD-2]}"
if [[ -n ${EZFIO_FILE} && -d ${EZFIO_FILE} ]]
if [[ -n "${EZFIO_FILE}" && -d "${EZFIO_FILE}" ]]
then
case "${prev2}" in
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
;;
esac
@ -228,7 +231,7 @@ _Complete()
return 0
;;
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
;;
*)
@ -260,3 +263,4 @@ _Complete()
}
complete -F _Complete ezfio

View File

View File

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

View File

@ -28,28 +28,24 @@ include make.config
.PHONY: default clean veryclean archive
default: make.config
cd src $(MAKE)
cd src && $(MAKE)
clean:
- 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
archive: veryclean
git archive --format=tar HEAD > EZFIO.$(VERSION).tar
mkdir EZFIO ; cd EZFIO ; tar -xvf ../EZFIO.$(VERSION).tar
rm EZFIO.$(VERSION).tar
tar -zcvf EZFIO.$(VERSION).tar.gz EZFIO
rm -rf EZFIO
make.config:
./configure.py
veryclean:
$(MAKE) -C src veryclean
rm -f make.config
rm -f Ocaml/ezfio.ml
rm -f Python/ezfio.py
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
automatically an I/O library from a simple configuration file. The
produced library contains Fortran subroutines to read/write the data
from/to disk, and to check if the data exists.
A Python and an Ocaml API are also provided.
from/to disk, and to check if the data exists. A Python and an Ocaml API
are also provided.
With EZFIO, the 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.
plain text file, and for array data the file is a gzipped text file.
Starting with version 2.0, EZFIO produces Python3 files.
Download
========
@ -19,7 +21,8 @@ The following packages are needed:
* `IRPF90 <http://irpf90.ups-tlse.fr>`_
* `Python <http://www.python.org>`_
* `GNU make <http://www.python.org>`_ or `Ninja <http://github.com/martine/ninja>`_
* `GNU make <https://www.gnu.org/software/make>`_
* `Zlib <https://www.zlib.net>`_
Tutorial
@ -32,7 +35,8 @@ the 3D space.
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
@ -40,9 +44,8 @@ Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file
EZFIO/
Get into the ``EZFIO`` directory and configure the library to produce the
desired suboutines. Get into the ``config`` directory and create a new file
``test.config``
containing::
desired suboutines. Get into the ``config`` directory and create a new
file ``test.config`` containing::
molecule
num_atoms integer
@ -56,14 +59,13 @@ containing::
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
new line.
Each data contained inside a container is characterized by a triplet
(name,type,dimension), preceded by at least one white space at the
beginning of the line.
new line. Each data contained inside a container is characterized by a
triplet (name,type,dimension), preceded by at least one white space at
the beginning of the line.
If the dimension of an array is a data, the name of the data can be used
as ``<container>_<data>`` in the definition of the dimension. For
example, the dimension (``molecule_num_atoms``) uses the data
If the dimension of an array is a data, the name of the data can be
used as ``<container>_<data>`` in the definition of the dimension.
For example, the dimension (``molecule_num_atoms``) uses the data
``num_atoms`` of container ``molecule``.
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
Or you can use Ninja to build the library:
.. code-block:: bash
$ ninja
The ``lib`` directory now contains the static library ``libezfio.a``, and a static
library for use under the IRPF90 environment (``libezfio_irp.a``).
The ``Python``, ``Ocaml`` and ``Bash`` directories contain the binding for these languages.
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
@ -186,7 +182,7 @@ Create a file named ``create_input.py`` with:
.. code-block:: python
#!/usr/bin/python2
#!/usr/bin/python3
import sys
EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory
@ -201,17 +197,17 @@ Create a file named ``create_input.py`` with:
Molecule = []
for line in input.splitlines():
new_list = map(eval,line.split())
new_list = list(map(eval,line.split()))
Molecule.append(new_list)
# Create the mass array
mass = map( lambda x: x[0], Molecule )
# print mass
mass = [ x[0] for x in Molecule ]
# print(mass)
# [16.0, 1.0, 1.0]
# Create the coord array
coord = map( lambda x: (x[1], x[2], x[3]), Molecule )
# print coord
coord = [ (x[1], x[2], x[3]) for x in Molecule ]
# print(coord)
# [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)]
# Select the EZFIO file
@ -223,16 +219,17 @@ Create a file named ``create_input.py`` with:
ezfio.molecule_coord = coord
# Check that the total mass is correct:
print ezfio.properties_mass # Should give 18.
print(ezfio.properties_mass) # Should give 18.
Execute the script:
.. code-block:: bash
$ python2 create_input.py
$ python3 create_input.py
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
@ -309,12 +306,12 @@ the EZFIO file.
end
Compile the fortran program and link it the ``libezfio.a`` library, and run the
executable.
Compile the fortran program and link it the ``libezfio.a`` library and
``zlib``, and run the executable.
.. 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
Data in the EZFIO file:
16.0000000 0.00000000 0.222396001 0.00000000
@ -362,13 +359,14 @@ The usage of the ``ezfio`` bash command is::
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
#!/bin/bash
source EZFIO/Bash/ezfio.sh
source EZFIO/Bash/ezfio.sh # Put correct path here
# Select the EZFIO file
ezfio set_file Water

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
import os
ROOT = os.path.dirname(__file__)+'/../../'
@ -6,7 +6,7 @@ ROOT = os.path.dirname(__file__)+'/../../'
file = open(ROOT+'version','r') ;
lines = file.readlines() ;
file.close() ;
v = map(int,lines[0].split('=')[1].split('.'));
v = list(map(int,lines[0].split('=')[1].split('.')));
v[2] += 1
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
export
# Dark magic below modify with caution!
# "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\_! _//^---^\\_
include irpf90.make
irpf90.make: $(wildcard *.irp.f) ../config/* IRPF90_temp/system.o IRPF90_temp/system_f.o
$(IRPF90)
ifeq ($(BUILD_SYSTEM),ninja)
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)
include ../version
.PHONY: static all
all: static ../Python/ezfio.py ../Ocaml/ezfio.ml
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
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
#No more irp_stack
../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
python2 create_python.py
$(PYTHON) create_python.py
../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
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -46,7 +46,7 @@ def run():
for group in groups.keys():
for var,type,dims,command in groups[group]:
if command is not "":
if command != "":
continue
dims_py = str(dims)
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
# 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
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -25,10 +25,11 @@
import os, sys
import time
import cStringIO as StringIO
import io as StringIO
from gzip import GzipFile
import tempfile
import threading
from functools import reduce
def version(x):
b = [int(i) for i in x.split('.')]
@ -40,7 +41,7 @@ def size(x):
def flatten(l):
res = []
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))
else:
res.append(i)
@ -101,7 +102,7 @@ def get_conv(type):
else:
raise TypeError
elif type == "ch":
conv = lambda x: x.strip()
conv = lambda x: x.decode('utf-8').strip() if isinstance(x,bytes) else x.strip()
else:
raise TypeError
return conv
@ -149,18 +150,18 @@ class ezfio_obj(object):
except OSError:
pass
file = open(path.strip()+'/.version','w')
print >>file,self.version
print(self.version, file=file)
file.close()
def error(self,where,txt):
print '------------------------------------------------------------'
print 'EZFIO File : '+self.filename
print 'EZFIO Error in : '+where.strip()
print '------------------------------------------------------------'
print ''
print txt.strip()
print ''
print '------------------------------------------------------------'
print('------------------------------------------------------------')
print('EZFIO File : '+self.filename)
print('EZFIO Error in : '+where.strip())
print('------------------------------------------------------------')
print('')
print(txt.strip())
print('')
print('------------------------------------------------------------')
raise IOError
def get_filename(self):
@ -233,7 +234,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
indices = []
values = []
for i in xrange(isize):
for i in range(isize):
try:
line = self.file.readline().split()
except:
@ -250,7 +251,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
if self.buffer_rank == -1:
self.error('write_buffer','No buffered file is open.')
for i in xrange(isize):
for i in range(isize):
for j in indices[i]:
self.file.write("%4d "%(j,))
self.file.write("%24.15e\n"%(values[i],))

View File

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

View File

@ -1,26 +1,26 @@
(*
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
118, route de Narbonne
31062 Toulouse Cedex 4
scemama@irsamc.ups-tlse.fr
*)
@ -31,39 +31,39 @@ Exceptions
==========
*)
exception Read_only of string;;
exception Read_only of string
(*
State variables
===============
*)
let read_only = ref false;;
let ezfio_filename = ref "EZFIO_File";;
let read_only = ref false
let ezfio_filename = ref "EZFIO_File"
(*
(*
Helper functions
=================
*)
let check_readonly =
if !read_only then
raise (Read_only "Read only attribute is set");
;;
raise (Read_only "Read only attribute is set")
let exists path =
let filename = path^"/.version" in
let filename = Filename.concat path ".version" in
Sys.file_exists filename
;;
let has group name =
let dirname = !ezfio_filename ^ "/" ^ group in
let dirname = Filename.concat !ezfio_filename group in
if (exists dirname) then
(Sys.file_exists (dirname ^ "/" ^ name) )
Sys.file_exists @@ Filename.concat dirname name
else
false
;;
let has_array group name = has group (name^".gz");;
let has_array group name = has group (name^".gz")
let mkdir path =
check_readonly;
@ -72,99 +72,59 @@ let mkdir path =
Unix.mkdir path 0o777;
let out_channel = open_out (path^"/.version") in
Printf.fprintf out_channel "%s\n" version ;
close_out out_channel;
;;
close_out out_channel
let create_group group =
let dirname = !ezfio_filename ^ "/" ^ group in
let dirname = Filename.concat !ezfio_filename group in
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 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 =
let maxval l =
match l with
| [] -> None
| [a] -> Some a
| hd::tail -> Some (List.fold_left max hd tail)
;;
let minval l =
let minval l =
match l with
| [] -> None
| [a] -> Some a
| 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 rec do_work accu = function
| 0 -> accu
| i ->
let newaccu =
| i ->
let newaccu =
if str.[i-1] == v then accu+1
else accu
else accu
in do_work newaccu (i-1)
in do_work 0 (String.length str)
;;
let n_count (l,_,v) =
let rec do_work accu = function
| [] -> accu
| h::tail ->
let newaccu =
| h::tail ->
let newaccu =
if h == v then accu+1
else accu
else accu
in do_work newaccu tail
in do_work 0 l
;;
(*
(*
Scalars
=======
*)
@ -175,32 +135,32 @@ Read
*)
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 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
begin
close_in in_channel ;
result
end
;;
let fortran_bool_of_string = function
| "T" | "t" -> true
| "F" | "f" -> false
| x -> raise (Failure ("fortran_bool_of_string should be T or F: "^x))
;;
let fortran_string_of_bool = function
| true -> "T\n"
| false-> "F\n"
;;
let read_int = read_scalar int_of_string ;;
let read_int64 = read_scalar Int64.of_string ;;
let read_float = read_scalar float_of_string ;;
let read_string= read_scalar (fun (x:string) -> x);;
let read_bool = read_scalar fortran_bool_of_string;;
let read_int = read_scalar int_of_string
let read_int64 = read_scalar Int64.of_string
let read_float = read_scalar float_of_string
let read_string= read_scalar (fun (x:string) -> x)
let read_bool = read_scalar fortran_bool_of_string
(*
Write
@ -208,28 +168,28 @@ Write
*)
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
and 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
and print_bool out_channel b = Printf.fprintf out_channel "%s\n" (fortran_string_of_bool b);;
let print_int64 out_channel i = Printf.fprintf out_channel "%20Ld\n" i
let print_float out_channel f = Printf.fprintf out_channel "%24.15e\n" f
let print_string out_channel s = Printf.fprintf out_channel "%s\n" s
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 =
check_readonly;
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
begin
print_fun out_channel s;
close_out out_channel;
close_out out_channel
end
;;
let write_int = write_scalar print_int
and write_int64 = write_scalar print_int64
and write_float = write_scalar print_float
and write_bool = write_scalar print_bool
and write_string = write_scalar print_string
;;
let write_int64 = write_scalar print_int64
let write_float = write_scalar print_float
let write_bool = write_scalar print_bool
let write_string = write_scalar print_string
@ -239,9 +199,9 @@ Arrays
*)
type 'a ezfio_data =
| Ezfio_item of 'a array
| Ezfio_item of 'a array
| Ezfio_data of ('a ezfio_data) array
;;
type 'a ezfio_array =
@ -249,14 +209,38 @@ type 'a ezfio_array =
dim : int array;
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 =
assert (rank > 0);
let read_1d data nmax =
let rec do_work accu data = function
| 0 -> (Array.of_list (List.rev accu), data)
| n ->
| n ->
begin
match data with
| 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)
in
let (data,rest) = do_work [] data dim.(m-1) in
(Ezfio_data data,rest)
in
(Ezfio_data data,rest)
in
let (result,_) = read_nd data rank in
{ rank= rank;
dim= dim;
data=result;
}
;;
let ezfio_get_element { rank=r ; dim=d ; data=data } coord =
(*assert ((List.length coord) == r);*)
let rec do_work buffer = function
| [c] ->
| [c] ->
begin match buffer with
| Ezfio_item buffer -> buffer.(c)
| Ezfio_data buffer -> raise (Failure "Error in ezfio_get_element")
end
| c::tail ->
| c::tail ->
begin match buffer with
| Ezfio_item buffer -> raise (Failure "Error in ezfio_get_element")
| 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")
in
do_work data coord
;;
let flattened_ezfio { rank ; dim ; data } =
@ -327,9 +311,9 @@ let flattened_ezfio { rank ; dim ; data } =
in
match data with
| Ezfio_item d -> d
| Ezfio_data d -> flatten_n rank d
;;
| Ezfio_item d -> 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 trimmed_line = trim (input_line in_channel) in
int_of_string trimmed_line
;;
let trimmed_line = String.trim (input_line in_channel) in
int_of_string trimmed_line
let read_dimensions in_channel =
let trimmed_line = trim (input_line in_channel) in
let list_of_str = split trimmed_line ' ' in
Array.of_list (List.map int_of_string list_of_str)
;;
let line = input_line in_channel in
let arr_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 in_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^ ".gz" in
let uz_filename = unzipped_filename in_filename in
let in_channel = open_in uz_filename in
let in_filename = (Filename.concat !ezfio_filename @@ Filename.concat group name) ^ ".gz" in
let in_channel = Unix.open_process_in ("zcat "^in_filename) in
(* Read rank *)
let rank = read_rank in_channel
let rank = read_rank in_channel
(* Read dimensions *)
and dimensions = read_dimensions in_channel
and dimensions = read_dimensions in_channel
in
begin
assert (rank == Array.length dimensions) ;
(* Read one-dimensional arrays *)
let read_1d nmax =
let read_1d nmax =
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
(* Read multi-dimensional arrays *)
let rec read_nd = function
| m when m<1 -> raise (Failure "dimension should not be <1")
| 1 -> read_1d dimensions.(0)
| m ->
| m ->
let rec do_work accu = function
| 0 -> Array.of_list (List.rev accu)
| n ->
| n ->
let newlist = read_nd (m-1) in
do_work (newlist::accu) (n-1)
in
@ -397,20 +371,20 @@ let read_array type_conversion group name : 'a ezfio_array =
rank = rank ;
dim = dimensions ;
data = read_nd rank ;
}
}
in
close_in in_channel ;
Sys.remove uz_filename ;
result;
match Unix.close_process_in in_channel with
| Unix.WEXITED _ -> result
| _ -> failwith ("Failed in reading compressed file "^in_filename)
end
;;
let read_int_array = read_array int_of_string
and read_int64_array = read_array Int64.of_string
and read_float_array = read_array float_of_string
and read_bool_array = read_array fortran_bool_of_string
and read_string_array = read_array (fun (x:string) -> x)
;;
let read_int64_array = read_array Int64.of_string
let read_float_array = read_array float_of_string
let read_bool_array = read_array fortran_bool_of_string
let read_string_array = read_array (fun (x:string) -> x)
(*
Write
@ -420,32 +394,29 @@ Write
let write_array print_fun group name a =
check_readonly;
create_group group;
let out_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^".gz" in
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in
let out_channel = open_out uz_filename in
let out_filename = (Filename.concat !ezfio_filename @@ Filename.concat group name)^".gz" in
let command = "gzip > "^out_filename in
let out_channel = Unix.open_process_out command in
let { rank=rank ; dim=dimensions ; data=data } = a in
let data = flattened_ezfio a
in
let data = flattened_ezfio a in
begin
(* Write rank *)
Printf.fprintf out_channel "%3d\n" rank;
(* Write 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;
close_out out_channel ;
let command = "gzip -c < "^uz_filename^" > "^out_filename
in
if (Sys.command command == 0) then (Sys.remove uz_filename )
else raise (Failure ("command failed:\n"^command))
match Unix.close_process_out out_channel with
| Unix.WEXITED _ -> ()
| _ -> failwith ("Failed writing compressed file "^out_filename)
end
;;
let write_int_array = write_array print_int
and write_int64_array = write_array print_int64
and write_float_array = write_array print_float
and write_string_array = write_array print_string
and write_bool_array = write_array print_bool;;
let write_int64_array = write_array print_int64
let write_float_array = write_array print_float
let write_string_array = write_array print_string
let write_bool_array = write_array print_bool
(*
Library routines
@ -455,7 +426,7 @@ let set_file filename =
if not (exists filename) then
begin
mkdir filename;
mkdir (filename^"/ezfio");
mkdir (Filename.concat filename "ezfio");
let command = Printf.sprintf "
LANG= date > %s/ezfio/creation
echo $USER > %s/ezfio/user
@ -465,7 +436,7 @@ let set_file filename =
raise (Failure ("Unable to create new ezfio file:\n"^filename))
end ;
ezfio_filename := filename
;;
(*$TAIL*)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -34,29 +34,26 @@ file = open("../version","r")
v = file.readline()
file.close()
v = v.split('=')[1].strip()
print >>file_py, """
print("""
def get_version(self):
return '%s'
version = property(fset=None,fget=get_version)
"""%(v)
file_c = open("../C/ezfio.h","w")
print >>file_c, c_header
"""%(v), file=file_py)
import sys
for group in groups.keys():
print path%{ 'group' : group }
print >>file_py, path_py%{ 'group' : group }
for group in list(groups.keys()):
print(path%{ 'group' : group })
print(path_py%{ 'group' : group }, file=file_py)
for var,type,dims,command in groups[group]:
command_py = command
dims_py = str(dims)
for g in groups.keys():
command_py = command_py.replace(g,'self.'+g)
dims_py = dims_py.replace(g,'self.'+g)
for g in list(groups.keys()):
command_py = re.sub("(\W)"+g, r"\1self."+g, command_py)
dims_py = dims_py.replace("(\W)"+g,r'\1self.'+g)
var = var.lower()
group = group.lower()
strdims = tuple(map(lambda x: '('+str(x)+')',dims))
strdims = tuple(['('+str(x)+')' for x in dims])
strdims = str(strdims).replace("'","")
if len(dims) == 1:
strdims = strdims[:-2]+")"
@ -79,9 +76,8 @@ for group in groups.keys():
'var': var,
'group': group,
'dims': strdims}
print attributes%d
print >>file_c, attributes_c%d
print >>file_py, attributes_py%d
print(attributes%d)
print(attributes_py%d, file=file_py)
else:
d = { 'type': type,
'var': var,
@ -92,16 +88,15 @@ for group in groups.keys():
'expr_py': command_py}
buffer = calculated%d
buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer)
print buffer
print >>file_py, calculated_py%d
print(buffer)
print(calculated_py%d, file=file_py)
elif type == "buffered":
d = { 'group': group,
'var': var,
'dims_py': dims_py,
'dims': dims }
print buffered%d
print >>file_c, buffered_c%d
print >>file_py, buffered_py%d
print(buffered%d)
print(buffered_py%d, file=file_py)
else:
dims_loop = ''
copy_loop = ''
@ -112,7 +107,7 @@ for group in groups.keys():
declar_loop = declar_loop[:-1]
for k,d in enumerate(dims):
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):
copy_loop += k*" "+" do i"+str(k+1)+"=1,"+str(d)+'\n'
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"
for k,d in enumerate(dims):
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)
@ -145,11 +140,7 @@ for group in groups.keys():
'dims_loop_py': dims_loop_py,
'copy_loop': copy_loop,
'declar_loop' : declar_loop}
print attributes_arr%d
print >>file_py, attributes_arr_py%d
print >>file_c, attributes_arr_c%d
print(attributes_arr%d)
print(attributes_arr_py%d, file=file_py)
print >>file_c, c_footer
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
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -58,23 +58,23 @@ BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s ]
END_PROVIDER
subroutine ezfio_set_%(group)s_%(var)s(%(var)s)
subroutine ezfio_set_%(group)s_%(var)s(v)
implicit none
BEGIN_DOC
! Sets the %(group)s/%(var)s attribute
END_DOC
%(type_set)s :: %(var)s
call ezfio_write_%(type_short)s(path_%(group)s,'%(var)s',%(var)s)
%(type_set)s :: v
call ezfio_write_%(type_short)s(path_%(group)s,'%(var)s',v)
FREE %(group)s_%(var)s
end subroutine
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none
BEGIN_DOC
! Gets the %(group)s/%(var)s attribute
END_DOC
%(type)s :: %(var)s
%(var)s = %(group)s_%(var)s
%(type)s :: v
v = %(group)s_%(var)s
end subroutine
subroutine ezfio_has_%(group)s_%(var)s(result)
@ -111,30 +111,30 @@ BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s, %(dims)s ]
END_PROVIDER
subroutine ezfio_set_%(group)s_%(var)s(%(var)s)
subroutine ezfio_set_%(group)s_%(var)s(v)
implicit none
BEGIN_DOC
! Sets the %(group)s/%(var)s attribute
END_DOC
%(type_set)s :: %(var)s (*)
%(type_set)s :: v (*)
integer :: rank, dim_max, i
integer :: dims(10)
rank = %(rank)s
character*(1024) :: message
%(dims_loop)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
end subroutine
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none
BEGIN_DOC
! Gets the %(group)s/%(var)s attribute
END_DOC
%(type)s, intent(out) :: %(var)s (*)
%(type)s, intent(out) :: v (*)
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
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
END_PROVIDER
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
subroutine ezfio_get_%(group)s_%(var)s(v)
implicit none
BEGIN_DOC
! Gets the %(group)s/%(var)s attribute
END_DOC
%(type)s, intent(out) :: %(var)s
%(var)s = %(group)s_%(var)s
%(type)s, intent(out) :: v
v = %(group)s_%(var)s
end
subroutine ezfio_free_%(group)s_%(var)s()
@ -239,48 +239,38 @@ end
#---------
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);
}
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 = """
void ezfio_set_%(group)s_%(var)s(%(ctype)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_();
}
"""
calculated_c = attributes_c
c_header = """#ifndef EZFIO_H\n#define EZFIO_H
#include <string.h>
c_header = """
#ifndef EZFIO_H
#define EZFIO_H
#ifdef __cplusplus
extern "C" {
#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
{
@ -292,7 +282,7 @@ void ezfio_set_file(char* filename)
{
long len;
len = strlen(filename);
ezfio_set_file_(filename,len);
ezfio_set_file_(filename,mlen);
}
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);
}
"""
c_footer = """
#ifdef __cplusplus
}
#endif
#endif
"""
""" ]
@ -363,7 +345,7 @@ attributes_py = """
attributes_arr_py = """
def get_%(group)s_%(var)s(self):
rank = %(rank)s
dims = range(rank)
dims = list(range(rank))
%(dims_loop_py)s
dim_max = 1
for d in dims:
@ -377,7 +359,7 @@ attributes_arr_py = """
def set_%(group)s_%(var)s(self,%(var)s):
rank = %(rank)s
dims = range(rank)
dims = list(range(rank))
%(dims_loop_py)s
dim_max = 1
for d in dims:

View File

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

View File

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

View File

@ -22,6 +22,7 @@
! 31062 Toulouse Cedex 4
! scemama@irsamc.ups-tlse.fr
BEGIN_PROVIDER [ integer, PID ]
&BEGIN_PROVIDER [ character*(256), PID_str ]
implicit none
@ -29,15 +30,12 @@
! Current process ID
END_DOC
integer :: getpid
character*(240) :: hostname
character*(240) :: hostname
PID = getpid()
write(PID_str,'(I8.8)') PID
call HOSTNM(hostname)
write(PID_str,'(A,''.'',I8.8,X)') trim(hostname), PID
PID_str = trim(PID_str)
print *, PID_str
call sleep(1)
END_PROVIDER
logical function ezfio_exists(path)
@ -56,6 +54,7 @@ logical function ezfio_exists(path)
end function
subroutine ezfio_mkdir(path)
use system
implicit none
BEGIN_DOC
! Creates a directory
@ -66,7 +65,7 @@ subroutine ezfio_mkdir(path)
call ezfio_error(irp_here,'Read-only file.')
endif
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')
write(libezfio_iunit,'(A)') libezfio_version
close(libezfio_iunit)
@ -75,6 +74,7 @@ end subroutine
subroutine libezfio_openz(filename,mode,err)
use system
implicit none
BEGIN_DOC
! Opens a compressed file
@ -86,7 +86,7 @@ subroutine libezfio_openz(filename,mode,err)
err=1
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')
err=0
else if (mode(1:1) == 'w') then
@ -97,7 +97,30 @@ subroutine libezfio_openz(filename,mode,err)
endif
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)
use system
implicit none
BEGIN_DOC
! Closes a compressed file
@ -107,18 +130,18 @@ subroutine libezfio_closez(filename,mode)
fifo = trim(filename)//'.'//trim(PID_str)
if (mode(1:1) == 'w') then
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')
endif
close(unit=libezfio_iunit,status='DELETE')
end
BEGIN_SHELL [ /usr/bin/env python2 ]
BEGIN_SHELL [ /usr/bin/env python3 ]
from f_types import format, t_short
template = """
template_nowrite = """
subroutine ezfio_read_%(type_short)s(dir,fil,dat)
implicit none
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')
write(libezfio_iunit,%(fmt)s) dat
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
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)
integer :: err
character*(1024) :: l_filename
character*(32), allocatable :: buffer(:)
l_filename=trim(dir)//'/'//fil//'.gz'
err = 0
@ -194,20 +218,21 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
endif
enddo
allocate (buffer(dim_max))
read(libezfio_iunit,'(A)') buffer(1:dim_max)
do i=1,dim_max
if (err /= 0) then
call ezfio_error(irp_here,'Error reading data in '//trim(l_filename)//&
'.')
endif
read(libezfio_iunit,%(fmt)s) dat(i)
read(buffer(i),%(fmt)s) dat(i)
enddo
deallocate(buffer)
call libezfio_closez(trim(l_filename),'r')
return
else
call ezfio_error(irp_here,'Attribute '//trim(l_filename)//' is not set')
endif
end
"""
template_write = """
subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
implicit none
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
%(type)s, intent(in) :: dat(dim_max)
integer :: err
integer :: i
character*(1024) :: l_filename(2)
character*(25), allocatable :: buffer(:)
if (libezfio_read_only) then
call ezfio_error(irp_here,'Read-only file.')
endif
@ -231,17 +258,22 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
if (err == 0) then
write(libezfio_iunit,'(I3)') rank
write(libezfio_iunit,'(30(I20,X))') dims(1:rank)
integer :: i
close(unit=libezfio_iunit)
allocate (buffer(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
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 system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) )
call rename(trim(l_filename(1)),trim(l_filename(2)) )
end
"""
template_no_logical = """
integer function n_count_%(type_short)s(array,isize,val)
implicit none
@ -264,9 +296,11 @@ end function
! Build Python functions
"""
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":
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 = """
def read_%(type_short)s(self,dir,fil):
@ -293,7 +327,7 @@ template_py = """
l_filename += [ dir.strip()+'/'+fil ]
dat = conv(dat)
file = open(l_filename[0],'w')
print >>file,'%(fmt)s'%%(dat,)
print('%(fmt)s'%%(dat,), file=file)
file.close()
os.rename(l_filename[0],l_filename[1])
@ -333,13 +367,13 @@ template_py = """
file.write("\\n")
dat = flatten(dat)
for i in xrange(dim_max):
for i in range(dim_max):
file.write("%(fmt)s\\n"%%(dat[i],))
file.flush()
buffer = file.getvalue()
file.close()
file = GzipFile(filename=l_filename[0],mode='wb')
file.write(buffer)
file.write(buffer.encode())
file.close()
os.rename(l_filename[0],l_filename[1])
except:
@ -349,21 +383,63 @@ template_py = """
file_py = open("libezfio_util-gen.py","w")
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
command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'"
cwd = os.getcwd()
cwd = cwd.split('src')[:-1]
cwd = '/'.join(cwd)
print >>file_py, """
print("""
LIBRARY = "%s"
"""%cwd
"""%cwd,file=file_py)
file_py.close()
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_DOC
! 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
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -31,7 +31,7 @@ import os, sys
lines = []
for filename in [ '../config/'+i for i in os.listdir('../config')]:
file = open(filename,'r')
lines += map(lambda x: (x,filename), file.readlines())
lines += [(x,filename) for x in file.readlines()]
try:
if lines[-1] != '':
lines.append( ('', filename) )
@ -51,7 +51,7 @@ for line, filename in lines:
groups[group] = my_list
elif line[0] != ' ': # New group
group = line.strip()
if group in groups.keys():
if group in list(groups.keys()):
my_list = groups[group]
else:
my_list = []
@ -76,12 +76,12 @@ for line, filename in lines:
my_list.append(tuple(buffer))
except:
import sys, time
print >>sys.stderr, ''
print >>sys.stderr, '*'*80
print >>sys.stderr, 'Error in EZFIO config file '+filename+' :'
print >>sys.stderr, line
print >>sys.stderr, '*'*80
print >>sys.stderr, ''
print('', file=sys.stderr)
print('*'*80, file=sys.stderr)
print('Error in EZFIO config file '+filename+' :', file=sys.stderr)
print(line, file=sys.stderr)
print('*'*80, file=sys.stderr)
print('', file=sys.stderr)
time.sleep(3)
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
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
@ -44,7 +44,7 @@ values = []
isize = 5
EZFIO.open_read_ao_two_int()
indices,values = EZFIO.read_buffer(isize)
print indices
print values
print(indices)
print(values)
EZFIO.close_read_ao_two_int()

View File

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