Home > data-import > gaze > import_csv_eye_files.m

import_csv_eye_files

PURPOSE ^

Imports the child_eye.csv and parent_eye.csv files and creates

SYNOPSIS ^

function [child_eye_data, parent_eye_data, time_sub_folder, time_eye_csv_list] = import_csv_eye_files(sub_id)

DESCRIPTION ^

 Imports the child_eye.csv and parent_eye.csv files and creates
 cont2_child_eye_xy and cont2_parent_eye_xy variables

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [child_eye_data, parent_eye_data, time_sub_folder, time_eye_csv_list] = import_csv_eye_files(sub_id)
0002 % Imports the child_eye.csv and parent_eye.csv files and creates
0003 % cont2_child_eye_xy and cont2_parent_eye_xy variables
0004 %
0005 sub_dir = get_subject_dir(sub_id);
0006 csv_list = dir(fullfile(sub_dir, '*_eye.csv'));
0007 
0008 % load under extra_p if not exist under sub_dir
0009 if ~isempty(csv_list)
0010     child_eye_file = fullfile(sub_dir, 'child_eye.csv');
0011     parent_eye_file = fullfile(sub_dir, 'parent_eye.csv');
0012 else
0013     csv_list = dir(fullfile(sub_dir, 'extra_p', '*_eye.csv'));
0014     child_eye_file = fullfile(sub_dir, 'extra_p', 'child_eye.csv');
0015     parent_eye_file = fullfile(sub_dir, 'extra_p', 'parent_eye.csv');
0016 end
0017 
0018 % report error if eye gaze file doesn't not exist under both directories
0019 if ~exist(child_eye_file, 'file')
0020     fprintf('%d does not have child_eye csv file\n', sub_id);
0021     child_eye_data = [];
0022 else
0023     child_eye_data = csvread(child_eye_file);
0024 end
0025 if ~exist(parent_eye_file, 'file')
0026     fprintf('%d does not have parent_eye csv file\n', sub_id);
0027     parent_eye_data = [];
0028 else
0029     parent_eye_data = csvread(parent_eye_file);
0030 end
0031 
0032 sub_info = get_subject_info(sub_id);
0033 
0034 % this paragraph of code calculate the max allowed date for the eye file to
0035 % be generated, which is 10 month after the subject folder is generated
0036 time_sub_folder = sub_info(3);
0037 time_eye_csv_list = nan(1,2);
0038 year_sub_folder = floor(time_sub_folder/10000);
0039 time_modified_date_allow = time_sub_folder + 1000; % allow 10 month
0040 month_modified_date_allow = time_modified_date_allow - year_sub_folder*10000;
0041 date_modified_date_allow = mod(month_modified_date_allow, 100);
0042 month_modified_date_allow = floor(month_modified_date_allow/100);
0043 if month_modified_date_allow > 12
0044     time_modified_date_allow = (year_sub_folder+1)*10000 + ...
0045         mod(month_modified_date_allow, 12)*100 + date_modified_date_allow;
0046 end
0047 
0048 fprintf('For %d, the subject folder is generated on %d\n', sub_id, time_sub_folder);
0049 for csvidx = 1:length(csv_list)
0050     tmpdate = csv_list(csvidx).date;
0051     time_eye_csv = year(tmpdate)*10000+month(tmpdate)*100+day(tmpdate);
0052     fprintf('-- the %s is last modified on %d\n', csv_list(csvidx).name, time_eye_csv);
0053     is_modified_correct_date = time_eye_csv <= time_modified_date_allow;
0054     if ~is_modified_correct_date
0055         fprintf('The last modified date of child_eye csv file is quite recently\n');
0056         is_proceed = input('Do you still want to proceed? (y/n)\n', 's');
0057         if lower(is_proceed(1)) == 'n'
0058             error('Exit function requested by user.');
0059         end
0060     end
0061     time_eye_csv_list(csvidx) = time_eye_csv;
0062 end
0063 
0064 end
0065 
0066 function year_int = year(date_string)
0067 % date_string has to be in the format of '27-Oct-2011 17:34:37'
0068 separator_idx = strfind(date_string, '-');
0069 year_int = str2double(date_string(separator_idx(2)+1:separator_idx(2)+4));
0070 end
0071 
0072 function month_int = month(date_string)
0073 % date_string has to be in the format of '27-Oct-2011 17:34:37'
0074 separator_idx = strfind(date_string, '-');
0075 month_str = date_string(separator_idx(1)+1:separator_idx(1)+3);
0076 month_int = -1;
0077 
0078 switch month_str
0079     case 'Jan'
0080         month_int = 1;
0081     case 'Feb'
0082         month_int = 2;
0083     case 'Mar'
0084         month_int = 3;
0085     case 'Apr'
0086         month_int = 4;
0087     case 'May'
0088         month_int = 5;
0089     case 'Jun'
0090         month_int = 6;
0091     case 'Jul'
0092         month_int = 7;
0093     case 'Aug'
0094         month_int = 8;
0095     case 'Sep'
0096         month_int = 9;
0097     case 'Oct'
0098         month_int = 10;
0099     case 'Nov'
0100         month_int = 11;
0101     case 'Dec'
0102         month_int = 12;
0103     otherwise
0104         error('Invalid month string %s', month_str);
0105 end
0106 
0107 end
0108 
0109 
0110 function data_int = day(date_string)
0111 separator_idx = strfind(date_string, '-');
0112 % date_string has to be in the format of '27-Oct-2011 17:34:37'
0113 data_int = str2double(date_string(1:separator_idx(1)-1));
0114 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005