% Copyright (C) 2016 by Deanna Needell, Rayan Saab, and Tina Woolf

% This file is part of ''Weighted L1-Minimization for Sparse Recovery under
%                        Arbitrary Prior Information''

% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.

% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.

% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

% rebuildFrame.m

function [ YQrec_L1, YQrec_WL1, YQrec_WL1M ] = rebuildFrame( blk_num, ifrm, im, vW, WL1_opts, WL1M_opts, YQprec_L1, YQrec_L1, YQprec_WL1, YQrec_WL1, YQprec_WL1M, YQrec_WL1M )
% Inputs: 
% blk_num     = number of blocks
% ifrm        = frame number
% im          = measurement number index
% vW          = array of constant weights used in weighted L1 with a single weight
% WL1_opts    = array of options being run for weighted L1 with a single weight
% WL1M_opts   = array of options being run for weighted L1 with multi-weights
% YQprec_L1   = recovered blocks with L1
% YQrec_L1    = recovered frames with L1
% YQprec_WL1  = recovered blocks with WL1
% YQrec_WL1   = recovered frames with WL1
% YQprec_WL1M = recovered blocks with WL1M
% YQrec_WL1M  = recovered frames with WL1M
%
% Outputs:
% YQrec_L1   = recovered frames with L1, updated to include frame ifrm
% YQrec_WL1  = recovered frames with WL1, updated to include frame ifrm
% YQrec_WL1M = recovered frames with WL1M, updated to include frame ifrm


if blk_num ==1
    
    YQrec_L1{ifrm}{im} = YQprec_L1{ifrm}{im}{1};
    for iw = 1:length(vW)
        for iwo = 1:length(WL1_opts)
            YQrec_WL1{ifrm}{im}{iw}{iwo} = YQprec_WL1{ifrm}{im}{1}{iw}{iwo};
        end
    end
    for iwo = 1:length(WL1M_opts)
        YQrec_WL1M{ifrm}{im}{iwo} = YQprec_WL1M{ifrm}{im}{1}{iwo};
    end
    
elseif blk_num == 4
    
    YQrec_L1{ifrm}{im} = [YQprec_L1{ifrm}{im}{1} YQprec_L1{ifrm}{im}{2}; YQprec_L1{ifrm}{im}{3} YQprec_L1{ifrm}{im}{4}];
    for iw = 1:length(vW)
        for iwo = 1:length(WL1_opts)
            YQrec_WL1{ifrm}{im}{iw}{iwo} = [YQprec_WL1{ifrm}{im}{1}{iw}{iwo} YQprec_WL1{ifrm}{im}{2}{iw}{iwo}; YQprec_WL1{ifrm}{im}{3}{iw}{iwo} YQprec_WL1{ifrm}{im}{4}{iw}{iwo}];               
        end
    end
    for iwo = 1:length(WL1M_opts)
        YQrec_WL1M{ifrm}{im}{iwo} = [YQprec_WL1M{ifrm}{im}{1}{iwo} YQprec_WL1M{ifrm}{im}{2}{iwo}; YQprec_WL1M{ifrm}{im}{3}{iwo} YQprec_WL1M{ifrm}{im}{4}{iwo}];               
    end
    
elseif blk_num == 8
    
    YQrec_L1{ifrm}{im} = [YQprec_L1{ifrm}{im}{1} YQprec_L1{ifrm}{im}{2} YQprec_L1{ifrm}{im}{3} YQprec_L1{ifrm}{im}{4}; YQprec_L1{ifrm}{im}{5} YQprec_L1{ifrm}{im}{6} YQprec_L1{ifrm}{im}{7} YQprec_L1{ifrm}{im}{8}];
    for iw = 1:length(vW)
        for iwo = 1:length(WL1_opts)
            YQrec_WL1{ifrm}{im}{iw}{iwo} = [YQprec_WL1{ifrm}{im}{1}{iw}{iwo} YQprec_WL1{ifrm}{im}{2}{iw}{iwo} YQprec_WL1{ifrm}{im}{3}{iw}{iwo} YQprec_WL1{ifrm}{im}{4}{iw}{iwo}; YQprec_WL1{ifrm}{im}{5}{iw}{iwo} YQprec_WL1{ifrm}{im}{6}{iw}{iwo} YQprec_WL1{ifrm}{im}{7}{iw}{iwo} YQprec_WL1{ifrm}{im}{8}{iw}{iwo}];   
        end
    end
    for iwo = 1:length(WL1M_opts)
        YQrec_WL1M{ifrm}{im}{iwo} = [YQprec_WL1M{ifrm}{im}{1}{iwo} YQprec_WL1M{ifrm}{im}{2}{iwo} YQprec_WL1M{ifrm}{im}{3}{iwo} YQprec_WL1M{ifrm}{im}{4}{iwo}; YQprec_WL1M{ifrm}{im}{5}{iwo} YQprec_WL1M{ifrm}{im}{6}{iwo} YQprec_WL1M{ifrm}{im}{7}{iwo} YQprec_WL1M{ifrm}{im}{8}{iwo}];    
    end
    
end


end

