Skip to content
Snippets Groups Projects
Commit 22d462d1 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Fixes and use of syntactic sugars.


Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@167 4c865b51-4357-4376-afb4-474e03ccb993
parent e6775b32
No related branches found
No related tags found
No related merge requests found
......@@ -114,38 +114,36 @@ while counter<100
end
%sort files by date order to copy in order
sfdates=[];
for n=1:length(sfiles)
sfdates(n)=sfiles(n).datenum;
end
[sfdates,i]=sort(sfdates);
[~,indx] = sort( {sfiles.('datenum')} );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% try to copy files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for n=1:length(sfiles)
sfname=sfiles(i(n)).name;
for n = 1:length(sfiles)
sfname = sfiles(indx(n)).name;
%check if sfname has already been taken by another condor job
test=0;
try
test=mym(sprintf('insert into %s (filename) values ("%s")', filetable, sfname));
test = mym(sprintf('insert into %s (filename) values ("%s")', filetable, sfname));
catch Mexc
gtPrintException(Mexc)
rethrow(Mexc)
end
if test==1 %no other job is copying this file, do copy
disp(sprintf('working on %s',sfname))
if test %no other job is copying this file, do copy
disp(['working on ' sfname])
if isfield(parameters.acq, 'interlaced_turns') && parameters.acq.interlaced_turns>0
%if using interlaced turns, may need some renaming
fnamein = fullfile(sourcedir, sfiles(i(n)).name);
newfname = sfRename(sfiles(i(n)).name); %determine how file should be renamed
fnamein = fullfile(sourcedir, sfiles(indx(n)).name);
newfname = sfRename(sfiles(indx(n)).name); %determine how file should be renamed
fnameout = fullfile(destdir, newfname);
fnameout_orig = fullfile(destdir_orig, sfiles(i(n)).name); %keep original data as collected
fnameout_orig = fullfile(destdir_orig, sfiles(indx(n)).name); %keep original data as collected
else %standard routine
fnamein = fullfile(sourcedir, sfiles(i(n)).name);
fnamein = fullfile(sourcedir, sfiles(indx(n)).name);
newfname = 1; %flag to do copy in this case
fnameout = fullfile(destdir, sfiles(i(n)).name);
fnameout_orig = fullfile(destdir_orig, sfiles(i(n)).name);
fnameout = fullfile(destdir, sfiles(indx(n)).name);
fnameout_orig = fullfile(destdir_orig, sfiles(indx(n)).name);
end
if ~isempty(newfname)
......
......@@ -82,11 +82,15 @@ disp('Can add other things that should be copied first')
% calculate how many jobs to launch
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%count files in source dir, nfiles
sfiles=dir([sourcedir '/*']);
cfiles=dir([destdir '/*']);
for n=1:length(cfiles)
cfnames{n}=cfiles(n).name;
end
sfiles = dir(fullfile(sourcedir, '*'));
cfiles = dir(fullfile(destdir, '*'));
% This can be quicker and faster:
cfnames = {cfiles.('name')};
% Slower and more tedious:
%for n = 1:length(cfiles)
% cfnames{n} = cfiles(n).name;
%end
n=1;
%go through the source list, remove directories, parameters.mat,
%and anything else already copied
......
......@@ -149,7 +149,7 @@ for ii=first_img:last_img
% % keep a record of the mean intensity
% mean_vals(ii+1)=gtImgMeanValue2(im(:,[1:prep.margin,end-prep.margin+1:end]));
%% check if we need ot update the reference images
% check if we need ot update the reference images
index1 = floor(ii/acq.refon)*acq.refon;
refname1 = fullfile(datadir, sprintf('refHST%04d.edf', index1) );
......@@ -157,7 +157,7 @@ for ii=first_img:last_img
if ( isfield(acq,'mono_tune') && acq.mono_tune ~= 0 ... % sabine if mono_tune
&& mod(ceil(ii/acq.refon)*acq.refon,acq.mono_tune) == 0 )
index2 = ceil(ii/acq.refon)*acq.refon-1;
index2 = max(0, index);
index2 = max(0, index2);
refname2 = fullfile(datadir, sprintf('refHST%04d.edf', index2));
else
index2 = ceil(ii/acq.refon)*acq.refon;
......
......@@ -26,17 +26,17 @@ function [img, varargout] = edf_read(filename, GT_bb, dispmes, info)
%% File Error Checking
if isempty(edfFile)
Mexc = MException('EDF:fileNotFound', ['Could not find ' filename]);
throw(Mexc)
throw(Mexc);
end
if edfFile.isdir == true
Mexc = MException('EDF:fileIsDirectory', [ filename ' is a directory instead of a file.']);
throw(Mexc)
throw(Mexc);
end
if edfFile.bytes == 0
Mexc = MException('EDF:fileIsEmpty', [ filename ' is an empty file.']);
throw(Mexc)
throw(Mexc);
end
% Let's read the header
......@@ -50,14 +50,14 @@ function [img, varargout] = edf_read(filename, GT_bb, dispmes, info)
else
if info.dim_3 > 1 && (exist('GT_bb','var') && ~isempty(GT_bb))
Mexc = MException('EDF:roiIn3d', 'Cannot use an ROI on 3D EDF file');
throw(Mexc)
throw(Mexc);
end
end
fid = fopen(filename,'r',info.byteorder);
if fid == -1
Mexc = MException('EDF:fileNotFound', ['Could not open ' fname]);
throw(Mexc)
throw(Mexc);
end
fseek(fid, info.headerlength, 'bof');
......@@ -101,7 +101,7 @@ function [img, varargout] = edf_read(filename, GT_bb, dispmes, info)
' Expected: ' num2str(dim_1*dim_2*info.dim_3) ...
', Got: ' num2str(count)];
Mexc = MException('EDF:fileCorrupted', report_string );
throw(Mexc)
throw(Mexc);
end
%% Let's reshape to the real format of the matrix
......
......@@ -17,7 +17,7 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
% and then from peter's pfWaitToRead(fname, bb, waitfortranslated)
% Modified by Nicola Vigano, 2011-2012, nicola.vigano@esrf.fr
%handle inputs
%% handle input
if ~exist('bb', 'var')
bb=[];
end
......@@ -28,18 +28,22 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
% disp(sprintf('waiting for images to have been translated %d times', waitfortranslated))
end
% wait for file to appear
%% wait for file to appear
if ~exist(fname,'file')
fprintf('Waiting for %s',fname);
seconds = 0;
fprintf('Waiting for "%s"\n',fname);
while ~exist(fname,'file')
pause(2)
seconds = seconds + 2;
end
fprintf('Found it!\n');
minutes = floor(seconds/60);
hours = floor(minutes/60);
fprintf('Found it (in %dh:%dm:%ds)!\n', hours, minutes, seconds);
pause(2)
end
% check whether file has been translated
%% check whether file has been translated
% (by gtApplyDrifts.m)
firsttime = true;
if waitfortranslated
......@@ -47,7 +51,7 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
while ~translated
try
info = edf_info(fname);
if isfield(info, 'istranslated') && str2num(info.istranslated)==waitfortranslated
if isfield(info, 'istranslated') && (str2double(info.istranslated) == waitfortranslated)
translated = true;
%disp('file has been translated!')
else
......@@ -68,7 +72,7 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
end
end
% try to read file
%% try to read file
while (true)
try
if ~exist('info', 'var')
......
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