Home > vbmeg > functions > common > loadfunc > subdirectory > vb_load_meg_info.m

vb_load_meg_info

PURPOSE ^

return MEGinfo type data from MEG-MAT file or EEG-MAT file

SYNOPSIS ^

function [meginfo] = vb_load_meg_info(megfile, info_type)

DESCRIPTION ^

 return MEGinfo type data from MEG-MAT file or EEG-MAT file

 [usage]
    [meginfo] = vb_load_meg_info(megfile, info_type);

 [input]
     megfile : <required> <<file>> measurement file
             :  meg-mat file(.meg.mat) or eeg-mat file(.eeg.mat)

   info_type : <optional> (bit sequence) type code you want [1]
             :  1) (0001) basic
             :      .SampleFreq
             :      .Nchannel
             :      .Nsample
             :      .Nrepeat
             :      .Pretrigger
             :      .device
             :      .sensor_weight (MEG)
             :      .Coord (EEG)
             :      .Measurement
             :  2) (0010) for brain sphere model
             :      .Vcenter
             :      .Vradius
             :  4) (0100) channel data
             :      .MEGch_id
             :      .MEGch_name
             :      .ChannelInfo
             :      .ExtraChannelInfo
             :      .saveman
             :  8) (1000) active conditions
             :      .ActiveChannel
             :      .ActiveTrial
             :      .Trial
             :  [NOTICE]
             :  You have to set *SUMMATION* value of bits by *DECIMAL* number.
             :  (combination example)
             :   3 (0011) --> basic + brain sphere model
             :   5 (0101) --> basic + channel data
             :   6 (0110) --> brain sphere model + channel data
             :   7 (0111) --> basic + brain sphere model + channel data
             :   9 (1001) --> basic + active conditions
             :  13 (1101) --> basic + channel_data + active conditions
             :  15 (1111) --> all

 [output]
    meginfo : newest format - sbi      @ see make_sbi_meg_data()
                            - yokogawa @ see make_yokogawa_data()

 [note]
   standard format:
   meginfo
    .Measurement   % measurement type
    .device        % meg device type
    .Nchannel      % number of active gradiometers
    .Nsample       % sampling number of measurement
    .Nrepeat       % repeat number
    .Pretrigger    % sampling number for pre-trigger
    .SampleFreq    % sampling frequency
    .Vcenter       % origin of sphere model [m]
    .Vradius       % radius of sphere model [m]
    .ActiveChannel % [Nchannel x 1 boolean] list of active channel flag
    .ActiveTrial   % [Ntrial x 1 boolean] list of active trial flag
    .MEGch_id
    .MEGch_name
    .MEG_ID
    .MRI_ID
    .Trial
    .ChannelInfo
    .ExtraChannelInfo
    .saveman

 measurement-dependent members are:
    .sensor_weight % for MEG
    .Coord         % for EEG

   if given is an eeg-mat file, convert EEGinfo to MEGinfo

   See also
     vb_load_measurement_info

 [history]
   2006-12-13 (Sako) modified for EEG
   2008-03-10 (Sako) renamed fields
   2008-04-15 (Sako) added Trial, Active*
   2009-08-03 (Sako) added info_type and changed the set of fields
   2010-01-22 (Sako) modified bug of INFOTYPE_ACTIVE
   2010-09-16 (Sako) modified to inherit info_type when 'INFO' type file
   2011-03-08 (Sako) added 'sensor_weight' for MEG and 'Coord' for EEG
   2011-06-01 (Sako) converted return values of vb_load_device to upper case
   2011-06-02 (Sako) modified according to the new data format
   2012-07-13 (Sako) supported an MEG-MAT file which has 'Pretriger' field.

 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    [meginfo] = vb_load_meg_info(megfile, info_type)
