From d12594598ee4e0be368c971245f0842af8c177da Mon Sep 17 00:00:00 2001 From: ThorBarRa Date: Sat, 9 May 2026 11:37:36 +0200 Subject: [PATCH] Changed selection rule. Now works not only with numbers, but with any text. Character that the name starts with are used to find matches now. --- beamtime/nappNorm.m | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/beamtime/nappNorm.m b/beamtime/nappNorm.m index c263e7e..a0f9c98 100644 --- a/beamtime/nappNorm.m +++ b/beamtime/nappNorm.m @@ -36,6 +36,7 @@ arguments options.range (1,:) double {mustBePositive} =[ ]; options.energyScale char {mustBeMember(options.energyScale, ... {'kinetic', 'binding'})} = 'kinetic' + options.spectrumNumberPrefixLength double {mustBePositive, mustBeInteger} = 7 end @@ -104,17 +105,17 @@ for i = 1:length(processIdx) bestRefRow = validRefs(minIdx); end case 'spectrumNumber' - % Extract the 4-digit number at the start of the name (e.g., '0033') - specNumStr = regexp(currName, '^\d{4}', 'match', 'once'); - if ~isempty(specNumStr) - % Find references that start with 'XXXX_' - searchPattern = [specNumStr, '_']; + % Use the first N characters of the name as the matching prefix + prefixLen = options.spectrumNumberPrefixLength; + if length(currName) >= prefixLen + searchPattern = currName(1:prefixLen); validRefs = refIdx(startsWith(DataTable.name(refIdx), searchPattern)); if ~isempty(validRefs) - bestRefRow = validRefs(1); % Take the first exact match + bestRefRow = validRefs(1); end else - warning('Row %d: Could not extract a 4-digit spectrum number from name "%s".', currRow, currName); + warning('Row %d: Name "%s" is shorter than the requested prefix length (%d). Skipping.', ... + currRow, currName, prefixLen); end % Validate we found a match @@ -221,9 +222,9 @@ for i = 1:length(processIdx) else [normFactor, MaxIdx] = max(DataTable.(options.tableVariable){bestRefRow}); if strcmpi(options.energyScale, 'kinetic') - fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.scientaEkin_eV{bestRefRow}(MaxIdx),normFactor ); + fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.scientaEkin_eV{bestRefRow}(MaxIdx),normFactor ); else - fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.bindingEnergy_eV{bestRefRow}(MaxIdx),normFactor ); + fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.bindingEnergy_eV{bestRefRow}(MaxIdx),normFactor ); end end @@ -284,9 +285,9 @@ for i = 1:length(processIdx) else [normFactor, MaxIdx] = max(DataTable.(options.tableVariable){bestRefRow}); if strcmpi(options.energyScale, 'kinetic') - fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.scientaEkin_eV{bestRefRow}(MaxIdx),normFactor ); + fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.scientaEkin_eV{bestRefRow}(MaxIdx),normFactor ); else - fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.bindingEnergy_eV{bestRefRow}(MaxIdx),normFactor ); + fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.bindingEnergy_eV{bestRefRow}(MaxIdx),normFactor ); end end if normFactor == 0, normFactor = 1; end % Protect against /0 @@ -352,11 +353,11 @@ for i = 1:length(processIdx) else [normFactor, MaxIdx] = max(DataTable.(options.tableVariable){bestRefRow}); - if strcmpi(options.energyScale, 'kinetic') + if strcmpi(options.energyScale, 'kinetic') fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.scientaEkin_eV{bestRefRow}(MaxIdx),normFactor ); - else + else fprintf('Norming %s with %s at %.1f eV: %.1e\n', DataTable.name{currRow}, DataTable.name{bestRefRow}, DataTable.bindingEnergy_eV{bestRefRow}(MaxIdx),normFactor ); - end + end end if normFactor == 0, normFactor = 1; end % Protect against /0 DataTable.spectrum_countsNorm{currRow} = yData ./ normFactor;