0001 function fileinfo = vb_fileinfo_active_field_convert_to(format, fileinfo, data_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if ~exist('format', 'var')
0025 error('format is required parameter.');
0026 end
0027 if ~exist('fileinfo', 'var')
0028 error('fileinfo is required parameter.');
0029 end
0030 if ~exist('data_file', 'var')
0031 error('fileinfo is required parameter.');
0032 end
0033 if exist(data_file, 'file') ~= 2
0034 error('Specified data_file not found.');
0035 end
0036
0037
0038
0039
0040 if isfield(fileinfo, 'channel_id')
0041 current_format = 'old';
0042 elseif isfield(fileinfo, 'ActiveChannel')
0043 current_format = 'new';
0044 end
0045
0046
0047 if strcmp(current_format, format), return; end
0048
0049
0050 ch_info = vb_load_channel_info(data_file);
0051
0052 switch(format)
0053 case 'old'
0054
0055 fileinfo.channel_id = ch_info.ID(fileinfo.ActiveChannel ~= 0);
0056 fileinfo.act_trial = find(fileinfo.ActiveTrial ~= 0);
0057
0058
0059 fileinfo = rmfield(fileinfo, 'ActiveChannel');
0060 fileinfo = rmfield(fileinfo, 'ActiveTrial');
0061
0062 case 'new'
0063
0064 ix = vb_util_get_index(ch_info.ID, fileinfo.channel_id);
0065 fileinfo.ActiveChannel = zeros(length(fileinfo.Nchannel), 1);
0066 fileinfo.ActiveChannel(ix) = 1;
0067 fileinfo.ActiveTrial = zeros(length(fileinfo.Ntotal), 1);
0068 fileinfo.ActiveTrial(fileinfo.act_trial) = 1;
0069
0070 fileinfo = rmfield(fileinfo, 'channel_id');
0071 fileinfo = rmfield(fileinfo, 'act_trial');
0072
0073 otherwise
0074 error('Invalid format was specified.');
0075 end
0076