function mg = MGAddLevel(mg,A,M,P,bd)

% Add a level data to the mg data 

% Add a level to the multigrid data struct-----
mg.A = {mg.A{1,1:mg.Levels},A};
if size(M,1) > 0
    mg.M = {mg.M{1,1:mg.Levels},M};
else
    mg.M = {mg.M{1,1:mg.Levels},[]};
end
if nargin == 5
    mg.bd = {mg.bd{1,1:mg.Levels},bd};
end

if mg.Levels == 1
    mg.P = {P};
else
    mg.P = {mg.P{1,1:mg.Levels-1},P};
end

mg.Levels = mg.Levels + 1;
mg.N = [mg.N,size(A,1)];