Home > classes > @history > eq.m

eq

PURPOSE ^

EQ overloads the == operator for history objects.

SYNOPSIS ^

function result = eq(c1,c2, varargin)

DESCRIPTION ^

 EQ overloads the == operator for history objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: EQ overloads the == operator for history objects.

              All fields are checked.

 CALL:        result = eq(c1,c2)
              result = eq(c1,c2,  exc_list)
              result = eq(c1,c2, 'property1', 'property2')
              result = eq(c1,c2, 'class/property', 'class/property')

 EXAMPLES:    result = eq(c1,c2, 'name', 'created')
              result = eq(c1,c2, 'ao/name')

 INPUTS:      c1,c2    - input history objects
              exc_list - exception list
                         List of properties which are not checked.

 OUTPUTS:     If the two history objects are considered equal, result == 1,
              otherwise, result == 0.

 VERSION:     $Id: eq.m,v 1.4 2007/12/04 18:16:11 ingo Exp $

 HISTORY:     29-08-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function result = eq(c1,c2, varargin)
0002 % EQ overloads the == operator for history objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: EQ overloads the == operator for history objects.
0007 %
0008 %              All fields are checked.
0009 %
0010 % CALL:        result = eq(c1,c2)
0011 %              result = eq(c1,c2,  exc_list)
0012 %              result = eq(c1,c2, 'property1', 'property2')
0013 %              result = eq(c1,c2, 'class/property', 'class/property')
0014 %
0015 % EXAMPLES:    result = eq(c1,c2, 'name', 'created')
0016 %              result = eq(c1,c2, 'ao/name')
0017 %
0018 % INPUTS:      c1,c2    - input history objects
0019 %              exc_list - exception list
0020 %                         List of properties which are not checked.
0021 %
0022 % OUTPUTS:     If the two history objects are considered equal, result == 1,
0023 %              otherwise, result == 0.
0024 %
0025 % VERSION:     $Id: eq.m,v 1.4 2007/12/04 18:16:11 ingo Exp $
0026 %
0027 % HISTORY:     29-08-2007 M Hewitson
0028 %                 Creation
0029 %
0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031 
0032 VERSION  = '$Id: eq.m,v 1.4 2007/12/04 18:16:11 ingo Exp $';
0033 
0034 % Check if this is a call for parameters
0035 if nargin == 2
0036   if isa(c1, 'history') && ischar(c2)
0037     in = char(c2);
0038     if strcmp(in, 'Params')
0039       result = plist;
0040       return
0041     elseif strcmp(in, 'Version')
0042       result = VERSION;
0043       return
0044     end
0045   end
0046 end
0047 
0048 result = 1;
0049 
0050 %% Check class
0051 if ~strcmp(class(c1), class(c2))
0052   result = 0;
0053   return
0054 end
0055 
0056 fields = fieldnames(c1);
0057 
0058 for ii = 1:length(fields)
0059   field   = fields{ii};
0060 
0061   ck_field = {field, ['history/' field]};
0062 
0063   % Is the field equal to history then add the name 'history'
0064   % to the exception list.
0065   if strcmp(field, 'inhists')
0066     ck_field{end+1} = 'history';
0067     ck_field{end+1} = 'history/history';
0068   end
0069 
0070   %% Check tag
0071   if ~(any(ismember(ck_field, varargin)))
0072 
0073     if isobject(c1.(field))
0074 
0075       if length(c1.(field)) ~= length(c2.(field))
0076         result = 0;
0077         return
0078       end
0079 
0080       for jj = 1:length(c1.(field))
0081         if ~eq(c1.(field)(jj), c2.(field)(jj), varargin{:})
0082           result = 0;
0083           disp(sprintf('\nNOT EQUAL: %s.%s', class(c1), field));
0084           return
0085         end
0086       end
0087     else
0088       if ~isequalwithequalnans(c1.(field), c2.(field))
0089         result = 0;
0090         disp(sprintf('\nNOT EQUAL: %s.%s', class(c1), field));
0091         return
0092       end
0093     end
0094 
0095   end
0096 end
0097 
0098 
0099 % function result = eq(w1,w2, varargin)
0100 %
0101 % % EQ overloads the == operator for history objects.
0102 % %
0103 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104 % %
0105 % % DESCRIPTION: EQ overloads the == operator for history objects.
0106 % %
0107 % %              The 'name', 'version', 'plist', 'inhists', 'invars', 'created',
0108 % %              fields are checked.
0109 % %
0110 % % CALL:        result = eq(h1,h2)
0111 % %
0112 % % INPUTS:      h1,h2 - input specwin objects
0113 % %
0114 % % OUTPUTS:     If the two history objects are considered equal, result == 1,
0115 % %              otherwise, result == 0.
0116 % %
0117 % % VERSION:     $Id: eq.m,v 1.4 2007/12/04 18:16:11 ingo Exp $
0118 % %
0119 % % HISTORY:     29-08-2007 M Hewitson
0120 % %                 Creation
0121 % %
0122 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0123 %
0124 % % Assume equality to begin with
0125 % result = 1;
0126 %
0127 % %% Check name
0128 % if ~ismember('name', varargin)
0129 %   if ~strcmp(w1.name, w2.name)
0130 %     result = 0;
0131 %     return
0132 %   end
0133 % end
0134 %
0135 % %% Check version
0136 % if ~ismember('version', varargin)
0137 %   if ~strcmp(w1.version, w2.version)
0138 %     result = 0;
0139 %     return
0140 %   end
0141 % end
0142 %
0143 % %% Check plist
0144 % if ~ismember('plist', varargin)
0145 %   if xor(isempty(w1.plist), isempty(w2.plist))
0146 %     result = 0;
0147 %   end
0148 %   if ~eq(w1.plist, w2.plist, varargin{:})
0149 %     result = 0;
0150 %     return;
0151 %   end
0152 % end
0153 %
0154 % %% check inhists
0155 %
0156 % if ~ismember('inhists', varargin)
0157 %   if length(w1.inhists) ~= length(w2.inhists)
0158 %     result = 0;
0159 %     return
0160 %   end
0161 %
0162 %   for j=1:length(w1.inhists)
0163 %     if ~eq(w1.inhists(j), w2.inhists(j), varargin{:})
0164 %       result = 0;
0165 %       return
0166 %     end
0167 %   end
0168 % end
0169 %
0170 % %% check invars
0171 % if ~ismember('invars', varargin)
0172 %   if length(w1.invars) ~= length(w2.invars)
0173 %     result = 0;
0174 %     return
0175 %   end
0176 %
0177 %   for j=1:length(w1.invars)
0178 %     if ~strcmp(w1.invars{j}, w2.invars{j})
0179 %       result = 0;
0180 %       return
0181 %     end
0182 %   end
0183 % end
0184 %
0185 % %% check created
0186 % if ~ismember('created', varargin)
0187 %   if w1.created ~= w2.created
0188 %     result = 0;
0189 %     return
0190 %   end
0191 % end

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003