clc;

Globals1D;

N_fp = 1;
N_faces = 2;
NODETOL = 1e-12;

N_vect = 1:8;
n = length(N_vect);

format_spec = '%0.15f';
for i = 1:n
    N = N_vect(i);
    N_p = N + 1;
    
    % zatim jsou r, s radkove vektory, proto ukladam transpozici
    r = GaussLobattoNodes(N_p);
    filename = sprintf('r_1D_N=%d.txt',N);
    MatrixToTextFile(r',filename,format_spec,' ');
    
    V = VandermondeMatrix1D(N,r); invV = inv(V);
    filename = sprintf('V_1D_N=%d.txt',N);
    MatrixToTextFile(V,filename,format_spec,' ');
    filename = sprintf('invV_1D_N=%d.txt',N);
    MatrixToTextFile(invV,filename,format_spec,' ');
    
    M = invV' * invV; invM = V * V';
    filename = sprintf('M_1D_N=%d.txt',N);
    MatrixToTextFile(M,filename,format_spec,' ');
    filename = sprintf('invM_1D_N=%d.txt',N);
    MatrixToTextFile(invM,filename,format_spec,' ');
    
    V_r = GradVandermondeMatrix1D(N,r);
    filename = sprintf('V_r_1D_N=%d.txt',N);
    MatrixToTextFile(V_r,filename,format_spec,' ');
    
    D_r = DiffMatrix1D(N,r,V);
    filename = sprintf('D_r_1D_N=%d.txt',N);
    MatrixToTextFile(D_r,filename,format_spec,' ');
    
    D_r_weak = (V * V_r') * M;
    filename = sprintf('D_r_weak_2D_N=%d.txt',N);
    MatrixToTextFile(D_r_weak,filename,format_spec,' ');
    
    fmask1 = find(abs(r + 1) < NODETOL); 
    fmask2 = find(abs(r - 1) < NODETOL);
    Fmask = [fmask1; fmask2;]';
    filename = sprintf('Fmask_1D_N=%d.txt',N);
    MatrixToTextFile(Fmask,filename,'%d',' ');

    LIFT = Lift1D();
    filename = sprintf('LIFT_1D_N=%d.txt',N);
    MatrixToTextFile(LIFT,filename,format_spec,' ');
end