load specified data from MEG-MAT file [usage] [data, channel_info] = vb_megfile_load_data(megfile, ... loadspec, new_file, return_swt, verbose_swt) [input] megfile : <required> <<file>> MEG-MAT file loadspec : <required> <<struct>> loading instruction .ChannelName : <optional> channel name list [Nch x 1] [] : name(string) list of target channel : The way to be used this depends on the : "ChannelSwitch" field : e.g. : {'1';'2';'3';'4'} : If this is empty, all the channels are : specified .ChannelSwitch : <optiolal> <<boolean>> [true] | false : Which is "ChannelName", to read, or not? : [true] : to read : false : to omit .ChannelType : <optional> <<string>> channel type ['MEG'] : 'MEG' : MEG channel data : 'EXTRA' : extra channel data : 'REFERENCE' : reference channel data : 'ALL' : 'MEG'+'EXTRA'+'REFERENCE' : - case insensitive .Trigger : <optional> [1] .Pretrigger : <optional> [0] .Posttrigger : <optional> [Nsample - 1] .TrialNumber : <optional> trial number list [] [Ntrial x 1] : "1" start : e.g. [1;2;3] : if this is empty, all the trials are specified .ActiveChannel : <optional> <<boolean>> [false] : active channel filter switch : true) active channels : false) all the channels .ActiveTrial : <optional> <<boolean>> [false] : active trial filter switch : valid only when data type is Evoked_Raw : true) active trials : false) all the trials .saveman : <optional> <<struct>> : When you want to make a new file, loaded data will be : stored in external directory. : If this field is invalid or switch field is set false, : data is stored internally. : .data_dir : data directory (relative path) : : ['(name of new_file)_bin'] : : @see vb_device_make_data_dir.m : .precision : data type ['float64'] : .switch : <<optional>> switch to store externally : : [true]) store the data externally : : false) store the data internally new_file : <optional> new MEG-MAT file name which is stored picked up : data and changed information [] : if this is empty, new file will not be created return_swt : <optional> <<boolean>> : switch whether return loaded data or not : [true] | false verbose_swt : <optional> <<boolean>> : switch whether output verbose message or not : [true] | false [output] data : loaded data [Nchannel x Nsample x Ntrial] channel_info : <<struct>> channel information of loaded data : .Active [Nchannel x 1] : .Name [Nchannel x 1] : .Type [Nchannel x 1] : .ID [Nchannel x 1] [note] If internal data is not empty, extract data from it. If they are empty, try to load data from binary files See also vb_megfile_load_data_external vb_util_check_variable_in_matfile [history] 2007-07-11 (Sako) initial version 2008-02-15 (Sako) thoroughly revised 2008-04-17 (Sako) devided into two keeping data types internal and external 2008-04-30 (Sako) deleted unused inner function 2008-06-05 (Sako) changed interface (argument and return) 2009-09-02 (Sako) modified not to abort if read_ch_list is empty 2010-02-10 (Sako) improved checking internal data 2010-06-30 (Sako) supported storing data externally (only MEG) 2011-02-09 (Sako) set initial values to loadspec.saveman if necessary 2011-07-07 (Sako) allowed that the loaded data can be stored internally Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [data, channel_info] = vb_megfile_load_data(megfile, ... 0002 loadspec, new_file, return_swt, verbose_swt) 0003 % load specified data from MEG-MAT file 0004 % 0005 % [usage] 0006 % [data, channel_info] = vb_megfile_load_data(megfile, ... 0007 % loadspec, new_file, return_swt, verbose_swt) 0008 % 0009 % [input] 0010 % megfile : <required> <<file>> MEG-MAT file 0011 % 0012 % loadspec : <required> <<struct>> loading instruction 0013 % .ChannelName : <optional> channel name list [Nch x 1] [] 0014 % : name(string) list of target channel 0015 % : The way to be used this depends on the 0016 % : "ChannelSwitch" field 0017 % : e.g. 0018 % : {'1';'2';'3';'4'} 0019 % : If this is empty, all the channels are 0020 % : specified 0021 % .ChannelSwitch : <optiolal> <<boolean>> [true] | false 0022 % : Which is "ChannelName", to read, or not? 0023 % : [true] : to read 0024 % : false : to omit 0025 % .ChannelType : <optional> <<string>> channel type ['MEG'] 0026 % : 'MEG' : MEG channel data 0027 % : 'EXTRA' : extra channel data 0028 % : 'REFERENCE' : reference channel data 0029 % : 'ALL' : 'MEG'+'EXTRA'+'REFERENCE' 0030 % : - case insensitive 0031 % .Trigger : <optional> [1] 0032 % .Pretrigger : <optional> [0] 0033 % .Posttrigger : <optional> [Nsample - 1] 0034 % .TrialNumber : <optional> trial number list [] [Ntrial x 1] 0035 % : "1" start 0036 % : e.g. [1;2;3] 0037 % : if this is empty, all the trials are specified 0038 % .ActiveChannel : <optional> <<boolean>> [false] 0039 % : active channel filter switch 0040 % : true) active channels 0041 % : false) all the channels 0042 % .ActiveTrial : <optional> <<boolean>> [false] 0043 % : active trial filter switch 0044 % : valid only when data type is Evoked_Raw 0045 % : true) active trials 0046 % : false) all the trials 0047 % .saveman : <optional> <<struct>> 0048 % : When you want to make a new file, loaded data will be 0049 % : stored in external directory. 0050 % : If this field is invalid or switch field is set false, 0051 % : data is stored internally. 0052 % : .data_dir : data directory (relative path) 0053 % : : ['(name of new_file)_bin'] 0054 % : : @see vb_device_make_data_dir.m 0055 % : .precision : data type ['float64'] 0056 % : .switch : <<optional>> switch to store externally 0057 % : : [true]) store the data externally 0058 % : : false) store the data internally 0059 % 0060 % new_file : <optional> new MEG-MAT file name which is stored picked up 0061 % : data and changed information [] 0062 % : if this is empty, new file will not be created 0063 % return_swt : <optional> <<boolean>> 0064 % : switch whether return loaded data or not 0065 % : [true] | false 0066 % verbose_swt : <optional> <<boolean>> 0067 % : switch whether output verbose message or not 0068 % : [true] | false 0069 % 0070 % [output] 0071 % data : loaded data [Nchannel x Nsample x Ntrial] 0072 % channel_info : <<struct>> channel information of loaded data 0073 % : .Active [Nchannel x 1] 0074 % : .Name [Nchannel x 1] 0075 % : .Type [Nchannel x 1] 0076 % : .ID [Nchannel x 1] 0077 % 0078 % [note] 0079 % If internal data is not empty, extract data from it. 0080 % If they are empty, try to load data from binary files 0081 % 0082 % See also 0083 % vb_megfile_load_data_external 0084 % vb_util_check_variable_in_matfile 0085 % 0086 % [history] 0087 % 2007-07-11 (Sako) initial version 0088 % 2008-02-15 (Sako) thoroughly revised 0089 % 2008-04-17 (Sako) devided into two keeping data types internal and external 0090 % 2008-04-30 (Sako) deleted unused inner function 0091 % 2008-06-05 (Sako) changed interface (argument and return) 0092 % 2009-09-02 (Sako) modified not to abort if read_ch_list is empty 0093 % 2010-02-10 (Sako) improved checking internal data 0094 % 2010-06-30 (Sako) supported storing data externally (only MEG) 0095 % 2011-02-09 (Sako) set initial values to loadspec.saveman if necessary 0096 % 2011-07-07 (Sako) allowed that the loaded data can be stored internally 0097 % 0098 % Copyright (C) 2011, ATR All Rights Reserved. 0099 % License : New BSD License(see VBMEG_LICENSE.txt) 0100 0101 % --- CHECK ARGUMENTS --- % 0102 if ~exist('megfile', 'var'), megfile = []; end 0103 if ~exist('loadspec', 'var'), loadspec = []; end 0104 if ~exist('new_file', 'var'), new_file = []; end 0105 if ~exist('return_swt', 'var'), return_swt = []; end 0106 if ~exist('verbose_swt', 'var'), verbose_swt = []; end 0107 [megfile, loadspec, new_file, return_swt, VERBOSE] = ... 0108 inner_check_arguments(megfile, loadspec, new_file, return_swt, verbose_swt); 0109 0110 % --- MAIN PROCEDURE --------------------------------------------------------- % 0111 % 0112 if isempty(loadspec) 0113 data = []; 0114 channel_info = []; 0115 return; 0116 end 0117 0118 % --- check internal data 0119 [state_bexp, const] = vb_util_check_variable_in_matfile(megfile, 'bexp'); 0120 [state_bexp_ext] = vb_util_check_variable_in_matfile(megfile, 'bexp_ext'); 0121 [state_refmg] = vb_util_check_variable_in_matfile(megfile, 'refmg'); 0122 0123 if state_bexp ~= const.VALID ... 0124 && state_bexp_ext ~= const.VALID ... 0125 && state_refmg ~= const.VALID 0126 [data, channel_info] = vb_megfile_load_data_external(megfile, ... 0127 loadspec, new_file, return_swt, VERBOSE); 0128 else 0129 [data, channel_info] = vb_megfile_load_data_internal(megfile, ... 0130 loadspec, new_file, return_swt, VERBOSE); 0131 end 0132 return; 0133 % 0134 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0135 0136 % --- INNER FUNCTIONS -------------------------------------------------------- % 0137 % 0138 % --- inner_check_arguments() 0139 % 0140 function [ ... 0141 megfile, loadspec, new_file, return_swt, VERBOSE] = ... 0142 inner_check_arguments(megfile, loadspec, new_file, return_swt, VERBOSE) 0143 0144 func_ = mfilename; 0145 0146 if isempty(megfile) 0147 error('(%s)megfile is a required parameter', func_); 0148 end 0149 0150 if exist(megfile, 'file') ~= 2 0151 error('(%s)cannot find megfile : %s', func_, megfile); 0152 end 0153 0154 meginfo = vb_megfile_load_meginfo(megfile); 0155 0156 % ----- check loadspec 0157 loadspec = vb_loadspec_check(loadspec, megfile); 0158 0159 0160 % ----- narrow channel by user-specified list and active filter 0161 [read_ch_list] = vb_meginfo_get_read_channels(meginfo, ... 0162 loadspec.ChannelName, loadspec.ChannelSwitch, loadspec.ActiveChannel); 0163 0164 if isempty(read_ch_list) 0165 % error('(%s) read channels are empty', func_); 0166 fprintf('(%s) read channels are empty\n', func_); 0167 loadspec = []; 0168 return; 0169 end 0170 % ------- reset channel spec in loadspec 0171 loadspec.ChannelName = read_ch_list; 0172 loadspec.ChannelSwitch = true; 0173 0174 if ~isempty(new_file) 0175 if isfield(loadspec, 'saveman') && vb_saveman_get_switch(loadspec.saveman) 0176 loadspec.saveman.data_dir = vb_device_make_data_dir(new_file); 0177 loadspec.saveman.precision = 'float64'; 0178 end 0179 end 0180 0181 if isempty(return_swt) 0182 return_swt = true; 0183 end 0184 0185 if isempty(new_file) && ~return_swt 0186 error('(%s)wrong combination - empty output file and no return', func_); 0187 end 0188 0189 if isempty(VERBOSE) 0190 VERBOSE = true; 0191 end 0192 return; 0193 % 0194 % --- end of inner_check_arguments() 0195 % 0196 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0197 0198 % --- END OF FILE --- %