0001 function [data_dir, filenames] = vb_saver_cmn_make_binary_file(proc_spec)
0002
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 if ~exist('proc_spec', 'var'), proc_spec = []; end
0033 [proc_spec] = inner_check_arguments(proc_spec);
0034
0035
0036
0037 n_ch = size(proc_spec.data, 1);
0038 data_dir = proc_spec.dir;
0039 filenames = cell(1, n_ch);
0040
0041 for i_ch = 1:n_ch
0042
0043 filename = sprintf('%s%s', proc_spec.ch_label{i_ch}, proc_spec.ext);
0044 new_file = sprintf('%s/%s', data_dir, filename);
0045 fid = fopen(new_file, 'wb');
0046 if fid == -1
0047 warining('(%s) cannot open file : %s\n', mfilename, new_file);
0048 continue;
0049 end
0050 fwrite(fid, proc_spec.data(i_ch, :), proc_spec.precision);
0051 fclose(fid);
0052
0053 filenames{i_ch} = filename;
0054 end
0055
0056 return
0057
0058 end
0059
0060
0061
0062
0063
0064
0065
0066 function [proc_spec] = inner_check_arguments(proc_spec)
0067 func_ = mfilename;
0068
0069
0070 if isempty(proc_spec)
0071 error('(%s) proc_spec is a required parameter', func_);
0072 end
0073
0074
0075 if ~isfield(proc_spec, 'data') || isempty(proc_spec.data)
0076 error('(%s) proc_spec.data is a required field', func_);
0077 end
0078
0079
0080 if ~isfield(proc_spec, 'ch_label') || isempty(proc_spec.ch_label)
0081 error('(%s) proc_spec.ch_label is a required field', func_);
0082 end
0083
0084 if ~iscell(proc_spec.ch_label)
0085 proc_spec.ch_label = {proc_spec.ch_label};
0086 end
0087
0088 n_ch_data = size(proc_spec.data, 1);
0089 n_ch_label = length(proc_spec.ch_label);
0090
0091 if n_ch_data ~= n_ch_label
0092 error('(%s) the number of channel must be the same data and ch_label', ...
0093 func_);
0094 end
0095
0096
0097 if ~isfield(proc_spec, 'dir') || isempty(proc_spec.dir)
0098 error('(%s) proc_spec.dir is a required field', func_);
0099 end
0100
0101
0102 if ~isfield(proc_spec, 'precision') || isempty(proc_spec.precision)
0103 error('(%s) proc_spec.precision is a required parameter', func_);
0104 end
0105
0106
0107 if ~isfield(proc_spec, 'ext') || isempty(proc_spec.ext)
0108 error('(%s) proc_spec.ext is a required parameter', func_);
0109 end
0110
0111 if proc_spec.ext(1) ~= '.'
0112 proc_spec.ext = ['.' proc_spec.ext];
0113 end
0114
0115 if exist(proc_spec.dir, 'dir') ~= 7
0116 fprintf('(%s) make directory : %s\n', func_, proc_spec.dir);
0117 mkdir(proc_spec.dir);
0118 end
0119 return
0120 end
0121
0122
0123
0124
0125
0126
0127