% Extract the channel elevations from each cross-section and find the
% lowest point to use for base elevations

clear

%% Load observation IDs and assign file to extract data

load('obs_rcl_ids.mat');
load('obs_xs_ids.mat');

fname = ['/Users/Colin/Documents/MATLAB/DFlow/abq_models/'...
    'abq2010add2012bath/run3051_30cmsdist/'...
    'abq10a12bf30cmsdistrst01_0000_20160104_090000_his.nc'];

%% Extract lowest elevation in channel

% Extract WSE and depth from output
obs_wse_all = ncread(fname,'waterlevel');
obs_depth_all = ncread(fname,'Waterdepth');

obs_wse = obs_wse_all(:,end);
obs_depth = obs_depth_all(:,end);

% Number of cross-sections
max_xs_id = max(obs_xs_ids);
minimum_z = zeros(max_xs_id,1);

for i = 1:max_xs_id
    
    wse_i = obs_wse(obs_xs_ids==i&obs_rcl_ids==2,1);
    depth_i = obs_depth(obs_xs_ids==i&obs_rcl_ids==2,1);
    
    num_i = numel(wse_i(:,1));
    
    bottom_z = wse_i(:,1) - depth_i(:,1);
    
    minimum_z(i,1) = min(bottom_z);
    
end

plot(1:max_xs_id,minimum_z);
        