% Calculate TSE for all test sequences and write results intos a file 
% Open output file to write TSE values
fid = fopen('TE_packet_exp_3_4.dat','wt');
if (fid == -1)
   error('The output file could not be opened.');
end
fprintf(fid, '%d\n', 7); % number of groups
 


% Output TSE for video v10
fprintf(fid, '%s\n', 'v10');
fprintf(fid, '%d\n', 11);

% Video v10 
tse(1) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v10_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v10_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v10_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v10_1280x720_I4.yuv','blkblr_v10_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v10_I4_17','\t%e',tse(11));
v10_tse=tse;


% Output TSE for video v11
fprintf(fid, '%s\n', 'v11');
fprintf(fid, '%d\n', 11);

% Video v11 
tse(1) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v11_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v11_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v11_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v11_1280x720_I4.yuv','blkblr_v11_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v11_I4_17','\t%e',tse(11));
v11_tse=tse;


% Output TSE for video v12
fprintf(fid, '%s\n', 'v12');
fprintf(fid, '%d\n', 11);

% Video v12 
tse(1) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v12_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v12_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v12_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v12_1280x720_I4.yuv','blkblr_v12_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v12_I4_17','\t%e',tse(11));
v12_tse=tse;

% Output TSE for video v1
fprintf(fid, '%s\n', 'v1');
fprintf(fid, '%d\n', 11);

% Video v1 
tse(1) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v1_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v1_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v1_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v1_1280x720_I4.yuv','blkblr_v1_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v1_I4_17','\t%e',tse(11));
v1_tse=tse;

% Output TSE for video v7
fprintf(fid, '%s\n', 'v7');
fprintf(fid, '%d\n', 11);

tse(1) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v7_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v7_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v7_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v7_1280x720_I4.yuv','blkblr_v7_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v7_I4_17','\t%e',tse(11));
v7_tse=tse;

% Output TSE for video v8
fprintf(fid, '%s\n', 'v8');
fprintf(fid, '%d\n', 11);

% Video v8 
tse(1) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v8_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v8_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v8_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v8_1280x720_I4.yuv','blkblr_v8_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v8_I4_17','\t%e',tse(11));
v8_tse=tse;


% Output TSE for video v9
fprintf(fid, '%s\n', 'v9');
fprintf(fid, '%d\n', 11);

% Video v9 
tse(1) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_0.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_0','\t%e',tse(1));
tse(2) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_2.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_2','\t%e',tse(2));
tse(3) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_3.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v9_I4_3','\t%e',tse(3));
tse(4) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_8.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_8','\t%e',tse(4));
tse(5) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_10.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_10','\t%e',tse(5));
tse(6) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_11.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_11','\t%e',tse(6));
tse(7) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_12.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_12','\t%e',tse(7));
tse(8) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_14.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v9_I4_14','\t%e',tse(8));
tse(9) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_15.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_15','\t%e',tse(9));
tse(10) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_16.yuv',1280,720,'420','y'); 
lineWrite(fid,'blkblr_v9_I4_16','\t%e',tse(10));
tse(11) = tseYUVvideo('v9_1280x720_I4.yuv','blkblr_v9_1280x720_I4_17.yuv',1280,720,'420','y');
lineWrite(fid,'blkblr_v9_I4_17','\t%e',tse(11));
v9_tse=tse;

save tse_videos_exp_3_4;
fclose(fid)

