Skip to content
Snippets Groups Projects
Commit aa77f069 authored by Laura Nervo's avatar Laura Nervo Committed by Nicola Vigano
Browse files

Forward Simulation : formatting (remove sprintf with strings) and change...

Forward Simulation : formatting (remove sprintf with strings) and change gtFsimCheckMissingGrains output, differing missing grains and old grains.

Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@759 4c865b51-4357-4376-afb4-474e03ccb993
parent 1cab765c
No related branches found
No related tags found
No related merge requests found
......@@ -7,82 +7,82 @@ function missing = gtFsimCheckMissingGrains(phase_num)
%
% OUTPUT:
% missing = structure with:
% ind = grainid of missing grain from
% ForwardSimulation
% is_grain = for each grain true if grain_[id].mat
% exists
% is_grain_r = is_grain reshaped as
% [nof_grain_per_job,njobs]
% ind = grainid of missing grain from
% ForwardSimulation
% is_grain = for each grain true if grain_[id].mat
% exists
% is_uptodate = true if date(grain_####.mat) >= date(last job
% submitted to OAR)
% get number of jobs for that functions from OAR
arrays=logviewOar('gtForwardSimulate_v2',[],false);
% if ~isempty(arrays.fname)
% if ~isempty(arrays.('gtForwardSimulate_v2').logs)
% filename = arrays.('gtForwardSimulate_v2').logs;
% [~,njobs] = unix(['grep "njobs" ' filename ' | awk -F" = " ''{print $2}''']);
% nof_jobs = str2double(njobs);
% end
% else
nof_jobs = 1;
% get last gtForwardSimulate_v2 run date from oar.log file
fid = fopen('oar.log');
o=textscan(fid,'%s %s %d %s %s');
fclose(fid);
datemax=max(datenum(o{4}(:)));
% end
% get last gtForwardSimulate_v2 run date from oar.log file
o=fileread('oar.log');
o2=textscan(o,'%s %s %d %s %s');
datemax=max(datenum(o2{4}(:)));
grain=[];
load(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],'index.mat' ),'grain');
% total number of grains
nof_grains = length(grain);
count=[];
list_grains=dir(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],'grain_*.mat'));
for i=1:length(list_grains)
num = str2double(list_grains(i).name(7:10));
if datenum(list_grains(i).date,'dd-mmm-yyyy')>=datemax
count(num) = true;
for ii=1:length(list_grains)
if datenum(list_grains(ii).date,'dd-mmm-yyyy')>=datemax
is_uptodate(ii) = true;
else
count(num) = false;
is_uptodate(ii) = false;
end
end
nof_grains_fsim = length(list_grains);
grain=load(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],'index.mat' ),'grain');
grain=grain.grain;
% total number of grains
nof_grains = length(grain);
% is_grain contains true if grain_#.mat exists, false if doesn't exist
is_grain=[];
for i=1:nof_grains
if exist(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],['grain_' sprintf('%04d.mat',i)] ),'file')
if count(i)
is_grain(i) = true;
else
disp(['grain # ' num2str(i) ' may not be updated'])
is_grain(i) = false;
end
for ii = 1: nof_grains
if exist(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],sprintf('grain_%04d.mat',ii)),'file')
is_grain(ii) = true;
else
is_grain(i) = false;
disp(['grain # ' num2str(ii) ' does not exist.'])
is_grain(ii) = false;
end
end
% grains per each job
grains = ceil(nof_grains/nof_jobs);
% fill with NaN to have exact division of nof_grains by nof_jobs
tot_n = nof_jobs * grains;
is_grain(nof_grains+1:tot_n)=NaN;
% grain number of missing files
ind=find(is_grain==0);
missing.ind = find(is_grain==false);
missing.is_grain = is_grain;
missing.old = find(is_uptodate==false);
missing.is_uptodate = is_uptodate;
if nof_grains ~= nof_grains_fsim
disp('Check number of grains from forward simulation: it differs from the total number of grains from INDEXTER')
disp(['Indexter : ' num2str(nof_grains)])
disp(['Forward Simulation : ' num2str(nof_grains_fsim)])
disp(['There should be ' num2str(nof_grains_fsim - nof_grains) ' grains to be removed. Run the following commands:'])
for ii=missing.old(1):missing.old(end)
if ii > nof_grains && ii <= nof_grains_fsim
disp([' delete( ''' fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],sprintf('grain_%04d.mat',ii)) ''' )'])
end
end
end
% reshape is_grain to have in each column each job status
% column = job number, row = grain number for that job
is_grain_r = reshape(is_grain,tot_n/nof_jobs,nof_jobs);
% check id in grain_####.mat
checkId_fsim = [];
for kk=1:nof_grains_fsim
load(fullfile( '4_grains',['phase_' sprintf('%02d',phase_num)],sprintf('grain_%04d.mat',kk)),'id');
check = [kk id];
if kk ~= id
checkId_fsim{end+1} = check;
end
end
missing.ind = ind;
missing.is_grain = is_grain;
missing.is_grain_r = is_grain_r;
checkId = [];
for ii=1:nof_grains
check = [ii grain{ii}.id];
if ii ~= grain{ii}.id
checkId{end+1} = check;
end
end
missing.checkFsim = cell2mat(checkId_fsim');
missing.checkIndex = cell2mat(checkId');
clear grain
......
function gtSetupForwardSimulation
% simple helper function to run gtForwardSimulate
% whatever the current version is ;-)
function gtSetupForwardSimulation()
% GTSETUPFORWARDSIMULATION Simple helper function to run gtForwardSimulate_v2
% gtSetupForwardSimulation()
% --------------------------
parameters = [];
......@@ -23,42 +24,45 @@ end
phaseID_str = sprintf('%02d',phaseID);
disp(['Setting up Forward Simulation for phase ' phaseID_str ' ' parameters.cryst(phaseID).name]);
filetable = sprintf('%s_filetable', parameters.acq.name);
% get the latest version of indexter output
grain = [];
filetable = [parameters.acq.name '_filetable'];
% get the latest version of indexter output
ngrains = [];
for ii = 1 : nof_phases
filename = fullfile(parameters.acq.dir, '4_grains', sprintf('phase_%02d', ii), 'index.mat');
load(filename, 'grain');
grain = [];
index_filename = fullfile(parameters.acq.dir, '4_grains', sprintf('phase_%02d',ii), 'index.mat');
load(index_filename, 'grain');
% how many grains in this dataset?
ngrains(ii) = length(grain);
end
%create / reset sample.mat spot2grain.mat
filename = fullfile(parameters.acq.dir, '4_grains', 'sample.mat');
if exist(filename, 'file') && (nof_phases > 1)
sample = GtSample.loadFromFile(filename); % do not create from scratch - we want to keep information related to other phases
% create / reset sample.mat spot2grain.mat
sample_filename = fullfile(parameters.acq.dir, '4_grains', 'sample.mat');
if ( exist(sample_filename, 'file') && nof_phases > 1 )
sample = GtSample.loadFromFile(sample_filename); % do not create from scratch - we want to keep information related to other phases
else
sample = GtSample(nof_phases);
sample.fileTable = sprintf('%s_filetable',parameters.acq.name);
sample.fileTable = [parameters.acq.name '_filetable'];
for ii = 1 : nof_phases
phase = GtPhase(parameters.cryst(ii).name, ngrains(ii));
sample.phases{ii} = phase;
end
save(filename, 'sample');
save(sample_filename, 'sample');
end
disp(['Reset phase number ' num2str(phaseID) ' in the sample.mat:'])
disp(['Name : ' parameters.cryst(phaseID).name])
disp(['nof_grains: ' num2str(ngrains(phaseID))])
disp(['Reset phase number ' phaseID_str ' in the sample.mat:'])
disp([' Phase name : ' parameters.cryst(phaseID).name])
disp([' Nof_grains : ' num2str(ngrains(phaseID))])
% check number of grain_####.mat :
missing = gtFsimCheckMissingGrains(phaseID);
filename = fullfile(parameters.acq.dir,'4_grains','spot2grain.mat');
difspot_num = mym(sprintf('select count(*) from %sdifspot', parameters.acq.name));
difspot_num = mym(['select count(*) from ' parameters.acq.name 'difspot']);
if exist(filename, 'file') && nof_phases>1
if ( exist(filename, 'file') && nof_phases > 1 )
check = inputwdefault('Do you want to reset spot2grain? [y/n]', 'n');
if ~strcmpi(check, 'y')
spot2grain = cell(difspot_num, 1); % cell array linking difspots with grainids
......@@ -75,7 +79,7 @@ check = inputwdefault('Use default parameters? [y/n]', 'y');
if ~strcmpi(check, 'y')
list = build_list_v2();
parameters.fsim = gtModifyStructure(parameters.fsim, list.fsim(:, 1:2));
save([parameters.acq.dir '/parameters.mat'],'parameters');
save(fullfile(parameters.acq.dir,'parameters.mat'),'parameters');
end
% launch forward simulation process to OAR - split to two jobs
......@@ -95,13 +99,12 @@ if strcmpi(check, 'y')
OAR_list{1,1}='njobs'; OAR_list{1,2}='How many OAR jobs?';
OAR_list{2,1}='walltime'; OAR_list{2,2}='Walltime for OAR jobs (hh:mm:ss)';
OAR_parameters=gtModifyStructure(OAR_parameters, OAR_list, 'Parameters for OAR');
OAR_parameters = gtModifyStructure(OAR_parameters, OAR_list, 'Parameters for OAR');
OAR_make('gtForwardSimulate_v2', 1, ngrains(phaseID), OAR_parameters.njobs, ...
[parameters.acq.dir ' ' num2str(phaseID)], true, ...
[parameters.acq.dir ' ' phaseID_str], true, ...
'walltime', OAR_parameters.walltime);
else
gtForwardSimulate_v2(1, ngrains(phaseID), pwd, phaseID);
end
......
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