% Copyright (c) 2011 Thomas Schaffter
%
% Author: Thomas Schaffter (firstname.name@gmail.com)
% Version: June 15, 2011
%
% UNFOLD_STRUCTURE Unfold and show the content of the given structure.
%    UNFOLD_STRUCTURE(STRUCT, ROOT) shows recursively the content of the
%    given structure STRUCT. ROOT is a string which must be set with the
%    variable name of STRUCT. Clean and generic implementation which can be
%    easily extended, e.g. for structures containing cells.
%
%    Usage: unfold_structure(myStructure, 'myStructure');
% sample output:
% >> unfold_structure(meta,'meta')
% meta.experiment: WHOTS,WHOI-Hawaii Ocean Timeseries Station
% meta.site: WHOTS
% meta.deployment: 7
% meta.PI: R. Weller, A. Plueddemann
% meta.platform_type: surface mooring
% meta.instrument.type: ASIMet logger
% meta.instrument.manufacturer: WHOI-UOP and Star Engineering
% meta.instrument.reference: http://frodo.whoi.edu/vmcm2/index.html,http://uop.whoi.edu
% meta.instrument.SN: 9  10
% meta.instrument.HRH.sn: 506
% meta.instrument.HRH.height_cm: 315
% meta.instrument.HRH.version: v4.29cf
% meta.instrument.HRH.model: ASIMet HRH module
% meta.instrument.HRH.reference: http://frodo.whoi.edu/asimet/asimet_module_specs.html#hrh_mod
% meta.instrument.BPR.sn: 505
% meta.instrument.BPR.height_cm: 312
% meta.instrument.BPR.version: v4.03cf
% meta.instrument.BPR.model: ASIMet BPR module
%
function unfold_structure(struct, root)

    names = fieldnames(struct);
    for i=1:length(names)
        
        value = struct.(names{i});
        if isstruct(value)
            unfold_structure(value, [root '.' names{i}])
        else
            disp([root '.' names{i} ': ' num2str(value)]);
        end
    end
end
