function model = flip_elements(model)
%FLIP_ELEMENTS  Flip elements of a NiHu mesh
%   MESH = FLIP_ELEMENTS(MESH) flips all the elements of a NiHu mesh

%   Copyright 2008-2010 P. Fiala
%   Budapest University of Technology and Economics
%   Dept. of Telecommunications

% Last modified 2012.12.19.

%
types = [12 23 24 34 36 38];

for t = 1 : length(types)
    type = types(t);
    sel = find(model.Elements(:,2) == type);
    if ~isempty(sel)
        ind = 4+(1:mod(type, 10));
        switch type
            case {12 23 24}
                model.Elements(sel,ind) = fliplr(model.Elements(sel,ind));
            case 34
                model.Elements(sel,ind) = model.Elements(sel, ind([1 3 2 4]));
            case 36
                % TODO: check for this type
                model.Elements(sel,ind) = fliplr(model.Elements(sel,4+[4 5 6 1 2 3]));
            case 38
                model.Elements(sel,ind) = fliplr(model.Elements(sel,4+[5 6 7 8 1 2 3 4]));
        end
    end
end
