%% program to create bed level with sloping bed
% uniform over width
% Andries Paarlberg
% 21-11-2017

f_out = '../bed_level_with_bedslope';
btype = 3; % bedleveltype 

%% specify variables
L = 29.7;    % length of domain in m
W = 7;
x0 = 0.3;
y0 = -1;
z0 = -0.39;
ib = 4e-4;

Nx = 99; %
Ny = 8;

dx = L/Nx;
dy = (W-y0)/Ny;

% create matrix with datapoints
% first X-direction
x  = [x0:dx:x0+L]';
z  = interp1([x(1) x(end)],[z0 z0-L*ib],x);
y  = repmat(y0,length(z),1);

% z=hu --> hu is bodemhoogte in u-punt

f_out = [f_out '_bedlevtype' num2str(btype)];

if btype == 1; % bedleveltype
    x = x + dx/2;
    z = z - ib*dx/2 - ib*dx/2;  % correctie voor dx/2 verschuiven naar waterstandspunten en naar tegelaanpak
    % toevoegen eerste gridpunt (voor visualisatie in fm)
    x = [x(1)-dx; x];
    z = [z(1)+ib*dx; z];
    y = [y(1); y];
end

XYZ = [];
% loop over width of channel
for wt = 0:dy:W
    XYZ = [XYZ; x y+wt z];
end
XYZ = sortrows(XYZ,[1 2]);

%%
file_id = fopen([f_out '.xyb'],'w');
for L=1:length(XYZ);
    fprintf(file_id,'%14.5f%14.5f%14.5f\n',XYZ(L,:));
end
fclose(file_id);
