From 071cd0257b862b7be6116507dd2e289db17cce48 Mon Sep 17 00:00:00 2001 From: Olivier Sauter <olivier.sauter@epfl.ch> Date: Sat, 10 Aug 2024 08:45:53 +0200 Subject: [PATCH] start adding other simple reads options for futils outputs --- matlab/IMAS/read_hdf5_simple.m | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/matlab/IMAS/read_hdf5_simple.m b/matlab/IMAS/read_hdf5_simple.m index f72da13b..10e90b25 100644 --- a/matlab/IMAS/read_hdf5_simple.m +++ b/matlab/IMAS/read_hdf5_simple.m @@ -2,6 +2,8 @@ function h5_struct = read_hdf5_simple(ids_h5_file,varargin) % % h5_struct = read_hdf5_simple(ids_h5_file,varargin) % +% varargin{1}: 'imas' (default), 'futils' (for ogyropsi files e.g.) type of hdf5 +% % on spcimas need to do: % export LD_PRELOAD_previous=$LD_PRELOAD % unset LD_PRELOAD @@ -15,21 +17,31 @@ 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; +file_type = 'imas', +if nargin>=2 && ~isempty(varargin{1}) + file_type = varargin{1} +end + +switch file_type + case {'futils', 'standard'} + keyboard + otherwise + [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; + 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 - istart = 1; + disp(sprintf('\n*************\nno Datasets\n*************\n')); 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