mirror of
https://gitlab.com/scemama/EZFIO.git
synced 2024-10-31 19:23:43 +01:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
66d3dd5d8e | |||
dba01c4fe0 | |||
0520b5e2cf | |||
d5805497fa | |||
ed1df9f3c1 | |||
ccee52d00c | |||
3777ff3d95 | |||
7560a01faa | |||
f7a141dca6 | |||
|
400dd83599 | ||
|
13a32e3de3 | ||
e2a79a0c53 | |||
ec1956dc99 | |||
7e6be9ab45 | |||
9cc4b60f79 | |||
cfb61939bc | |||
e27ef1c7f4 | |||
baa47ab0a9 | |||
0f4a79c240 | |||
fa6d40a857 | |||
744cbac511 |
@ -1,10 +1,13 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# ezfio shell command with completion
|
||||
#
|
||||
|
||||
EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
|
||||
|
||||
function _ezfio_py()
|
||||
{
|
||||
python2 ${EZFIO_ROOT}/Python/ezfio.py "$@"
|
||||
python3 ${EZFIO_ROOT}/Python/ezfio.py "$@"
|
||||
}
|
||||
|
||||
|
||||
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
|
7
Makefile
7
Makefile
@ -35,22 +35,17 @@ 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}
|
||||
|
76
README.rst
76
README.rst
@ -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
|
||||
|
@ -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)
|
||||
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")
|
||||
|
@ -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__":
|
||||
|
31
build.ninja
31
build.ninja
@ -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
|
146
configure.py
146
configure.py
@ -1,146 +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 -fopenmp',
|
||||
"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 ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o > /dev/null ; {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()
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/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()
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/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
9
make.config
Normal 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
|
19
src/Makefile
19
src/Makefile
@ -29,7 +29,7 @@ export
|
||||
|
||||
include irpf90.make
|
||||
|
||||
irpf90.make: $(wildcard *.irp.f) ../config/*
|
||||
irpf90.make: $(wildcard *.irp.f) ../config/* IRPF90_temp/system.o IRPF90_temp/system_f.o
|
||||
$(IRPF90)
|
||||
|
||||
include ../version
|
||||
@ -40,22 +40,29 @@ 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
|
||||
$(AR) cru ../lib/libezfio.a $(OBJ1)
|
||||
$(ARCHIVE) ../lib/libezfio.a IRPF90_temp/system_f.o IRPF90_temp/system.o $(OBJ1)
|
||||
$(RANLIB) ../lib/libezfio.a
|
||||
|
||||
../lib/libezfio_irp.a: ../lib/libezfio.a
|
||||
rm -f ../lib/libezfio_irp.a
|
||||
cp ../lib/libezfio.a ../lib/libezfio_irp.a
|
||||
$(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o
|
||||
$(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
|
||||
|
||||
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
#
|
||||
|
@ -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],))
|
||||
|
@ -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'):
|
||||
@ -56,12 +56,18 @@ def main():
|
||||
|
||||
elif command.startswith('set'):
|
||||
text = sys.stdin.read()
|
||||
true = True
|
||||
false = False
|
||||
TRUE = True
|
||||
FALSE = False
|
||||
T = True
|
||||
F = False
|
||||
try:
|
||||
data = eval(text)
|
||||
except NameError:
|
||||
data = text
|
||||
except:
|
||||
print "Syntax Error"
|
||||
print("Syntax Error")
|
||||
return 1
|
||||
if data is None:
|
||||
data = "None"
|
||||
|
321
src/ezfio.ml
321
src/ezfio.ml
@ -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,48 +321,36 @@ 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->
|
||||
let buffer = trim (input_line in_channel) in
|
||||
let buffer = String.trim (input_line in_channel) in
|
||||
try type_conversion buffer with
|
||||
| Failure s -> failwith (s^": "^buffer)))
|
||||
in
|
||||
@ -386,10 +358,10 @@ let read_array type_conversion group name : 'a ezfio_array =
|
||||
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
|
||||
@ -399,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
|
||||
@ -422,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
|
||||
@ -457,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
|
||||
@ -467,7 +436,7 @@ let set_file filename =
|
||||
raise (Failure ("Unable to create new ezfio file:\n"^filename))
|
||||
end ;
|
||||
ezfio_filename := filename
|
||||
;;
|
||||
|
||||
|
||||
|
||||
(*$TAIL*)
|
||||
|
@ -27,7 +27,7 @@ format= {
|
||||
'integer' : ["'(I20)'", "%20d"],
|
||||
'real' : ["'(E24.15)'","%24.15E"],
|
||||
'double precision': ["'(E24.15)'","%24.15E"],
|
||||
'logical' : ["'(L)'","%c"],
|
||||
'logical' : ["'(L1)'","%c"],
|
||||
'character*(*)' : ["'(A)'","%s"]
|
||||
}
|
||||
|
||||
|
@ -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,26 +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)
|
||||
"""%(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]+")"
|
||||
@ -76,8 +76,8 @@ for group in groups.keys():
|
||||
'var': var,
|
||||
'group': group,
|
||||
'dims': strdims}
|
||||
print attributes%d
|
||||
print >>file_py, attributes_py%d
|
||||
print(attributes%d)
|
||||
print(attributes_py%d, file=file_py)
|
||||
else:
|
||||
d = { 'type': type,
|
||||
'var': var,
|
||||
@ -88,15 +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_py, buffered_py%d
|
||||
print(buffered%d)
|
||||
print(buffered_py%d, file=file_py)
|
||||
else:
|
||||
dims_loop = ''
|
||||
copy_loop = ''
|
||||
@ -107,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 ("
|
||||
@ -119,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)
|
||||
@ -140,7 +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(attributes_arr%d)
|
||||
print(attributes_arr_py%d, file=file_py)
|
||||
|
||||
file_py.close()
|
||||
|
@ -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()
|
||||
@ -345,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:
|
||||
@ -359,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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
@ -53,6 +54,7 @@ logical function ezfio_exists(path)
|
||||
end function
|
||||
|
||||
subroutine ezfio_mkdir(path)
|
||||
use system
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Creates a directory
|
||||
@ -63,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)
|
||||
@ -72,6 +74,7 @@ end subroutine
|
||||
|
||||
|
||||
subroutine libezfio_openz(filename,mode,err)
|
||||
use system
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Opens a compressed file
|
||||
@ -83,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
|
||||
@ -117,6 +120,7 @@ subroutine libezfio_reopenz_unformatted(filename,mode,err)
|
||||
end
|
||||
|
||||
subroutine libezfio_closez(filename,mode)
|
||||
use system
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Closes a compressed file
|
||||
@ -126,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
|
||||
@ -216,11 +220,9 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
|
||||
allocate (buffer(dim_max))
|
||||
read(libezfio_iunit,'(A)') buffer(1:dim_max)
|
||||
!$OMP PARALLEL DO PRIVATE(i)
|
||||
do i=1,dim_max
|
||||
read(buffer(i),%(fmt)s) dat(i)
|
||||
enddo
|
||||
!$OMP END PARALLEL DO
|
||||
deallocate(buffer)
|
||||
call libezfio_closez(trim(l_filename),'r')
|
||||
return
|
||||
@ -228,7 +230,9 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
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
|
||||
@ -255,14 +259,11 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
write(libezfio_iunit,'(I3)') rank
|
||||
write(libezfio_iunit,'(30(I20,X))') dims(1:rank)
|
||||
close(unit=libezfio_iunit)
|
||||
|
||||
allocate (buffer(dim_max))
|
||||
!$OMP PARALLEL DO PRIVATE(i)
|
||||
do i=1,dim_max
|
||||
write(buffer(i)(1:24), %(fmt)s) dat(i)
|
||||
buffer(i)(25:25) = ACHAR(10)
|
||||
enddo
|
||||
!$OMP END PARALLEL DO
|
||||
call libezfio_reopenz_unformatted(trim(l_filename(1)),'wb',err)
|
||||
write(libezfio_iunit) buffer
|
||||
call libezfio_closez(trim(l_filename(1)),'w')
|
||||
@ -272,6 +273,7 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
template_no_logical = """
|
||||
integer function n_count_%(type_short)s(array,isize,val)
|
||||
implicit none
|
||||
@ -294,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):
|
||||
@ -323,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])
|
||||
|
||||
@ -363,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:
|
||||
@ -379,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
|
||||
|
@ -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
45
src/system.c
Normal 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
24
src/system_f.f90
Normal 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
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user