classdef cif
    % cif('path')
    %
    % class handling cif data
    % Any field returns a value belonging to that field name. Use
    % cif.('field-name') for field names that are not valid matlab field
    % names. Cif files containing multiple crystal structure, the first one
    % will be retrieved.
    %
    % path      Path to the cif file to be opened.
    %
    
% $Name: SpinW$ ($Version: 2.1$)
% $Author: S. Toth$ ($Contact: sandor.toth@psi.ch$)
% $Revision: 238 $ ($Date: 07-Feb-2015 $)
% $License: GNU GENERAL PUBLIC LICENSE$

    properties (Access = private)
        cifdat
    end
    
    methods
        function obj = cif(path)
            obj.cifdat = struct('name','','val',[],'type','');
            
            if nargin == 1
                obj.cifdat = obj.importcif(path);
            end
            
        end
        
        function B = subsref(obj, S)
            B = [];
            switch S.type
                case '.'
                    for ii = 1:numel(obj.cifdat)
                        if strcmp(S.subs, obj.cifdat(ii).name)
                            B = obj.cifdat(ii).val;
                            break;
                        end
                    end
                    
                    if strcmp(S.subs, 'cifdat')
                        B = obj.cifdat;
                    end
            end
            
        end
    end
    
end
