function [dataPath, logPath] = sd_practice_block(cfg,Gparams)

log = [];
log.cfg = cfg;

% Set up data and log paths
dataPath = [Gparams.DataPath, 'data_S', num2str(Gparams.subject_number),'_sd_practice_block_', num2str(cfg.curBlock)];
while(exist([dataPath, '.mat'], 'file'))
    dataPath = [dataPath, '_1'];
end
dataPath = [dataPath, '.mat'];

logPath = [Gparams.LogPath, 'log_S', num2str(Gparams.subject_number),'_sd_practice_block_', num2str(cfg.curBlock)];
while(exist([logPath, '.mat'], 'file'))
    logPath = [logPath, '_1'];
end
logPath = [logPath, '.mat'];

% Create a trial sequence
trials              = cfg.trials;
orientation_base    = Gparams.stim.sd_orientation;

h_location          = [zeros(1,trials+1)];
orientation         = [-orientation_base*ones(1,trials/4), ...
                       zeros(1,trials/2+1), ...
                       orientation_base*ones(1,trials/4)];
button_mapping      = [ones(1,trials/8), 2*ones(1,trials/8), ...
                       ones(1,trials/4), 2*ones(1,trials/4), round(rand)+1, ...
                       ones(1,trials/8), 2*ones(1,trials/8)];

% join the parts of the matrix
% 1st row: horizontal location 
% 2nd row: orientation of stimulus
% 3rd row: button mapping
trialmatrix            = [h_location; orientation; button_mapping];

% Randomize trial order
trialmatrix = trialmatrix(:,randperm(size(trialmatrix,2)));

% log the trial matrix
log.trialmatrix = trialmatrix;

data            = cell(size(trialmatrix,2), 1);
log.trialinfo   = cell(size(trialmatrix,2), 1);
log.trialoutput = cell(size(trialmatrix,2), 1);

save(logPath, 'log');

% Show fixation screen before first trial
Screen('DrawDots', Gparams.pWindow, [(Gparams.ScreenResX - 1)/2, (Gparams.ScreenResY-1)/2], Gparams.FixDotSize, 255, [], 1);
time = Screen('Flip', Gparams.pWindow);
WaitSecs('UntilTime', time + 2);


% loop over trials
for iTrial = 1:size(trialmatrix,2)

    funcfg                                  = [];
    funcfg.h_location                       = trialmatrix(1,iTrial);
    funcfg.stimulus_orientation             = trialmatrix(2,iTrial);
    funcfg.button_mapping                   = trialmatrix(3,iTrial);

    % save information about trial in log structure
    log.trialinfo{iTrial} = [ ...
        funcfg.h_location,...
        funcfg.stimulus_orientation];

    log.trialoutput{iTrial} = sd_practice_trial(funcfg, Gparams);

    data{iTrial} = [ ...
        Gparams.subject_number, ...
        cfg.curBlock, ...
        iTrial, ...
        funcfg.h_location,... % location of the stimulus
        funcfg.stimulus_orientation,... % orientation of the stimulus
        funcfg.button_mapping,... % button mapping 
        log.trialoutput{iTrial}.afc_response.button, ...
        log.trialoutput{iTrial}.afc_response.decision, ...
        log.trialoutput{iTrial}.afc_response.rt];


    % save data
    save(dataPath, 'data');
    save(logPath, 'log');

    % Interrupt trial?
    [~, ~, keyCode] = KbCheck;
    if (ismember(KbName('F8'), find(keyCode)))
        DrawFormattedText(Gparams.pWindow, 'De onderzoeker heeft het expimeriment gepauzeerd.\n\n Even wachten a.j.b.', 'center', 'center', 255);
        Screen('Flip', Gparams.pWindow);

        while(KbCheck);
            WaitSecs(0.01);
        end;

        keyCode = 0;
        while(~ismember(KbName('F8'), find(keyCode)))
            [~, ~, keyCode] = KbCheck;
            WaitSecs(0.01);
        end

        Screen('Flip', Gparams.pWindow);

        WaitSecs(2);
    end

end

%% Feedback
data_mat = cell2mat(data);

nr_correct  = sum(data_mat(data_mat(:,5) == -Gparams.stim.sd_orientation,8) == 0) + sum(data_mat(data_mat(:,5) == Gparams.stim.sd_orientation,8) == 1) + sum(data_mat(:,5) == 0);
nr_tot      = sum(data_mat(:,5) == -Gparams.stim.sd_orientation) + sum(data_mat(:,5) == Gparams.stim.sd_orientation) + sum(data_mat(:,5) == 0);

msg = ['Dit blok heb je ' num2str(nr_correct) ' van de ' num2str(nr_tot) ' zebras goed gespot! \n\n\n' ...
    'Druk op een toets om door te gaan.'];

showtext(msg,Gparams)

end
