Version:2.0.0

Version:2.0.1
This commit is contained in:
Anthony Scemama 2020-01-27 11:32:17 +01:00
parent 9cc4b60f79
commit 7e6be9ab45
15 changed files with 83 additions and 84 deletions

View File

@ -7,7 +7,7 @@ EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
function _ezfio_py() function _ezfio_py()
{ {
python2 ${EZFIO_ROOT}/Python/ezfio.py "$@" python3 ${EZFIO_ROOT}/Python/ezfio.py "$@"
} }

View File

@ -180,7 +180,7 @@ Create a file named ``create_input.py`` with:
.. code-block:: python .. code-block:: python
#!/usr/bin/python2 #!/usr/bin/python3
import sys import sys
EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory
@ -195,17 +195,17 @@ Create a file named ``create_input.py`` with:
Molecule = [] Molecule = []
for line in input.splitlines(): for line in input.splitlines():
new_list = map(eval,line.split()) new_list = list(map(eval,line.split()))
Molecule.append(new_list) Molecule.append(new_list)
# Create the mass array # Create the mass array
mass = map( lambda x: x[0], Molecule ) mass = [ x[0] for x in Molecule ]
# print mass # print(mass)
# [16.0, 1.0, 1.0] # [16.0, 1.0, 1.0]
# Create the coord array # Create the coord array
coord = map( lambda x: (x[1], x[2], x[3]), Molecule ) coord = [ (x[1], x[2], x[3]) for x in Molecule ]
# print coord # print(coord)
# [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)] # [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)]
# Select the EZFIO file # Select the EZFIO file
@ -217,13 +217,13 @@ Create a file named ``create_input.py`` with:
ezfio.molecule_coord = coord ezfio.molecule_coord = coord
# Check that the total mass is correct: # Check that the total mass is correct:
print ezfio.properties_mass # Should give 18. print(ezfio.properties_mass) # Should give 18.
Execute the script: Execute the script:
.. code-block:: bash .. code-block:: bash
$ python2 create_input.py $ python3 create_input.py
18.0 18.0
The printed mass is correct, and a new directory (``Water``) was created The printed mass is correct, and a new directory (``Water``) was created
@ -364,7 +364,7 @@ Here is the same script as the Python script, but using Bash
#!/bin/bash #!/bin/bash
source EZFIO/Bash/ezfio.sh source EZFIO/Bash/ezfio.sh # Put correct path here
# Select the EZFIO file # Select the EZFIO file
ezfio set_file Water ezfio set_file Water

View File

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

View File

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

View File

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

View File

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

View File

@ -6,4 +6,4 @@ FC ?= gfortran -g -ffree-line-length-none -fPIC # -fopenmp
FCFLAGS ?= -fPIC FCFLAGS ?= -fPIC
AR ?= ar AR ?= ar
RANLIB ?= ranlib RANLIB ?= ranlib
PYTHON ?= python2 PYTHON ?= python3

View File

