10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2025-01-03 10:05:41 +01:00

Added archive/unarchive scripts

This commit is contained in:
Anthony Scemama 2015-03-03 16:28:24 +01:00
parent 2fe3f824a6
commit cf872f6514
5 changed files with 216 additions and 127 deletions

44
bin/archive_ezfio.py Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python
import sys
import os
sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path
import cPickle as pickle
from ezfio import ezfio_obj, ezfio
# Hide errors
def f(where,txt):
raise IOError
ezfio.error = f
def main():
if len(sys.argv) == 1:
print "syntax: %s <EZFIO_Filename>"%(sys.argv[0])
sys.exit(1)
ezfio_filename = sys.argv[1]
ezfio.set_filename(ezfio_filename)
get_functions = filter(
lambda x: x.startswith("has_"),
ezfio_obj.__dict__.keys() )
d = {}
for f in get_functions:
f_name = f[4:]
try:
exec """d['%s'] = ezfio.%s"""%(f_name,f_name)
except:
print "%-40s [%5s]"%(f_name, "Empty")
else:
print "%-40s [%5s]"%(f_name, " OK ")
dump = pickle.dumps(d)
file = open(ezfio_filename+".ezar","w")
file.write(dump)
file.close()
if __name__ == "__main__":
main()

51
bin/unarchive_ezfio.py Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env python
import sys
import os
sys.path = [ os.path.dirname(__file__)+"/../Python" ]+sys.path
import cPickle as pickle
from ezfio import ezfio_obj, ezfio
# Hide errors
#def f(where,txt):
# raise IOError
#ezfio.error = f
def main():
if len(sys.argv) == 1:
print "syntax: %s <EZFIO_Archive.ezar>"%(sys.argv[0])
sys.exit(1)
ezfio_filename = sys.argv[1].split(".ezar")[0]
file = open(ezfio_filename+".ezar","r")
dump = file.read()
file.close()
ezfio.set_filename(ezfio_filename)
d = pickle.loads(dump)
set_functions = d.keys()
nerrors_old = len(d)+1
nerrors = nerrors_old+1
while nerrors != nerrors_old:
nerrors_old = nerrors
nerrors = 0
failed = []
for f_name in set_functions:
try:
exec """ezfio.%s = d['%s']"""%(f_name,f_name)
except:
nerrors += 1
failed.append(f_name)
if nerrors != 0:
print "Unarchive failed:"
for i in failed:
print i
sys.exit(1)
if __name__ == "__main__":
main()

View File

@ -42,11 +42,6 @@ logical function ezfio_exists(path)
character*(32) :: V character*(32) :: V
read(libezfio_iunit,*) V read(libezfio_iunit,*) V
close(libezfio_iunit) close(libezfio_iunit)
! integer :: char_to_version
! if (char_to_version(V) > char_to_version(libezfio_version)) then
! call ezfio_error(irp_here, "This file was generated with version "//trim(V)//&
! " but the current installed version is "//trim(libezfio_version)//".")
! endif
endif endif
end function end function
@ -63,7 +58,6 @@ subroutine ezfio_mkdir(path)
write(libezfio_iunit,'(A)') libezfio_version write(libezfio_iunit,'(A)') libezfio_version
close(libezfio_iunit) close(libezfio_iunit)
endif endif
end subroutine end subroutine
@ -156,7 +150,7 @@ subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
read(libezfio_iunit,'(I3)') rank_read read(libezfio_iunit,'(I3)') rank_read
if (rank_read /= rank) then if (rank_read /= rank) then
call ezfio_error(irp_here,'Rank of data '//trim(l_filename)//& call ezfio_error(irp_here,'Rank of data '//trim(l_filename)// &
' different from array.') ' different from array.')
endif endif
@ -185,6 +179,7 @@ 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') call ezfio_error(irp_here,'Attribute '//trim(l_filename)//' is not set')
endif endif
end end
subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
implicit none implicit none
character*(*), intent(in) :: dir, fil character*(*), intent(in) :: dir, fil
@ -229,8 +224,8 @@ integer function n_count_%(type_short)s(array,isize,val)
n_count_%(type_short)s = n_count_%(type_short)s +1 n_count_%(type_short)s = n_count_%(type_short)s +1
endif endif
enddo enddo
end function end function
! Build Python functions ! Build Python functions
""" """
for t in format.keys(): for t in format.keys():
@ -335,7 +330,7 @@ END_SHELL
BEGIN_PROVIDER [ integer, libezfio_buffer_rank ] BEGIN_PROVIDER [ integer, libezfio_buffer_rank ]
BEGIN_DOC BEGIN_DOC
! Rank of the buffer ready for reading ! Rank of the buffer ready for reading
END_DOC END_DOC
libezfio_buffer_rank = -1 libezfio_buffer_rank = -1
END_PROVIDER END_PROVIDER
@ -368,7 +363,6 @@ subroutine ezfio_open_write_buffer(dir,fil,rank)
endif endif
write(libezfio_iunit,'(I2)') rank write(libezfio_iunit,'(I2)') rank
end end
subroutine ezfio_open_read_buffer(dir,fil,rank) subroutine ezfio_open_read_buffer(dir,fil,rank)
@ -466,7 +460,7 @@ subroutine ezfio_write_buffer(indices,values,isize)
endif endif
write(cformat,*) '(',num,'(',libezfio_buffer_rank,'(I4,X),E24.15,A1))' write(cformat,*) '(',num,'(',libezfio_buffer_rank,'(I4,X),E24.15,A1))'
write(libezfio_iunit,cformat) ((indices((i-1)*libezfio_buffer_rank+j), j=1,libezfio_buffer_rank), & write(libezfio_iunit,cformat) ((indices((i-1)*libezfio_buffer_rank+j), j=1,libezfio_buffer_rank),&
values(i), i=1,isize) values(i), i=1,isize)
end end

View File

@ -45,8 +45,8 @@ groups = {}
group = None group = None
my_list = [] my_list = []
for line, filename in lines: for line, filename in lines:
line = line.lower()
try: try:
if len(line.strip()) == 0: if len(line.strip()) == 0:
groups[group] = my_list groups[group] = my_list
elif line[0] != ' ': # New group elif line[0] != ' ': # New group

View File

@ -1 +1 @@
VERSION=1.1.11 VERSION=1.2.1