function varargout = mswdecfunc(option,dec,varargin)
%MSWDECFUNC Multisignal 1-D utilities functions.

%   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 17-Mar-2006.
%   Copyright 1995-2020 The MathWorks, Inc.

%#codegen

dirCAT = 1;
if strcmp(dec.dirDec,'r')
    dirCAT = 2;
elseif strcmp(dec.dirDec,'c')
    dirCAT = 1;
end

if strcmp(option,'dircat')
    if dirCAT == 1
        varargout = {1};
    else
        varargout = {2};
    end
elseif strcmp(option,'flip')||strcmp(option,'transpose')
    if strcmp(dec.dirDec,'r')
        dec.dirDec = 'c';
    else
        dec.dirDec = 'r';
    end
    dec.dataSize = fliplr(dec.dataSize);
    dec.ca = dec.ca';
    for k = 1:dec.level
        dec.cd{k} = dec.cd{k}';
    end
    varargout = {dec,dirCAT};
elseif strcmp(option,'longs')||strcmp(option,'decSizes')
    level = dec.level;
    decSizes = zeros(level+2,2);
    decSizes(end,:) = dec.dataSize;
    temp_cd = dec.cd;
    for j = 1:level
        temp = temp_cd{j};
        decSizes(end-j,:) = size(temp);
    end
    decSizes(1,:) = size(dec.ca);
    
    if ~isempty(varargin)
        decSizes = flipud(decSizes);
    end
    
    if strcmp(option,'decSizes')
        varargout = {decSizes,dirCAT};
    else
        longs = decSizes(:,dirCAT);
        if isequal(dec.dirDec,'r')
            longs = longs';
        end
        varargout = {longs,dirCAT};
    end
end