@ -25,10 +25,11 @@
import os, sys import os, sys
import time import time
import cStringIO as StringIO import io as StringIO
from gzip import GzipFile from gzip import GzipFile
import tempfile import tempfile
import threading import threading
from functools import reduce
def version(x): def version(x):
b = [int(i) for i in x.split('.')] b = [int(i) for i in x.split('.')]
@ -40,7 +41,7 @@ def size(x):
def flatten(l): def flatten(l):
res = [] res = []
for i in l: for i in l:
if hasattr(i, "__iter__") and not isinstance(i, basestring): if hasattr(i, "__iter__") and not isinstance(i, str):
res.extend(flatten(i)) res.extend(flatten(i))
else: else:
res.append(i) res.append(i)
@ -149,18 +150,18 @@ class ezfio_obj(object):
except OSError: except OSError:
pass pass
file = open(path.strip()+'/.version','w') file = open(path.strip()+'/.version','w')
print >>file,self.version print(self.version, file=file)
file.close() file.close()
def error(self,where,txt): def error(self,where,txt):
print '------------------------------------------------------------' print('------------------------------------------------------------')
print 'EZFIO File : '+self.filename print('EZFIO File : '+self.filename)
print 'EZFIO Error in : '+where.strip() print('EZFIO Error in : '+where.strip())
print '------------------------------------------------------------' print('------------------------------------------------------------')
print '' print('')
print txt.strip() print(txt.strip())
print '' print('')
print '------------------------------------------------------------' print('------------------------------------------------------------')
raise IOError raise IOError
def get_filename(self): def get_filename(self):
@ -233,7 +234,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
indices = [] indices = []
values = [] values = []
for i in xrange(isize): for i in range(isize):
try: try:
line = self.file.readline().split() line = self.file.readline().split()
except: except:
@ -250,7 +251,7 @@ echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
if self.buffer_rank == -1: if self.buffer_rank == -1:
self.error('write_buffer','No buffered file is open.') self.error('write_buffer','No buffered file is open.')
for i in xrange(isize): for i in range(isize):
for j in indices[i]: for j in indices[i]:
self.file.write("%4d "%(j,)) self.file.write("%4d "%(j,))
self.file.write("%24.15e\n"%(values[i],)) self.file.write("%24.15e\n"%(values[i],))

View File

@ -32,7 +32,7 @@ def main():
try: try:
EZFIO_FILE = os.environ["EZFIO_FILE"] EZFIO_FILE = os.environ["EZFIO_FILE"]
except KeyError: except KeyError:
print "EZFIO_FILE not defined" print("EZFIO_FILE not defined")
return 1 return 1
ezfio.set_file(EZFIO_FILE) ezfio.set_file(EZFIO_FILE)
@ -42,7 +42,7 @@ def main():
try: try:
f = getattr(ezfio,command) f = getattr(ezfio,command)
except AttributeError: except AttributeError:
print "{0} not found".format(command) print("{0} not found".format(command))
return 1 return 1
if command.startswith('has'): if command.startswith('has'):
@ -67,7 +67,7 @@ def main():
except NameError: except NameError:
data = text data = text
except: except:
print "Syntax Error" print("Syntax Error")
return 1 return 1
if data is None: if data is None:
data = "None" data = "None"

View File

