mirror of
https://gitlab.com/scemama/EZFIO.git
synced 2025-01-03 01:55:44 +01:00
Added ezfio_array_of_array
This commit is contained in:
parent
ed1df9f3c1
commit
d5805497fa
24
src/ezfio.ml
24
src/ezfio.ml
@ -210,6 +210,30 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user