function out = generate_et_struct(mids,ilength,before,ee,zz)

% This code generates an input data struct suitable for forwardTB.m.
%
% Syntax: out = generate_et_struct(mids,ilength,before,ee,zz)
%
% mids is a vector of the midpoints of interglacials, oldest first
% ilength is length of interglacial
% before is whatever gets pasted on the front (that is, at the beginning
% in a time-runs-forward sense). A special case of this is
% that a scalar here just adds exposure at the beginning of the first
% exposure period. Alternatively, just use a vector of exposure and burial
% durations (not ages). So three 40 ka cycles with 10 ka exposure each
% would look like [10 30 10 30 10 30]. Must be even numel because assumed
% alternating exposure/burial periods. 
% if you don't want this send []. 
% ee is an erosion rate to add to the input struct. 
% zz is cover thickness
%
% 
% Greg Balco -- Berkeley Geochronology Center -- May 2016

if nargin < 5;
    zz = 0;
end;
if nargin < 4;
    ee = 0;
end;
if nargin < 3;
    before = [];
end;

out.tt = [];

% Build vector for defined interglacials

for a = 1:length(mids);
    out.tt(end+1) = mids(a) + ilength./2; % Beginning of interglacial
    out.tt(end+1) = mids(a) - ilength./2; % End of interglacial
end;

% Prepend

if ~isempty(before);
    if length(before) == 1;
        out.tt(1) = out.tt(1) + before;
    else
        to_add = fliplr(cumsum(fliplr(before))) + out.tt(1);
        out.tt = [to_add out.tt];
    end;
end;

out.ee = ee;
out.zz = zz; % leave this for later




