function Gparams = defGParams(Gparams)

%% Get information about experiment

prompt = {'Enter subject number:','Enter location:'};
dlg_title = 'Experiment Information';
num_lines = 1;
defaultans = {'','cubicle'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);

Gparams.subject_number      = str2num(answer{1});
Gparams.location            = answer{2};

Gparams.datetime = datestr(now);

%% Set up Psychtoolbox Screen and parameters
KbName('UnifyKeyNames');

Gparams.bg = 127.5; % set background color

allScreens = Screen('Screens');

switch Gparams.location
    case 'office'
        rng('shuffle'); % Randomize seed of random number generator
        Gparams.DistToScreen    = .57;		% in meters
        Gparams.ScreenWidth     = .53;		% in meters
        Gparams.pWindow = Screen('OpenWindow', allScreens(1), Gparams.bg);

        Gparams.DataPath    = ['../Data/S', num2str(Gparams.subject_number) '/'];
        Gparams.LogPath     = [Gparams.DataPath, 'Log/'];
        Gparams.StimPath    = [Gparams.DataPath, 'Stimuli/'];
    case 'laptop'
        rng('shuffle'); % Randomize seed of random number generator
        Gparams.DistToScreen    = .57;		% in meters
        Gparams.ScreenWidth     = .286;		% in meters
        Gparams.pWindow = Screen('OpenWindow', allScreens(1), Gparams.bg);
        
        Gparams.DataPath    = ['../Data/S', num2str(Gparams.subject_number) '/'];
        Gparams.LogPath     = [Gparams.DataPath, 'Log/'];
        Gparams.StimPath    = [Gparams.DataPath, 'Stimuli/'];
    case 'cubicle'
        rng('shuffle'); % Randomize seed of random number generator
        Gparams.DistToScreen    = .53;		% in meters
        Gparams.ScreenWidth     = .531;		% in meters
        Gparams.pWindow = Screen('OpenWindow', allScreens(1), Gparams.bg);

        Gparams.DataPath    = ['../Data/S', num2str(Gparams.subject_number) '/'];
        Gparams.LogPath     = [Gparams.DataPath, 'Log/'];
        Gparams.StimPath    = [Gparams.DataPath, 'Stimuli/'];
    case 'home'
        rng('shuffle'); % Randomize seed of random number generator
        Gparams.DistToScreen    = .53;		% in meters
        Gparams.ScreenWidth     = .407;		% in meters
        Gparams.pWindow = Screen('OpenWindow', allScreens(2), Gparams.bg);

        Gparams.DataPath    = ['../Data/S', num2str(Gparams.subject_number) '/'];
        Gparams.LogPath     = [Gparams.DataPath, 'Log/'];
        Gparams.StimPath    = [Gparams.DataPath, 'Stimuli/'];
end

if (~exist(Gparams.DataPath))
    mkdir(Gparams.DataPath);
end
if (~exist(Gparams.LogPath))
    mkdir(Gparams.LogPath);
end
if (~exist(Gparams.StimPath))
    mkdir([Gparams.StimPath, 'SD/']);
    mkdir([Gparams.StimPath, 'TAE/']);
end

% general screen parameters
[Gparams.ScreenResX, Gparams.ScreenResY]    = Screen('WindowSize', Gparams.pWindow);
Gparams.flipinterval                        = Screen('GetFlipInterval',Gparams.pWindow);
Screen('BlendFunction', Gparams.pWindow, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Gparams.FixDotSize = deg2pix(.25, Gparams);
Gparams.flip_lag = .015;
Screen('TextSize',Gparams.pWindow, 19);
Screen('TextFont',Gparams.pWindow,'Helvatica');

% general stimulus parameters
Gparams.stim.imSize             = 9;
Gparams.stim.contrast           = .25;
Gparams.stim.window_sd          = 1.5;
Gparams.stim.thetakappa         = 2.3;  % The concentration parameter of the von Mises distribution over orientations  (think of inverse standard deviation). The lower the parameter is the broader is the distribution (i.e. less concentrated) and the more orientations will be in the stimulus. The more orientations there are in the stimulus the more noisy it will look.
Gparams.stim.f_spat_mean        = 0.75;  % Mean of the Gaussian over spatial frequencies (in cycles/degree)
Gparams.stim.f_spat_sd          = 0.3;  % Standard deviation of the Guassian over spatial frequencies (in cycles/degree)
Gparams.stim.rms_contrast       = 15;   % Root-mean square contrast of the stimulus
Gparams.stim.mean_grey_value    = Gparams.bg; % Greyscale value of the background
Gparams.stim.h_eccentricity     = 10;

% sd stimulus parameters
Gparams.stim.sd_orientation     = 5;  % = -5, 0, 5
Gparams.stim.sd_prop_left       = .25;
Gparams.stim.sd_prop_vertical   = .5;
Gparams.stim.sd_prop_right      = .25;

% tae stimulus parameters
Gparams.stim.tae_adaptor_deg    = 20;  % = -20, 20
Gparams.stim.tae_stim_levels    = -12:6:12;  % -12, -6, 0, 6, 12

% general mask parameters
Gparams.mask.window_sd      = 1.5;
Gparams.mask.sd_smooth      = 0.3;
Gparams.mask.contrast       = .5;

% cue parameters
Gparams.cue.size            = deg2pix(0.4, Gparams);
Gparams.cue.color           = [255 255 255];

% general timing information
Gparams.timing.prestimdur           = 0.5 - Gparams.flip_lag;
Gparams.timing.maskdur              = 0.2 - Gparams.flip_lag;

Gparams.timing.warning              = 0.5 - Gparams.flip_lag;
Gparams.timing.iti                  = 0.5 - Gparams.flip_lag - Gparams.flipinterval; % One frame is spent in the block function

% sd timing information
Gparams.timing.sd_cuedur            = 0.5 - Gparams.flip_lag;
Gparams.timing.sd_stimdur           = 0.1 - Gparams.flip_lag;
Gparams.timing.sd_responsedelay     = 0.5 - Gparams.flip_lag;

% tae timing information
Gparams.timing.tae_cuedur           = 0.5 - Gparams.flip_lag;
Gparams.timing.tae_adaptordur       = 1 - Gparams.flip_lag;
Gparams.timing.tae_interdur         = 0.5 - Gparams.flip_lag;
Gparams.timing.tae_stimdur          = 0.1 - Gparams.flip_lag;
Gparams.timing.tae_responsedelay    = 0.5 - Gparams.flip_lag;

% Save the parameters of the experiment
save([Gparams.DataPath, 'Gparams.mat'], 'Gparams');
