Changeset 1013


Ignore:
Timestamp:
Oct 4, 2017, 3:55:18 PM (7 years ago)
Author:
g7moreau
Message:
  • Remove property svn:executable
Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/hdf5load.m

    • Property svn:executable deleted
    r947 r1013  
    1313function datasets = hdf5load(filename)
    1414
    15 hinfo=hdf5info(filename);
     15    hinfo=hdf5info(filename);
    1616
    17 datasets=struct;
    18 hinfo.GroupHierarchy;
    19 datasets=hdf5load_recursion(datasets,hinfo.GroupHierarchy);
    20 
     17    datasets=struct;
     18    hinfo.GroupHierarchy;
     19    datasets=hdf5load_recursion(datasets,hinfo.GroupHierarchy);
     20end
  • trunk/src/hdf5load_recursion.m

    • Property svn:executable deleted
    r947 r1013  
    1414function datastruct = hdf5load_recursive(datastruct,GroupHierarchy)
    1515
    16 % Load the datasets (the leafs of the tree):
    17 for i=[1:size(GroupHierarchy.Datasets,2)]
    18     data=hdf5read(GroupHierarchy.Datasets(i));
    19     switch class(data)
    20         case 'hdf5.h5string'
    21             try
    22                 if size(data,2)>1
    23                     buffer=data ;
    24                     data = {} ;
    25                     for j=1:size(buffer,2)
    26                         data{j}=buffer(j).Data;
    27                     end
    28                 else
    29                     data=data.Data;
    30                 end
    31             catch
    32             end
    33         case 'hdf5.h5array'
    34             try
    35                 if size(data,2)>1
    36                     buffer=data ;
    37                     data = {} ;
    38                     for j=1:size(buffer,2)
    39                         data{j}=buffer(j).Data;
    40                     end
    41                 else
    42                     data=data.Data;
    43                 end
    44             catch
    45             end
    46        
     16    % Load the datasets (the leafs of the tree):
     17    for i=[1:size(GroupHierarchy.Datasets,2)]
     18        data=hdf5read(GroupHierarchy.Datasets(i));
     19        switch class(data)
     20            case 'hdf5.h5string'
     21                try
     22                    if size(data,2)>1
     23                        buffer=data;
     24                        data = {};
     25                        for j=1:size(buffer,2)
     26                            data{j}=buffer(j).Data;
     27                        end
     28                    else
     29                        data=data.Data;
     30                    end
     31                catch
     32                end
     33            case 'hdf5.h5array'
     34                try
     35                    if size(data,2)>1
     36                        buffer=data;
     37                        data = {};
     38                        for j=1:size(buffer,2)
     39                       data{j}=buffer(j).Data;
     40                        end
     41                    else
     42                        data=data.Data;
     43                    end
     44                catch
     45                end
     46        end
     47        name=GroupHierarchy.Datasets(i).Name;
     48        name=strrep(name,'/','.');
     49        eval(['datastruct' name '= data ;'])
    4750    end
    48     name=GroupHierarchy.Datasets(i).Name;
    49     name=strrep(name,'/','.');
    50     eval(['datastruct' name '= data ;'])
     51    for i=[1:size(GroupHierarchy.Attributes,2)]
     52        data=hdf5read(GroupHierarchy.Attributes(i));
     53        switch class(data)
     54            case 'hdf5.h5string'
     55                try
     56                    if size(data,2)>1
     57                        buffer=data;
     58                        data = {};
     59                        for j=1:size(buffer,2)
     60                       data{j}=buffer(j).Data;
     61                        end
     62                    else
     63                        data=data.Data;
     64                    end
     65                catch
     66                end
     67            case 'hdf5.h5array'
     68                try
     69                    if size(data,2)>1
     70                        buffer=data;
     71                        data = {};
     72                        for j=1:size(buffer,2)
     73                       data{j}=buffer(j).Data;
     74                        end
     75                    else
     76                        data=data.Data;
     77                    end
     78                catch
     79                end
     80        end
     81        name=GroupHierarchy.Attributes(i).Name;
     82        name=strrep(name,'/','.');
     83        eval(['datastruct' name '= data ;'])
     84    end
     85
     86    % Then load the branches:
     87    % Create structures for the group and pass them on recursively:
     88    for i=[1:size(GroupHierarchy.Groups,2)]
     89        name=GroupHierarchy.Groups(i).Name;
     90        name=strrep(name,'/','.');
     91        eval(['datastruct' name '= struct ;']);
     92        datastruct = hdf5load_recursion(datastruct,GroupHierarchy.Groups(i));
     93    end
    5194end
    52 for i=[1:size(GroupHierarchy.Attributes,2)]
    53     data=hdf5read(GroupHierarchy.Attributes(i));
    54     switch class(data)
    55         case 'hdf5.h5string'
    56             try
    57                 if size(data,2)>1
    58                     buffer=data ;
    59                     data = {} ;
    60                     for j=1:size(buffer,2)
    61                         data{j}=buffer(j).Data;
    62                     end
    63                 else
    64                     data=data.Data;
    65                 end
    66             catch
    67             end
    68         case 'hdf5.h5array'
    69             try
    70                 if size(data,2)>1
    71                     buffer=data ;
    72                     data = {} ;
    73                     for j=1:size(buffer,2)
    74                         data{j}=buffer(j).Data;
    75                     end
    76                 else
    77                     data=data.Data;
    78                 end
    79             catch
    80         end
    81     end
    82     name=GroupHierarchy.Attributes(i).Name;
    83     name=strrep(name,'/','.');
    84     eval(['datastruct' name '= data ;'])
    85 end
    86 
    87 % Then load the branches:
    88 % Create structures for the group and pass them on recursively:
    89 for i=[1:size(GroupHierarchy.Groups,2)]
    90     name=GroupHierarchy.Groups(i).Name;
    91     name=strrep(name,'/','.');
    92     eval(['datastruct' name '= struct ;']);
    93     datastruct = hdf5load_recursion(datastruct,GroupHierarchy.Groups(i));
    94 end
    95 
  • trunk/src/hdf5save.m

    • Property svn:executable deleted
    r947 r1013  
    1313function hdf5save(filename,varargin)
    1414
    15 % this is just a wrapper function that calls a recursive function that
    16 % will save recursively structs.
     15    % this is just a wrapper function that calls a recursive function that
     16    % will save recursively structs.
    1717
    18 nvars=size(varargin,2)/2;
     18    nvars=size(varargin,2)/2;
    1919
    20 if nvars~=floor(nvars) ;
    21     error('expecting a name for each variable') ;
     20    if nvars~=floor(nvars);
     21        error('expecting a name for each variable');
     22    end
     23
     24    %  Assign variables to save in workspace so as to be able to get them back
     25    %  with recursive fonctions.
     26    for i=[1:nvars]
     27        str=varargin{2*i};
     28        var=evalin('caller',str);
     29        assignin('base',str,var);
     30    end
     31
     32    hdf5save_recursion(filename,'',1,varargin)
    2233end
    23 
    24 %  Assign variables to save in workspace so as to be able to get them back
    25 %  with recursive fonctions.
    26 for i=[1:nvars]
    27     str=varargin{2*i};
    28     var=evalin('caller',str);
    29     assignin('base',str,var);
    30 end
    31 
    32 hdf5save_recursion(filename,'',1,varargin)
    33 
  • trunk/src/hdf5save_recursion.m

    • Property svn:executable deleted
    r947 r1013  
    1515function hdf5save_recursion(filename,prefix,new,varcell)
    1616
    17 if ~strcmp(class(filename),'char') ;
    18     error('first argument should be a string giving the path to the hdf5 file to save') ;
    19 end
     17    if ~strcmp(class(filename),'char');
     18        error('first argument should be a string giving the path to the hdf5 file to save');
     19    end
    2020
    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 end
     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    end
    2424
    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 end
     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    end
    2828
    29 nvars=size(varcell,2)/2;
     29    nvars=size(varcell,2)/2;
    3030
    31 if nvars~=floor(nvars) ;
    32     error('expecting a name for each variable') ;
    33 end
     31    if nvars~=floor(nvars);
     32        error('expecting a name for each variable');
     33    end
    3434
    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
    6162    end
    6263end
    63 
  • trunk/src/readimx.mexa64

    • Property svn:executable deleted
Note: See TracChangeset for help on using the changeset viewer.