function DataTable = addSampleNotes(DataTable,fileNumber,notesToAdd,dataMonth,dataYear,tableSelection) %addSampleNotes adds a sample description to the data % % FileList = addSampleNotes(FileList,44,'Ice with N2 and phenol in Ar (bad data)',2,2022); % % Input to this function are % % * the name of the data table, % * the file numbers of the SES scans to which the info should be added % * a text string describing the sample, % * the month and the year that the data was acquired % * optional: 'XPS' or 'NEXAFS' as last input argument to limit to either XPS data or NEXAFS % data % check if "sample" table variable (column) exist, if not add it existColumn = strcmp('sample',DataTable.Properties.VariableNames); if ~any(existColumn) DataTable.sample = cellstr(repmat(' ',size(DataTable,1),1)); end for ii = 1:length(fileNumber) if ~exist('tableSelection','var') % select the data tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii)))) & ... (month(DataTable.lastModifiedDatenum) == dataMonth) &... (year(DataTable.lastModifiedDatenum) == dataYear); else if matches(tableSelection,'XPS') % select the data tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii))) | startsWith(DataTable.name, sprintf('NAPP%04.0f',fileNumber(ii)))) & ... (month(DataTable.lastModifiedDatenum) == dataMonth) &... (year(DataTable.lastModifiedDatenum) == dataYear) &... (endsWith(DataTable.name, '.ibw')); elseif (matches(tableSelection,'NEXAFS') | matches(tableSelection,'.h5')) % select the data tmpMatch = (startsWith(DataTable.name, sprintf('%04.0f',fileNumber(ii)))) & ... (month(DataTable.lastModifiedDatenum) == dataMonth) &... (year(DataTable.lastModifiedDatenum) == dataYear)&... (endsWith(DataTable.name, '.h5')); end end % clear existing data (to prevent 2 entries per field) existColumn = strcmp('sample',DataTable.Properties.VariableNames); if any(existColumn) if ~isempty(DataTable(tmpMatch,:).sample) DataTable(tmpMatch,:).sample = cellstr(repmat(' ',size(DataTable(tmpMatch,:),1),1)); end end DataTable(tmpMatch,:).sample = cellstr(repmat(notesToAdd,size(DataTable(tmpMatch,:),1),1)); end end