%Agglomerates postprocessed channel width measurements from multiple
%transects.
%Required inputs: iss_for_display (interpolated stratigraphic surface for
%display).

for trs = 1:3 %ts = transect
load(strcat('outputWidthMeasurementsMarsRivers_Transect_',num2str(trs)))
    w(trs).s = s(11); %l for w, i.e. width
    w(trs).t = t; %w aggregated using tie numbers
    
    %Needed: replace fixed interp rms errors with dynamically loaded errors
%(using ArcGIS-output .TXT files).
for n = 1:length(w(trs).t)
if trs == 1 %interpolation rms error
    w(trs).t(n).interp_rms_error = [20.221 17.523 0 0 0]; %(using ArcGIS-output .TXT files).
elseif trs == 2
    w(trs).t(n).interp_rms_error = [4.848 3.978 0 0 0]; %(using ArcGIS-output .TXT files).
elseif trs == 3
    w(trs).t(n).interp_rms_error = [50 50 0 0 0];
end
end

for n = 1:length(w(trs).s.cx)
if trs == 1 %interpolation rms error
    w(trs).s.interp_rms_error = repmat([20.221 17.523 0 0 0],length(w(trs).s.cx),1); %(using ArcGIS-output .TXT files).
elseif trs == 2
    w(trs).s.interp_rms_error = repmat([4.848 3.978 0 0 0],length(w(trs).s.cx),1); %(using ArcGIS-output .TXT files).
elseif trs == 3
    w(trs).s.interp_rms_error = repmat([50 50 0 0 0],length(w(trs).s.cx),1);
end

end
disp('Warning: Overriding interp rms with hand coded rms values from rms_data.txt files!')

    
end

for trs = 1:3
    for irhm = 1:length(w(trs).s.cx)
        for iss = 1:5
                w(trs).czadjusted(irhm,iss) = w(trs).s.czs(irhm,iss);
        end
    end
end

for trs = 1:3 %Assign transect numbers (for plotting)
    for itrs = 1:length(w(trs).s.cx)
        w(trs).s.trs(itrs) = trs;
        w(trs).s.dtm(itrs) = trs+1;
        if trs == 1 & w(trs).s.cx(itrs) < 9e3; %Transect 1 consists of 2 DTMs 
            w(trs).s.dtm(itrs) = 1;
        end
    end
    
    for itrs = 1:length(w(trs).t)
        w(trs).t(itrs).trs = trs;
        w(trs).t(itrs).dtm = trs+1;
        if trs == 1 & w(trs).t(itrs).cx < 9e3; %Transect 1 consists of 2 DTMs 
            w(trs).t(itrs).dtm = 1;
        end
    end
end

    wall   = [w(1).t w(2).t w(3).t]; %All widths (collated using TieNumber)
    
    mynames=fieldnames(w(1).s);
    for i = 1:length(mynames)
      if min(size(w(1).s.(mynames{i})'))==1
          wallbp.(mynames{i})=[w(1).s.(mynames{i})'; w(2).s.(mynames{i})'; w(3).s.(mynames{i})'];
      else
          wallbp.(mynames{i})=[w(1).s.(mynames{i})', w(2).s.(mynames{i})', w(3).s.(mynames{i})']';
      end
    end
    
    
    for m = 1:length(wall)
        stratz(m) = [wall(m).czs(iss_for_display)];    
        wall(m).zs_for_display = wall(m).czs(iss_for_display);
        wall(m).zserr_for_display = wall(m).interp_rms_error(iss_for_display);
    end
    
    for m = 1:length(wallbp.cx)
        stratzbp(m) = [wallbp.czs(m,iss_for_display)];    
        wallbp.zs_for_display(m) =    wallbp.czs(m,iss_for_display);
        wallbp.zserr_for_display(m) = wallbp.interp_rms_error(m,iss_for_display);
    end

    disp('Loading of postprocessed channel width measurements is complete.')
clear irhm iss itrs m trs