@@ -44,7 +44,13 @@ function savesnirf(data, outfile,varargin)
44
44
end
45
45
46
46
if (~isempty(outfile ))
47
- if (~isempty(regexp(outfile ,' \.[Hh]5$' , ' once' )) || ~isempty(regexp(outfile ,' \.[Ss][Nn][Ii][Rr][Ff]$' , ' once' )))
47
+ if (~isempty(regexp(outfile ,' \.[Hh]5$' , ' once' )))
48
+ saveh5(data ,outfile ,opt );
49
+ elseif (~isempty(regexp(outfile ,' \.[Ss][Nn][Ii][Rr][Ff]$' , ' once' )))
50
+ data.nirs.data= forceindex(data .nirs .data ,' measurementList' );
51
+ data.nirs= forceindex(data .nirs ,' data' );
52
+ data.nirs= forceindex(data .nirs ,' stim' );
53
+ data.nirs= forceindex(data .nirs ,' aux' );
48
54
saveh5(data ,outfile ,opt );
49
55
elseif (~isempty(regexp(outfile ,' \.[Jj][Nn][Ii][Rr][Ss]$' , ' once' ))|| ~isempty(regexp(outfile ,' \.[Jj][Ss][Oo][Nn]$' , ' once' )))
50
56
savejson(' SNIRDData' ,data ,' FileName' ,outfile ,opt );
@@ -56,3 +62,16 @@ function savesnirf(data, outfile,varargin)
56
62
error(' only support .snirf, .h5, .jnirs, .bnirs and .mat files' );
57
63
end
58
64
end
65
+
66
+ % force adding index 1 to the group name for singular struct and cell
67
+ function newroot = forceindex(root ,name )
68
+ newroot= root ;
69
+ fields= fieldnames(newroot );
70
+ idx= find(ismember(fields ,name ));
71
+ if (~isempty(idx ) && length(newroot.(name ))==1 )
72
+ newroot.(sprintf(' %s 1' ,name ))=newroot.(name );
73
+ newroot= rmfield(newroot ,name );
74
+ fields{idx(1 )}=sprintf(' %s 1' ,name );
75
+ newroot= orderfields(newroot ,fields );
76
+ end
77
+
0 commit comments