mirror of https://gitlab.com/scemama/EZFIO.git
Compare commits
15 Commits
Author | SHA1 | Date |
---|---|---|
Anthony Scemama | 66d3dd5d8e | |
Anthony Scemama | dba01c4fe0 | |
Anthony Scemama | 0520b5e2cf | |
Anthony Scemama | d5805497fa | |
Anthony Scemama | ed1df9f3c1 | |
Anthony Scemama | ccee52d00c | |
Anthony Scemama | 3777ff3d95 | |
Anthony Scemama | 7560a01faa | |
Pierre-Francois Loos | f7a141dca6 | |
Anthony Scemama | 400dd83599 | |
Kevin Gasperich | 13a32e3de3 | |
Anthony Scemama | e2a79a0c53 | |
Anthony Scemama | ec1956dc99 | |
Anthony Scemama | 7e6be9ab45 | |
Anthony Scemama | 9cc4b60f79 |
|
@ -7,7 +7,7 @@ EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
|
|||
|
||||
function _ezfio_py()
|
||||
{
|
||||
python2 ${EZFIO_ROOT}/Python/ezfio.py "$@"
|
||||
python3 ${EZFIO_ROOT}/Python/ezfio.py "$@"
|
||||
}
|
||||
|
||||
|
||||
|
|
20
README.rst
20
README.rst
|
@ -12,6 +12,8 @@ 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.
|
||||
|
||||
Starting with version 2.0, EZFIO produces Python3 files.
|
||||
|
||||
Download
|
||||
========
|
||||
|
||||
|
@ -180,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
|
||||
|
@ -195,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
|
||||
|
@ -217,13 +219,13 @@ 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
|
||||
|
@ -364,7 +366,7 @@ Here is the same script as the Python script, but using 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__":
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
VERSION ?= 1.4.0
|
||||
VERSION ?= 2.0.7
|
||||
RANLIB ?= ranlib
|
||||
IRPF90 ?= irpf90
|
||||
CC ?= gcc
|
||||
FC ?= gfortran -g -ffree-line-length-none -fPIC # -fopenmp
|
||||
FC ?= gfortran -g -ffree-line-length-none -fPIC
|
||||
FCFLAGS ?= -fPIC
|
||||
AR ?= ar
|
||||
ARCHIVE ?= ar crs
|
||||
RANLIB ?= ranlib
|
||||
PYTHON ?= python2
|
||||
PYTHON ?= python3
|
||||
|
|
|
@ -50,13 +50,12 @@ IRPF90_temp/system_f.o: system_f.f90
|
|||
|
||||
../lib/libezfio.a: IRPF90_temp/irpf90.a
|
||||
rm -f ../lib/libezfio.a
|
||||
$(AR) cru ../lib/libezfio.a IRPF90_temp/system_f.o IRPF90_temp/system.o $(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
|
||||
|
||||
|
||||
|
|
|
@ -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'):
|
||||
|
@ -67,7 +67,7 @@ def main():
|
|||
except NameError:
|
||||
data = text
|
||||
except:
|
||||
print "Syntax Error"
|
||||
print("Syntax Error")
|
||||
return 1
|
||||
if data is None:
|
||||
data = "None"
|
||||
|
|
94
src/ezfio.ml
94
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
|
||||
*)
|
||||
|
||||
|
@ -40,7 +40,7 @@ State variables
|
|||
let read_only = ref false
|
||||
let ezfio_filename = ref "EZFIO_File"
|
||||
|
||||
(*
|
||||
(*
|
||||
Helper functions
|
||||
=================
|
||||
*)
|
||||
|
@ -54,7 +54,7 @@ let exists path =
|
|||
let filename = Filename.concat path ".version" in
|
||||
Sys.file_exists filename
|
||||
|
||||
|
||||
|
||||
let has group name =
|
||||
let dirname = Filename.concat !ezfio_filename group in
|
||||
if (exists dirname) then
|
||||
|
@ -82,14 +82,14 @@ let create_group group =
|
|||
|
||||
|
||||
|
||||
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
|
||||
|
@ -105,10 +105,10 @@ 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)
|
||||
|
||||
|
@ -116,15 +116,15 @@ let n_count_ch (str,_,v) =
|
|||
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
|
||||
=======
|
||||
*)
|
||||
|
@ -156,7 +156,7 @@ let fortran_string_of_bool = function
|
|||
| false-> "F\n"
|
||||
|
||||
|
||||
let read_int = read_scalar int_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)
|
||||
|
@ -183,7 +183,7 @@ let write_scalar print_fun group name s =
|
|||
close_out out_channel
|
||||
end
|
||||
|
||||
|
||||
|
||||
let write_int = write_scalar print_int
|
||||
let write_int64 = write_scalar print_int64
|
||||
let write_float = write_scalar print_float
|
||||
|
@ -199,7 +199,7 @@ Arrays
|
|||
*)
|
||||
|
||||
type 'a ezfio_data =
|
||||
| Ezfio_item of 'a array
|
||||
| Ezfio_item of 'a array
|
||||
| Ezfio_data of ('a ezfio_data) array
|
||||
|
||||
|
||||
|
@ -210,13 +210,37 @@ type 'a ezfio_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)
|
||||
|
@ -237,8 +261,8 @@ 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;
|
||||
|
@ -250,12 +274,12 @@ let ezfio_array_of_list ~rank ~dim ~data =
|
|||
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
|
||||
|
@ -299,7 +323,7 @@ Read
|
|||
|
||||
let read_rank in_channel =
|
||||
let trimmed_line = String.trim (input_line in_channel) in
|
||||
int_of_string trimmed_line
|
||||
int_of_string trimmed_line
|
||||
|
||||
|
||||
let read_dimensions in_channel =
|
||||
|
@ -317,7 +341,7 @@ let read_array type_conversion group name : 'a ezfio_array =
|
|||
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
|
||||
in
|
||||
|
@ -334,7 +358,7 @@ 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 ->
|
||||
|
@ -342,19 +366,19 @@ let read_array type_conversion group name : 'a ezfio_array =
|
|||
do_work (newlist::accu) (n-1)
|
||||
in
|
||||
Ezfio_data (do_work [] dimensions.(m-1))
|
||||
in
|
||||
in
|
||||
let result = {
|
||||
rank = rank ;
|
||||
dim = dimensions ;
|
||||
data = read_nd rank ;
|
||||
}
|
||||
in
|
||||
}
|
||||
in
|
||||
match Unix.close_process_in in_channel with
|
||||
| Unix.WEXITED _ -> result
|
||||
| _ -> failwith ("Failed in reading compressed file "^in_filename)
|
||||
| _ -> failwith ("Failed in reading compressed file "^in_filename)
|
||||
end
|
||||
|
||||
|
||||
|
||||
let read_int_array = read_array int_of_string
|
||||
let read_int64_array = read_array Int64.of_string
|
||||
let read_float_array = read_array float_of_string
|
||||
|
@ -375,7 +399,7 @@ let write_array print_fun group name a =
|
|||
let out_channel = Unix.open_process_out command in
|
||||
let { rank=rank ; dim=dimensions ; data=data } = a in
|
||||
let data = flattened_ezfio a in
|
||||
begin
|
||||
begin
|
||||
(* Write rank *)
|
||||
Printf.fprintf out_channel "%3d\n" rank;
|
||||
(* Write dimensions *)
|
||||
|
@ -384,7 +408,7 @@ let write_array print_fun group name a =
|
|||
Array.iter (print_fun out_channel) data;
|
||||
match Unix.close_process_out out_channel with
|
||||
| Unix.WEXITED _ -> ()
|
||||
| _ -> failwith ("Failed writing compressed file "^out_filename)
|
||||
| _ -> failwith ("Failed writing compressed file "^out_filename)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -181,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
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ subroutine libezfio_closez(filename,mode)
|
|||
end
|
||||
|
||||
|
||||
BEGIN_SHELL [ /usr/bin/env python2 ]
|
||||
BEGIN_SHELL [ /usr/bin/env python3 ]
|
||||
from f_types import format, t_short
|
||||
|
||||
|
||||
|
@ -220,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
|
||||
|
@ -262,12 +260,10 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
|||
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')
|
||||
|
@ -300,11 +296,11 @@ end function
|
|||
! Build Python functions
|
||||
"""
|
||||
for t in format.keys():
|
||||
print template_nowrite%{ '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] }
|
||||
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):
|
||||
|
@ -331,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])
|
||||
|
||||
|
@ -371,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:
|
||||
|
@ -387,16 +383,16 @@ 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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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