3 %> @brief Merges several
"Pirouette .dat" files into a dataset
5 %> @c data.groupcodes is made from file name. File name is trimmed at the trimdot-th dot counted from right to left. E.g.,
6 %> This allows one to trim
"sample.0.dat" at the penultimate dot (ignodedoctount=2) or "sample.dat" at the last dot
9 %> data.obsnames will contain the file names
11 %> For reference on parameters, please check @ref mergetool.m
16 %> @param trimdot See pirtool
20 function [data, flag_error] =
pir2data(wild, trimdot, flag_image, height)
22 if ~exist('trimdot', 'var')
26 [filenames, groupcodes] =
resolve_dir(wild, trimdot, flag_image);
28 no_files = length(filenames);
31 if no_files/height ~= floor(no_files/height)
32 irerror('Pir2Data: Invalid image height!');
37 idxs = find(wild == '/');
41 path_ = wild(1:idxs(end));
51 filename = fullfile(path_, filenames{i});
54 h = fopen(filename,
'r');
56 irerror(sprintf(
'Pir2Data: Could not open file ''%s''!', filename));
60 fprintf(
'%d/%d: %s ...\n', i, no_files, filenames{i});
69 if isnumeric(s) && s == -1 % EOF
84 if flag_wns && ~flag_wants_wns
85 irerror(sprintf(
'Pir2Data: Found wavenumbers specification but expecting something else in file ''%s''!', filenames{i}));
87 if flag_point && ~flag_wants_point
88 irerror(sprintf(
'Pir2Data: Found y-value but expecting something else in file ''%s''!', filenames{i}));
93 wns = eval([
'[' s(4:end)
']']);
95 nf = length(wns_global);
101 cnt_point = cnt_point+1;
102 x(cnt_point) = eval(s);
109 irerror(
'Pir2Data: Wavenumbers specification not found in file ''%s''!', filenames{i});
114 % Initializes dataset
if first row
115 data.X = zeros(no_files, nf);
116 data.classes = zeros(no_files, 1);
117 data.obsnames = cell(no_files, 1);
118 data.groupcodes = cell(no_files, 1);
120 data.classlabels = {
'Class 0'};
126 data.classes(ii) = 0;
127 data.obsnames{ii} = filenames{i};
128 data.groupcodes{ii} = groupcodes{i};
130 irerror(
'Pir2Data: Wrong number of data points in file ''%s''!', filenames{i});
139 cnt_error = cnt_error+1;
140 errors{end+1} = filename;
148 irverbose(sprintf(
'NOTICE: only %d/%d files were successfully read. Import failed on following files:', no_files-cnt_error, no_files));
152 flag_error = cnt_error;
154 data.X = data.X(1:ii, :);
155 data.classes = data.classes(1:ii, :);
156 data.obsnames = data.obsnames(1:ii, :);
157 data.groupcodes = data.groupcodes(1:ii, :);
162 data.height = height;
function irverbose(in s, in level)
function progress2_change(in prgrss, in title, in perc, in i, in n)
function progress2_open(in title, in perc, in i, in n)
function resolve_dir(in wild, in trimdot, in flag_image)
function pir2data(in wild, in trimdot, in flag_image, in height)
function progress2_close(in prgrss)