% format all results
clear 

%sphnam='STD'
%sphnam='SELE_FD'
%sphnam='SELE_MWG'
sphnam='SELE_EDF'
%sphnam='SELE_GAP'
%sphnam='EDF2'


%dres=zeros(13,5,2,2,4);
if strcmp(sphnam,'STD')
 sphnamt='STD';
% load 'dres_all_new_STD.txt' dres
 load 'dres_all_nwsphABK_STD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), STD option in SPH: module}\\label{tabResSTDnew} \n']
elseif strcmp(sphnam,'SELE_FD')
 sphnamt='SELE\\_FD';
% load 'dres_all_new_SELE_FD.txt' dres
 load 'dres_all_nwsphABK_SELE_FD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_FD option in SPH: module}\\label{tabResSELE_FDnew} \n']
elseif strcmp(sphnam,'SELE_MWG')
 sphnamt='SELE\\_MWG';
 load 'dres_all_nwsphABK_SELE_MWG.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_GAP option in SPH: module}\\label{tabResSELE_GAPnew} \n']
elseif strcmp(sphnam,'SELE_EDF')
 sphnamt='SELE\\_EDF';
 load 'dres_all_nwsphABK_SELE_EDF.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_GAP option in SPH: module}\\label{tabResSELE_GAPnew} \n']
%elseif strcmp(sphnam,'SELE_GAP')
% load 'dres_all_new_SELE_GAP.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_GAP option in SPH: module}\\label{tabResSELE_GAPnew} \n']
%elseif strcmp(sphnam,'EDF')
% load 'dres_all_new_EDF.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), EDF option in SPH: module}\\label{tabResEDFnew} \n']
%elseif strcmp(sphnam,'STD2')
% load 'dres_all_new2_STD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), STD option in SPH: module}\\label{tabResSTDnew} \n']
%elseif strcmp(sphnam,'SELE_FD2')
% load 'dres_all_new2_SELE_FD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_FD option in SPH: module}\\label{tabResSELE_FDnew} \n']
%elseif strcmp(sphnam,'SELE_GAP2')
% load 'dres_all_new2_SELE_GAP.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_GAP option in SPH: module}\\label{tabResSELE_GAPnew} \n']
%elseif strcmp(sphnam,'EDF2')
% load 'dres_all_new2_EDF.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), EDF option in SPH: module}\\label{tabResEDFnew} \n']
end

ihet=1;
ihet2=2;
ihom=5;
ipin=4;

for isp=1:2;

if (isp==1)
  fcmesh='coarse';
else
  fcmesh='fine';
end


resname=['resalltabs' num2str(isp) '_nwA_' sphnam '.tex']
%resname=['resalltabs' num2str(isp) 'SELgauss_all.tex']
fresul=fopen(resname,'w')
%captionA=['\\caption{Relative error between reconstruction and transport calculations, Interpolated flux for core}\\label{tabResSELgauss} \n']

fprintf(fresul,'\\begin{table}[htbp] \\begin{center} \n',' ');
captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), ' fcmesh ' mesh, ' sphnamt ' option in SPH: module}\\label{' resname '} \n']
fprintf(fresul,captionA);
fprintf(fresul,'\\begin{small} \n',' ');
%fprintf(fresul,'\\begin{tiny} \n',' ');
fprintf(fresul,'\\vspace{0.5cm} \n');
fprintf(fresul,'\\begin{tabular}{||m{0.05\\textwidth}c||*{4}{m{0.05\\textwidth}}||*{4}{m{0.05\\textwidth}}||*{4}{m{0.05\\textwidth}}||*{4}{m{0.05\\textwidth}}||} \n\\hline \n',' ');
fprintf(fresul,'& & \\multicolumn{4}{c||}{Pin by Pin }& \\multicolumn{4}{c||}{Heterogeneous (het2)} & \\multicolumn{4}{c||}{Heterogeneous (het1)} & \\multicolumn{4}{c||}{Homogeneous} \\\\  \n',' ');

if (isp==1)
fprintf(fresul,'& & \\multicolumn{4}{c||}{   }& \\multicolumn{4}{c||}{4x4*} & \\multicolumn{4}{c||}{4x4*} & \\multicolumn{4}{c||}{4x4} \\\\ \n \n',' ');
elseif (isp==2)
fprintf(fresul,'& & \\multicolumn{4}{c||}{   }& \\multicolumn{4}{c||}{8x8*} & \\multicolumn{4}{c||}{8x8*} & \\multicolumn{4}{c||}{8x8} \\\\ \n \n',' ');
end
%fprintf(fresul,'& & \\multicolumn{4}{c||}{''EDF''}& \\multicolumn{4}{c||}{''SELE\\_GAP''} & \\multicolumn{4}{c||}{''EDF''} & \\multicolumn{4}{c||}{''SELE\\_FD''} & \\multicolumn{4}{c||}{''SELE\\_FD''} \\\\   \n',' ');
fprintf(fresul,'& & min & max & rms & $\\delta$ & min & max & rms & $\\delta$  &min & max & rms & $\\delta$  &min & max & rms & $\\delta$  \\\\ \\hline  \n',' ');
%for icasep=0:0
%icase=13;
for icase=1:12
icasep=icase;
for rt=2:3
if (rt==3) 
row=[' \\multirow{-2}{*}{C' num2str(icasep) '}& DUAL 3 3 & - & - & - & - &' ...
      num2str(dres(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihet2,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihet2,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihet2,isp,rt-1,2)-dres(icase,ihet2,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihet,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihet,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihet,isp,rt-1,2)-dres(icase,ihet,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihom,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihom,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihom,isp,rt-1,2)-dres(icase,ihom,isp,rt-1,1),'%6.2f')  '\\\\ \n'];
else
row=[' &DUAL 2 3 &' num2str(dres(icase,ipin,1,rt-1,1),'%6.2f') '&' num2str(dres(icase,ipin,1,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ipin,1,rt-1,3),'%6.2f') '&' num2str(dres(icase,ipin,1,rt-1,2)-dres(icase,ipin,1,rt-1,1),'%6.2f') '&' ...
      num2str(dres(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihet2,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihet2,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihet2,isp,rt-1,2)-dres(icase,ihet2,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihet,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihet,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihet,isp,rt-1,2)-dres(icase,ihet,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres(icase,ihom,isp,rt-1,2),'%6.2f')  '&' num2str(dres(icase,ihom,isp,rt-1,3),'%6.2f') '&' num2str(dres(icase,ihom,isp,rt-1,2)-dres(icase,ihom,isp,rt-1,1),'%6.2f')  '\\\\ \n'];
end
fprintf(fresul,row);

end
fprintf(fresul,'\\hline \n');
end
fprintf(fresul,'\\hline \n');


fprintf(fresul,'\\end{tabular} \n');
%if (strcmp(sphnam,'SELE_GAP') | strcmp(sphnam,'EDF'))
% fprintf(fresul,'Homogeneous calculations performed with the ''SELE\\_FD'' option in SPH: module  \n ');
%end
fprintf(fresul,'\\end{small} \n',' ');
%fprintf(fresul,'\\end{tiny} \n',' ');
fprintf(fresul,'\\end{center} \\end{table} \n\n');
fclose(fresul)


end