%IMPORT_PLE_DATA --  Script importing data of the PercLearn Experiment.
%
%  Reads an ASCII file named 'raw_data.dat'. It should contain 19 columns:
%    1. subject number
%    2. subject group
%    3. session (day)
%    4. block
%    5. overall trial number
%    6. block trial number
%    7. time stamp
%    8. noise orientation (1=negative, 2=positive)
%    9. Gabor orientation (1=negative, 2=positive)
%   10. difficulty level (max Gabor contrast)
%   11. position (1=above fixation, 2=below fixation)
%   12. actual noise orientation (in degrees)
%   13. actual Gabor orientation (in degrees)
%   14. actual Gabor peak contrast
%   15. actual position (in pixels relative to fixation at center screen)
%   16. response (1='negative', 2='positive', 0='bad key')
%   17. correct (1 if response==Gabor_orientation, 0 otherwise)
%   18. response time (in msec from the onset of the stimulus)
%   19. exit code (0='successful trial', 1='bad key', 2='missed frame')
%
%  After this script executes, the following 19 variables are created
%  in the workspace: sbj, group, session, block, exp_tr, blk_tr, clock,
%  noise_orient, Gabor_orient, difficulty, position, noise_degr,
%  Gabor_degr, Gabor_Cpeak, offset, resp, corr, RT, exitcode.
%
%  See also PLEDATA_BY_SBJ, PLEXP1.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.1.1 $  $Date: 2008-12-12 $
%
% Part of the Hebbian Perceptual Learning Model version 1.1 for MATLAB.
% http://alexpetrov.com/proj/plearn/
% Copyright (c) Alexander Petrov 1999-2008, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in PercLearn_license.m

%%%%%%%%%%%%%%%%%  Read the raw ASCII file

fprintf(1,'\nLoading ASCII file RAW_DATA.DAT.  Please wait...\n') ;
load raw_data.dat -ascii ;
[rows cols] = size(raw_data) ;
fprintf(1,'\n%d rows and %d columns loaded.\n',rows,cols) ;

% Do a (superficial) consistency check
if (find(isnan(raw_data)))
  warning ('NaNs found in raw_data. Check the raw ASCII file.') ;
else
  fprintf(1,'The RAW_DATA matrix contains no missing values.\n') ;
end;


%%%%%%%%%%%%%%%%%  Slice the big matrix into variables
fprintf(1,'\nSlicing the big matrix into variables, columnwise:\n') ;

% Description of the subject and session: columns 1 through 4
sbj   = raw_data(:,1) ;     % subject number
group = raw_data(:,2) ;     % group number
session = raw_data(:,3) ;   % session (day)
block = raw_data(:,4) ;     % block
fprintf(1,'  Extracted variables SBJ, GROUP, SESSION, and BLOCK.\n') ;

% Trial numbers: columns 5 and 6
exp_tr = raw_data(:,5) ;    % overall trial number
blk_tr = raw_data(:,6) ;    % block trial number
fprintf(1,'  Extracted variables EXP_TR and BLK_TR (trial number).\n') ;

% Absolute time since the beginning of experiment: column 7
clock = raw_data(:,7) ;
fprintf(1,'  Extracted variable CLOCK.\n') ;

%    8. noise orientation (1=negative, 2=positive)
%    9. Gabor orientation (1=negative, 2=positive)
%   10. difficulty level (max Gabor contrast)
%   11. position (1=above fixation, 2=below fixation)

% Logical description of the stimulus: columns 8-11
noise_orient = raw_data(:,8) ;      % 1=negative, 2=positive
Gabor_orient = raw_data(:,9) ;      % 1=negative, 2=positive
fprintf(1,'  Extracted variables NOISE_ORIENT and GABOR_ORIENT.\n') ;
difficulty = raw_data(:,10) ;       % difficulty level: 1,2,3
position = raw_data(:,11) ;         % 1=above fixation, 2=below fix.
fprintf(1,'  Extracted variables DIFFICULTY and POSITION.\n') ;

% Physical description of the stimulus: columns 12-15
noise_degr = raw_data(:,12) ;       % degrees relative to vertical
Gabor_degr = raw_data(:,13) ;       % degrees relative to vertical
fprintf(1,'  Extracted variables NOISE_DEGR and GABOR_DEGR.\n') ;
Gabor_Cpeak = raw_data(:,14) ;      % peak contrast of the Gabor patch
offset = raw_data(:,15) ;           % pixels above or below fixation cross
fprintf(1,'  Extracted variables GABOR_CPEAK and OFFSET.\n') ;

% Responses obtained from the subject: columns 16-19
resp = raw_data(:,16) ;     % 1='negative', 2='positive', 0='bad key'
correctp = raw_data(:,17) ; % correct = (resp==Gabor_orient)
RT   = raw_data(:,18) ;     % response time [msec] from stimulus onset
exitcode = raw_data(:,19) ; % 0='successful', 1='bad key', 2='missed frame'
fprintf(1,'  Extracted variables RESP, CORRECTP, RT, and EXITCODE.\n') ;


%%%%%%%%%%%%%%%%%  Clear

clear raw_data rows cols ;
fprintf(1,'Cleared the big matrix RAW_DATA.\n\n') ;

%fprintf(1,'The workspace now contains the following variables:\n\n') ;
%whos

%%%%% End of IMPORT_DATA.M
