Home > functions > device > eeg > vb_eegfile_load_data.m

vb_eegfile_load_data

PURPOSE ^

load eeg data file and return eeg data (Nchannel x Nsample x Ntrial)

SYNOPSIS ^

function [eeg_data, channel_info] =vb_eegfile_load_data(eegfile, loadspec, newfile, verbose_swt)

DESCRIPTION ^

 load eeg data file and return eeg data (Nchannel x Nsample x Ntrial)

 [usage]
   [eeg_data, channel_info] = ...
     vb_eegfile_load_data(eegfile, loadspec, newfile, verbose_swt)

 [input]
    eegfile : <required> <<file>> EEG-MAT file

   loadspec : <optional> <<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 ['EEG']
                 :  'EEG'   : EEG main channel data
                 :  'EXTRA' : extra channel data
                 :  'ALL'   : 'EEG' + 'EXTRA'
                 :  - case insensitive
        .Trigger : <optional> [1] sample list of trigger[Ntrigger x1 double]
     .Pretrigger : <optional> [0] number of sample before trigger
    .Posttrigger : <optional> [Nsample - 1] number of sample after trigger
    .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
   .bin_data_dir : <optional> directory to newly store data
                 :  This field is valid only when #3 argument newfile is 
                 :  specified.
                 :  ['name of newfile'_bin]

   newfile : <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
   verbose_swt : <optional> <<boolean>> verbose message switch
               :      true : output
               :   [false] : do not output

 [output]
      eeg_data : eeg channel 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]
   it has been prepared for only BIOSEMI EEG-MAT file

 [history]
   2008-03-31 (Sako) initial version
   2008-04-16 (Sako) added ActiveSwitch to LoadSpec
   2008-06-06 (Sako) you can specify ChannelType and get channel_info
   2009-07-16 (Sako) modified making channel_info (EEGinfo.ChannelInfo)
   2009-07-29 (Sako) refactored
   2009-08-10 (Sako) supported the condition that ex_info.Type is empty
   2009-12-25 (Sako) modified not to calibrate when loading data
   2011-02-08 (Sako) added .bin_data_dir to loadspec to store data externally
   2011-09-28 (Sako) supported the case without position infomation

 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 [eeg_data, channel_info] = ...
