From cd80d31f8e0606a723af307cc6c0428016c17568 Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Tue, 6 Aug 2024 11:04:40 +0200
Subject: [PATCH] simple h5 IDS file to flat structure read

---
 matlab/IMAS/read_hdf5_simple.m | 35 ++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 matlab/IMAS/read_hdf5_simple.m

diff --git a/matlab/IMAS/read_hdf5_simple.m b/matlab/IMAS/read_hdf5_simple.m
new file mode 100644
index 00000000..f72da13b
--- /dev/null
+++ b/matlab/IMAS/read_hdf5_simple.m
@@ -0,0 +1,35 @@
+function h5_struct = read_hdf5_simple(ids_h5_file,varargin)
+%
+% h5_struct = read_hdf5_simple(ids_h5_file,varargin)
+%
+% on spcimas need to do:
+%    export LD_PRELOAD_previous=$LD_PRELOAD
+%    unset LD_PRELOAD
+%    matlab
+%    >> h5disp('/tmp/yildiz//imasdb/tcv/3/80000/999/summary.h5')
+%    (to reset: export LD_PRELOAD=$LD_PRELOAD_previous )
+
+try
+  aa=hdf5info(ids_h5_file);
+catch
+  error('could not hdf5info(file)')
+end
+
+[a1,ids_name,a3]=fileparts(aa.Filename);
+h5_struct.ids_name = ids_name;
+h5_struct.Filename = aa.GroupHierarchy.Filename;
+
+if isfield(aa.GroupHierarchy.Groups,'Datasets')
+  for i=1:numel(aa.GroupHierarchy.Groups.Datasets)
+    if strcmp(aa.GroupHierarchy.Groups.Datasets(i).Name(1),'/')
+      istart = 2;
+    else
+      istart = 1;
+    end
+    struct_flatname = regexprep(lower(regexprep(aa.GroupHierarchy.Groups.Datasets(i).Name(istart:end),'[/&[]]','.')),'\.+','_');
+    struct_flatname = regexprep(struct_flatname,[h5_struct.ids_name '_'],'');
+    h5_struct.(struct_flatname) = h5read(aa.GroupHierarchy.Groups.Datasets(i).Filename,aa.GroupHierarchy.Groups.Datasets(i).Name);
+  end
+else
+  disp(sprintf('\n*************\nno Datasets\n*************\n'));
+end
-- 
GitLab