mirror of https://gitlab.com/scemama/EZFIO.git
Compare commits
13 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 |
|
@ -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
|
||||
========
|
||||
|
||||
|
|
|
@ -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 ?= 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
|
||||
|
||||
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -102,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
|
||||
|
|
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"]
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ for group in list(groups.keys()):
|
|||
command_py = command
|
||||
dims_py = str(dims)
|
||||
for g in list(groups.keys()):
|
||||
command_py = command_py.replace(g,'self.'+g)
|
||||
dims_py = dims_py.replace(g,'self.'+g)
|
||||
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(['('+str(x)+')' for x in dims])
|
||||
|
@ -107,7 +107,7 @@ for group in list(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 ("
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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