Changeset 1013 for trunk/src/hdf5save_recursion.m
- Timestamp:
- Oct 4, 2017, 3:55:18 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/hdf5save_recursion.m
- Property svn:executable deleted
r947 r1013 15 15 function hdf5save_recursion(filename,prefix,new,varcell) 16 16 17 if ~strcmp(class(filename),'char');18 error('first argument should be a string giving the path to the hdf5 file to save');19 end17 if ~strcmp(class(filename),'char'); 18 error('first argument should be a string giving the path to the hdf5 file to save'); 19 end 20 20 21 if ~strcmp(class(prefix),'char');22 error('second argument should be a string giving the name of the groupe to save the data in');23 end21 if ~strcmp(class(prefix),'char'); 22 error('second argument should be a string giving the name of the groupe to save the data in'); 23 end 24 24 25 if new~=1 && new~=0;26 error('third argument should be 0 or 1: 0 to append data, and 1 to create a new file')27 end25 if new~=1 && new~=0; 26 error('third argument should be 0 or 1: 0 to append data, and 1 to create a new file'); 27 end 28 28 29 nvars=size(varcell,2)/2;29 nvars=size(varcell,2)/2; 30 30 31 if nvars~=floor(nvars);32 error('expecting a name for each variable');33 end31 if nvars~=floor(nvars); 32 error('expecting a name for each variable'); 33 end 34 34 35 for i=[1:nvars] 36 str=varcell{2*i}; 37 var=evalin('base',str); 38 name=varcell{2*i-1}; 39 type=class(var); 40 location=strcat('/',prefix,name); 41 %disp(['variable name in workspace : ',str]); 42 %disp(['variable name to put : ',name]); 43 switch type 44 case 'struct' 45 names=fieldnames(var); 46 for j=1:size(names,1) ; 47 if (j~=1 || i~=1) 48 new=0 ; 49 end 50 varname=strcat(name,'.',names{j}); 51 hdf5save_recursion(filename,strcat(name,'/'),new,{names{j},varname}); 52 end 53 otherwise 54 location=strcat('/',prefix,name); 55 if new==1 && i==1 ; 56 hdf5write(filename,location,var); 57 else 58 %disp(['location : ',location]); 59 hdf5write(filename,location,var,'WriteMode', 'append'); 60 end 35 for i=[1:nvars] 36 str=varcell{2*i}; 37 var=evalin('base',str); 38 name=varcell{2*i-1}; 39 type=class(var); 40 location=strcat('/',prefix,name); 41 %disp(['variable name in workspace : ',str]); 42 %disp(['variable name to put : ',name]); 43 switch type 44 case 'struct' 45 names=fieldnames(var); 46 for j=1:size(names,1); 47 if (j~=1 || i~=1) 48 new=0; 49 end 50 varname=strcat(name,'.',names{j}); 51 hdf5save_recursion(filename,strcat(name,'/'),new,{names{j},varname}); 52 end 53 otherwise 54 location=strcat('/',prefix,name); 55 if new==1 && i==1; 56 hdf5write(filename,location,var); 57 else 58 %disp(['location : ',location]); 59 hdf5write(filename,location,var,'WriteMode', 'append'); 60 end 61 end 61 62 end 62 63 end 63
Note: See TracChangeset
for help on using the changeset viewer.