@ -34,26 +34,26 @@ file = open("../version","r")
v = file.readline() v = file.readline()
file.close() file.close()
v = v.split('=')[1].strip() v = v.split('=')[1].strip()
print >>file_py, """ print("""
def get_version(self): def get_version(self):
return '%s' return '%s'
version = property(fset=None,fget=get_version) version = property(fset=None,fget=get_version)
"""%(v) """%(v), file=file_py)
import sys import sys
for group in groups.keys(): for group in list(groups.keys()):
print path%{ 'group' : group } print(path%{ 'group' : group })
print >>file_py, path_py%{ 'group' : group } print(path_py%{ 'group' : group }, file=file_py)
for var,type,dims,command in groups[group]: for var,type,dims,command in groups[group]:
command_py = command command_py = command
dims_py = str(dims) dims_py = str(dims)
for g in groups.keys(): for g in list(groups.keys()):
command_py = command_py.replace(g,'self.'+g) command_py = command_py.replace(g,'self.'+g)
dims_py = dims_py.replace(g,'self.'+g) dims_py = dims_py.replace(g,'self.'+g)
var = var.lower() var = var.lower()
group = group.lower() group = group.lower()
strdims = tuple(map(lambda x: '('+str(x)+')',dims)) strdims = tuple(['('+str(x)+')' for x in dims])
strdims = str(strdims).replace("'","") strdims = str(strdims).replace("'","")
if len(dims) == 1: if len(dims) == 1:
strdims = strdims[:-2]+")" strdims = strdims[:-2]+")"
@ -76,8 +76,8 @@ for group in groups.keys():
'var': var, 'var': var,
'group': group, 'group': group,
'dims': strdims} 'dims': strdims}
print attributes%d print(attributes%d)
print >>file_py, attributes_py%d print(attributes_py%d, file=file_py)
else: else:
d = { 'type': type, d = { 'type': type,
'var': var, 'var': var,
@ -88,15 +88,15 @@ for group in groups.keys():
'expr_py': command_py} 'expr_py': command_py}
buffer = calculated%d buffer = calculated%d
buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer) buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer)
print buffer print(buffer)
print >>file_py, calculated_py%d print(calculated_py%d, file=file_py)
elif type == "buffered": elif type == "buffered":
d = { 'group': group, d = { 'group': group,
'var': var, 'var': var,
'dims_py': dims_py, 'dims_py': dims_py,
'dims': dims } 'dims': dims }
print buffered%d print(buffered%d)
print >>file_py, buffered_py%d print(buffered_py%d, file=file_py)
else: else:
dims_loop = '' dims_loop = ''
copy_loop = '' copy_loop = ''
@ -119,7 +119,7 @@ for group in groups.keys():
copy_loop = copy_loop[:-1]%{'var': var,'group': group} + ")\n" copy_loop = copy_loop[:-1]%{'var': var,'group': group} + ")\n"
for k,d in enumerate(dims): for k,d in enumerate(dims):
copy_loop += (len(dims)-k-1)*" "+" enddo\n" copy_loop += (len(dims)-k-1)*" "+" enddo\n"
for g in groups.keys(): for g in list(groups.keys()):
dims_loop_py = dims_loop_py.replace(" "+g,' self.'+g) dims_loop_py = dims_loop_py.replace(" "+g,' self.'+g)
dims_loop_py = dims_loop_py.replace("*"+g,'*self.'+g) dims_loop_py = dims_loop_py.replace("*"+g,'*self.'+g)
dims_loop_py = dims_loop_py.replace("/"+g,'/self.'+g) dims_loop_py = dims_loop_py.replace("/"+g,'/self.'+g)
@ -140,7 +140,7 @@ for group in groups.keys():
'dims_loop_py': dims_loop_py, 'dims_loop_py': dims_loop_py,
'copy_loop': copy_loop, 'copy_loop': copy_loop,
'declar_loop' : declar_loop} 'declar_loop' : declar_loop}
print attributes_arr%d print(attributes_arr%d)
print >>file_py, attributes_arr_py%d print(attributes_arr_py%d, file=file_py)
file_py.close() file_py.close()

View File

@ -345,7 +345,7 @@ attributes_py = """
attributes_arr_py = """ attributes_arr_py = """
def get_%(group)s_%(var)s(self): def get_%(group)s_%(var)s(self):
rank = %(rank)s rank = %(rank)s
dims = range(rank) dims = list(range(rank))
%(dims_loop_py)s %(dims_loop_py)s
dim_max = 1 dim_max = 1
for d in dims: for d in dims:
@ -359,7 +359,7 @@ attributes_arr_py = """
def set_%(group)s_%(var)s(self,%(var)s): def set_%(group)s_%(var)s(self,%(var)s):
rank = %(rank)s rank = %(rank)s
dims = range(rank) dims = list(range(rank))
%(dims_loop_py)s %(dims_loop_py)s
dim_max = 1 dim_max = 1
for d in dims: for d in dims:

View File

@ -184,6 +184,6 @@ subroutine ezfio_finish()
BEGIN_SHELL [ /usr/bin/env python3 ] BEGIN_SHELL [ /usr/bin/env python3 ]
import os import os
from zlib import crc32 from zlib import crc32
print ' call irp_finalize_%s'%(str(abs(crc32(os.getcwd())))) print(' call irp_finalize_%s'%(str(abs(crc32(os.getcwd().encode())))))
END_SHELL END_SHELL
end end

View File

