Home > functions > device > meg > vb_megfile_make_loaded_megfile.m

vb_megfile_make_loaded_megfile

PURPOSE ^

make MEG-MAT file which includes loaded data and updated information

SYNOPSIS ^

function vb_megfile_make_loaded_megfile(megfile,ch_list, loaddata, newfile, overswt, coord_type)

DESCRIPTION ^

 make MEG-MAT file which includes loaded data and updated information

 [usage]
   vb_megfile_make_loaded_megfile(megfile, ...
     ch_list, loaddata, newfile, overswt, coord_type)

 [input]
    megfile : <required> <<file>> MEG-MAT file before loading
    ch_list : <required> <<struct>> channel label list of loaded data
   loaddata : <required> loaded data
            :  [Nchannel x Nsample x Ntrial]
    newfile : <required> <<file>> new MEG-MAT file name
    overswt : <optional> switch whether overwrite or not if newfile exists
            :  [true] : overwrite
            :   false : does not overwrite
 coord_type : <optional> <<string>> coordinate type ['']

 [output]
   none

 [note]
   If length of channel and channel number of loaded data are different,
   this function aborts running.

 [history]
   2007-07-12 (Sako) initial version
   2011-07-20 (Sako) modified how to set sensor_weight_ref
   2011-07-29 (Sako) the function to get sensor position was replaced

 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 vb_megfile_make_loaded_megfile(megfile, ...
0002   ch_list, loaddata, newfile, overswt, coord_type)
0003 % make MEG-MAT file which includes loaded data and updated information
0004 %
0005 % [usage]
0006 %   vb_megfile_make_loaded_megfile(megfile, ...
0007 %     ch_list, loaddata, newfile, overswt, coord_type)
0008 %
0009 % [input]
0010 %    megfile : <required> <<file>> MEG-MAT file before loading
0011 %    ch_list : <required> <<struct>> channel label list of loaded data
0012 %   loaddata : <required> loaded data
0013 %            :  [Nchannel x Nsample x Ntrial]
0014 %    newfile : <required> <<file>> new MEG-MAT file name
0015 %    overswt : <optional> switch whether overwrite or not if newfile exists
0016 %            :  [true] : overwrite
0017 %            :   false : does not overwrite
0018 % coord_type : <optional> <<string>> coordinate type ['']
0019 %
0020 % [output]
0021 %   none
0022 %
0023 % [note]
0024 %   If length of channel and channel number of loaded data are different,
0025 %   this function aborts running.
0026 %
0027 % [history]
0028 %   2007-07-12 (Sako) initial version
0029 %   2011-07-20 (Sako) modified how to set sensor_weight_ref
0030 %   2011-07-29 (Sako) the function to get sensor position was replaced
0031 %
0032 % Copyright (C) 2011, ATR All Rights Reserved.
0033 % License : New BSD License(see VBMEG_LICENSE.txt)
0034 
0035 
0036 % --- CHECK ARGUMENTS --- %
0037 if ~exist('megfile', 'var'), megfile = []; end
0038 if ~exist('ch_list', 'var'), ch_list = []; end
0039 if ~exist('loaddata', 'var'), loaddata = []; end
0040 if ~exist('newfile', 'var'), newfile = []; end
0041 if ~exist('overswt', 'var'), overswt = []; end
0042 if ~exist('coord_type', 'var'), coord_type = ''; end
0043 [megfile, ch_list, loaddata, newfile, overswt, coord_type] = ...
0044   inner_check_arguments(megfile, ...
0045     ch_list, loaddata, newfile, overswt, coord_type);
0046 
0047 % --- MAIN PROCEDURE --------------------------------------------------------- %
0048 %
0049 func_ = mfilename;
0050 error('(%s) !!!SORRY THIS FUNCTION PROHIBITED!!!', func_);
0051 
0052 bexp              = [];
0053 eeg               = [];
0054 refmg             = [];
0055 
0056 MEGinfo           = [];
0057 
0058 ExtraChannelInfo  = [];
0059 saveman           = [];
0060 
0061 Nchannel_all = size(loaddata,1);
0062 Nsample      = size(loaddata,2);
0063 Ntrial       = size(loaddata,3);
0064 
0065 [meginfo] = vb_megfile_load_meginfo(megfile);
0066 [swm] = vb_meginfo_get_sensor_weight_meg(meginfo);
0067 [swr] = vb_meginfo_get_sensor_weight_refmg(meginfo);
0068 [p,qp] = vb_load_sensor(megfile, 'MEG');
0069 [ref_p,ref_qp] = vb_load_sensor(megfile, 'REF');
0070 
0071 [ch_info] = vb_megfile_get_applicable_channel(megfile, ch_list);
0072 
0073 % --- MEG CHANNEL
0074 meg_ch = vb_ch_info_get_channel_list_meg(ch_info);
0075 if ~isempty(meg_ch)
0076   % position
0077   org_meg_ch = vb_meginfo_get_channel_label_meg(meginfo);
0078 
0079   [res, idx] = vb_util_is_included_list(org_meg_ch, meg_ch);
0080   pick = p(idx,:);
0081   Qpick = qp(idx,:);
0082   if ~isempty(swm)
0083     sensor_weight = swm(idx,:);
0084   end
0085   Nchannel_meg = length(meg_ch,1);
0086 %   MEGch_id = (1:Nchannel_meg)'; % [N x 1]
0087   MEGch_id = idx;
0088   bexp = loaddata(1:Nchannel_meg,:,:);
0089   
0090 else
0091   Nchannel_meg = 0;
0092   MEGch_id = [];
0093   MEGch_name = [];
0094   pick = [];
0095   Qpick = [];
0096   sensor_weight = [];
0097 end
0098 
0099 % --- EXTRA CHANNEL
0100 ext_ch = vb_ch_info_get_channel_list_ext(ch_info);
0101 if ~isempty(ext_ch)
0102   Nchannel_ext = size(ext_ch,1);
0103   ch_start = Nchannel_meg;
0104   EXTch_id = (ch_start+1):(ch_start+Nchannel_ext);
0105   eeg = loaddata(EXTch_id,:,:);
0106 
0107 else
0108   Nchannel_ext = 0;
0109   EXTch_id = [];
0110 end
0111 
0112 
0113 % --- REFFERENCE CHANNEL
0114 ref_ch = vb_ch_info_get_channel_list_ref(ch_info);
0115 if ~isempty(ref_ch)
0116   Nchannel_ref = size(ref_ch,1);
0117   ch_start = Nchannel_meg+Nchannel_ext;
0118   REFch_id = (ch_start+1):(ch_start+Nchannel_ref);
0119   refmg = loaddata(REFch_id,:,:);
0120   
0121   % position
0122   org_ref_ch = vb_meginfo_get_channel_label_refmg(meginfo);
0123   [res, idx] = vb_util_check_numerical_lists(org_ref_ch, ref_ch);
0124   ref_pick = ref_p(idx,:);
0125   ref_Qpick = ref_qp(idx,:);
0126   
0127   if ~isempty(swr)
0128     sensor_weight_ref = swr(idx,:);
0129   end
0130 
0131 else
0132   Nchannel_ref = 0;
0133   REFch_id = [];
0134   ref_pick = [];
0135   ref_Qpick = [];
0136   sensor_weight_ref = [];
0137 end
0138 
0139 % --- make new MEGinfo
0140 MEGinfo = vb_megfile_load_meginfo(megfile);
0141 MEGinfo.Nchannel_all      = Nchannel_all;
0142 MEGinfo.Nchannel_org      = Nchannel_meg;
0143 MEGinfo.Nchannel          = Nchannel_meg;
0144 
0145 MEGinfo.sensor_weight     = sensor_weight;
0146 
0147 MEGinfo = vb_meginfo_set_sensor_weight_refmg(MEGinfo, sensor_weight_ref);
0148 
0149 MEGinfo.Nsample           = Nsample;
0150 MEGinfo.Nrepeat_org       = Ntrial;
0151 MEGinfo.Nrepeat           = Ntrial;
0152 MEGinfo.TrialNumber       = Ntrial;
0153 MEGinfo.MEGch_id          = MEGch_id;
0154 MEGinfo.MEGch_name        = meg_ch;
0155 MEGinfo.ExtraChannelInfo  = ExtraChannelInfo;
0156 MEGinfo.saveman           = saveman;
0157 
0158 [Measurement] = vb_megfile_get_measurement(megfile);
0159 
0160 %
0161 % --- MEGinfo.EEGinfo
0162 %
0163 %   % header
0164 % [org_eg, org_ns, org_sf, org_nr] = meginfo_get_eeg_header(meginfo);
0165 % MEGinfo = meginfo_set_eeg_header(MEGinfo, org_eg, org_ns, org_sf, org_nr);
0166 MEGinfo.EEGinfo = vb_meginfo_filter_EEGinfo(meginfo, ch_list);
0167 
0168 
0169 % --- check existence of new file
0170 if (exist(newfile, 'file') == 2 && overswt) ...
0171     || exist(newfile, 'file') ~= 2
0172   % save
0173   vb_fsave(newfile, 'MEGinfo', 'pick', 'Qpick', 'ref_pick', 'ref_Qpick', ...
0174     'Measurement', 'bexp', 'eeg', 'refmg');
0175 else
0176   warning('(%s)cannot overwrite new MEG-MAT file : %s\n', func_, newfile);
0177 end
0178 %
0179 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0180 
0181 % --- INNER FUNCTIONS -------------------------------------------------------- %
0182 %
0183 % --- inner_check_arguments()
0184 %
0185 function [megfile, ch_list, loaddata, newfile, overswt, coord_type] = ...
0186   inner_check_arguments(megfile, ...
0187     ch_list, loaddata, newfile, overswt, coord_type)
0188 func_ = mfilename;
0189 if isempty(megfile)
0190   error('(%s)megfile is a required parameter', func_);
0191 end
0192 
0193 if isempty(ch_list)
0194   error('(%s)ch_list is a required parameter', func_);
0195 end
0196 
0197 if isempty(loaddata)
0198   error('(%s)loaddata is a required parameter', func_);
0199 end
0200 
0201 if isempty(newfile)
0202   error('(%s)newfile is a required parameter', func_);
0203 end
0204 
0205 if isempty(overswt)
0206   overswt = true;
0207 end
0208 
0209 if isempty(coord_type)
0210   % require no action
0211 end
0212 
0213 % --- check file
0214 if exist(megfile, 'file') ~= 2
0215   error('(%s)cannot find megfile : %s', megfile);
0216 end
0217 
0218 % --- check size
0219 if size(vb_util_arrange_list(ch_list,1),2) ~= size(loaddata,1)
0220   error('(%s)channel sizes are different ch_list and loaddata', func_);
0221 end
0222 return;
0223 %
0224 % --- end of inner_check_arguments()
0225 
0226 % --- END OF FILE --- %

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