0001 function [data] = vb_meg_yokogawa_store_bin_channel(ykgwfile, ...
0002 meg_info, out_base, verbose_swt)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 if ~exist('ykgwfile', 'var'), ykgwfile = ''; end
0041 if ~exist('meg_info', 'var'), meg_info = []; end
0042 if ~exist('out_base', 'var'), out_base = ''; end
0043 if ~exist('verbose_swt', 'var'), verbose_swt = []; end
0044 [ykgwfile, meg_info, out_base, VERBOSE] = ...
0045 inner_check_arguments(ykgwfile, meg_info, out_base, verbose_swt);
0046
0047
0048
0049 const = vb_define_yokogawa;
0050 func_ = mfilename;
0051
0052 data = [];
0053
0054
0055 meg_ch_str = vb_meginfo_get_channel_label_meg(meg_info);
0056 ext_ch_str = vb_meginfo_get_channel_label_extra(meg_info);
0057 ref_ch_str = vb_meginfo_get_channel_label_refmg(meg_info);
0058 combined_ch_str = vb_meginfo_get_channel_label_whole(meg_info);
0059
0060
0061
0062
0063 Nch_meg = length(meg_ch_str);
0064 meg_ch = zeros(Nch_meg,1);
0065 for i_ch = 1:Nch_meg
0066 meg_ch(i_ch) = str2double(meg_ch_str(i_ch));
0067 end
0068
0069 Nch_ext = length(ext_ch_str);
0070 ext_ch = zeros(Nch_ext,1);
0071 for i_ch = 1:Nch_ext
0072 ext_ch(i_ch) = str2double(ext_ch_str(i_ch));
0073 end
0074
0075 Nch_ref = length(ref_ch_str);
0076 ref_ch = zeros(Nch_ref,1);
0077 for i_ch = 1:Nch_ref
0078 ref_ch(i_ch) = str2double(ref_ch_str(i_ch));
0079 end
0080
0081 Nch = length(combined_ch_str);
0082 combined_ch = zeros(Nch,1);
0083 for i_ch = 1:Nch
0084 combined_ch(i_ch) = str2double(combined_ch_str(i_ch));
0085 end
0086
0087
0088 Nchannel_meg = vb_meginfo_get_channel_number_meg(meg_info);
0089 Nchannel_ext = vb_meginfo_get_channel_number_extra(meg_info);
0090 Nchannel_ref = vb_meginfo_get_channel_number_refmg(meg_info);
0091 Nchannel_all = Nchannel_meg + Nchannel_ext + Nchannel_ref;
0092
0093
0094 Nsample = vb_meginfo_get_sample_number(meg_info);
0095
0096
0097 PRECISION = vb_meginfo_get_precision(meg_info);
0098
0099
0100 ch_file = cell(Nchannel_all,1);
0101
0102
0103 chf_fid = zeros(Nchannel_all,1);
0104
0105
0106
0107
0108
0109 data_dir = [out_base '/' vb_saveman_get_dir(meg_info.saveman)];
0110
0111
0112 for ic = 1:Nchannel_all
0113 ch_file{ic} = sprintf('%s%s%d.%s', ...
0114 data_dir, filesep, combined_ch(ic), const.EXT_CHANNEL_BIN);
0115
0116 chf_fid(ic) = fopen(ch_file{ic}, 'wb');
0117 if chf_fid(ic) == -1
0118 error('(%s)cannot open file (%s)', func_, ch_file{ic});
0119 end
0120 end
0121
0122 if VERBOSE
0123 fprintf('opening channel file (%d) done.\n', Nchannel_all);
0124 end
0125
0126 AD_label = 0:Nchannel_all-1;
0127
0128
0129
0130
0131
0132
0133 MemoryMax = meg_info.memory_max;
0134
0135 Nblock = fix(MemoryMax/Nchannel_all);
0136
0137 acq_type = vb_meginfo_get_acqtype(meg_info);
0138
0139
0140 block = zeros(Nchannel_all, Nblock+1);
0141
0142
0143 nstart = 0;
0144
0145 if VERBOSE
0146 digit_num = vb_util_get_digit_number(Nsample);
0147 MSG_LEN = inner_print_progress(nstart, Nsample, digit_num);
0148 end
0149
0150 if strcmp(acq_type, 'Continuous_Raw') || strcmp(acq_type, 'Evoked_Ave')
0151 while nstart < Nsample
0152 ndata = nstart + Nblock;
0153 if ndata > Nsample
0154 if nstart == 0
0155 Nblock = Nsample;
0156 else
0157 Nblock = Nsample - nstart;
0158 end
0159 end
0160
0161 block = getYkgwData(ykgwfile, nstart, Nblock);
0162
0163
0164 nstart = nstart + Nblock;
0165
0166 for ic = 1:Nchannel_all
0167
0168 CUR_CH = combined_ch(ic);
0169
0170 block_idx = CUR_CH == AD_label(:);
0171 my_data = block(block_idx,:);
0172
0173 fwrite(chf_fid(ic), my_data(:), PRECISION);
0174 end
0175
0176
0177 if VERBOSE
0178 for ib = 1:MSG_LEN
0179 fprintf('\b');
0180 end
0181 inner_print_progress(nstart, Nsample, digit_num);
0182 end
0183 end
0184
0185 elseif strcmp(acq_type, 'Evoked_Raw')
0186 Ntrial = vb_info_get_trial_number(meg_info);
0187
0188 if VERBOSE, n_line = 1; end
0189
0190
0191 for i_trial = 1:Ntrial
0192 block = getYkgwData(ykgwfile, i_trial, 1);
0193
0194
0195 for i_ch = 1:Nchannel_all
0196
0197 CUR_CH = combined_ch(i_ch);
0198 block_idx = CUR_CH == AD_label(:);
0199
0200 my_data = block(block_idx,:);
0201 fwrite(chf_fid(i_ch), my_data(:), PRECISION);
0202 end
0203
0204 if VERBOSE
0205 fprintf('.');
0206 if (i_trial/50) == n_line
0207 fprintf('[%d/%d]\n', i_trial, Ntrial);
0208 n_line = n_line + 1;
0209 end
0210 end
0211 end
0212
0213 else
0214 error('(%s) unknown acq_type : %s', mfilename, acq_type);
0215 end
0216
0217 if VERBOSE
0218 fprintf('\n');
0219 end
0220
0221 for ic = 1:Nchannel_all
0222 fclose(chf_fid(ic));
0223 end
0224
0225 return;
0226
0227
0228
0229
0230
0231
0232
0233
0234 function [ykgwfile, meg_info, out_base, verbose_swt] = ...
0235 inner_check_arguments(ykgwfile, meg_info, out_base, verbose_swt)
0236
0237 func_ = mfilename;
0238
0239 if isempty(ykgwfile)
0240 error('(%s) ykgwfile is a required parameter', func_);
0241 end
0242
0243 if isempty(meg_info)
0244 error('(%s) meg_info is a required parameter', func_);
0245 end
0246
0247 if isempty(out_base)
0248 error('(%s) out_base is a required parameter', func_);
0249 end
0250
0251 if isempty(verbose_swt)
0252 verbose_swt = true;
0253 end
0254 return;
0255
0256
0257
0258
0259
0260 function str_len = inner_print_progress(present_num, whole_num, digit_num)
0261
0262 cmd_tmp = sprintf('[%%0%dd / %%0%dd] (%%3d%%%%)', digit_num, digit_num);
0263 prog_rate = floor((present_num / whole_num) * 100);
0264 cmd_str = sprintf( ...
0265 'fprintf(''--- done : %s ...'', present_num, whole_num, prog_rate)', ...
0266 cmd_tmp);
0267 eval(cmd_str);
0268
0269
0270
0271 str_len = 4+7+5+digit_num*2+7+4;
0272 return;
0273
0274
0275
0276
0277
0278