function B = subsref(hndl,S)
%HANDLE/SUBSREF

%   $Revision: 1.8 $  $Date: 1998/06/03 22:23:56 $
%   J.H. Roh & B.A. Jones 4-25-97.
%   Copyright (c) 1984-98 by The MathWorks, Inc.


switch S(1).type
case {'()' '{}' }
   indices = S(1).subs;
   structH = struct(hndl);
   tmp = structH(indices{:});
   B = class(tmp,'scribehandle');
   if length(S)>1
      B = subsref(B,S(2:end));
   end
case '.'
   Hstruct = struct(hndl);
   HG = squeeze(struct2cell(Hstruct));
   switch S(1).subs
   case 'Object'
      for idx = 1:prod(size(HG))
         ud = getappdata(HG{idx},'ScribeObjectData');
         MLObj = ud.ObjectStore;
         if idx == 1
        	B = MLObj;
         else
        	B = [B MLObj];
         end
      end
	  B = reshape(B,size(hndl));
   case 'HGHandle'
      if prod(size(HG)) == 1
         B = HG{1};
      else
         B = HG;
      end
   otherwise
      for idx = 1:prod(size(HG))
         ud = getappdata(HG{idx},'ScribeObjectData');
         MLObj = ud.ObjectStore;
         if idx == 1
	         B = {subsref(MLObj,S)};
         else
             B = [B {subsref(MLObj,S)}];
         end
      end
      if prod(size(hndl)) == 1
          B = B{:};
      else
          B = reshape(B,size(hndl));
      end
   end
end % switch