0002   vb_eegfile_load_data(eegfile, loadspec, newfile, verbose_swt)
0003 % load eeg data file and return eeg data (Nchannel x Nsample x Ntrial)
0004 %
0005 % [usage]
0006 %   [eeg_data, channel_info] = ...
0007 %     vb_eegfile_load_data(eegfile, loadspec, newfile, verbose_swt)
0008 %
0009 % [input]
0010 %    eegfile : <required> <<file>> EEG-MAT file
0011 %
0012 %   loadspec : <optional> <<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 ['EEG']
0026 %                 :  'EEG'   : EEG main channel data
0027 %                 :  'EXTRA' : extra channel data
0028 %                 :  'ALL'   : 'EEG' + 'EXTRA'
0029 %                 :  - case insensitive
0030 %        .Trigger : <optional> [1] sample list of trigger[Ntrigger x1 double]
0031 %     .Pretrigger : <optional> [0] number of sample before trigger
0032 %    .Posttrigger : <optional> [Nsample - 1] number of sample after trigger
0033 %    .TrialNumber : <optional> trial number list [] [Ntrial x 1]
0034 %                 :   "1" start
0035 %                 :    e.g. [1;2;3]
0036 %                 :    if this is empty, all the trials are specified
0037 %  .ActiveChannel : <optional> <<boolean>> [false]
0038 %                 :  active channel filter switch
0039 %                 :    true) active channels
0040 %                 :   false) all the channels
0041 %    .ActiveTrial : <optional> <<boolean>> [false]
0042 %                 :  active trial filter switch
0043 %                 :  valid only when data type is Evoked_Raw
0044 %                 :    true) active trials
0045 %                 :   false) all the trials
0046 %   .bin_data_dir : <optional> directory to newly store data
0047 %                 :  This field is valid only when #3 argument newfile is
0048 %                 :  specified.
0049 %                 :  ['name of newfile'_bin]
0050 %
0051 %   newfile : <optional> new MEG-MAT file name which is stored picked up
0052 %           :  data and changed information []
0053 %           :  if this is empty, new file will not be created
0054 %   verbose_swt : <optional> <<boolean>> verbose message switch
0055 %               :      true : output
0056 %               :   [false] : do not output
0057 %
0058 % [output]
0059 %      eeg_data : eeg channel data (Nchannel x Nsample x Ntrial)
0060 %  channel_info : <<struct>> channel information of loaded data
0061 %               :  .Active [Nchannel x 1]
0062 %               :  .Name   [Nchannel x 1]
0063 %               :  .Type   [Nchannel x 1]
0064 %               :  .ID     [Nchannel x 1]
0065 % [note]
0066 %   it has been prepared for only BIOSEMI EEG-MAT file
0067 %
0068 % [history]
0069 %   2008-03-31 (Sako) initial version
0070 %   2008-04-16 (Sako) added ActiveSwitch to LoadSpec
0071 %   2008-06-06 (Sako) you can specify ChannelType and get channel_info
0072 %   2009-07-16 (Sako) modified making channel_info (EEGinfo.ChannelInfo)
0073 %   2009-07-29 (Sako) refactored
0074 %   2009-08-10 (Sako) supported the condition that ex_info.Type is empty
0075 %   2009-12-25 (Sako) modified not to calibrate when loading data
0076 %   2011-02-08 (Sako) added .bin_data_dir to loadspec to store data externally
0077 %   2011-09-28 (Sako) supported the case without position infomation
0078 %
0079 % Copyright (C) 2011, ATR All Rights Reserved.
0080 % License : New BSD License(see VBMEG_LICENSE.txt)
0081 
0082 % --- CHECK ARGUMENTS --- %
0083 if ~exist('eegfile', 'var'), eegfile = []; end
0084 if ~exist('loadspec', 'var'), loadspec = []; end
0085 if ~exist('newfile', 'var'), newfile = ''; end
0086 if ~exist('verbose_swt', 'var'), verbose_swt = []; end
0087 [eegfile, loadspec, newfile, ch_list, target_sample, tr_list, ...
0088   eegfile_dir, VERBOSE] = ...
0089     inner_check_arguments(eegfile, loadspec, newfile, verbose_swt);
0090 
0091 % --- MAIN PROCEDURE --------------------------------------------------------- %
0092 %
0093 % ----- constants
0094 func_ = mfilename;
0095 vb_define_device;
0096 
0097 old_eeginfo = vb_eegfile_load_eeginfo(eegfile);
0098 
0099 % ----- read channel label
0100 eeg_labels = vb_eeginfo_get_channel_label(old_eeginfo, false);
0101 ext_labels = vb_eeginfo_get_channel_label_extra(old_eeginfo, false);
0102 
0103 % --- loadspec has been arranged in inner_check_arguments()
0104 [eeg_ch_list, eeg_idx] = vb_util_get_labels_to_read(eeg_labels, ...
0105             loadspec.ChannelName, loadspec.ChannelSwitch);
0106 [ext_ch_list, ext_idx] = vb_util_get_labels_to_read(ext_labels, ...
0107             loadspec.ChannelName, loadspec.ChannelSwitch);
0108           
0109 % ----- eeg and ext are managed devided
0110 N_channel = vb_info_get_channel_number(old_eeginfo);
0111 ext_idx_tmp = ext_idx + N_channel;
0112 
0113 %
0114 % --- !!! decide target channels here !!!
0115 %
0116 act_ch_list = [eeg_ch_list;ext_ch_list];
0117 act_idx = [eeg_idx;ext_idx_tmp];
0118 
0119 n_channel_new = length(act_ch_list);
0120 if n_channel_new == 0
0121   error('(%s)cannot make channel list', func_);
0122 end
0123 
0124 n_sample_new = target_sample(1,2)-target_sample(1,1) + 1;
0125 
0126 n_trial = vb_info_get_Nrepeat(old_eeginfo);
0127 
0128 if n_trial == 1
0129   n_trial_new = size(target_sample, 1);
0130 
0131 else
0132   n_trial_new = length(tr_list);
0133 end
0134 
0135 % ----- allocate buffer
0136 eeg_data = zeros(n_channel_new, n_sample_new, n_trial_new);
0137 
0138 % --- information to store data
0139 data_type = vb_eeginfo_get_datatype(old_eeginfo);
0140 act_data_type = data_type(act_idx);
0141 
0142 file_ext = FILE_EXT_BIN_CH_EEG;
0143 
0144 % ----- is base data external or internal?
0145 % -----  - storing internally is old fashioned
0146 internal_data = vb_eegfile_load_internal_data(eegfile);
0147 
0148 % ----- "trial" will be set as the new EEGinfo.Trial
0149 if isempty(internal_data)
0150   % --- EXTERNAL
0151   
0152   n_sample = vb_info_get_sample_number(old_eeginfo);
0153 
0154   % ----- binary data directory
0155   src_data_dir = [eegfile_dir filesep vb_eeginfo_get_datadir(old_eeginfo)];
0156 
0157   % ----- header
0158   EDF = vb_eeginfo_get_header(old_eeginfo);
0159   
0160 %   % ----- constant because base data is continuous data
0161 %   trial_number = 1;
0162   
0163   % ---------------------------- %
0164   % ----- LOAD BINARY DATA ----- %
0165   % ---------------------------- %
0166   for i_ch = 1:n_channel_new
0167 
0168     src_datafile = sprintf('%s%s%s.%s', ...
0169       src_data_dir, filesep, act_ch_list{i_ch}, file_ext);
0170 
0171     fid = fopen(src_datafile, 'r');
0172     if fid < 0
0173       error('(%s)cannot open : %s', func_, src_datafile); 
0174     end
0175 
0176     % ----- status channel check
0177     if strcmp(act_ch_list{i_ch}, STATUS_CH_LABEL)
0178       status_ch = true;
0179       data_size = STATUS_BIN_DATA_SIZE;
0180     else
0181       status_ch = false;
0182       data_size = STANDARD_BIN_DATA_SIZE;
0183     end
0184 
0185     if VERBOSE, fprintf('  --- read channel: ''%s''\n', act_ch_list{i_ch}); end
0186 
0187     % ----- read data according to n_trial
0188     ch_data = fread(fid, inf, act_data_type{i_ch});
0189     fclose(fid);
0190 
0191     if n_trial == 1
0192       % --- continuous data
0193 
0194       for i_trial = 1:n_trial_new
0195         sample_from = target_sample(i_trial, 1);
0196         sample_to   = target_sample(i_trial, 2);
0197         sample_idx  = sample_from:sample_to;
0198 
0199         this_eeg = ch_data(sample_idx);
0200 
0201         % converting to phisical value is done when importing
0202         eeg_data(i_ch,:,i_trial) = this_eeg;
0203       end
0204 
0205     else
0206       % --- chopped trial data
0207       org_ch_data = reshape(ch_data, n_sample, n_trial);
0208       
0209       % --- target_sample expected to be [1 x 2]
0210       sample_from = target_sample(1,1);
0211       sample_to   = target_sample(1,2);
0212       sample_idx  = sample_from:sample_to;
0213       eeg_data(i_ch,:,:) = org_ch_data(sample_idx, tr_list);
0214     end
0215   
0216     if VERBOSE
0217       fprintf(' ------------------------------------------------------\n');
0218     end
0219   end % channel loop
0220 
0221   
0222 else  % internal data is not empty
0223 
0224   % --- INTERNAL
0225   n_trial = vb_info_get_Nrepeat(old_eeginfo);
0226   if n_trial == 1
0227     % continuous data
0228     n_trial_new = size(target_sample, 1);
0229 
0230     % --- chop to make trial data
0231     for i_trial = 1:n_trial_new
0232       sample_idx = target_sample(i_trial,1):target_sample(i_trial,2);
0233       eeg_data(:,:,i_trial) = internal_data(act_idx, sample_idx);
0234     end
0235 
0236   else
0237     % chopped data
0238     sample_idx = target_sample(1,1):target_sample(1,2);
0239     eeg_data = internal_data(act_idx, sample_idx, tr_list);
0240   end
0241 end % data is external or internal
0242 
0243 %
0244 % --- update EEGinfo
0245 %
0246 EEGinfo = old_eeginfo;
0247 
0248 EEGinfo.ChannelID = old_eeginfo.ChannelID(eeg_idx);
0249 EEGinfo.ChannelName = eeg_ch_list;
0250 EEGinfo.Nchannel = length(eeg_idx);
0251   
0252 % ----- sensor position
0253 old_sensor_pos = vb_eeginfo_get_sensor_position(EEGinfo);
0254 if ~isempty(old_sensor_pos)
0255   EEGinfo = vb_eeginfo_set_sensor_position(EEGinfo, old_sensor_pos(eeg_idx,:));
0256 end
0257   
0258 % ----- data type of each sensor
0259 EEGinfo.DataType = EEGinfo.DataType(act_idx);
0260     
0261 % ----- sample information
0262 EEGinfo.Nsample = n_sample_new;
0263 EEGinfo.RecordTime = EEGinfo.Nsample / EEGinfo.SampleFrequency;
0264 
0265 % ----- ExtraChannelInfo
0266 old_exinfo = vb_info_get_channel_info(old_eeginfo, 1);
0267 new_exinfo.Channel_active = old_exinfo.Active(ext_idx);
0268 new_exinfo.Channel_name   = old_exinfo.Name(ext_idx);
0269 new_exinfo.Channel_id     = old_exinfo.ID(ext_idx);
0270 
0271 if isempty(old_exinfo.Type)
0272   new_exinfo.Channel_type   = ones(length(ext_idx), 1);
0273 else
0274   new_exinfo.Channel_type   = old_exinfo.Type(ext_idx);
0275 end
0276 
0277 EEGinfo.ExtraChannelInfo = new_exinfo;
0278 
0279 % --- EEGinfo.Trial
0280 if ~isempty(loadspec.TrialNumber)
0281   % --- chopped trial --> narrowed down chopped trial
0282   old_trial = vb_info_get_trial_data(EEGinfo, loadspec.TrialNumber);
0283 
0284   sample_idx = target_sample(1,1):target_sample(1,2);
0285 
0286   for i_trial = 1:length(old_trial)
0287     new_trial(i_trial) = old_trial(i_trial);
0288     
0289     % --- update only sample
0290     sample_old = old_trial(i_trial).sample;
0291     new_trial(i_trial).sample = sample_old(sample_idx);
0292   end
0293 
0294 else
0295   old_trial = vb_info_get_trial_data(EEGinfo);
0296   n_trial_old = length(old_trial);
0297 
0298   if n_trial_old == 1
0299     % --- continuous --> chopped trial or continuous
0300     n_trial_new = size(target_sample, 1);
0301     for i_trial = 1:n_trial_new
0302       sample_idx = target_sample(i_trial,1):target_sample(i_trial,2);
0303       new_trial(i_trial).sample = sample_idx;
0304       new_trial(i_trial).number = i_trial;
0305       new_trial(i_trial).Active = true;
0306     end
0307   else
0308     % --- chopped trial --> narrowed down chopped trial
0309     sample_idx = target_sample(1,1):target_sample(1,2);
0310 
0311     for i_trial = length(old_trial)
0312       new_trial(i_trial) = old_trial(i_trial);
0313     
0314       % --- update only sample
0315       sample_old = old_trial(i_trial).sample;
0316       new_trial(i_trial).sample = sample_old(sample_idx);
0317     end
0318   end
0319 end
0320 % [N x 1]
0321 EEGinfo.Trial = vb_util_arrange_list(new_trial, 0);
0322 
0323 EEGinfo = vb_info_adjust_trial(EEGinfo);
0324 
0325 % ----- Pretrigger
0326 if ~isempty(loadspec.Pretrigger)
0327   EEGinfo = vb_info_set_pre_trigger(EEGinfo, loadspec.Pretrigger);
0328 end
0329 
0330 % ----- new ActiveChannel
0331 old_active_channel = vb_info_get_active_channel(old_eeginfo);
0332 new_ActiveChannel = old_active_channel(eeg_idx);
0333 EEGinfo = vb_info_set_active_channel(EEGinfo, new_ActiveChannel);
0334   
0335 % ----- EEGinfo.ChannelInfo
0336 %   .Active [Nchannel x 1]
0337 %   .Name   [Nchannel x 1]
0338 %   .Type   [Nchannel x 1]
0339 %   .ID     [Nchannel x 1]
0340 eeg_channel_info = ...
0341   vb_eeginfo_make_channel_info(EEGinfo, loadspec.ChannelName, 1);
0342 EEGinfo.ChannelInfo = eeg_channel_info;
0343 
0344 % --- channel_info as a return value
0345 channel_info = vb_eeginfo_make_channel_info(EEGinfo, loadspec.ChannelName, 0);
0346 
0347 if ~isempty(newfile)
0348   % --- make new file
0349 
0350   ParentInfo = inner_make_parent_info(eegfile);
0351   % ----- create new EEG-MAT file
0352   Measurement = 'EEG';
0353   if VERBOSE
0354     fprintf(' --- now on saving to new EEG-MAT file : %s ...', newfile);
0355   end
0356 
0357   % --- file data
0358   if ~isfield(loadspec, 'new_data_dir') || isempty(loadspec.new_data_dir)
0359     data_in = true;
0360   else
0361     data_in = false;
0362   end
0363   
0364   EEGinfo.File.BaseFile  = eegfile;
0365   EEGinfo.File.OutputDir = loadspec.new_path;
0366   EEGinfo.File.EEGFile   = loadspec.new_name;
0367   EEGinfo.File.DataDir   = loadspec.bin_data_dir;
0368 
0369   loadspec = inner_remove_temporary_fields(loadspec);
0370   LoadSpec = loadspec;
0371 
0372   if data_in
0373     % --- The data is stored inside of EEG-MAT file.
0374     vb_fsave(newfile, ...
0375       'eeg_data', 'EEGinfo', 'Measurement', 'ParentInfo', 'LoadSpec');
0376   else
0377     % --- The data is stored outside of EEG-MAT file.
0378     vb_fsave(newfile, ...
0379       'EEGinfo', 'Measurement', 'ParentInfo', 'LoadSpec');
0380 
0381     dst_data_dir = loadspec.new_data_dir;
0382     for i_ch = 1:n_channel_new
0383       inner_store_data_externally( dst_data_dir, ...
0384         act_ch_list{i_ch}, eeg_data(i_ch,:), act_data_type{i_ch}, file_ext)
0385     end
0386   end
0387   
0388   if VERBOSE
0389     fprintf(' done!\n');
0390   end
0391 end
0392 
0393 return;
0394 %
0395 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0396 
0397 
0398 % --- INNER FUNCTIONS -------------------------------------------------------- %
0399 %
0400 % --- inner_check_arguments()
0401 %
0402 function [eegfile, loadspec, newfile, ...
0403   read_ch_list, target_samples, trial_list, ...
0404   eegfile_dir, verbose_swt] = ...
0405     inner_check_arguments(eegfile, loadspec, newfile, verbose_swt)
0406 
0407 func_ = mfilename;
0408 
0409 if isempty(eegfile)
0410   error('(%s)eegfile is a required parameter', func_);
0411 end
0412 
0413 if exist(eegfile, 'file') ~= 2
0414   error('(%s)cannot find eegfile: %s', func_, eegfile);
0415 end
0416 
0417 eegfile_dir = vb_get_file_parts(eegfile);
0418 
0419 % eeg_data = [];
0420 
0421 % ----- set default values for loadspec
0422 loadspec = vb_loadspec_check(loadspec, eegfile);
0423 
0424 % ----- narrow channel by user-specified list and active filter
0425 eeginfo = vb_eegfile_load_eeginfo(eegfile);
0426 [read_ch_list] = vb_eeginfo_get_read_channels(eeginfo, ...
0427   loadspec.ChannelName, loadspec.ChannelSwitch, loadspec.ActiveChannel);
0428 
0429 if isempty(read_ch_list)
0430   error('(%s) read channels are empty', func_);
0431 end
0432 % ------- reset channel spec in loadspec
0433 loadspec.ChannelName = read_ch_list;
0434 loadspec.ChannelSwitch = true;
0435 
0436 target_samples = vb_loadspec_make_trial_sample(loadspec);
0437 if isempty(target_samples)
0438   n_sample = vb_info_get_sample_number(eeginfo);
0439   target_samples = [1 n_sample];
0440 end
0441 
0442 % ----- check TrialNumber
0443 N_trial = vb_info_get_Nrepeat(eeginfo);
0444 if N_trial == 1
0445   trial_list = [];
0446 else
0447   % --- trigger info
0448   if size(target_samples, 1) > 1
0449     fprintf('(%s) loadspec.Trigger may be wrong\n', mfilename);
0450     target_samples = target_samples(1,:);
0451   end
0452   
0453   if isempty(loadspec.TrialNumber)
0454     cur_trial = vb_info_get_trial_data(eeginfo);
0455   else
0456     cur_trial = vb_info_get_trial_data(eeginfo, loadspec.TrialNumber);
0457   end
0458 
0459   trial_list = [cur_trial.number];
0460 
0461   if loadspec.ActiveTrial
0462     active_list = [cur_trial.Active];
0463     trial_list = trial_list(active_list==true);
0464   end
0465 end
0466 loadspec.TrialNumber = trial_list;
0467 
0468 % % ------- valid trial
0469 % if vb_info_active_trial_is_valid(eeginfo) && loadspec.ActiveTrial
0470 %   active_idx = vb_info_get_active_trial_index(eeginfo);
0471 %   trial_list = vb_info_get_trial_list(eeginfo);
0472 %   if ~isfield(loadspec, 'TrialNumber') || isempty(loadspec.TrialNumber)
0473 %     loadspec.TrialNumber = trial_list(active_idx);
0474 %   else
0475 %     idx = vb_util_get_index(loadspec.TrialNumber, active_idx);
0476 %     loadspec.TrialNumber = loadspec.TrialNumber(idx);
0477 %   end
0478 % else
0479 %   % It may not have to do anything
0480 % end
0481 
0482 if ~isempty(newfile)
0483   [new_path, new_name] = vb_get_file_parts(newfile);
0484 
0485   if ~isempty(new_path) && exist(new_path, 'dir') ~= 7
0486     vb_mkdir(new_path);
0487   end
0488 
0489   loadspec.new_path = new_path;
0490   loadspec.new_name = new_name;
0491   
0492   if ~isfield(loadspec, 'bin_data_dir') || isempty(loadspec.bin_data_dir)
0493     % --- if loadspec.bin_data_dir is invalid, store data inside.
0494     loadspec.bin_data_dir = '';
0495     new_data_dir = '';
0496   else
0497     new_data_dir = [new_path '/' loadspec.bin_data_dir];
0498   end
0499   
0500   if ~isempty(new_data_dir) && exist(new_data_dir, 'dir') ~= 7
0501     vb_mkdir(new_data_dir);
0502   end
0503   loadspec.new_data_dir = new_data_dir;
0504 end
0505 
0506 if isempty(verbose_swt)
0507 %   verbose_swt = true;
0508   verbose_swt = false;
0509 end
0510 return;
0511 %
0512 % --- end of inner_check_arguments()
0513 
0514 % --- inner_make_parent_info()
0515 %
0516 function parent_info = inner_make_parent_info(eegfile)
0517 tmp_eeg = load(eegfile);
0518 parent_info.EEGinfo = tmp_eeg.EEGinfo;
0519 if isfield(tmp_eeg, 'ParentInfo')
0520   parent_info.ParentInfo = tmp_eeg.ParentInfo;
0521 end
0522 if isfield(tmp_eeg, 'LoadSpec')
0523   parent_info.LoadSpec = tmp_eeg.LoadSpec;
0524 end
0525 return;
0526 %
0527 % --- end of inner_make_parent_info()
0528 
0529 
0530 % --- inner_store_data_externally()
0531 %
0532 function inner_store_data_externally(data_dir, ch_name, cur_data, d_type, f_ext)
0533 
0534 datafile = sprintf('%s%s%s.%s', data_dir, filesep, ch_name, f_ext);
0535 cur_fid = fopen(datafile, 'wb');
0536 if cur_fid == -1
0537   error('(%s)cannot open file (%s)', mfilename, datafile);
0538 end
0539 
0540 fwrite(cur_fid, cur_data, d_type);
0541 fclose(cur_fid);
0542 % fprintf('--- %s\n', datafile);
0543 return;
0544 %
0545 % --- end of inner_store_data_externally
0546 
0547 % --- inner_remove_temporary_fields()
0548 %
0549 function loadspec = inner_remove_temporary_fields(loadspec)
0550 target_field{1} = 'new_path';
0551 target_field{2} = 'new_name';
0552 target_field{3} = 'new_data_dir';
0553 
0554 for i_field = 1:length(target_field)
0555   if isfield(loadspec, target_field{i_field})
0556     loadspec = rmfield(loadspec, target_field{i_field});
0557   end
0558 end
0559 
0560 return;
0561 %
0562 % --- end of inner_remove_temporary_fields()
0563 
0564 %
0565 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0566 
0567 % --- END OF FILE --- %

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