%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;
close all;

fprintf(1, '\n\n== start == \n\n');



%%%%%%%%%%%%%%%%%%%%

%for run = ['B', 'D', 'J', 'L', 'S','T' ];
for run = ['L', 'S', 'T' ]
    
    if run=='B'
        data_set     = 'B_frames'
    end
    
    if run=='D'
        data_set     = 'D_frames'
    end
    
    if run=='J'
        data_set     = 'J_frames'
    end
    
    if run=='L'
        data_set     = 'L_frames'
    end
    
    if run=='S'
        data_set     = 'S_frames'
    end
    
    if run=='T'
        data_set     = 'T_frames'
    end
    
   
    
    %%%%%%%%%%%%%%%%%%%%
    
    
    
    input_dir  = [data_set, '/'];
    
    % generate output directory
    output_dir = input_dir;
    
    
    filestub_0 ='f_000';
    filestub_1 ='f_00';
    filestub_2 ='f_0';
    filestub_3 ='f_';
    
    filestub = filestub_0;
    
    num_of_frames = 999;
    
    %%% determine size
    f=1;
    I1=imread([input_dir, filestub, num2str(f) ,'.tif' ]);
    [rows, cols] = size(I1);
    
    %%% skip * show_skip =100 corresponds to 5 times slow down for 500fps data
    %short
    start = num_of_frames -15*15;
    skip = 2;
    show_fps =10;
    
    %%%% long
    %start = 1;
    %skip = 1;
    %show_fps =15;
    
    %name of avi-file
    mov = avifile([run,'.avi'], 'fps', show_fps);
    
    for f = start: skip : num_of_frames
        
        if f>= 10^1
            filestub = filestub_1;
        end
        
        if f>= 10^2
            filestub = filestub_2;
        end
        
        if f>= 10^3
            filestub = filestub_3;
        end
        
        if mod(f,50) ==0
            fprintf('\n load frame = %d', f);
        end
        
        
        I = imread([input_dir, filestub, num2str(f) ,'.tif' ]);
        
        
        imshow(I,'InitialMagnification', 'fit');
        axis off;
        %title(f);
        
        %F(f) = getframe(gca);
        %mov = addframe(mov, F(f));
        mov = addframe(mov, I );
    end
    
    mov=close(mov);
    
end

fprintf('\n\n === done === \n\n');

clear all;




