-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ./datatypes, ./datasets, ./files, ./groups, ./util, ./serialize | ||
import std / tables | ||
|
||
proc toH5*[K; V](h5f: H5File, tab: Table[K, V] | OrderedTable[K, V], name = "", path = "/") = | ||
## Stores the given `Table` as in the H5 file. | ||
## This is done by constructing a group for the table and adding a | ||
## compound dataset with (key, value) pairs in each row. | ||
bind `/` | ||
let grp = path / name | ||
discard h5f.create_group(grp) | ||
|
||
var data = newSeqOfCap[(K, V)](tab.len) | ||
for k, v in tab: | ||
data.add (k, v) | ||
h5f.toH5(data, "table", grp) | ||
|
||
proc fromH5*[K; V](h5f: H5File, res: var (Table[K, V] | OrderedTable[K, V]), name = "", path = "/", exclude: seq[string] = @[]) = | ||
## Reads a Table of the given type stored by `toH5` | ||
bind `/` | ||
let grp = h5f[(path / name).grp_str] | ||
var data: seq[(K, V)] | ||
h5f.fromH5(data, "table", grp.name) | ||
res = default(typeof(res)) | ||
for i in 0 ..< data.len: | ||
let (k, v) = data[i] | ||
res[k] = v |