Home > functions > device > active_check > vb_get_multi_fileinfo.m

vb_get_multi_fileinfo

PURPOSE ^

Load file information for multiple session files

SYNOPSIS ^

function [fileinfo] = vb_get_multi_fileinfo(datafile, outfile)

DESCRIPTION ^

 Load file information for multiple session files
 --- Usage
  [fileinfo] = vb_get_multi_fileinfo(datafile)
  [fileinfo] = vb_get_multi_fileinfo(datafile, outfile)
 --- Input
 datafile : cell array of multiple data file names
 datafile{n} : n-th file name  [n=1:Nsession]
 --- Optional Input
 outfile : output file name to save multiple file information 'fileinfo'
           if 'outfile' is not given, no output file is made
 --- Output
 fileinfo : structure with file information for multiple files
 fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
 fileinfo.Nchannel     : # of total channels
 fileinfo.channel_id   : active channel id [1 x (# of acticeChannel)]
 fileinfo.Nsample      : # of samples in one trial
 fileinfo.Ntotal       : # of all trials 
 fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
 fileinfo.session_id   : session index for each trial [1 x Ntotal]
 fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
  - The above fields have info. for all trials in multiple epoch files
  - following fields are active trial info.
 fileinfo.act_trial    : active trial index among all trials [1 x Nactive]
 fileinfo.err_trial    : error trial index  [1 x Nerror]

 Masa-aki Sato 2009-1-31
 Sako 2009-09-01 substituted vb_load_measurement_info for vb_load_meg_info
 Sako 2009-12-15 modified vb_load_measurement_info to return MEG format info

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [fileinfo] = vb_get_multi_fileinfo(datafile, outfile)
0002 % Load file information for multiple session files
0003 % --- Usage
0004 %  [fileinfo] = vb_get_multi_fileinfo(datafile)
0005 %  [fileinfo] = vb_get_multi_fileinfo(datafile, outfile)
0006 % --- Input
0007 % datafile : cell array of multiple data file names
0008 % datafile{n} : n-th file name  [n=1:Nsession]
0009 % --- Optional Input
0010 % outfile : output file name to save multiple file information 'fileinfo'
0011 %           if 'outfile' is not given, no output file is made
0012 % --- Output
0013 % fileinfo : structure with file information for multiple files
0014 % fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
0015 % fileinfo.Nchannel     : # of total channels
0016 % fileinfo.channel_id   : active channel id [1 x (# of acticeChannel)]
0017 % fileinfo.Nsample      : # of samples in one trial
0018 % fileinfo.Ntotal       : # of all trials
0019 % fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
0020 % fileinfo.session_id   : session index for each trial [1 x Ntotal]
0021 % fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
0022 %  - The above fields have info. for all trials in multiple epoch files
0023 %  - following fields are active trial info.
0024 % fileinfo.act_trial    : active trial index among all trials [1 x Nactive]
0025 % fileinfo.err_trial    : error trial index  [1 x Nerror]
0026 %
0027 % Masa-aki Sato 2009-1-31
0028 % Sako 2009-09-01 substituted vb_load_measurement_info for vb_load_meg_info
0029 % Sako 2009-12-15 modified vb_load_measurement_info to return MEG format info
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 if ~iscell(datafile),
0035     tmp = datafile;
0036     datafile = {tmp};
0037 end;
0038 
0039 % Number of EEG file
0040 Nfile = length(datafile);
0041 
0042 %% ---- EEGinfo ---- %%
0043 info     = vb_load_measurement_info(datafile{1}, 'MEGINFO');
0044 fsamp    = info.SampleFreq;
0045 Nsample  = info.Nsample;
0046 Nchannel = info.Nchannel;
0047 
0048 % Trial number for each file
0049 Ntrial    = zeros(1,Nfile);
0050 trial_id  = cell(1,Nfile);
0051 cond_id = [];
0052 
0053 Nst = 0;
0054 
0055 for n=1:Nfile
0056     info = vb_load_measurement_info(datafile{n}, 'MEGINFO');
0057     
0058     if fsamp ~= info.SampleFreq,
0059         error('SampleFrequency does not match');
0060     end
0061     if Nsample ~= info.Nsample,
0062         error('NSample does not match');
0063     end
0064 
0065     if Nchannel ~= info.Nchannel,
0066         error('Nchannel does not match');
0067     end
0068     
0069     Ntrial(n) = info.Nrepeat;
0070     ix_trial = (1:Ntrial(n)) + Nst;
0071     Nst = Ntrial(n) + Nst;
0072     
0073     trial_id{n}  = ix_trial;
0074     
0075     if isfield(info,'cond_id')
0076         cond_id = [cond_id, info.cond_id];
0077     else
0078         cond_id = [cond_id, ones(1,Ntrial(n))];
0079     end
0080 end
0081 
0082 Ntotal = sum(Ntrial);
0083 session_id = zeros(1,Ntotal);
0084 
0085 for n=1:Nfile
0086     session_id(trial_id{n}) = n;
0087 end
0088 
0089 fileinfo.filename  = datafile;
0090 fileinfo.Ntotal    = Ntotal;
0091 fileinfo.Ntrial    = Ntrial;
0092 fileinfo.Nsample   = Nsample;
0093 fileinfo.Nchannel  = Nchannel;
0094 
0095 fileinfo.channel_id = 1:Nchannel;
0096 fileinfo.cond_id    = cond_id;
0097 
0098 fileinfo.session_id = session_id;
0099 fileinfo.act_trial  = 1:Ntotal;
0100 fileinfo.err_trial  = [];
0101 
0102 %% ---- info ---- %%
0103 
0104 if exist('outfile','var') && ~isempty(outfile)
0105     fprintf('Number of files: %d\n',Nfile)
0106     fprintf('Number of all trials: %d\n', Ntotal)
0107     fprintf('Save fileinfo: %s\n',outfile)
0108     
0109     Measurement = 'INFO';
0110     
0111     vb_fsave(outfile,'fileinfo','Measurement')
0112 end
0113 
0114 return

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005