Skip to content
Snippets Groups Projects
Commit edbc5565 authored by Laura Nervo's avatar Laura Nervo
Browse files

Updated and generalized use of gtUpdateDifspotGrainIDs


Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 234e05c5
No related branches found
No related tags found
No related merge requests found
function gtUpdateDifspotGrainIDs(grain, parameters) function gtUpdateDifspotGrainIDs(table, variable, type, lastcolumn, queryname, queryvalues, values)
% GTUPDATEDIFSPOTIDS Updates table's column with values adding a new column
% gtUpdateDifspotGrainIDs(table, variable, type, lastcolumn, queryname, queryvalues, values)
% ------------------------------------------------------------------------------------------
% Adds/updates values to a specific set of rows in a table in the db
%
% Usage:
% for ii=1:length(dir('4_grains/phase_01/grain_*.mat'))
% gr{ii} = load(sprintf('4_grains/phase_01/grain_%04d.mat',ii),'difspotID');
% end
% difspotID = gtIndexAllGrainValues(gr, 'difspotID',[],[],[],false);
% gtUpdateDifspotGrainIDs([parameters.acq.name 'difspot'], 'grainID', 'int', 'integral', 'difspotID', difspotID, 1:length(gr))
%
% Version 002 08-11-2013 by LNervo
%if it doesn't already exist, we may need to add a grainid column to % if it doesn't already exist, we may need to add a grainid column to
%difspot table % difspot table
[a,b,c,d,e,f]=mym(sprintf('show columns from %sdifspot like "grainID"',parameters.acq.name));
[a,~,~,~,~,~]=mym(['SHOW COLUMNS FROM ' table ' LIKE "' variable '"']);
if isempty(a) if isempty(a)
%add the field %add the field
mym(sprintf('ALTER TABLE graintracking.%sdifspot ADD COLUMN grainID INT AFTER integral', parameters.acq.name)); mym(['ALTER TABLE graintracking.' table ' ADD COLUMN ' variable ' ' type ' AFTER ' lastcolumn]);
disp('adding grainID field to the difspot table') disp(['adding column ' variable ' to the ' table ' table'])
end end
%then loop through, updating according to the grain structure information
for i=1:length(grain) % then loop through, updating according to the grain structure information
disp(sprintf('doing grain %d', i)) for ii=1:length(queryvalues)
ids=grain{i}.difspots; fprintf('done %04d', values(ii))
for j=1:length(ids) ids = queryvalues{ii};
mysqlcmd=dbUpdate(sprintf('%sdifspot',parameters.acq.name),'difspotID',ids(j),'GrainID',i); for jj=1:length(ids)
mysqlcmd = gtDBUpdate(table, queryname, ids(jj), variable, values(ii));
mym(mysqlcmd); mym(mysqlcmd);
end end
fprintf('\b\b\b\b\b\b\b\b\b\b')
end end
disp(' ')
disp(['updated column ' variable ' from ' table ' table'])
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment