%OUT_TYPE = DI_FINDTYPEX(IN1_TYPE,IN2_TYPE)
%    Determines the output type that should be used for
%    concatenation between data of types IN1_TYPE and IN2_TYPE.
%
% Note: There is no extended checking. So unknown data types can
% pass unnoticed. This should not be a problem, since this function
% is private.

% (C) Copyright 1999-2002               Pattern Recognition Group
%     All rights reserved               Faculty of Applied Physics
%                                       Delft University of Technology
%                                       Lorentzweg 1
%                                       2628 CJ Delft
%                                       The Netherlands
%
% Cris Luengo, May 2000.
% 24 May 2000: Recovered this code from the old version of FINDTYPE.
% 15 November 2002: Fixed binary images to work in MATLAB 6.5 (R13)

function out_type = di_findtypex(in1_type,in2_type)
if strcmp(in1_type,in2_type)
   % Same type
   out_type = in1_type;
else
   % Different types
   if strcmp(in1_type,'dcomplex') | strcmp(in2_type,'dcomplex')
      out_type = 'dcomplex';
   elseif strcmp(in1_type,'scomplex') | strcmp(in2_type,'scomplex')
      if strcmp(in1_type,'dfloat') | strcmp(in2_type,'dfloat')
         out_type = 'dcomplex';
      else
         out_type = 'scomplex';
      end
   elseif strcmp(in1_type,'dfloat') | strcmp(in2_type,'dfloat')
      out_type = 'dfloat';
   elseif strcmp(in1_type,'sfloat') | strcmp(in2_type,'sfloat')
      out_type = 'sfloat';
   elseif strcmp(in1_type,'bin') & strcmp(in2_type,'bin')
      out_type = 'bin';
   % All that is left now is SINTxx or UINTxx
   elseif strncmp(in1_type,'sint',4) | strncmp(in2_type,'sint',4)
      out_type = 'sint';
   elseif strncmp(in1_type,'uint',4) | strncmp(in2_type,'uint',4)
      out_type = 'uint';
   else
      error('Unkown image types.')
   end
   % In case of sint or uint, what length?
   if strcmp(out_type,'sint') | strcmp(out_type,'uint')
      intlen1 = 8;
      if strncmp(in1_type,'sint',4) | strncmp(in1_type,'uint',4)
         intlen1 = str2num(in1_type(5:end));
      end
      intlen2 = 8;
      if strncmp(in2_type,'sint',4) | strncmp(in2_type,'uint',4)
         intlen2 = str2num(in2_type(5:end));
      end
      out_type = [out_type num2str(max(intlen1,intlen2))];
   end
end
