3 %> @brief Merges several OPUS binary 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] =
opus2data(wild, trimdot, flag_image, height)
25 [filenames, groupcodes] =
resolve_dir(wild, trimdot, flag_image);
27 no_files = length(filenames);
30 if no_files/height ~= floor(no_files/height)
31 irerror('Opus2Data: Invalid image height!');
36 path_ = fileparts(wild);
40 namestotry = {
'Ratio',
'RatioChanged',
'RatioAbsorption'};
41 idxs = 1:numel(namestotry);
50 filename = fullfile(path_, filenames{i});
51 flag_imported = 0; % whether file was imported successfully
54 for j = 1:numel(namestotry)
57 [Y, X] = ImportOpus(filename, namestotry{idxsnow(j)}); % Jake
's code is currently not closing the handle if it throws an exception
62 lastmsg = 'Although the file opened, the
import function returned empty
';
66 temp = idxsnow; % Makes priority to data block that was found in one file
68 idxsnow = [idxsnow(j), temp];
86 irverbose(sprintf('Not possible to read file %s. Last error message was
''%s
''', filename, lastmsg), 3);
87 if isa(lastME,
'MException')
90 cnt_error = cnt_error+1;
91 errors{end+1} = filename;
93 if length(Y) < numel(Y)
94 irverbose(sprintf('File "%s" has more than one spectrum', filename), 3);
95 cnt_error = cnt_error+1;
96 errors{end+1} = filename;
100 % Initializes dataset
if first row
105 data.X = zeros(no_files, nf);
106 data.classes = zeros(no_files, 1);
107 data.obsnames = cell(no_files, 1);
108 data.groupcodes = cell(no_files, 1);
109 data.classlabels = {
'Class 0'};
114 irverbose(sprintf(
'Wrong number of data points (%d) in file "%s" (should be %d)!', length(Y), filenames{i}, nf), 3);
122 data.classes(ii) = 0;
123 data.obsnames{ii} = filenames{i};
124 data.groupcodes{ii} = groupcodes{i};
135 irverbose(sprintf(
'NOTICE: only %d/%d files were successfully read. Import failed on following files:', no_files-cnt_error, no_files));
139 flag_error = cnt_error;
142 data.X = data.X(1:ii, :);
143 data.classes = data.classes(1:ii, :);
144 data.obsnames = data.obsnames(1:ii, :);
145 data.groupcodes = data.groupcodes(1:ii, :);
149 data.height = height;
function irverbose(in s, in level)
function progress2_change(in prgrss, in title, in perc, in i, in n)
function opus2data(in wild, in trimdot, in flag_image, in height)
function progress2_open(in title, in perc, in i, in n)
function resolve_dir(in wild, in trimdot, in flag_image)
function progress2_close(in prgrss)