first_position = 0;
last_position = 0;

first_stack = 1;
last_stack = 40;

color = 1;

read_prefix = 'mov2__ ';

img_width = 500;
img_height = 500;
total_num_slices = 100;

toggler = 0;

% Could replace some of this with TiffStackImport

for position = first_position:last_position
    
    cd(['Position ' num2str(position)])
    
    tiff_stack = Tiff([read_prefix 'Stack ' num2str(first_stack) ' Position ' num2str(position) ' Color ' num2str(color) '.tiff']);
    
    for j =1:total_num_slices
        if toggler ==0;
            if tiff_stack.lastDirectory == 0
                tiff_stack.nextDirectory;
            elseif tiff_stack.lastDirectory ==1
                last_directory = tiff_stack.currentDirectory;
                toggler =1;
            end
        end
    end
    
    stack = zeros(img_height,img_width,last_directory);
    
    for i = first_stack:last_stack
        tiff_stack = Tiff([read_prefix 'Stack ' num2str(i) ' Position ' num2str(position) ' Color ' num2str(color) '.tiff']);
        for j = 1:last_directory
            
            stack(:,:, j) = tiff_stack.read;
            
            if tiff_stack.lastDirectory ~= 1
                tiff_stack.nextDirectory
            end
            
        end
        
        save([num2str(position) '_' num2str(i,'%04d') '.mat'], 'stack')
        
    end
    
    cd ..
end