%% generate_pvs_horizontal
%   generate the pvs code for a condition in the horizontal(top)
%   grid, done in seperate function because it will get called
%   multiple times for the same condition in a 2d table.
% inputs:
%   object:PVS_checker - PVS_checker object
%   g1:Grid - left grid
%   g2:Grid - top grid
%   depth:int - number representing depth inside the table
% outputs:
%   code:string - pvs code
%
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function code = generate_pvs_horizontal(object,g1,g2_cell,depth)

code = [];

code = [code sprintf('COND\n')];
elsecell = [];
for i=1:size(g1.cells,2)
    g1cond = g1.cells(i).cond_text;
    % condition string of otherwise corresponds to an else
    % statement, we allow this statement to be in any order
    % in the cells of the grid, so we need to find where it
    % is, if it exists.
    if (strcmp(g1cond,'otherwise'))
        elsecell = g1.cells(i);
        found = 1;
        continue
    end
    code = [code sprintf('%s->',object.matlab_to_pvs_syntax_translation(strtrim(char(g1.cells(i).cond_text))))];
    resultcell = object.data.Grid0.search_return(g1.cells(i),g2_cell);
    if(~isempty(resultcell))
        code = [code object.matlab_to_pvs_syntax_translation(strtrim(char(resultcell.result_text)))];
        
        if(isempty(elsecell))
            if(i~= size(g1.cells,2))
                code = [code sprintf(',\n')];
            else
                code = [code sprintf('\n')];
            end
        else
            code = [code sprintf(',\n')];
        end
    else
    end
end
if(~isempty(elsecell))
    resultcell = object.data.Grid0.search_return(elsecell,g2_cell);
    code = [code sprintf('ELSE->%s\n',object.matlab_to_pvs_syntax_translation(strtrim(char(resultcell.result_text))))];
    
end
code = [code sprintf('ENDCOND')];




end

