% format all results
clear 

%sphnam='STD'
%sphnam='SELE_FD'
%sphnam='SELE_GAP'
%sphnam='EDF'


dres=zeros(13,5,2,2,4);
%if strcmp(sphnam,'STD')
% load 'dres_all_new_STD.txt' dres
 load 'dres_all_newsph2_STD.txt' dres
% load 'dres_all_nwsph_STD.txt' dres
% load 'dres_all_nwsphBK_STD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), STD option in SPH: module}\\label{tabResSTDnew} \n']
 dres1=dres;
%elseif strcmp(sphnam,'SELE_FD')
% load 'dres_all_new_SELE_FD.txt' dres
 load 'dres_all_newsph2_SELE_FD.txt' dres
% load 'dres_all_nwsph_SELE_FD.txt' dres
% load 'dres_all_nwsphBK_SELE_FD.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_FD option in SPH: module}\\label{tabResSELE_FDnew} \n']
 dres2=dres;
%elseif strcmp(sphnam,'SELE_GAP')
% load 'dres_all_new_SELE_GAP.txt' dres
 load 'dres_all_newsph2_SELE_MWG.txt' dres
% load 'dres_all_nwsph_SELE_MWG.txt' dres
% load 'dres_all_nwsphBK_SELE_MWG.txt' dres
% load 'dres_all_newsph2t_SELE_MWG.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), SELE\\_MWG option in SPH: module}\\label{tabResSELE_GAPnew} \n']
 dres3=dres;
%elseif strcmp(sphnam,'EDF')
% load 'dres_all_new_EDF.txt' dres
 load 'dres_all_newsph2_SELE_EDF.txt' dres
% load 'dres_all_nwsph_SELE_EDF.txt' dres
% load 'dres_all_nwsphBK_SELE_EDF.txt' dres
% load 'dres_all_newsph2t_SELE_MWG.txt' dres
% captionA=['\\caption{Relative error between reconstruction and transport calculations (\\%%), EDF option in SPH: module}\\label{tabResEDFnew} \n']
 dres4=dres;
 %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) '_newsph2_all.tex']
%resname=['resalltabs' num2str(isp) '_nwsph_allBK0.tex']
%resname=['resalltabs' num2str(isp) 'SELgauss_all.tex']
fresul=fopen(resname,'w')
captionA=['\\caption{Range of relative error $\\delta$ between reconstruction and transport calculations for all options, ' fcmesh ' mesh (\\%%)}\\label{' resname '} \n']

fprintf(fresul,'\\begin{table}[htbp] \\begin{center} \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 ',' ');
elseif (isp==2)
fprintf(fresul,'& & \\multicolumn{4}{c||}{   }& \\multicolumn{4}{c||}{8x8*} & \\multicolumn{4}{c||}{8x8*} & \\multicolumn{4}{c||}{8x8} \\\\ \n ',' ');
end
%fprintf(fresul,'& & \\multicolumn{4}{c||}{''EDF''}& \\multicolumn{4}{c||}{''SELE\\_MWG''} & \\multicolumn{4}{c||}{''EDF''} & \\multicolumn{4}{c||}{''SELE\\_FD''} & \\multicolumn{4}{c||}{''SELE\\_FD''} \\\\   \n',' ');
fprintf(fresul,'& & \\rotatebox{90}{STD} & \\rotatebox{90}{SELE\\_FD} & \\rotatebox{90}{SELE\\_MWG} & \\rotatebox{90}{SELE\\_EDF} & \\rotatebox{90}{STD} & \\rotatebox{90}{SELE\\_FD} & \\rotatebox{90}{SELE\\_MWG} & \\rotatebox{90}{SELE\\_EDF}& \\rotatebox{90}{STD} & \\rotatebox{90}{SELE\\_FD} & \\rotatebox{90}{SELE\\_MWG} & \\rotatebox{90}{SELE\\_EDF}& \\rotatebox{90}{STD} & \\rotatebox{90}{SELE\\_FD} & \\rotatebox{90}{SELE\\_MWG} & \\rotatebox{90}{SELE\\_EDF}  \\\\ \\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(dres1(icase,ihet2,isp,rt-1,2)-dres1(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihet2,isp,rt-1,2)-dres2(icase,ihet2,isp,rt-1,1),'%6.2f')  '&' num2str(dres3(icase,ihet2,isp,rt-1,2)-dres3(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihet2,isp,rt-1,2)-dres4(icase,ihet2,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres1(icase,ihet,isp,rt-1,2)-dres1(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihet,isp,rt-1,2)-dres2(icase,ihet,isp,rt-1,1),'%6.2f')  '&' num2str(dres3(icase,ihet,isp,rt-1,2)-dres3(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihet,isp,rt-1,2)-dres4(icase,ihet,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres1(icase,ihom,isp,rt-1,2)-dres1(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihom,isp,rt-1,2)-dres2(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres3(icase,ihom,isp,rt-1,2)-dres3(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihom,isp,rt-1,2)-dres4(icase,ihom,isp,rt-1,1),'%6.2f')   '\\\\ \n'];
else
row=[' &DUAL 2 3 &'       num2str(dres1(icase,ipin,1,rt-1,2)-dres1(icase,ipin,1,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ipin,1,rt-1,2)-dres2(icase,ipin,1,rt-1,1),'%6.2f')  '&' num2str(dres3(icase,ipin,1,rt-1,2)-dres3(icase,ipin,1,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ipin,1,rt-1,2)-dres4(icase,ipin,1,rt-1,1),'%6.2f') '&' ...
      num2str(dres1(icase,ihet2,isp,rt-1,2)-dres1(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihet2,isp,rt-1,2)-dres2(icase,ihet2,isp,rt-1,1),'%6.2f')  '&' num2str(dres3(icase,ihet2,isp,rt-1,2)-dres3(icase,ihet2,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihet2,isp,rt-1,2)-dres4(icase,ihet2,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres1(icase,ihet,isp,rt-1,2)-dres1(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihet,isp,rt-1,2)-dres2(icase,ihet,isp,rt-1,1),'%6.2f')  '&' num2str(dres3(icase,ihet,isp,rt-1,2)-dres3(icase,ihet,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihet,isp,rt-1,2)-dres4(icase,ihet,isp,rt-1,1),'%6.2f') '&' ...
      num2str(dres1(icase,ihom,isp,rt-1,2)-dres1(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres2(icase,ihom,isp,rt-1,2)-dres2(icase,ihom,isp,rt-1,1),'%6.2f') '&'  num2str(dres3(icase,ihom,isp,rt-1,2)-dres3(icase,ihom,isp,rt-1,1),'%6.2f') '&' num2str(dres4(icase,ihom,isp,rt-1,2)-dres4(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 when SELE\\_MWG or EDF option are chosen. \n ');
%end
fprintf(fresul,'\\end{small} \n',' ');
 %fprintf(fresul,'\\end{tiny} \n',' ');
fprintf(fresul,'\\end{center} \\end{table} \n\n');
fclose(fresul)


end %isp loop

