Home > vbmeg > functions > device > meg > vb_megfile_load_data.m

vb_megfile_load_data

PURPOSE ^

load specified data from MEG-MAT file

SYNOPSIS ^

function [data, channel_info] = vb_megfile_load_data(megfile,loadspec, new_file, return_swt, verbose_swt)

DESCRIPTION ^

 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
                   :  'AXIAL'     : AxialGradioMeter (only MEG)
                   :  'PLANAR'    : PlanarGradioMeter (only MEG)
                   :  '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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005