0002 % return MEGinfo type data from MEG-MAT file or EEG-MAT file
0003 %
0004 % [usage]
0005 %    [meginfo] = vb_load_meg_info(megfile, info_type);
0006 %
0007 % [input]
0008 %     megfile : <required> <<file>> measurement file
0009 %             :  meg-mat file(.meg.mat) or eeg-mat file(.eeg.mat)
0010 %
0011 %   info_type : <optional> (bit sequence) type code you want [1]
0012 %             :  1) (0001) basic
0013 %             :      .SampleFreq
0014 %             :      .Nchannel
0015 %             :      .Nsample
0016 %             :      .Nrepeat
0017 %             :      .Pretrigger
0018 %             :      .device
0019 %             :      .sensor_weight (MEG)
0020 %             :      .Coord (EEG)
0021 %             :      .Measurement
0022 %             :  2) (0010) for brain sphere model
0023 %             :      .Vcenter
0024 %             :      .Vradius
0025 %             :  4) (0100) channel data
0026 %             :      .MEGch_id
0027 %             :      .MEGch_name
0028 %             :      .ChannelInfo
0029 %             :      .ExtraChannelInfo
0030 %             :      .saveman
0031 %             :  8) (1000) active conditions
0032 %             :      .ActiveChannel
0033 %             :      .ActiveTrial
0034 %             :      .Trial
0035 %             :  [NOTICE]
0036 %             :  You have to set *SUMMATION* value of bits by *DECIMAL* number.
0037 %             :  (combination example)
0038 %             :   3 (0011) --> basic + brain sphere model
0039 %             :   5 (0101) --> basic + channel data
0040 %             :   6 (0110) --> brain sphere model + channel data
0041 %             :   7 (0111) --> basic + brain sphere model + channel data
0042 %             :   9 (1001) --> basic + active conditions
0043 %             :  13 (1101) --> basic + channel_data + active conditions
0044 %             :  15 (1111) --> all
0045 %
0046 % [output]
0047 %    meginfo : newest format - sbi      @ see make_sbi_meg_data()
0048 %                            - yokogawa @ see make_yokogawa_data()
0049 %
0050 % [note]
0051 %   standard format:
0052 %   meginfo
0053 %    .Measurement   % measurement type
0054 %    .device        % meg device type
0055 %    .Nchannel      % number of active gradiometers
0056 %    .Nsample       % sampling number of measurement
0057 %    .Nrepeat       % repeat number
0058 %    .Pretrigger    % sampling number for pre-trigger
0059 %    .SampleFreq    % sampling frequency
0060 %    .Vcenter       % origin of sphere model [m]
0061 %    .Vradius       % radius of sphere model [m]
0062 %    .ActiveChannel % [Nchannel x 1 boolean] list of active channel flag
0063 %    .ActiveTrial   % [Ntrial x 1 boolean] list of active trial flag
0064 %    .MEGch_id
0065 %    .MEGch_name
0066 %    .MEG_ID
0067 %    .MRI_ID
0068 %    .Trial
0069 %    .ChannelInfo
0070 %    .ExtraChannelInfo
0071 %    .saveman
0072 %
0073 % measurement-dependent members are:
0074 %    .sensor_weight % for MEG
0075 %    .Coord         % for EEG
0076 %
0077 %   if given is an eeg-mat file, convert EEGinfo to MEGinfo
0078 %
0079 %   See also
0080 %     vb_load_measurement_info
0081 %
0082 % [history]
0083 %   2006-12-13 (Sako) modified for EEG
0084 %   2008-03-10 (Sako) renamed fields
0085 %   2008-04-15 (Sako) added Trial, Active*
0086 %   2009-08-03 (Sako) added info_type and changed the set of fields
0087 %   2010-01-22 (Sako) modified bug of INFOTYPE_ACTIVE
0088 %   2010-09-16 (Sako) modified to inherit info_type when 'INFO' type file
0089 %   2011-03-08 (Sako) added 'sensor_weight' for MEG and 'Coord' for EEG
0090 %   2011-06-01 (Sako) converted return values of vb_load_device to upper case
0091 %   2011-06-02 (Sako) modified according to the new data format
0092 %   2012-07-13 (Sako) supported an MEG-MAT file which has 'Pretriger' field.
0093 %
0094 % Copyright (C) 2011, ATR All Rights Reserved.
0095 % License : New BSD License(see VBMEG_LICENSE.txt)
0096 
0097 % --- CHECK ARGUMENTS --- %
0098 if ~exist('megfile', 'var'), megfile = ''; end
0099 if ~exist('info_type', 'var'), info_type = []; end
0100 [megfile, info_type] = inner_check_arguments(megfile, info_type);
0101 
0102 % --- MAIN PROCEDURE --------------------------------------------------------- %
0103 %
0104 [measurement] = vb_load_device(megfile);
0105 Measurement = upper(measurement);
0106 
0107 switch  Measurement
0108 
0109   case  'MEG'
0110     % this script is in original vb_load_meg_info
0111     load(megfile, 'MEGinfo');
0112 
0113   case  'EEG'
0114     MEGinfo = vb_load_measurement_info(megfile, 'meginfo');
0115 
0116   case  'INFO'
0117     load(megfile, 'fileinfo');
0118     fileinfo = vb_fileinfo_active_field_convert_to('new', fileinfo, megfile);
0119 
0120     MEGinfo = vb_load_meg_info(fileinfo.filename{1}, info_type);
0121     MEGinfo.ActiveChannel = fileinfo.ActiveChannel;
0122     MEGinfo.ActiveTrial   = fileinfo.ActiveTrial;
0123     
0124     MEGinfo.Nrepeat       = fileinfo.Ntotal;
0125   otherwise
0126     error('unknown Measurement : %s', Measurement);
0127 end
0128 
0129 meginfo = inner_read_meg_info(MEGinfo, Measurement, info_type, megfile);
0130 return;
0131 %
0132 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0133 
0134 % --- INNER FUNCTIONS -------------------------------------------------------- %
0135 %
0136 % --- inner_check_arguments()
0137 %
0138 function [megfile, info_type] = inner_check_arguments(megfile, info_type)
0139 func_ = mfilename;
0140 
0141 if isempty(megfile)
0142   error('(%s) megfile is a required parameter', func_);
0143 end
0144 
0145 if isempty(info_type)
0146   info_type = 1; % basic
0147 end
0148 return;
0149 %
0150 % --- end of inner_check_arguments()
0151 
0152 
0153 % --- inner_read_meg_info()
0154 %
0155 function [meginfo] = ...
0156   inner_read_meg_info(MEGinfo, Measurement, info_type, megfile)
0157 func_ = mfilename;
0158 
0159 meginfo = [];
0160 
0161 % --- constants
0162 INFOTYPE_BASIC   = 1; % 0001
0163 INFOTYPE_SPHERE  = 2; % 0010
0164 INFOTYPE_CHANNEL = 4; % 0100
0165 INFOTYPE_ACTIVE  = 8; % 1000
0166 
0167 % --- BASIC TYPE
0168 if bitand(info_type, INFOTYPE_BASIC) == INFOTYPE_BASIC
0169   % --- .SampleFreq
0170   if isfield(MEGinfo, 'SampleFreq')
0171     meginfo.SampleFreq = MEGinfo.SampleFreq;
0172   else
0173     warning('(%s) megfile(%s) does not have SampleFreq\n', func_, megfile);
0174   end
0175 
0176   % --- .Nchannel
0177   if isfield(MEGinfo, 'Nchannel')
0178     meginfo.Nchannel = MEGinfo.Nchannel;
0179   else
0180     warning('(%s) megfile(%s) does not have Nchannel\n', func_, megfile);
0181   end
0182 
0183   % --- .Nsample
0184   if isfield(MEGinfo, 'Nsample')
0185     meginfo.Nsample = MEGinfo.Nsample;
0186   else
0187     warning('(%s) megfile(%s) does not have Nsample\n', func_, megfile);
0188   end
0189 
0190   % --- .Nrepeat
0191   if isfield(MEGinfo, 'Nrepeat')
0192     meginfo.Nrepeat = MEGinfo.Nrepeat;
0193   else
0194     warning('(%s) megfile(%s) does not have Nrepeat\n', func_, megfile);
0195   end
0196 
0197   % --- .Pretrigger
0198   meginfo.Pretrigger = vb_meginfo_get_pre_trigger(MEGinfo);
0199 
0200   % --- .Measurement
0201   if isfield(MEGinfo, 'Measurement')
0202     meginfo.Measurement = MEGinfo.Measurement;
0203   else
0204 %     warning('(%s) megfile(%s) does not have Measurement\n', func_, megfile);
0205   end
0206 
0207   % --- .device
0208   if isfield(MEGinfo, 'device')
0209     meginfo.device = MEGinfo.device;
0210   else
0211     warning('(%s) megfile(%s) does not have device\n', func_, megfile);
0212   end
0213   
0214   % --- (MEG) .sensor_weight
0215   if strcmp(Measurement, 'MEG') == 1
0216     if isfield(MEGinfo, 'sensor_weight')
0217       meginfo.sensor_weight = MEGinfo.sensor_weight;
0218     else
0219       warning('(%s) megfile(%s) does not have sensor_weight\n', func_, megfile);
0220     end
0221   end
0222   
0223   % --- (EEG) .Coord
0224   if strcmp(Measurement, 'EEG') == 1
0225     EEGinfo = vb_eegfile_load_eeginfo(megfile);
0226     if isfield(EEGinfo, 'Coord')
0227       meginfo.Coord = EEGinfo.Coord;
0228     else
0229       warning('(%s) megfile(%s) does not have Coord\n', func_, megfile);
0230     end
0231   end
0232 end
0233     
0234 if bitand(info_type, INFOTYPE_SPHERE) == INFOTYPE_SPHERE
0235   % --- .Vcenter
0236   if isfield(MEGinfo, 'Vcenter')
0237     meginfo.Vcenter = MEGinfo.Vcenter;
0238   else
0239     warning('(%s) megfile(%s) does not have Vcenter\n', func_, megfile);
0240   end
0241 
0242   % --- .Vradius
0243   if isfield(MEGinfo, 'Vradius')
0244     meginfo.Vradius = MEGinfo.Vradius;
0245   else
0246     warning('(%s) megfile(%s) does not have Vradius\n', func_, megfile);
0247   end
0248 end
0249     
0250 if bitand(info_type, INFOTYPE_CHANNEL) == INFOTYPE_CHANNEL
0251   % --- .MEGch_id
0252   if isfield(MEGinfo, 'MEGch_id')
0253     meginfo.MEGch_id = MEGinfo.MEGch_id;
0254   else
0255     warning('(%s) megfile(%s) does not have MEGch_id\n', func_, megfile);
0256   end
0257 
0258   % --- .MEGch_name
0259   if isfield(MEGinfo, 'MEGch_name')
0260     meginfo.MEGch_name = MEGinfo.MEGch_name;
0261   else
0262     warning('(%s) megfile(%s) does not have MEGch_name\n', func_, megfile);
0263   end
0264 
0265   % --- .ChannelInfo
0266   if isfield(MEGinfo, 'ChannelInfo')
0267     meginfo.ChannelInfo = MEGinfo.ChannelInfo;
0268   else
0269     warning('(%s) megfile(%s) does not have ChannelInfo\n', func_, megfile);
0270   end
0271 
0272   % --- .ExtraChannelInfo
0273   if isfield(MEGinfo, 'ExtraChannelInfo')
0274     meginfo.ExtraChannelInfo = MEGinfo.ExtraChannelInfo;
0275   else
0276     warning('(%s) megfile(%s) does not have ExtraChannelInfo\n', ...
0277       func_, megfile);
0278   end
0279 
0280   % --- .saveman
0281   if isfield(MEGinfo, 'saveman')
0282     meginfo.saveman = MEGinfo.saveman;
0283   else
0284     warning('(%s) megfile(%s) does not have saveman\n', func_, megfile);
0285   end
0286 end
0287     
0288 if bitand(info_type, INFOTYPE_ACTIVE) == INFOTYPE_ACTIVE
0289   % --- .ActiveChannel
0290   if isfield(MEGinfo, 'ActiveChannel')
0291     meginfo.ActiveChannel = MEGinfo.ActiveChannel;
0292   else
0293     warning('(%s) megfile(%s) does not have ActiveChannel\n', func_, megfile);
0294   end
0295 
0296   % --- .ActiveTrial
0297   if isfield(MEGinfo, 'ActiveTrial')
0298     meginfo.ActiveTrial = MEGinfo.ActiveTrial;
0299   else
0300     warning('(%s) megfile(%s) does not have ActiveTrial\n', func_, megfile);
0301   end
0302 
0303   % --- .Trial
0304   if isfield(MEGinfo, 'Trial')
0305     meginfo.Trial = MEGinfo.Trial;
0306   else
0307     warning('(%s) megfile(%s) does not have Trial\n', func_, megfile);
0308   end
0309 end
0310 return;
0311 %
0312 % --- enf of inner_read_meg_info()
0313 %
0314 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0315 
0316 %%% END OF FILE %%%

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