function [ skel, MotionEXP ] = ConvertEUCH2EXP( MotionEU,skelEU, skeltype )
%CONVERTBVH2EXP Reads a BVH file and stores it into skel and exp map matrix
%   Detailed explanation goes here

skel_temp = skelEU;

if nargin > 1
    skel_temp.type = skeltype;
end







for mm = 1:length(MotionEU)
    
    disp(['Processing Motion #',num2str(mm)]);
    
    M_temp = MotionEU{mm};
    
    for ii = 2:size(skel_temp.tree,2)
        M_temp(:,skel_temp.tree(ii).posInd) = 0;
        %skel_temp.tree(ii).posInd = [];
    end
    
    clear M M_e;
    
    % Convert them into exp maps
    lastM = []; %%% THIS DOES NOT WORK FOR THE FIRST FRAME!!!
    for ii=1:size(M_temp,1)
        [skel_e,M_e(ii,:)] = bvh2expmap_skipbad(skel_temp,M_temp(ii,:), lastM, ii);
        lastM = M_e(ii,:);
    end
    
    skel = skel_e;
    
    fixind = 1;
    
    if fixind==0
        
        
        
        M = M_e;
        for ii=1:length(skel.tree)
            %skel.tree(ii).expmapInd = skel.tree(ii).rotInd;
            %skel.tree(ii).order = 'zyx';
        end
        
        
        % zxy
    else
        %fixind
        counter = 4;
        %new skel
        
        %root
        j = 1;
        %skel.tree(j).rotInd = [counter+2 counter+1 counter];
        %skel.tree(j).expmapInd = [counter+2 counter+1 counter];
        skel.tree(j).channels = [{'Xposition'},{'Yposition'},{'Zposition'},{'Zrotation'},{'Yrotation'},{'Xrotation'}];
        skel.tree(j).order = 'zyx';
        counter = counter + 6;
        %the rest
        for j=2:size(skel.tree,2)
            if ~isempty(skel_e.tree(j).rotInd)
                %skel.tree(j).rotInd = [counter+2 counter+1 counter];
                %skel.tree(j).expmapInd = [counter+2 counter+1 counter];
                % skel.tree(j).channels = [{'Zrotation'},{'Yrotation'},{'Xrotation'}];
                skel.tree(j).channels = [{'Xposition'},{'Yposition'},{'Zposition'},{'Zrotation'},{'Yrotation'},{'Xrotation'}];
                skel.tree(j).order = 'zyx';
                counter = counter + 6;
            end
        end
        
        
        
        % new channels
        M(:,1:6) = M_e(:,1:6);
        for i=10:6:size(M_e,2)
            M(:,i) = M_e(:,i);
            M(:,i+1) = M_e(:,i+1);
            M(:,i+2) = M_e(:,i+2);
            
            M(:,i-1) = 0;%M_e(:,i-1);
            M(:,i-2) = 0;%M_e(:,i-2);
            M(:,i-3) = 0;%M_e(:,i-3);
        end
        
        %M = M_e;
    end
    MotionEXP{mm} = M;
end

end