@ -300,11 +300,11 @@ end function
! Build Python functions ! Build Python functions
""" """
for t in format.keys(): 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"): 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": if t != "logical":
print template_no_logical%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] } print(template_no_logical%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] })
template_py = """ template_py = """
def read_%(type_short)s(self,dir,fil): def read_%(type_short)s(self,dir,fil):
@ -331,7 +331,7 @@ template_py = """
l_filename += [ dir.strip()+'/'+fil ] l_filename += [ dir.strip()+'/'+fil ]
dat = conv(dat) dat = conv(dat)
file = open(l_filename[0],'w') file = open(l_filename[0],'w')
print >>file,'%(fmt)s'%%(dat,) print('%(fmt)s'%%(dat,), file=file)
file.close() file.close()
os.rename(l_filename[0],l_filename[1]) os.rename(l_filename[0],l_filename[1])
@ -371,13 +371,13 @@ template_py = """
file.write("\\n") file.write("\\n")
dat = flatten(dat) dat = flatten(dat)
for i in xrange(dim_max): for i in range(dim_max):
file.write("%(fmt)s\\n"%%(dat[i],)) file.write("%(fmt)s\\n"%%(dat[i],))
file.flush() file.flush()
buffer = file.getvalue() buffer = file.getvalue()
file.close() file.close()
file = GzipFile(filename=l_filename[0],mode='wb') file = GzipFile(filename=l_filename[0],mode='wb')
file.write(buffer) file.write(buffer.encode())
file.close() file.close()
os.rename(l_filename[0],l_filename[1]) os.rename(l_filename[0],l_filename[1])
except: except:
@ -387,16 +387,16 @@ template_py = """
file_py = open("libezfio_util-gen.py","w") file_py = open("libezfio_util-gen.py","w")
for t in format.keys(): for t in format.keys():
print >>file_py, template_py%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][1] } print (template_py%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][1] }, file=file_py)
import os import os
command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'" command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'"
cwd = os.getcwd() cwd = os.getcwd()
cwd = cwd.split('src')[:-1] cwd = cwd.split('src')[:-1]
cwd = '/'.join(cwd) cwd = '/'.join(cwd)
print >>file_py, """ print("""
LIBRARY = "%s" LIBRARY = "%s"
"""%cwd """%cwd,file=file_py)
file_py.close() file_py.close()

View File

@ -31,7 +31,7 @@ import os, sys
lines = [] lines = []
for filename in [ '../config/'+i for i in os.listdir('../config')]: for filename in [ '../config/'+i for i in os.listdir('../config')]:
file = open(filename,'r') file = open(filename,'r')
lines += map(lambda x: (x,filename), file.readlines()) lines += [(x,filename) for x in file.readlines()]
try: try:
if lines[-1] != '': if lines[-1] != '':
lines.append( ('', filename) ) lines.append( ('', filename) )
@ -51,7 +51,7 @@ for line, filename in lines:
groups[group] = my_list groups[group] = my_list
elif line[0] != ' ': # New group elif line[0] != ' ': # New group
group = line.strip() group = line.strip()
if group in groups.keys(): if group in list(groups.keys()):
my_list = groups[group] my_list = groups[group]
else: else:
my_list = [] my_list = []
@ -76,12 +76,12 @@ for line, filename in lines:
my_list.append(tuple(buffer)) my_list.append(tuple(buffer))
except: except:
import sys, time import sys, time
print >>sys.stderr, '' print('', file=sys.stderr)
print >>sys.stderr, '*'*80 print('*'*80, file=sys.stderr)
print >>sys.stderr, 'Error in EZFIO config file '+filename+' :' print('Error in EZFIO config file '+filename+' :', file=sys.stderr)
print >>sys.stderr, line print(line, file=sys.stderr)
print >>sys.stderr, '*'*80 print('*'*80, file=sys.stderr)
print >>sys.stderr, '' print('', file=sys.stderr)
time.sleep(3) time.sleep(3)
sys.exit(1) sys.exit(1)

View File

@ -1 +1 @@
VERSION=2.0 VERSION=2.0.1