source: trunk/src/civ.m @ 252

Last change on this file since 252 was 252, checked in by sommeria, 13 years ago

various bugs corrected.

File size: 199.2 KB
RevLine 
[112]1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
[2]2%------------------------------------------------------------------------
3%  provides an interface for the software CIVx
4% function varargout = civ(varargin)
5% provides an interface for the software CIVx
6%
7%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
9%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[112]10%     This file is part of the toolbox UVMAT.
11%
[2]12%     UVMAT is free software; you can redistribute it and/or modify
13%     it under the terms of the GNU General Public License as published by
14%     the Free Software Foundation; either version 2 of the License, or
15%     (at your option) any later version.
[112]16%
[2]17%     UVMAT is distributed in the hope that it will be useful,
18%     but WITHOUT ANY WARRANTY; without even the implied warranty of
19%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
21%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
22function varargout = civ(varargin)
23
[220]24% Last Modified by GUIDE v2.5 11-Mar-2011 08:21:21
[2]25% Begin initialization code - DO NOT EDIT
26gui_Singleton = 1;
27gui_State = struct('gui_Name',       mfilename, ...
[112]28    'gui_Singleton',  gui_Singleton, ...
29    'gui_OpeningFcn', @civ_OpeningFcn, ...
30    'gui_OutputFcn',  @civ_OutputFcn, ...
31    'gui_LayoutFcn',  [] , ...
32    'gui_Callback',   []);
[2]33if nargin && ischar(varargin{1})
34    gui_State.gui_Callback = str2func(varargin{1});
35end
36
37if nargout
38    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
39else
40    gui_mainfcn(gui_State, varargin{:});
41end
42% End initialization code - DO NOT EDIT
43
[12]44%------------------------------------------------------------------------
[2]45% --- Executes just before civ is made visible.
[71]46function civ_OpeningFcn(hObject, eventdata, handles, param)
[12]47%------------------------------------------------------------------------
[2]48% This function has no output args, see OutputFcn.
49% hObject    handle to figure
50% eventdata  reserved - to be defined in a future version of MATLAB
51% handles    structure with handles and user data (see GUIDATA)
52% varargin   command line arguments to civ (see VARARGIN)
[84]53global patch_newBin %=1 if new patch processing available
[112]54%filebase: root name
[2]55%nom_type: nomencalture used ('png_old','_i_j'...)
56%list of field numbers to process
[112]57%subdir: subdirectory of the opened netcdf file
[2]58%ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
59%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
60% Choose default command line output for civ
61handles.output = hObject;
62% Update handles structure
63guidata(hObject, handles);
[252]64set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)
[2]65%default initial parameters
66filebase=''; % root file name ('filebase'.civ)
67ext=[];
[238]68set(handles.CivAll,'String',{'CivX';'CivAll';'CivUvmat'})
[252]69set(handles.subdomain_patch1,'String','1500')% default values
70set(handles.subdomain_patch2,'String','1500')
71delete(handles.grid_patch1)
72delete(handles.get_gridpatch1)
73delete(handles.grid_patch2)
74delete(handles.get_gridpatch2)
75
[71]76%default input parameters:
[153]77num_i1=1; % set of field i numbers
78num_i2=1; % set of field i numbers
79num_j1=1; % set of field j numbers (fields a)
80num_j2=1; % second set of field j numbers (fields b)
[71]81subdir='A'; % subdir for the netcdf result files
[112]82ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
83%load the initial parameters if the interface is started from uvmat
[71]84if exist('param','var')&&isstruct(param)% the interface is opened from uvmat
85    filebase=param.RootName;
86    nom_type_read=param.NomType;
[153]87    num_i1=param.num1;
88    if isnan(num_i1),num_i1=1;end
89    num_i2=param.num2;
90    if isnan(num_i2),num_i2=num_i1;end
91    num_j1=param.num_a;
92    if isnan(num_j1),num_j1=1;end
93    num_j2=param.num_b;
94    if isnan(num_j2),num_j2=num_j1;end
[71]95    subdir=param.SubDir;
96    ind_opening=param.IndOpening;
97    ext=param.ImaExt;
[2]98end
[153]99browse.num_i1=num_i1;
100browse.num_i2=num_i2;
101browse.num_j1=num_j1;
102browse.num_j2=num_j2;
[122]103if ~isempty(ext) && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
[112]104    set(handles.ImaExt,'String',ext)
[128]105    browse.ext_ima=ext;
[112]106    if exist('nom_type_read','var')
107        browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
108    end
[2]109elseif isequal(ext,'.nc')
110    if exist('nom_type_read','var')
111        browse.nom_type_nc=nom_type_read;% the netcdf  nomenclature is stored
112    end
113end
[71]114set(handles.RootName,'String',filebase);
[2]115set(handles.ImaDoc,'String',ext)
116
[122]117%read names of the .exe file to adjust the interface according to available binaries
[2]118path_uvmat=which('uvmat');% check the path detected for source file uvmat
119path_UVMAT=fileparts(path_uvmat); %path to UVMAT
[45]120errormsg=[];%default error message
[112]121xmlfile='PARAM.xml';
[54]122if exist(xmlfile,'file')
123    try
[112]124        t=xmltree(xmlfile);
125        sparam=convert(t);
[54]126    catch
[112]127        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
[227]128        return
[2]129    end
[54]130else
131    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
[227]132    return
[2]133end
[71]134
[110]135
[45]136if ~isempty(errormsg)
[112]137    msgbox_uvmat('ERROR',errormsg);
[45]138end
[71]139% patch_newBin='';
140test_batch=0;%default: ,no batch mode available
141if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode')
142    test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
[2]143end
144if test_batch==0
[84]145    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
[2]146    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
147end
[94]148if isfield(sparam.RunParam,'CivBin')
149    if ~exist(sparam.RunParam.CivBin,'file')
[112]150        sparam.RunParam.CivBin=fullfile(path_UVMAT,sparam.RunParam.CivBin);
[94]151    end
[97]152else
153    sparam.RunParam.CivBin='';
[94]154end
[96]155patch_newBin=exist(sparam.RunParam.CivBin,'file');
[2]156set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
157set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
158
159%initiate advised operations
160if isequal(ind_opening,[])
161    ind_opening=1; % default
162end
163% set default operation options
[112]164enable_civ1(handles,'off')
165enable_civ2(handles,'off')
166enable_pair1(handles,'on')
167enable_fix1(handles,'off')
168desable_patch1(handles)
169desable_fix2(handles)
170desable_patch2(handles)
171set(handles.CIV1,'Value',0)
172set(handles.FIX1,'Value',0)
173set(handles.PATCH1,'Value',0)
174set(handles.CIV2,'Value',0)
175set(handles.FIX2,'Value',0)
176set(handles.PATCH2,'Value',0)
177set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
[2]178if isequal(ind_opening,1)
179    set(handles.CIV1,'Value',1)
180    enable_civ1(handles,'on')
181elseif isequal(ind_opening,2)
182    set(handles.FIX1,'Value',1)
183    enable_fix1(handles,'on')
184elseif isequal(ind_opening,3)
185    set(handles.PATCH1,'Value',1)
186    enable_patch1(handles)
187elseif isequal(ind_opening,4)
188    set(handles.CIV2,'Value',1)
[224]189    enable_civ2(handles,'on')
[2]190elseif isequal(ind_opening,5)
191    set(handles.FIX2,'Value',1)
192    enable_fix2(handles)
[112]193    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
194    set(handles.list_pair_civ2,'Enable','On')
195    set(handles.list_pair_civ2,'Enable','On')
196    enable_pair1(handles,'off')
[2]197elseif isequal(ind_opening,6)
198    set(handles.PATCH2,'Value',1)
199    enable_patch2(handles)
200    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
201    set(handles.list_pair_civ2,'Enable','On')
202    enable_pair1(handles,'off')
203end
204
205% set the range of fields (1:1 by default) and selected pair
[153]206if isequal(num_i2,num_i1)
207    num_ref_i=num_i1;
[2]208else
[153]209    num_ref_i=floor((num_i1+num_i2)/2);
210    browse.incr_pair(1)=num_i2-num_i1;
[2]211    browse.incr_pair(2)=0;
212end
[153]213if isequal(num_j1,num_j2)
214    if isnan(num_j1)
[2]215        num_ref_j=1;
216    else
[153]217        num_ref_j=num_j1;
[2]218    end
219else
[153]220    num_ref_j=floor((num_j1+num_j2)/2);
221    browse.incr_pair(2)=num_j2-num_j1;
[2]222end
223set(handles.first_i,'String',num2str(num_ref_i));
224set(handles.last_i,'String',num2str(num_ref_i));
225set(handles.first_j,'String',num2str(num_ref_j));
226set(handles.last_j,'String',num2str(num_ref_j));
227set(handles.ref_i,'String',num2str(num_ref_i));
228set(handles.ref_j,'String',num2str(num_ref_j));
[71]229set(handles.ref_i_civ2,'String',num2str(num_ref_i));
230set(handles.ref_j_civ2,'String',num2str(num_ref_j));
[2]231set(handles.browse_root,'UserData',browse);
[220]232if exist('param','var') && isfield(param,'RootName') && ~isempty(param.RootName)%varargin the interface is opened from uvmat
[112]233    RootName_Callback(hObject, eventdata, handles);
[2]234end
235
[150]236% set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
237% set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
238% set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
239% set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
[2]240
[12]241%------------------------------------------------------------------------
[2]242% --- Outputs from this function are returned to the command line.
243function varargout = civ_OutputFcn(hObject, eventdata, handles)
[12]244%------------------------------------------------------------------------
[2]245% varargout  cell array for returning output args (see VARARGOUT);
246% hObject    handle to figure
247% eventdata  reserved - to be defined in a future version of MATLAB
248% handles    structure with handles and user data (see GUIDATA)
249% Get default command line output from handles structure
250varargout{1} = handles.output;
251
[12]252%------------------------------------------------------------------------
[2]253% --- Executes on button press in browse_root.
254function browse_root_Callback(hObject, eventdata, handles)
[12]255%------------------------------------------------------------------------
[2]256%get the input file properties
[71]257filebase=get(handles.RootName,'String');
[2]258oldfile=''; %default
[39]259if isempty(filebase)|| isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
[112]260    dir_perso=prefdir;
261    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
262    if exist(profil_perso,'file')
263        h=load (profil_perso);
264        if isfield(h,'filebase')&& ischar(h.filebase)
265            oldfile=h.filebase;
266        end
267        if isfield(h,'RootPath') && ischar(h.RootPath)
268            oldfile=h.RootPath;
269        end
270    end
271else
272    oldfile=filebase;
273end
[2]274ind_opening=1;%default
275browse.incr_pair=[0 0]; %default
[238]276menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
[174]277       '*.xml',  '.xml files '; ...
278        '*.civ',  '.civ files '; ...
279        '*.png','.png image files'; ...
280        '*.jpg',' jpeg image files'; ...
281        '*.tif','.tif image files'; ...
282        '*.avi;*.AVI','.avi movie files'; ...
283        '*.nc','.netcdf files'; ...
284        '*.*',  'All Files (*.*)'};
[2]285[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
[112]286fileinput=[PathName FileName];%complete file name
[2]287sizf=size(fileinput);
288if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
289[path,name,ext]=fileparts(fileinput);
290testeditxml=0;
291if isequal(ext,'.xml')
292    testeditxml=1;
293    t_browse=xmltree(fileinput);
294    head_element=get(t_browse,1);
[45]295    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
[2]296        testeditxml=0;
297    end
298end
[45]299if testeditxml==1 || isequal(ext,'.xls')
[112]300    heditxml=editxml({fileinput});
301    set(heditxml,'Tag','browser')
302    waitfor(heditxml,'Tag','idle')
303    if ~ishandle(heditxml)
304        return
305    end
306    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
307    set(handles.browse,'UserData',fileinput)% store for future opening with browser
308    fileinput=get(attr,'UserData');
309    if ~exist(fileinput,'file')
310        return
311    end
[2]312end
[82]313[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
[2]314filebase=fullfile(RootPath,RootFile);
[89]315num_i1=str2double(str1);
316if isnan(num_i1),num_i1=1;end
317num_i2=str2double(str2);
318if isnan(num_i2),num_i2=num_i1;end
[54]319num_j1=stra2num(str_a);
[89]320if isnan(num_j1),num_j1=1;end
[54]321num_j2=stra2num(str_b);
[112]322if isnan(num_j2),num_j2=num_j1;end
[2]323if isequal(get(handles.compare,'Value'),1)
324    browse=[];%initialisation
325else
326    browse=get(handles.browse_root,'UserData');
327end
[122]328browse.num_i1=num_i1;
329browse.num_i2=num_i2;
330browse.num_j1=num_j1;
331browse.num_j2=num_j2;
332if length(ext)>1 && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
[2]333    browse.nom_type_ima=nom_type;
[122]334    browse.ext_ima=ext;
[177]335    set(handles.ImaExt,'String',ext)
[2]336end
337set(handles.ImaDoc,'String',ext);
338
339%%%%% read the state of the selected netcdf file to advise default operation
340if isequal(ext,'.nc')
341    browse.nom_type_nc=nom_type;
[112]342    ind_opening=2;% propose 'fix' as the default option
[246]343    Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','absolut_time_T0','fix','patch','civ2','fix2');
344    if ~isempty(Data.CivStage)%test for civ files
345        ind_opening=Data.CivStage;
346        set(handles.CivAll,'Value',3)
347    end
348    if ~isempty(Data.absolut_time_T0)%test for civx files
349        set(handles.CivAll,'Value',1)
[2]350        if isfield(Data,'fix') && isequal(Data.fix,1)
351            ind_opening=3;
352        end
[246]353        if isequal(Data.patch,1)
[2]354            ind_opening=4;
355        end
[246]356        if isequal(Data.civ2,1)
[2]357            ind_opening=5;
358        end
[246]359        if  isequal(Data.fix2,1)
[2]360            ind_opening=6;
361        end
362        testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
363    else
[112]364        ind_opening=3; %GUI used only for patch
[2]365        testciv=0;
366    end
367    set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
368    set(handles.subdir_civ2,'String',subdir);
369    browse.testciv=testciv;
370    browse.ind_opening=ind_opening;
371end
[71]372set(handles.RootName,'String',filebase);
[2]373set(handles.ImaDoc,'String',ext);
[45]374if ~isempty(num_i1)
[82]375    ref_i=num_i1;
[45]376    if ~isempty(num_i2)
377        ref_i=floor((ref_i+num_i2)/2);% reference image number corresponding to the file
378        browse.incr_pair(1)=num_i2-num_i1;
[2]379        browse.incr_pair(2)=0;
380    end
381    set(handles.first_i,'String',num2str(ref_i));
382    set(handles.last_i,'String',num2str(ref_i));
[71]383    set(handles.ref_i,'String',num2str(ref_i));
384    set(handles.ref_i_civ2,'String',num2str(ref_i))
[2]385end
[45]386if isempty(num_j1)
[2]387    set(handles.ref_j,'String','1');
[71]388    set(handles.ref_j_civ2,'String','1');
[2]389else
[45]390    ref_j=num_j1;
391    if ~isempty(num_j2)
392        ref_j=floor((num_j1+num_j2)/2);
[112]393        browse.incr_pair(2)=num_j2-num_j1;
[2]394    end
395    set(handles.first_j,'String',num2str(ref_j));
396    set(handles.last_j,'String',num2str(ref_j));
[112]397    set(handles.ref_j,'String',num2str(ref_j));
[71]398    set(handles.ref_j_civ2,'String',num2str(ref_j));
[2]399end
400
401% set default operation options
402enable_civ1(handles,'off')
403enable_civ2(handles,'off')
404enable_pair1(handles,'on')
405enable_fix1(handles,'off')
406desable_patch1(handles)
407desable_fix2(handles)
408desable_patch2(handles)
409set(handles.CIV1,'Value',0)
410set(handles.FIX1,'Value',0)
411set(handles.PATCH1,'Value',0)
412set(handles.CIV2,'Value',0)
413set(handles.FIX2,'Value',0)
414set(handles.PATCH2,'Value',0)
415set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
416if isequal(ind_opening,1)
417    set(handles.CIV1,'Value',1)
418    enable_civ1(handles,'on')
419elseif isequal(ind_opening,2)
420    set(handles.FIX1,'Value',1)
421    enable_fix1(handles,'on')
422elseif isequal(ind_opening,3)
423    set(handles.PATCH1,'Value',1)
424    enable_patch1(handles)
425elseif isequal(ind_opening,4)
426    set(handles.CIV2,'Value',1)
[224]427    enable_civ2(handles,'on')
[2]428elseif isequal(ind_opening,5)
429    enable_pair1(handles,'off')
430    set(handles.FIX2,'Value',1)
431    enable_fix2(handles)
[112]432    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
433    set(handles.list_pair_civ2,'Enable','On')
434    set(handles.list_pair_civ2,'Enable','On')
[2]435elseif isequal(ind_opening,6)
436    enable_pair1(handles,'off')
437    set(handles.PATCH2,'Value',1)
438    enable_patch2(handles)
439    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
440    set(handles.list_pair_civ2,'Enable','On')
441end
442set(handles.browse_root,'UserData',browse);% store information from browser
443
[71]444RootName_Callback(hObject, eventdata, handles);
[2]445
[12]446%------------------------------------------------------------------------
[2]447function ImaDoc_Callback(hObject, eventdata, handles)
[12]448%------------------------------------------------------------------------
[71]449RootName_Callback(hObject, eventdata, handles)
[2]450
[12]451%------------------------------------------------------------------------
[54]452% --- function activated when a new filebase (image series) is introduced
[71]453function RootName_Callback(hObject, eventdata, handles)
[12]454%------------------------------------------------------------------------
[2]455set(handles.compare,'Visible','on')
[122]456ext_ima='';%default
[2]457nom_type_ima=[];%default
458field_count=1;%default
459nom_type_nc=[];
460time=[];
[71]461TimeUnit='frame'; %default
462CoordUnit='px';%default
[2]463pxcmx_search=[];%default
464pxcmy_search=[];%default
[71]465filebase=get(handles.RootName,'String');
[128]466ext_imadoc=get(handles.ImaDoc,'String');
[135]467browse=get(handles.browse_root,'UserData');%default
[122]468if isfield(browse,'nom_type_ima')
469    nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
[133]470end
471if isfield(browse,'ext_ima')
[122]472    ext_ima=browse.ext_ima;
[2]473end
[122]474if isfield(browse,'nom_type_nc')
475    nom_type_nc=browse.nom_type_nc;% get an image nomenclature type already determined by an input image name
476end
477if isfield(browse,'num_i1')
478    field_count=browse.num_i1;% get an image index type already determined by an input file
479end
[252]480set(handles.civ,'UserData',[]); %refresh list of previous civ files (for STATUS)
[2]481
482%default first_i and j and increments
[137]483first_i=str2double(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
484if isnan(first_i)|| first_i < 1
[2]485    first_i=1; %default first_i
486end
[137]487last_i=str2double(get(handles.last_i,'String'));
488if isnan(last_i)|| last_i < first_i
[2]489    last_i=first_i;  %default last_i
490end
[137]491first_j=str2double(get(handles.first_j,'String'));
492if isnan(first_j)|| first_j < 1
[2]493    first_j=1; %default first_j
494end
[137]495last_j=str2double(get(handles.last_j,'String'));
496if isnan(last_j)|| last_j < first_j
[2]497    last_j=first_j; %default last_j
498end
[137]499incr_i=str2double(get(handles.incr_i,'String'));
500if isnan(incr_i) || incr_i < 1;
[2]501    set(handles.incr_i,'String','1') %default incr_i
502end
[137]503incr_j=str2double(get(handles.incr_j,'String'));
504if isnan(incr_j) || incr_j < 1;
[2]505    set(handles.incr_j,'String','1') %default incr_j
506end
507dt=[];%default
508testmode=0;%default
509nbfield=[]; %default
510nburst=[];%default
511pxcmx=1;
[112]512pxcmy=1;
[2]513
[112]514%look for an image documentation file
[128]515if ~strcmp(ext_imadoc,'.xml') && ~strcmp(ext_imadoc,'.civ')&& ~strcmpi(ext_imadoc,'.avi')
[2]516    if exist([filebase '.xml'],'file')
[128]517        ext_imadoc='.xml';
[2]518    elseif exist([filebase '.civxml'],'file')
[128]519        ext_imadoc='.civxml';
[2]520    elseif exist([filebase '.civ'],'file')
[128]521        ext_imadoc='.civ';
[112]522    elseif exist([filebase '.avi'],'file')
[128]523        ext_imadoc='.avi';
[2]524    elseif exist([filebase '.AVI'],'file')
[128]525        ext_imadoc='.AVI';
[2]526    end
[128]527    set(handles.ImaDoc,'String',ext_imadoc)
[2]528end
529
530%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
[84]531mode=''; %default
532set(handles.ImaDoc,'BackgroundColor',[1 1 0])
533drawnow
[128]534if isequal(ext_imadoc,'.civxml') || isequal(ext_imadoc,'.xml')|| isequal(ext_imadoc,'.civ')
[2]535    set(handles.ref_i,'Visible','On')%use a reference index
536    set(handles.ref_j,'Visible','On')
[128]537elseif isequal(ext_imadoc,'.avi') || isequal(ext_imadoc,'.AVI')
[2]538    set(handles.ref_j,'Visible','Off')
539else
540    set(handles.ref_i,'Visible','Off')
541    set(handles.ref_j,'Visible','Off')
542end
[12]543testima_xml=0;
[128]544if isequal(ext_imadoc,'.civxml')%TO ABANDON
[122]545    [nbfield,nbfield2,time]=read_civxml([filebase '.civxml']);
[2]546    mode='pair j1-j2';
547    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
[112]548        nom_type_ima='_i_j';
[2]549    end
[128]550elseif isequal(ext_imadoc,'.xml')
[73]551    [XmlData,warntext]=imadoc2struct([filebase '.xml']);
[2]552    ext_ima_read=[];
553    nom_type_read=[];
[12]554    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
[2]555        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
[112]556        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
[45]557        if ~exist(fullname,'file')
[12]558            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
559        end
[2]560    end
[84]561    if isfield(XmlData,'Time')
[85]562        time=XmlData.Time;
[84]563        nbfield=size(time,1);
[122]564        nbfield2=size(time,2);
[127]565        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
[122]566        if isequal(nbfield,1) && ~isequal(nbfield2,1)% .Time is a line vector
[127]567            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D'))
[84]568                time=time';
[122]569                nbfield=nbfield2;
570                nbfield2=1;
[84]571            end
572        end
573    end
[71]574    if isfield(XmlData,'TimeUnit')
575        TimeUnit=XmlData.TimeUnit;
[2]576    end
[71]577    if isfield(XmlData,'Npx')
578        npx=XmlData.Npx;
579        npy=XmlData.Npy;
580    end
[2]581    pxcmx_search=1;
582    pxcmy_search=1;
583    if isfield(XmlData,'GeometryCalib')
584        tsai=XmlData.GeometryCalib;
[112]585        if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R')
586            rot2D=tsai.R(1:2,[1,2]);
587            pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
588            pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
[2]589        end
[112]590        if isfield(tsai,'CoordUnit')
591            CoordUnit=tsai.CoordUnit;
[2]592        end
[112]593    end
[128]594elseif strcmp(ext_imadoc,'.civ')% case of .civ image documentation file
[112]595    [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
596    if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
597    elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
598    end
[128]599    nom_type_ima='001a';
600elseif strcmpi(ext_imadoc,'.avi')
[112]601    nom_type_ima='*';
[128]602    ext_ima=ext_imadoc;
[177]603    set(handles.mode,'Value',1);
[112]604    set(handles.mode,'String',{'series(Di)'})
605    dt=0.04;%default
[128]606    if exist([filebase ext_imadoc],'file')==2
607        info=aviinfo([filebase ext_imadoc]);%read infos on the avi movie
[112]608        dt=1/info.FramesPerSecond;%time interval between successive frames
609        nbfield=info.NumFrames;%number of frames
610    end
611    time=(dt*(0:nbfield-1))';%list of image times
[2]612end
613if isempty(time)
614    set(handles.ImaDoc,'String',''); %xml file not used for timing
615end
616set(handles.ImaDoc,'BackgroundColor',[1 1 1])
617
[122]618%get the imabe nomenclature type if not defined by the input file nor by the xml file
619dirima=[];%default
[12]620if isempty(nom_type_ima)
621    %look for double image series '_i_j'
622    dirima=dir([filebase '_' num2str(first_i) '_' num2str(first_j) '.*']);
623    if isempty(dirima)
[112]624        % look for images series  with sub marker '_'
625        dirima=dir([filebase '_*' num2str(first_i) '.*']);
626        if isempty(dirima)
627            % look for other images series
628            dirima=dir([filebase '*' num2str(first_i) '.*']);
[122]629            if isempty(dirima)
630                % look for other images series witth letter appendix
631                appendix=char(96+first_j);
632                dirima=dir([filebase '*' num2str(first_i) appendix '.*']);
[112]633            end
634        end
[12]635    end
[112]636end
[122]637for ilist=1:numel(dirima)
638    [pp,ff,fc,str2,str_a,str_b,ext_list,nom_type_list]=name2display(dirima(ilist).name);
639    form=imformats(ext_list(2:end));
640    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
641        ext_ima=ext_list;
642        nom_type_ima=nom_type_list;
643            break
644    end
645end
646% no image documentation file found: look for a series of existing files,images by priority or .nc files
647if isempty(nom_type_ima)
[128]648    ext_search=ext_imadoc;
[122]649    nom_type_search=nom_type_nc;
650else
651    ext_search=ext_ima;
652    nom_type_search=nom_type_ima;
653end
654if isempty(time) && ~strcmp(nom_type_search,'none') && ~strcmp(nom_type_search,'') && ~strcmp(nom_type_search,'*')
[12]655    subdir=get(handles.subdir_civ1,'String');
656    incr_pair=[0 0];%default
657    if isfield(browse,'incr_pair')
[112]658        incr_pair=browse.incr_pair;
[12]659    end
[112]660    %     nbdetect=0;%test of detected images
[122]661    field_i=browse.num_i2;
[153]662    imagename=name_generator(filebase,field_i,1,ext_search,nom_type_search);
663    imagename_plus='';
[12]664    idetect=1;
[153]665    while idetect %look for the maximum file number in the series
666        imagename_plus=name_generator(filebase,field_i+1,1,ext_search,nom_type_search);
667        idetect=(exist(imagename_plus,'file')==2)&& ~strcmp(imagename,imagename_plus);
[81]668        if idetect
[12]669            field_i=field_i+1;
[81]670        end
[112]671        %SEE CASE OF NETCDF FILES
672        %             nbdetect=nbdetect+(exist(imagename,'file')==2);
[12]673    end
[122]674    nbfield=field_i;% last detected field number
675    field_i=browse.num_i1;%look for the minimum file number in the series
[153]676    imagename_min='';
[12]677    idetect=1;
[112]678    while idetect==1
[153]679        imagename_min=name_generator(filebase,field_i-1,1,ext_search,nom_type_search);
680        idetect=(exist(imagename_min,'file')==2)&& ~strcmp(imagename,imagename_min);
[81]681        if idetect
[112]682            field_i=field_i-1;
[81]683        end
[12]684    end
[122]685    first_i=max(field_i,1);
686    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
687        field_i=browse.num_i1;
688        field_j=browse.num_j2;
[177]689        imagename=name_generator(filebase,field_i,field_j,ext_search,nom_type_search);
[153]690        imagename_plus='';
[89]691        jdetect=1;
692        while jdetect==1 %look for the maximum file number in the series
[153]693            imagename_plus=name_generator(filebase,field_i,field_j+1,ext_search,nom_type_search);
694            jdetect=(exist(imagename_plus,'file')==2)&& ~strcmp(imagename,imagename_plus);
[89]695            if jdetect
696                field_j=field_j+1;
697            end
698            %SEE CASE OF NETCDF FILES
699            %             nbdetect=nbdetect+(exist(imagename,'file')==2);
700        end
[122]701        nbfield2=field_j;% last detected field number
[120]702     end
[122]703 
[89]704    %determine the set of times and possible intervals for CIV
[137]705    %   dt=(1/1000)*str2double(get(handles.dt,'String'));
[122]706    time=(0:nbfield-1)';% time=file index -1  by default
707    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
708        [x,y]=meshgrid(0:nbfield2-1,0:nbfield-1);
[120]709        time=x+y;
[89]710    end
[2]711end
[120]712
[2]713if exist('time','var')
714    if size(time,1)+size(time,2)>=3 % if there are at least two time values to define dt
715        nbfield=size(time,1);
716        nbfield2=size(time,2);
[71]717        set(handles.RootName,'UserData',time); %store the set of times
718        set(handles.dt_unit,'String',['dt in m' TimeUnit]);
719        set(handles.dt_unit_civ2,'String',['dt in m' TimeUnit]);
720        set(handles.TimeUnit,'String',TimeUnit);
[2]721        set(handles.nb_field,'String',num2str(nbfield));
722        set(handles.nb_field2,'String',num2str(nbfield2));
723    end
724end
[71]725set(handles.CoordUnit,'String',CoordUnit)
[2]726set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
727% npxy=[npy npx];
[71]728set(handles.ImaExt,'String',ext_ima)
[2]729set(handles.first_i,'String',num2str(first_i));
730set(handles.last_i,'String',num2str(last_i));%
731set(handles.first_j,'String',num2str(first_j));
732set(handles.last_j,'String',num2str(last_j));%
733browse.nom_type_ima=nom_type_ima;
734set(handles.browse_root,'UserData',browse)% store the nomenclature type
735
[112]736%%%%%%%%%%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
[177]737test_ima_i=numel(nom_type_ima)>1 && isempty(regexp(nom_type_ima(2:end),'\D','once'));%images with single indexing
[122]738if test_ima_i || isequal(nom_type_nc,'_i1-i2')||~(exist('nbfield2','var')&&(nbfield2~=1))
[2]739    set(handles.mode,'Value',1)
[177]740    set(handles.mode,'String',{'series(Di)'})   
[2]741elseif (nbfield==1)% simple series in j
[177]742    set(handles.mode,'Value',1)
[2]743    set(handles.mode,'String',{'series(Dj)'})
744else
745    set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
[122]746    if nbfield2 <= 10
[112]747        set(handles.mode,'Value',1)% advice 'pair j1-j2' for small burst
[2]748    end
749end
750
[112]751%update the subdir
[2]752pathdir=fileparts(filebase);%path to the current xml file
753listot=dir(pathdir);
754idir=0;
755listdir={''};%default
756for ilist=1:length(listot)
757    if listot(ilist).isdir
758        name=listot(ilist).name;
759        if ~isequal(name,'.') && ~isequal(name,'..')
760            idir=idir+1;
761            listdir{idir,1}=listot(ilist).name;
762        end
763    end
764end
[112]765set(handles.list_subdir_civ1,'Value',1)
[2]766set(handles.list_subdir_civ2,'Value',1)
[107]767set(handles.list_subdir_civ1,'String',[{'browse...'};listdir])
768set(handles.list_subdir_civ2,'String',[{'browse...'};listdir])
[2]769%check wether the current subdir exists:
770subdir_civ1=get(handles.subdir_civ1,'String');
771subdir_civ2=get(handles.subdir_civ2,'String');
772
[112]773mode_Callback(hObject, eventdata, handles)
[2]774
[177]775%% desable status and RUN button
[150]776% set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
777% set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
778% set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
779% set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
[2]780set(handles.RUN, 'Enable','On')
781set(handles.RUN,'BackgroundColor',[1 0 0])
[122]782set(handles.BATCH,'Enable','On')
783set(handles.BATCH,'BackgroundColor',[1 0 0])
[178]784if isfield(handles,'status')
[177]785set(handles.status,'Value',0);%suppress status display
786status_Callback(hObject, eventdata, handles)
[178]787end
[112]788
[177]789%% store the root input filename for future opening
[2]790dir_perso=prefdir;
791profil_perso=fullfile(prefdir,'uvmat_perso.mat');
792RootPath=fileparts(filebase);
793if exist(profil_perso,'file')
794    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
795else
[147]796    txt=ver('MATLAB');
797    Release=txt.Release;
[137]798    relnumb=str2double(Release(3:4));
[2]799    if relnumb >= 14
[112]800        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
[2]801    else
802        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
803    end
804end
805
[12]806%------------------------------------------------------------------------
[2]807% --- Executes on button press in mode.
808function mode_Callback(hObject, eventdata, handles)
[12]809%------------------------------------------------------------------------
[2]810browse=get(handles.browse_root,'UserData');
811compare_list=get(handles.compare,'String');
812val=get(handles.compare,'Value');
813compare=compare_list{val};
814if strcmp(compare,'displacement')
815    mode='displacement';
816else
817    mode_list=get(handles.mode,'String');
[236]818    if ischar(mode_list)
819        mode_list={mode_list};
820    end
[2]821    mode_value=get(handles.mode,'Value');
822    mode=mode_list{mode_value};
823end
824displ_num=[];%default
[137]825ref_i=str2double(get(handles.ref_i,'String'));
[2]826% last_i=str2num(get(handles.last_i,'String'));
[71]827time=get(handles.RootName,'UserData'); %get the set of times
[2]828siztime=size(time);
829nbfield=siztime(1);
830nbfield2=siztime(2);
831indchosen=1;  %%first pair selected by default
832if isequal(mode,'pair j1-j2')%| isequal(mode,'st_pair j1-j2')
833    dt=1;
834    displ='';
835    index=0;
836    numlist_a=[];
837    numlist_B=[];
838    %get all the time intervals in bursts
839    displ_dt=1;%default
840    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
841    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
842        for numod_b=(numod_a+1):nbfield2
[112]843            index=index+1;
844            numlist_a(index)=numod_a;
845            numlist_b(index)=numod_b;
846            if ~isempty(time)
[54]847                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
[2]848                displ_dt(index)=dt(numod_a,numod_b);
[112]849            else
850                displ_dt(index)=1;
851            end
852        end
853    end
854    [dtsort,indsort]=sort(displ_dt);
855    if ~isempty(numlist_a)
856        displ_num(1,:)=numlist_a(indsort);
857        displ_num(2,:)=numlist_b(indsort);
858    end
859    displ_num(3,:)=0;
860    displ_num(4,:)=0;
861    set(handles.jtext,'Visible','Off')
[2]862    set(handles.first_j,'Visible','Off')
863    set(handles.last_j,'Visible','Off')
864    set(handles.incr_j,'Visible','Off')
865    set(handles.nb_field2,'Visible','Off')
866    set(handles.ref_j,'Visible','Off')
867elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
[112]868    for index=1:min(nbfield2-1,200)
869        displ_num(1,index)=-floor(index/2);
870        displ_num(2,index)=ceil(index/2);
871        displ_num(3,index)=0;
872        displ_num(4,index)=0;
873    end
874    set(handles.jtext,'Visible','On')
875    set(handles.first_j,'Visible','On')
876    set(handles.last_j,'Visible','On')
877    set(handles.incr_j,'Visible','On')
878    set(handles.nb_field2,'Visible','On')
879    set(handles.ref_j,'Visible','On')
880    if nbfield > 1
[2]881        set(handles.itext,'Visible','On')
882        set(handles.first_i,'Visible','On')
883        set(handles.last_i,'Visible','On')
884        set(handles.incr_i,'Visible','On')
885        set(handles.nb_field,'Visible','On')
886        set(handles.ref_i,'Visible','On')
887    else
888        set(handles.itext,'Visible','Off')
889        set(handles.first_i,'Visible','Off')
890        set(handles.last_i,'Visible','Off')
891        set(handles.incr_i,'Visible','Off')
892        set(handles.nb_field,'Visible','Off')
893        set(handles.ref_i,'Visible','Off')
894    end
[112]895elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
896    for index=1:200%min(nbfield-1,200)
897        displ_num(1,index)=0;
898        displ_num(2,index)=0;
899        displ_num(3,index)=-floor(index/2);
900        displ_num(4,index)=ceil(index/2);
901    end
902    set(handles.itext,'Visible','On')
903    set(handles.first_i,'Visible','On')
904    set(handles.last_i,'Visible','On')
905    set(handles.incr_i,'Visible','On')
906    set(handles.nb_field,'Visible','On')
907    set(handles.ref_i,'Visible','On')
908    if nbfield2 > 1
[2]909        set(handles.jtext,'Visible','On')
910        set(handles.first_j,'Visible','On')
911        set(handles.last_j,'Visible','On')
912        set(handles.incr_j,'Visible','On')
913        set(handles.nb_field2,'Visible','On')
914        set(handles.ref_j,'Visible','On')
[112]915    else
[2]916        set(handles.jtext,'Visible','Off')
917        set(handles.first_j,'Visible','Off')
918        set(handles.last_j,'Visible','Off')
919        set(handles.incr_j,'Visible','Off')
920        set(handles.nb_field2,'Visible','Off')
921        set(handles.ref_j,'Visible','Off')
922    end
923elseif isequal(mode,'displacement')%the pairs have the same indices
[112]924    displ_num(1,1)=0;
925    displ_num(2,1)=0;
926    displ_num(3,1)=0;
927    displ_num(4,1)=0;
928    if nbfield > 1
[2]929        set(handles.itext,'Visible','On')
930        set(handles.first_i,'Visible','On')
931        set(handles.last_i,'Visible','On')
932        set(handles.incr_i,'Visible','On')
933        set(handles.nb_field,'Visible','On')
934        set(handles.ref_i,'Visible','On')
935    else
936        set(handles.itext,'Visible','Off')
937        set(handles.first_i,'Visible','Off')
938        set(handles.last_i,'Visible','Off')
939        set(handles.incr_i,'Visible','Off')
940        set(handles.nb_field,'Visible','Off')
941        set(handles.ref_i,'Visible','Off')
942    end
943    if nbfield2 > 1
[112]944        set(handles.jtext,'Visible','On')
945        set(handles.first_j,'Visible','On')
946        set(handles.last_j,'Visible','On')
947        set(handles.incr_j,'Visible','On')
948        set(handles.nb_field2,'Visible','On')
949        set(handles.ref_j,'Visible','On')
[2]950    else
951        set(handles.jtext,'Visible','Off')
952        set(handles.first_j,'Visible','Off')
953        set(handles.last_j,'Visible','Off')
954        set(handles.incr_j,'Visible','Off')
955        set(handles.nb_field2,'Visible','Off')
956        set(handles.ref_j,'Visible','Off')
957    end
[112]958end
[2]959set(handles.list_pair_civ1,'UserData',displ_num);
960find_netcpair_civ1(hObject, eventdata, handles)
961find_netcpair_civ2(hObject, eventdata, handles)
962
[12]963%------------------------------------------------------------------------
[2]964% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
965% the field series set by first_i, incr, last_i
966function find_netcpair_civ1(hObject, eventdata, handles)
[12]967%------------------------------------------------------------------------
[2]968set(gcf,'Pointer','watch')
969%nomenclature types
[71]970filebase=get(handles.RootName,'String');
[2]971[filepath,Nme,ext_dir]=fileparts(filebase);
972browse=get(handles.browse_root,'UserData');
973compare_list=get(handles.compare,'String');
974val=get(handles.compare,'Value');
975compare=compare_list{val};
976if strcmp(compare,'displacement')
977    mode='displacement';
978else
979    mode_list=get(handles.mode,'String');
980    mode_value=get(handles.mode,'Value');
981    mode=mode_list{mode_value};
982end
983
984% nomenclature type of the .nc files
985nom_type_ima=[];%default
986if isfield(browse,'nom_type_ima')
987    nom_type_ima=browse.nom_type_ima;
988end
989
[112]990%determine nom_type_nc:
[2]991nom_type_nc=[];%default
992if isfield(browse,'nom_type_nc')
993    nom_type_nc=browse.nom_type_nc;
994end
995if isempty(nom_type_nc)
[112]996    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
[2]997end
998browse.nom_type_nc=nom_type_nc;
999set(handles.browse_root,'UserData',browse)
1000
1001%reads .nc subdirectoy and image numbers from the interface
1002subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
[45]1003% first_i=str2num(get(handles.first_i,'String'));
1004% last_i=str2num(get(handles.last_i,'String'));
1005% incr=str2num(get(handles.incr_i,'String'));
1006% num1=first_i:incr:last_i;
1007% if isempty(num1)
1008%     set(handles.list_pair_civ1,'String',{''});
1009%     return
1010% end
1011ref_i=str2double(get(handles.ref_i,'String'));
[2]1012if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1013    ref_j=0;
1014else
[45]1015    ref_j=str2double(get(handles.ref_j,'String'));
[2]1016end
[71]1017time=get(handles.RootName,'UserData');%get the set of times
[2]1018if isempty(time)
1019    time=[0 1];
[112]1020end
[71]1021%dt_unit=str2double(get(handles.dt,'String'));% used when there is no image documentation file
1022dt_unit=1000;%default
[2]1023displ_num=get(handles.list_pair_civ1,'UserData');
1024
[112]1025%eliminate the first pairs inconsistent with the position
1026if isempty(displ_num)
1027    nbpair=0;
1028else
[2]1029    nbpair=length(displ_num(1,:));%nbre of displayed pairs
1030    if  isequal(mode,'series(Di)')  %| isequal(mode,'st_series(Di)')
1031        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
1032    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1033        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1034    end
[112]1035end
[2]1036nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1037
[112]1038%look for existing processed pairs involving the field at the middle of the series if civ1 will not
[2]1039% be performed, while the result is needed for next steps.
1040displ_pair={''};
1041select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
1042testpair=0;
1043if get(handles.CIV1,'Value')==0 %
[112]1044    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
1045        msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
1046        set(handles.list_pair_civ1,'String',{});
1047        return
[2]1048    end
[112]1049    for ipair=1:nbpair
[2]1050        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1051            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1052        select(ipair)=exist(filename,'file')==2;
1053    end
1054    if ~exist('select','var') || isequal(select,zeros(size(1:nbpair)))
[112]1055        if isfield(browse,'incr_pair')
[2]1056            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1057            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
1058            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1059            num_j2=ref_j+ceil(browse.incr_pair(2)/2);
1060            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
1061            select(1)=exist(filename,'file')==2;
1062            testpair=1;
1063        else
[112]1064            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1065                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
1066            else
1067                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
1068            end
[112]1069            set(handles.list_pair_civ1,'String',{''});
1070            %COMPLETER CAS STEREO
[2]1071            return
1072        end
1073    end
1074end
1075if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
1076    if testpair
[73]1077        displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
1078        %     elseif ~isequal(get(handles.root_txt,'String'),'dt(ms)=')
1079        %        for ipair=1:nbpair
1080        %           if select(ipair)
1081        %               if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1082        %               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1083        %               displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1084        %               end
1085        %           else
1086        %              displ_pair{ipair}='...'; %pair not displayed in the menu
1087        %           end
1088        %        end
[2]1089    else
[73]1090        for ipair=1:nbpair
1091            if select(ipair)
1092                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1093                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1094                    displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1095                else
1096                    displ_pair{ipair}='...'; %pair not displayed in the menu
1097                end
1098            end
1099        end
[2]1100    end
1101elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
1102    if testpair
[112]1103        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
[2]1104    else
[112]1105        for ipair=1:nbpair
1106            if select(ipair)
1107                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1108                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1109                    displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1110                end
1111            elseif testpair
1112                displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
1113            else
1114                displ_pair{ipair}='...'; %pair not displayed in the menu
1115            end
1116        end
1117    end
[2]1118elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
1119    for ipair=1:nbpair
1120        if select(ipair)
[112]1121            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1122            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1123                ' :dt= ' num2str(dt*1000)];
1124        else
1125            displ_pair{ipair}='...'; %pair not displayed in the menu
1126        end
1127    end
[2]1128elseif isequal(mode,'displacement')
[112]1129    displ_pair={'Di=Dj=0'};
1130end
[2]1131set(handles.list_pair_civ1,'String',displ_pair');
[229]1132ichoice=find(select,1);
[45]1133if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1134initial=get(handles.list_pair_civ1,'Value');%initial choice of pair
[112]1135if initial>nbpair
1136    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
[45]1137end
1138if numel(select)>=initial && ~isequal(select(initial),1)
[2]1139    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
1140end
[45]1141
[2]1142%set(handles.list_pair_civ2,'String',displ_pair');
1143initial=get(handles.list_pair_civ2,'Value');
1144if initial>length(displ_pair')%|~isequal(select(initial),1)
1145    if ichoice <= length(displ_pair')
1146        set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
1147    else
1148        set(handles.list_pair_civ2,'Value',1);% same pair proposed by default for civ2
1149    end
1150end
1151set(handles.list_pair_civ2,'String',displ_pair');
1152set(gcf,'Pointer','arrow')
[12]1153
1154%------------------------------------------------------------------------
[112]1155% determine the menu for civ2 pairs depending on the existing netcdf file at the
1156%middle of the series set by first_i, incr, last_i
[2]1157function find_netcpair_civ2(hObject, eventdata, handles)
[12]1158%------------------------------------------------------------------------
[2]1159set(gcf,'Pointer','watch')
1160%nomenclature types
[71]1161filebase=get(handles.RootName,'String');
[2]1162[filepath,Nme,ext_dir]=fileparts(filebase);
1163browse=get(handles.browse_root,'UserData');
1164compare_list=get(handles.compare,'String');
1165val=get(handles.compare,'Value');
1166compare=compare_list{val};
1167if strcmp(compare,'displacement')
1168    mode='displacement';
1169else
[252]1170    mode_list=get(handles.mode,'String')
1171    mode_value=get(handles.mode,'Value')
[2]1172    mode=mode_list{mode_value};
1173end
1174
1175% nomenclature type of the .nc files
1176nom_type_ima='ima_num';%default
1177if isfield(browse,'nom_type_ima')
1178    nom_type_ima=browse.nom_type_ima;
1179end
1180nom_type_nc='_i1-i2';%default
1181if isfield(browse,'nom_type_nc')
1182    nom_type_nc=browse.nom_type_nc;
1183end
[94]1184if isequal(nom_type_ima,'png_old') || isequal(nom_type_ima,'netc_old')|| isequal(nom_type_ima,'raw_SMD')|| isequal(nom_type_nc,'netc_old')
[2]1185    nom_type_nc='netc_old';%nom_type for the netcdf files
[94]1186elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
[2]1187    nom_type_nc='none';
[94]1188elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
[112]1189    nom_type_nc='_i1-i2';
[2]1190else
1191    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
1192        nom_type_nc='_i1-i2_j'; % PIV in volume
1193    else
1194        nom_type_nc='_i_j1-j2';
[112]1195    end
[2]1196end
1197browse.nom_type_nc=nom_type_nc;
1198set(handles.browse_root,'UserData',browse)
1199
1200%reads .nc subdirectory and image numbers from the interface
1201subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
1202subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
[45]1203% first_i=str2num(get(handles.first_i,'String'));
1204% last_i=str2num(get(handles.last_i,'String'));
1205% incr=str2num(get(handles.incr_i,'String'));
1206% num1=first_i:incr:last_i;
1207% if isempty(num1)
1208%     set(handles.list_pair_civ2,'Value',1);
1209%     set(handles.list_pair_civ2,'String',{''});
1210%     return
1211% end
[137]1212ref_i=str2double(get(handles.ref_i_civ2,'String'));
[2]1213if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1214    ref_j=0;
1215else
[137]1216    ref_j=str2double(get(handles.ref_j_civ2,'String'));
[2]1217end
[71]1218time=get(handles.RootName,'UserData'); %get the set of times
[2]1219if isempty(time)
1220    time=[0 1];%default
1221end
[71]1222%dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
[73]1223%dt_unit=1000;
[2]1224displ_num=get(handles.list_pair_civ1,'UserData');
1225
1226
[112]1227%eliminate the first pairs inconsistent with the position
[2]1228if isempty(displ_num)
1229    nbpair=0;
1230else
1231    nbpair=length(displ_num(1,:));%nbre of displayed pairs
[112]1232    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
[2]1233        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
[112]1234    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1235        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1236    end
1237end
1238nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1239
[112]1240%look for existing processed pairs involving the field at the middle of the series if civ1 will not
[2]1241% be performed, while the result is needed for next steps.
1242displ_pair={''}; %default
1243select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
1244if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
[112]1245    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
1246        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
1247        set(handles.list_pair_civ2,'Value',1);
1248        set(handles.list_pair_civ2,'String',{''});
1249        return
[2]1250    end
[112]1251    for ipair=1:nbpair
[2]1252        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1253            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1254        select(ipair)=exist(filename,'file')==2;
1255    end
1256    if  isequal(select,zeros(size(1:nbpair)))
[112]1257        if isfield(browse,'incr_pair')
[2]1258            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1259            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
1260            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1261            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
1262            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
1263            select(1)=exist(filename,'file')==2;
1264        else
[112]1265            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1266                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
1267            else
1268                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
1269            end
[112]1270            set(handles.list_pair_civ2,'Value',1);
1271            set(handles.list_pair_civ2,'String',{''});
[2]1272            return
1273        end
1274    end
1275end
[112]1276if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
1277    for ipair=1:nbpair
1278        if select(ipair)
1279            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
[2]1280                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1281                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
[112]1282            end
1283        else
1284            displ_pair{ipair}='...'; %pair not displayed in the menu
1285        end
1286    end
[2]1287elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
[112]1288    for ipair=1:nbpair
1289        if select(ipair)
1290            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1291                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1292                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1293            end
1294        else
1295            displ_pair{ipair}='...'; %pair not displayed in the menu
1296        end
1297    end
[2]1298elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
1299    for ipair=1:nbpair
1300        if select(ipair)
[112]1301            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1302            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1303                ' :dt= ' num2str(dt*1000)];
1304        else
1305            displ_pair{ipair}='...'; %pair not displayed in the menu
1306        end
1307    end
[2]1308elseif isequal(mode,'displacement')
[112]1309    displ_pair={'Di=Dj=0'};
1310end
[2]1311val=get(handles.list_pair_civ2,'Value');
[229]1312ichoice=find(select,1);
[137]1313if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1314if get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0
[2]1315    val=ichoice;% first valid pair proposed by default in the menu
1316end
1317if val>length(displ_pair')
1318    set(handles.list_pair_civ2,'Value',1);% first valid pair proposed by default in the menu
1319else
1320    set(handles.list_pair_civ2,'Value',val);
1321end
1322set(handles.list_pair_civ2,'String',displ_pair');
[12]1323set(gcf,'Pointer','arrow')
[2]1324
1325
[41]1326
[227]1327
[12]1328%------------------------------------------------------------------------
[2]1329% --- Executes on selection change in list_pair_civ1.
1330function list_pair_civ1_Callback(hObject, eventdata, handles)
[12]1331%------------------------------------------------------------------------
[2]1332%reproduce by default the chosen pair in the civ2 menu
1333list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
1334index_pair=get(handles.list_pair_civ1,'Value');
1335displ_num=get(handles.list_pair_civ1,'UserData');
[137]1336% num_a=displ_num(1,index_pair);
1337% num_b=displ_num(2,index_pair);
[2]1338list_pair2=get(handles.list_pair_civ2,'String');%get the menu of image pairs
1339if index_pair<=length(list_pair2)
1340    set(handles.list_pair_civ2,'Value',index_pair);
1341end
1342
[112]1343%update first_i and last_i according to the chosen image pairs
[2]1344mode_list=get(handles.mode,'String');
1345mode_value=get(handles.mode,'Value');
1346mode=mode_list{mode_value};
1347if isequal(mode,'series(Di)')
[137]1348    first_i=str2double(get(handles.first_i,'String'));
1349    last_i=str2double(get(handles.last_i,'String'));
1350    incr_i=str2double(get(handles.incr_i,'String'));
[2]1351    num1=first_i:incr_i:last_i;
[137]1352    lastfield=str2double(get(handles.nb_field,'String'));
1353    if ~isnan(lastfield)
[229]1354        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1355            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1356        num1=num1(test_find);
[2]1357    end
1358    set(handles.first_i,'String',num2str(num1(1)));
1359    set(handles.last_i,'String',num2str(num1(end)));
1360elseif isequal(mode,'series(Dj)')
[137]1361    first_j=str2double(get(handles.first_j,'String'));
1362    last_j=str2double(get(handles.last_j,'String'));
1363    incr_j=str2double(get(handles.incr_j,'String'));
[2]1364    num_j=first_j:incr_j:last_j;
[137]1365    lastfield2=str2double(get(handles.nb_field2,'String'));
1366    if ~isnan(lastfield2)
[229]1367        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1368            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1369        num1=num_j(test_find);
[2]1370    end
1371    set(handles.first_j,'String',num2str(num1(1)));
1372    set(handles.last_j,'String',num2str(num1(end)));
[112]1373end
[2]1374
[12]1375%------------------------------------------------------------------------
[2]1376% --- Executes on selection change in list_pair_civ2.
1377function list_pair_civ2_Callback(hObject, eventdata, handles)
[12]1378%------------------------------------------------------------------------
[112]1379index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
[2]1380
[112]1381%update first_i and last_i according to the chosen image pairs
[2]1382mode_list=get(handles.mode,'String');
1383mode_value=get(handles.mode,'Value');
1384mode=mode_list{mode_value};
1385if isequal(mode,'series(Di)')
[137]1386    first_i=str2double(get(handles.first_i,'String'));
1387    last_i=str2double(get(handles.last_i,'String'));
1388    incr_i=str2double(get(handles.incr_i,'String'));
[2]1389    num1=first_i:incr_i:last_i;
[137]1390    lastfield=str2double(get(handles.nb_field,'String'));
1391    if ~isnan(lastfield)
[229]1392        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1393            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1394        num1=num1(test_find);
[2]1395    end
1396    set(handles.first_i,'String',num2str(num1(1)));
1397    set(handles.last_i,'String',num2str(num1(end)));
1398elseif isequal(mode,'series(Dj)')
[137]1399    first_j=str2double(get(handles.first_j,'String'));
1400    last_j=str2double(get(handles.last_j,'String'));
1401    incr_j=str2double(get(handles.incr_j,'String'));
[2]1402    num_j=first_j:incr_j:last_j;
[137]1403    lastfield2=str2double(get(handles.nb_field2,'String'));
1404    if ~isnan(lastfield2)
[229]1405        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1406            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1407        num1=num_j(test_find);
[2]1408    end
1409    set(handles.first_j,'String',num2str(num1(1)));
1410    set(handles.last_j,'String',num2str(num1(end)));
[112]1411end
[2]1412
[177]1413%------------------------------------------------------------------------
1414% --- Executes on button press in RUN: processing on local computer
[67]1415function RUN_Callback(hObject, eventdata, handles)
1416%------------------------------------------------------------------------
[73]1417set(handles.RUN, 'Enable','Off')
1418set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[67]1419batch=0;
[229]1420errormsg=launch_jobs(hObject, eventdata, handles,batch);
[73]1421set(handles.RUN, 'Enable','On')
1422set(handles.RUN,'BackgroundColor',[1 0 0])
[36]1423
[177]1424% start status callback to visualise results
[229]1425if ~isempty(errormsg)
1426    display(errormsg)
1427    msgbox_uvmat('ERROR',errormsg)
[236]1428elseif  isfield(handles,'status') %&& ~isequal(get(handles.CivAll,'Value'),3)
[225]1429    set(handles.status,'Value',1);%suppress status display
1430    status_Callback(hObject, eventdata, handles)
[178]1431end
[177]1432
[12]1433%------------------------------------------------------------------------
[2]1434% --- Executes on button press in BATCH: remote processing
1435function BATCH_Callback(hObject, eventdata, handles)
[177]1436% -----------------------------------------------------------------------
[73]1437set(handles.BATCH, 'Enable','Off')
1438set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[67]1439batch=1;
[229]1440errormsg=launch_jobs(hObject, eventdata, handles, batch);
[73]1441set(handles.BATCH, 'Enable','On')
1442set(handles.BATCH,'BackgroundColor',[1 0 0])
[67]1443
[177]1444% start status callback to visualise results
[229]1445if ~isempty(errormsg)
1446    display(errormsg)
1447    msgbox_uvmat('ERROR',errormsg)
1448elseif isfield(handles,'status')
1449    set(handles.status,'Value',1);%suppress status display
1450    status_Callback(hObject, eventdata, handles)
[178]1451end
[227]1452
[67]1453%------------------------------------------------------------------------
[133]1454% --- Lauch command called by RUN and BATCH: remote processing
[229]1455function errormsg=launch_jobs(hObject, eventdata, handles, batch)
[67]1456%-----------------------------------------------------------------------
[229]1457errormsg='';%default
[133]1458%% check the selected list of operations:
[2]1459operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
1460box_test(1)=get(handles.CIV1,'Value');
1461box_test(2)=get(handles.FIX1,'Value');
1462box_test(3)=get(handles.PATCH1,'Value');
1463box_test(4)=get(handles.CIV2,'Value');
1464box_test(5)=get(handles.FIX2,'Value');
1465box_test(6)=get(handles.PATCH2,'Value');
[180]1466index_first=find(box_test==1,1);
1467if isempty(index_first)
[229]1468    errormsg='no selected operation';
[2]1469    return
1470end
[180]1471index_last=find(box_test==1,1,'last');
[159]1472box_used=box_test(index_first : index_last);
[2]1473[box_missing,ind_missing]=min(box_used);
[180]1474if isequal(box_missing,0); %there is a missing step in the sequence of operations
[229]1475    errormsg=['missing' cell2mat(operations(ind_missing))];
[2]1476    return
1477end
1478
[177]1479%% check mask if selecetd
[2]1480if isequal(get(handles.get_mask_civ1,'Value'),1)
[12]1481    maskname=get(handles.mask_civ1,'String');
1482    if ~exist(maskname,'file')
1483        get_mask_civ1_Callback(hObject, eventdata, handles);
1484    end
[2]1485end
1486if isequal(get(handles.get_mask_fix1,'Value'),1)
[12]1487    maskname=get(handles.mask_fix1,'String');
1488    if ~exist(maskname,'file')
1489        get_mask_fix1_Callback(hObject, eventdata, handles);
1490    end
[2]1491end
1492if isequal(get(handles.get_mask_civ2,'Value'),1)
[12]1493    maskname=get(handles.mask_civ2,'String');
1494    if ~exist(maskname,'file')
[112]1495        get_mask_civ2_Callback(hObject, eventdata, handles);
[12]1496    end
[2]1497end
1498if isequal(get(handles.get_mask_fix2,'Value'),1)
[12]1499    maskname=get(handles.mask_fix2,'String');
1500    if ~exist(maskname,'file')
[112]1501        get_mask_fix2_Callback(hObject, eventdata, handles);
[12]1502    end
[2]1503end
1504
[177]1505%% reinitialise status callback
[178]1506if isfield(handles,'status')
[180]1507    set(handles.status,'Value',0);%suppress status display
1508    status_Callback(hObject, eventdata, handles)
[178]1509end
[133]1510
1511%% set the list of files and check them
1512display('checking the files...')
[227]1513[ref_i,ref_j,errormsg]=find_ref_indices(handles);
1514if ~isempty(errormsg)
1515    return
1516end
[133]1517[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=...
[227]1518    set_civ_filenames(handles,ref_i,ref_j,box_test);
[177]1519set(handles.civ,'UserData',filecell);%store for futur use of status callback
[137]1520if isempty(filecell)% (error message displayed in fct set_civ_filenames)
[133]1521    return
1522end
1523nbfield=numel(num1_civ1);
1524nbslice=numel(num_a_civ1);
1525
1526%% read names of the .exe files for PIV and patch
1527path_UVMAT=fileparts(which('uvmat')); %path to the source directory of uvmat
[112]1528xmlfile='PARAM.xml';
[133]1529if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
[54]1530    t=xmltree(xmlfile);
[67]1531    s=convert(t);
[2]1532end
[127]1533test_interp=0;
1534if batch
[67]1535    if isfield(s,'BatchParam')
1536        sparam=s.BatchParam;
1537        if ~ismember(sparam.BatchMode,{'sge'})
[229]1538            errormsg=['batch mode ' sparam.BatchMode ' not supported by UVMAT'];
1539            return
[67]1540        end
1541    else
[229]1542        errormsg='no batch civ binaries defined in PARAM.xml';
[67]1543        return
1544    end
[225]1545    if isfield(sparam,'BatchMode')
1546        batch_mode=sparam.BatchMode;
1547    end
1548    % choice of batch priority:
1549    ind_answer=2;
1550    [s,w]=unix('qstat -q civ.q|grep job_| wc -l'); %check the waiting list (command unix)
1551    if isequal(s,0)
1552        w(end)=[];
[232]1553        str_displ={[w ' jobs in the waiting list'];...
1554            '***********************';...
1555            'JOBS PRIORITY POLICY';...
1556            '- urgent = less than 100 images pairs';...
1557            '- normal = during the experiments';...
1558            '- low = post processing';...
1559            '***********************';...
1560            'Select a priority:'};
1561            ' ';...
1562            str={'urgent';'normal';'low'};
[225]1563        [ind_answer,v] = listdlg('PromptString',str_displ,...
1564            'SelectionMode','single',...
[232]1565            'ListString',str,'ListSize',[200 100],'Name','job priority','InitialValue',3);
[225]1566        if isequal(v,0) % to handle Cancel button and figure close,
[229]1567            errormsg='job cancelled';
[225]1568            return % a better way should be create
1569        end
1570    else
1571        msgbox_uvmat('ERROR','sge batch system not available')
1572        return
1573    end
[67]1574else
1575    if isfield(s,'RunParam')
1576        sparam=s.RunParam;
1577    else
[225]1578        msgbox_uvmat('ERROR','no run civ binaries defined in PARAM.xml')
[67]1579        return
1580    end
[225]1581end
[238]1582
1583%% choose the civ program
1584ProgList=get(handles.CivAll,'String');
1585index=get(handles.CivAll,'Value');
1586CivX=isequal(ProgList{index},'CivX');
1587CivAll=isequal(ProgList{index},'CivAll');
1588CivUvmat=isequal(ProgList{index},'CivUvmat');
1589%CivAll=isequal(get(handles.CivAll,'Value'),2); % Boolean for new civ programs
1590if CivAll && isfield(sparam,'CivBin')
[225]1591    CivBin=sparam.CivBin;
1592    if ~exist(CivBin,'file') || ~isempty(which(CivBin))% if path defined as relative to uvmat
1593        sparam.CivBin=fullfile(path_UVMAT,CivBin);
1594        if ~exist(sparam.CivBin,'file')
1595             msgbox_uvmat('ERROR',['CIVx binary ' CivBin ' defined in PARAM.xm does not exist'])
1596             return
[112]1597        end
[94]1598    end
[225]1599end
1600if isfield(sparam,'Civ1Bin')
1601    Civ1Bin=sparam.Civ1Bin;
1602    if ~exist(Civ1Bin,'file')||~isempty(which(Civ1Bin))% if path defined as relative to uvmat
1603        sparam.Civ1Bin=fullfile(path_UVMAT,Civ1Bin);
1604        if ~exist(sparam.Civ1Bin,'file')
1605             msgbox_uvmat('ERROR',['civ1 binary ' Civ1Bin ' defined in PARAM.xm does not exist'])
1606             return
[112]1607        end
[94]1608    end
[225]1609end
1610if isfield(sparam,'Civ2Bin')
1611    Civ2Bin=sparam.Civ2Bin;
1612    if ~exist(Civ2Bin,'file')||~isempty(which(Civ2Bin))% if path defined as relative to uvmat     
1613        sparam.Civ2Bin=fullfile(path_UVMAT,Civ2Bin);
1614        if ~exist(sparam.Civ2Bin,'file')
1615             msgbox_uvmat('ERROR',['civ2 binary ' Civ2Bin ' defined in PARAM.xm does not exist'])
1616             return
[112]1617        end
[94]1618    end
[225]1619end
1620if  isfield(sparam,'PatchBin')
1621    if ~exist(sparam.PatchBin,'file')||~isempty(which(sparam.PatchBin))% if path defined as relative to uvmat
1622        sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
[94]1623    end
[73]1624end
[225]1625if isfield(sparam,'FixBin')
1626    if ~exist(sparam.FixBin,'file')||~isempty(which(sparam.FixBin))% if path defined as relative to uvmat
1627        sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
[2]1628    end
1629end
1630
1631
[225]1632
[133]1633%% get civ1 parameters:
[112]1634display('files OK, processing...')
[2]1635if box_test(1)==1
1636    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
[112]1637end
[2]1638
[133]1639%% get fix1 parameters
[112]1640if box_test(2)==1
[2]1641    flagindex1(1)=get(handles.vec_Fmin2, 'Value');
1642    flagindex1(2)=get(handles.vec_F3, 'Value');
1643    flagindex1(3)=get(handles.vec_F2, 'Value');
[127]1644    thresh_vecC1=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
1645    thresh_vel1=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
[2]1646    test_mask=get(handles.get_mask_fix1,'Value');
1647    nbslice_mask=get(handles.mask_fix1,'UserData'); % get the number of slices (= number of masks)
1648    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX
[112]1649    %     inf_sup=get(handles.inf_sup1,'Value');80
1650    %     fileref=get(handles.ref_fix1,'String');
1651    %     refpath=get(handles.ref_fix1,'UserData');
1652    %     fileref=fullfile(refpath,fileref);
[2]1653    menu=get(handles.field_ref1,'String');
1654    index=get(handles.field_ref1,'Value');
1655    if isempty(menu)
1656        fieldchoice='';
1657    else
1658        fieldchoice=menu{index};
[112]1659        msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
1660    end
[2]1661end
[112]1662
[133]1663%% get patch1 parameters
[67]1664if box_test(3)==1
[127]1665    rho_patch1=str2double(get(handles.rho_patch1,'String'));
1666    if isnan(rho_patch1)
[112]1667        rho_patch1='1000';
1668        set(handles.rho_patch1,'String','1')
1669    else
1670        rho_patch1=num2str(1000*rho_patch1);
1671    end
1672    nx_patch1=get(handles.nx_patch1,'String');
1673    ny_patch1=get(handles.ny_patch1,'String');
[127]1674    if isnan(str2double(nx_patch1))
[112]1675        nx_patch1='50' ;%default
1676        set(handles.nx_patch1,'String','50');
1677    end
[127]1678    if isnan(str2double(ny_patch1))
[112]1679        ny_patch1='50' ;%default
1680        set(handles.ny_patch1,'String','50');
1681    end
1682    subdomain_patch1=get(handles.subdomain_patch1,'String');
1683    thresh_patch1=get(handles.thresh_patch1,'String');
1684end
1685
[133]1686%% get civ2 parameters:
[2]1687if box_test(4)==1
1688    par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
1689end
1690
[133]1691%% get fix2 parameters
[112]1692if box_test(5)==1
[2]1693    flagindex2(1)=get(handles.vec_Fmin2_2, 'Value');
1694    flagindex2(2)=get(handles.vec_F3_2, 'Value');
1695    flagindex2(3)=get(handles.vec_F4, 'Value');
[127]1696    thresh_vec2C=str2double(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
1697    thresh_vel2=str2double(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
[2]1698    test_mask=get(handles.get_mask_fix2,'Value');
1699    nbslice_mask=get(handles.mask_fix2,'UserData'); % get the number of slices (= number of masks)
[112]1700    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
1701    %     inf_sup=get(handles.inf_sup2,'Value');
1702    %     ref=get(handles.ref_fix2,'UserData');
1703   
[2]1704    %%%%%%%%%%%%%%%%%%%
1705end
1706
[133]1707%% get patch2 parameters
[2]1708if box_test(6)==1
[127]1709    rho_patch2=str2double(get(handles.rho_patch2,'String'));
1710    if isnan(rho_patch2)
[2]1711        rho_patch2='1000';
1712        set(handles.rho_patch2,'String','1')
1713    else
1714        rho_patch2=num2str(1000*rho_patch2);
1715    end
1716    nx_patch2=get(handles.nx_patch2,'String');
1717    ny_patch2=get(handles.ny_patch2,'String');
[127]1718    if isnan(str2double(nx_patch2))
[2]1719        nx_patch2='50' ;%default
1720        set(handles.nx_patch2,'String','50');
1721    end
[127]1722    if isnan(str2double(ny_patch2))
[2]1723        ny_patch2='50' ;%default
1724        set(handles.ny_patch2,'String','50');
1725    end
1726    subdomain_patch2=get(handles.subdomain_patch2,'String');
1727    thresh_patch2=get(handles.thresh_patch2,'String');
[112]1728    %              test_interp=get(handles.test_interp,'Value');
[2]1729end
1730
[133]1731%% MAIN LOOP
[71]1732time=get(handles.RootName,'UserData'); %get the set of times
[134]1733super_cmd=[];
1734
[2]1735for ifile=1:nbfield
1736    for j=1:nbslice
[112]1737        i_cmd=0;
[2]1738        cmd='';
[73]1739        if isunix % check: necessaire aussi en RUN?
[112]1740            cmd='#!/bin/bash \n';
1741            cmd=[cmd '#$ -cwd \n'];
1742            cmd=[cmd 'hostname && date \n'];
[220]1743            cmd=[cmd 'umask 002 \n'];%allow writting access to created files for user group
[2]1744        end
[238]1745        if CivAll
1746            CivAllxml=xmltree;% xml contents,  all parameters
1747            CivAllCmd='';
1748            CivAllxml=set(CivAllxml,1,'name','CivDoc');
[2]1749        end
[174]1750        [Rootbat,Filebat]=fileparts(filecell.nc.civ1{ifile,j});%output netcdf file (without extention)
[177]1751        flname=fullfile(Rootbat,Filebat);
[159]1752        if batch
[174]1753            filename_bat=fullfile(Rootbat,['job_' Filebat]);
[159]1754         else
[177]1755            filename_bat=flname;
[159]1756        end
[174]1757        filename_bat=[filename_bat '.bat'];
[2]1758       
[112]1759        %CIV1
[2]1760        if box_test(1)==1
[41]1761            par_civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
[112]1762            par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
[2]1763            par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
[112]1764            par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
[2]1765            par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
[112]1766            par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
[2]1767            test_mask=get(handles.get_mask_civ1,'Value');
[112]1768            if test_mask==0
[2]1769                par_civ1.maskname='noFile use default';
1770                par_civ1.maskflag='n';
1771            else
1772                maskdispl=get(handles.mask_civ1,'String');
[12]1773                if exist(maskdispl,'file')
1774                    par_civ1.maskname=maskdispl;
[112]1775                    par_civ1.maskflag='y';
[2]1776                else
[136]1777                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1778                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1779                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
1780                    par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1781                    if exist(par_civ1.maskname,'file')
[82]1782                        par_civ1.maskflag='y';
[12]1783                    else
1784                        par_civ1.maskname='noFile use default';
[112]1785                        par_civ1.maskflag='n';
[12]1786                    end
[2]1787                end
1788            end
1789           
1790            test_grid=get(handles.browse_gridciv1,'Value');
1791            if test_grid
1792                par_civ1.gridflag='y';
1793                gridname=get(handles.grid_civ1,'String');
1794                if isequal(gridname(end-3:end),'grid')
[137]1795                    nbslice_grid=str2double(gridname(1:end-4)); %
1796                    if ~isnan(nbslice_grid)
[2]1797                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]1798                        par_civ1.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]1799                        if ~exist(par_civ1.gridname,'file')
[112]1800                            msgbox_uvmat('ERROR','grid file absent for civ1')
[2]1801                        end
1802                    elseif exist(gridname,'file')
[112]1803                        par_civ1.gridname=gridname;
[2]1804                    else
1805                        msgbox_uvmat('ERROR','grid file absent for civ1')
1806                    end
1807                end
1808            else
[112]1809                par_civ1.gridname='noFile use default';
1810                par_civ1.gridflag='n';
[2]1811            end
[112]1812            %
[2]1813            i_cmd=i_cmd+1;
[238]1814            if isequal(CivAll,0)
[230]1815                civ1_exe=CIV1_CMD(fullfile(Rootbat,Filebat),'',par_civ1,handles,sparam);%create the parameter file .civ1.cmx and set the execution string civ1_exe
[229]1816%                 if(isunix)
1817%                      cmd=[cmd 'cp -f ' flname '.civ1.cmx ' flname '.cmx\n'];
1818%                 else
1819%                     flname=regexprep(flname,'\\','\\\\');
1820%                     cmd=[cmd 'copy /Y "' flname '.civ1.cmx" "' flname '.cmx"\n'];
1821%                 end
[230]1822                cmd=[cmd civ1_exe '\n'];
[2]1823            else
[238]1824                CivAllCmd=[CivAllCmd ' civ1 '];
[174]1825                str=CIV1_CMD_Unified(fullfile(Rootbat,Filebat),'',par_civ1);
[112]1826                fieldnames=fields(str);
[238]1827                [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
[2]1828                for ilist=1:length(fieldnames)
[112]1829                    val=eval(['str.' fieldnames{ilist}]);
1830                    if ischar(val)
[238]1831                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
1832                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1833                    end
1834                end
[2]1835            end
1836        end
1837       
[112]1838        % FIX1
1839        if box_test(2)==1
1840            test_mask=get(handles.get_mask_fix1,'Value');
1841            if test_mask==0
[2]1842                maskname='';
[112]1843            else
[2]1844                maskdispl=get(handles.mask_fix1,'String');
[137]1845                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]1846                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
[136]1847                maskbase=[filecell.filebase '_' maskdispl];
[2]1848                maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
[112]1849            end
[238]1850            if CivX
[163]1851                if isunix %unix system
[94]1852                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
[112]1853                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1854                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
[163]1855                else %windows system
1856                    cmd_FIX=['"' sparam.FixBin '" -f "' filecell.nc.civ1{ifile,j} '" -fi1 ' num2str(flagindex1(1)) ...
1857                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1858                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName "' maskname '"'];
1859                    cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
1860                end
[94]1861                cmd=[cmd cmd_FIX '\n'];
[238]1862            elseif CivAll
[2]1863                fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
1864                fix1.fi1=num2str(flagindex1(1));
1865                fix1.fi2=num2str(flagindex1(2));
1866                fix1.fi3=num2str(flagindex1(3));
1867                fix1.threshC=num2str(thresh_vecC1);
[112]1868                fix1.threshV=num2str(thresh_vel1);
[2]1869                fieldnames=fields(fix1);
[238]1870                [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
[2]1871                for ilist=1:length(fieldnames)
[112]1872                    val=eval(['fix1.' fieldnames{ilist}]);
1873                    if ischar(val)
[238]1874                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
1875                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1876                    end
1877                end
[238]1878                CivAllCmd=[CivAllCmd ' fix1 '];
[112]1879            end
1880        end
1881       
1882        %PATCH1
1883        if box_test(3)==1
[238]1884            if isequal(CivAll,0)
[112]1885                cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
1886                cmd=[cmd cmd_PATCH '\n'];
1887            else
1888                patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1889                patch1.nopt=subdomain_patch1;
1890                patch1.maxdiff=thresh_patch1;
1891                patch1.ro=rho_patch1;
1892                test_grid=get(handles.get_gridpatch1,'Value');
1893                if test_grid
1894                    patch1.gridflag='y';
1895                    gridname=get(handles.grid_patch1,'String');
1896                    if isequal(gridname(end-3:end),'grid')
[137]1897                        nbslice_grid=str2double(gridname(1:end-4)); %
1898                        if ~isnan(nbslice_grid)
[112]1899                            num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]1900                            patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[112]1901                            if ~exist(patch1.gridPatch,'file')
1902                                msgbox_uvmat('ERROR','grid file absent for patch1')
1903                            end
1904                        elseif exist(gridname,'file')
1905                            patch1.gridPatch=gridname;
1906                        else
1907                            msgbox_uvmat('ERROR','grid file absent for patch1')
[2]1908                        end
1909                    end
[112]1910                else
1911                    patch1.gridPatch='none';
1912                    patch1.gridflag='n';
1913                    patch1.m=nx_patch1;
1914                    patch1.n=ny_patch1;
[2]1915                end
[112]1916                patch1.convectFlow='n';
1917                fieldnames=fields(patch1);
[238]1918                [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
[2]1919                for ilist=1:length(fieldnames)
[112]1920                    val=eval(['patch1.' fieldnames{ilist}]);
1921                    if ischar(val)
[238]1922                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
1923                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1924                    end
1925                end
[238]1926                CivAllCmd=[CivAllCmd ' patch1 '];
[112]1927            end
[2]1928        end
[112]1929       
[127]1930        if box_test(4)==1 || box_test(5)==1 || box_test(6)==1
[112]1931            filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
[229]1932            filename_cmx(end-1:end+1)='cmx';%name of cmx file
[112]1933        end
1934       
1935        if box_test(4)==1
[2]1936            par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
1937            par_civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
[174]1938            [Rootbat,Filebat]=fileparts(filecell.nc.civ2{ifile,j});%output netcdf file (without extention)
[2]1939            par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
[112]1940            par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
[2]1941            par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
[112]1942            par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
[2]1943            par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
[229]1944            par_civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
[2]1945            test_mask=get(handles.get_mask_civ2,'Value');
[112]1946            if test_mask==0
[2]1947                par_civ2.maskname='noFile use default';
1948                par_civ2.maskflag='n';
1949            else
1950                maskdispl=get(handles.mask_civ2,'String');
[12]1951                if exist(maskdispl,'file')
1952                    par_civ2.maskname=maskdispl;
1953                    par_civ2.maskflag='y';
[2]1954                else
[136]1955                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1956                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1957                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
1958                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1959                    if exist(par_civ2.maskname,'file')
[112]1960                        par_civ2.maskflag='y';
[12]1961                    else
1962                        par_civ2.maskname='noFile use default';
[112]1963                        par_civ2.maskflag='n';
[12]1964                    end
[2]1965                end
1966            end
1967            %TESTgrid
[137]1968            %test_grid=get(handles.browse_gridciv2,'Value');
[2]1969            gridname=get(handles.grid_civ2,'String');
[137]1970            %gridflag='y';
[2]1971            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
[137]1972                nbslice_grid=str2double(gridname(1:end-4)); %
1973                if ~isnan(nbslice_grid)
[2]1974                    par_civ2.gridflag='y';
1975                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]1976                    par_civ2.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]1977                    if exist(par_civ2.gridname,'file')
[112]1978                        par_civ2.gridflag='y';
[2]1979                    else
1980                        par_civ2.gridname='noFile use default';
[112]1981                        par_civ2.gridflag='n';
[2]1982                    end
1983                elseif exist(gridname,'file')
[112]1984                    par_civ2.gridflag='y';
[2]1985                else
1986                    par_civ2.gridname='noFile use default';
[112]1987                    par_civ2.gridflag='n';
[2]1988                end
1989            end
1990            i_cmd=i_cmd+1;
[177]1991            flname=fullfile(Rootbat,Filebat);
[230]1992           
[238]1993            if isequal(CivAll,0)
[230]1994                cmd_CIV2=CIV2_CMD(flname,[],par_civ2,sparam);%creates the cmx file [fullfile(Rootbat,Filebat) '.civ2.cmx]
1995%                 if(isunix)
1996                 cmd=[cmd cmd_CIV2 '\n'];
1997%                 else
1998%                     flname=regexprep(flname,'\\','\\\\');
1999%                     cmd=[cmd 'copy /Y "' flname '.civ2.cmx" "' flname '.cmx"\n' cmd_CIV2 '\n'];
2000%                 end
[2]2001            else
[238]2002                CivAllCmd=[CivAllCmd ' civ2 '];
[220]2003                str=CIV2_CMD_Unified(flname,'',par_civ2);
[112]2004                fieldnames=fields(str);
[238]2005                [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
[2]2006                for ilist=1:length(fieldnames)
2007                    val=eval(['str.' fieldnames{ilist}]);
2008                    if ischar(val)
[238]2009                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
2010                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[2]2011                    end
[112]2012                end
[2]2013            end
[112]2014        end
2015       
2016        % FIX2
2017        if box_test(5)==1
2018            test_mask=get(handles.get_mask_fix2,'Value');
2019            if test_mask==0
2020                maskname=''; %no mask used
[2]2021            else
2022                maskdispl=get(handles.mask_fix2,'String');
[136]2023                maskbase=[filecell.filebase '_' maskdispl]; %
[137]2024                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]2025                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2026                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
[112]2027            end
[238]2028            if isequal(CivAll,0)
[163]2029                if isunix
[94]2030                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
[112]2031                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2032                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
[163]2033                else
2034                    cmd_FIX=['"' sparam.FixBin '" -f "' filecell.nc.civ2{ifile,j} '" -fi1 ' num2str(flagindex2(1)) ...
2035                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2036                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName "' maskname '"'];
2037                    cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
2038                end
[112]2039                cmd=[cmd cmd_FIX '\n'];
2040            else
[2]2041                fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
2042                fix2.fi1=num2str(flagindex2(1));
2043                fix2.fi2=num2str(flagindex2(2));
2044                fix2.fi3=num2str(flagindex2(3));
2045                fix2.threshC=num2str(thresh_vec2C);
[112]2046                fix2.threshV=num2str(thresh_vel2);
[2]2047                fieldnames=fields(fix2);
[238]2048                [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
[2]2049                for ilist=1:length(fieldnames)
[112]2050                    val=eval(['fix2.' fieldnames{ilist}]);
2051                    if ischar(val)
[238]2052                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
2053                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]2054                    end
2055                end
[238]2056                CivAllCmd=[CivAllCmd ' fix2 '];
[112]2057            end
2058        end
2059       
2060        %PATCH2
2061        if box_test(6)==1
[238]2062            if isequal(CivAll,0)
[94]2063                cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
[90]2064                cmd=[cmd cmd_PATCH '\n'];
[12]2065            else
2066                patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
[220]2067                patch2.nopt=subdomain_patch2;
2068                patch2.maxdiff=thresh_patch2;
2069                patch2.ro=rho_patch2;
[12]2070                test_grid=get(handles.get_gridpatch2,'Value');
2071                if test_grid
2072                    patch2.gridflag='y';
2073                    gridname=get(handles.grid_patch2,'String');
2074                    if isequal(gridname(end-3:end),'grid')
[137]2075                        nbslice_grid=str2double(gridname(1:end-4)); %
2076                        if ~isnan(nbslice_grid)
[12]2077                            num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]2078                            patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[12]2079                            if ~exist(patch2.gridPatch,'file')
[112]2080                                msgbox_uvmat('ERROR','grid file absent for patch2')
[12]2081                            end
2082                        elseif exist(gridname,'file')
[112]2083                            patch2.gridPatch=gridname;
[12]2084                        else
2085                            msgbox_uvmat('ERROR','grid file absent for patch2')
[2]2086                        end
2087                    end
[12]2088                else
[112]2089                    patch2.gridPatch='none';
2090                    patch2.gridflag='n';
2091                    patch2.m=nx_patch2;
2092                    patch2.n=ny_patch2;
[2]2093                end
[12]2094                patch2.convectFlow='n';
2095                fieldnames=fields(patch2);
[238]2096                [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
[12]2097                for ilist=1:length(fieldnames)
[112]2098                    val=eval(['patch2.' fieldnames{ilist}]);
2099                    if ischar(val)
[238]2100                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
2101                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]2102                    end
2103                end
[238]2104                CivAllCmd=[CivAllCmd ' patch2 '];
[112]2105            end
[12]2106        end
[238]2107        if CivAll
2108            save(CivAllxml,[flname '.xml']);
2109            cmd=[cmd sparam.CivBin ' -f ' flname '.xml '  CivAllCmd ' >' flname '.log' '\n'];
[12]2110        end
[112]2111        % create the .bat file:
[159]2112        [fid,message]=fopen(filename_bat,'w');
2113        if isequal(fid,-1)
2114            msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
2115            return
[12]2116        end
[39]2117        fprintf(fid,cmd);
2118        fclose(fid);
[67]2119        if batch
2120            switch batch_mode
2121                case 'sge'
2122                    pvalue=num2str((1-ind_answer)*500);
[177]2123                    display(['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
2124                    eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
[67]2125            end
[238]2126        elseif ~CivUvmat
[112]2127            %% to lauch the jobs locally :
[12]2128            if(isunix)
[135]2129                cmd_str=['. ' filename_bat];
[133]2130            else %case of Windows
[163]2131                cmd_str=['@call "' regexprep(filename_bat,'\\','\\\\') '"'];
[2]2132            end
[135]2133            super_cmd=[super_cmd cmd_str '\n'];         
2134            disp(cmd_str);
[225]2135        else       %run PIVlab if selected
[244]2136            drawnow
[238]2137            if box_test(1)==1
2138                Param.Civ1=par_civ1;
2139            end
2140            if box_test(2)==1
2141                fix1.WarnFlags=[];
2142                if get(handles.vec_Fmin2,'Value')
2143                    fix1.WarnFlags=[fix1.WarnFlags -2];
2144                end
2145                if get(handles.vec_F3,'Value')
2146                    fix1.WarnFlags=[fix1.WarnFlags 3];
2147                end
2148                fix1.LowerBoundCorr=thresh_vecC1;
2149                if get(handles.inf_sup1,'Value')
2150                    fix1.UppperBoundVel=thresh_vel1;
2151                else
2152                     fix1.LowerBoundVel=thresh_vel1;
[251]2153                end   
2154                if get(handles.get_mask_fix1,'Value')
2155                    fix1.MaskName=maskname;
2156                end     
[238]2157                Param.Fix1=fix1;
2158            end
2159            if box_test(3)==1
2160                Param.Patch1.Rho=rho_patch1;
2161                Param.Patch1.Threshold=thresh_patch1;
2162                Param.Patch1.SubDomain=subdomain_patch1;
2163            end
[248]2164            if box_test(4)==1
2165                Param.Civ2=par_civ2;
2166            end
[252]2167            if box_test(5)==1
2168                fix2.WarnFlags=[];
2169                if get(handles.vec_Fmin2_2,'Value')
2170                    fix2.WarnFlags=[fix2.WarnFlags -2];
2171                end
2172                if get(handles.vec_F4,'Value')
2173                    fix2.WarnFlags=[fix2.WarnFlags 4];
2174                end
2175                if get(handles.vec_F3_2,'Value')
2176                    fix2.WarnFlags=[fix2.WarnFlags 3];
2177                end
2178                fix2.LowerBoundCorr=thresh_vec2C;
2179                if get(handles.inf_sup2,'Value')
2180                    fix2.UppperBoundVel=thresh_vel2;
2181                else
2182                    fix2.LowerBoundVel=thresh_vel2;
2183                end   
2184                if get(handles.get_mask_fix2,'Value')
2185                    fix2.MaskName=maskname;
2186                end     
2187                Param.Fix2=fix2;
2188            end
[238]2189            [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
[225]2190            if isempty(errormsg)
2191                display([filecell.nc.civ1{ifile,j} ' written'])
2192            else
2193                msgbox_uvmat('ERROR',errormsg)
2194            end
2195        end                 
[112]2196    end
[2]2197end
[134]2198
[238]2199if ~batch && ~CivUvmat
[159]2200    [Rootbat,Filebat,extbat]=fileparts(filename_bat);
[229]2201    filename_superbat=fullfile(Rootbat,'job_list.bat');
[134]2202    fid=fopen(filename_superbat,'w');
2203    fprintf(fid,super_cmd');
2204    fclose(fid);
[219]2205     if(isunix)
2206        system(['chmod +x ' filename_superbat])
2207     end
[192]2208     system([filename_superbat ' &'])% execute main commmand
[133]2209end
[2]2210
[137]2211%% save interface state
[2]2212if isfield(filecell,'nc')
2213    if isfield(filecell.nc,'civ2')
2214        fileresu=filecell.nc.civ2{1,1};
2215    else
2216        fileresu=filecell.nc.civ1{1,1};
2217    end
2218end
2219[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
2220namedoc=fullfile(RootPath,subdir,RootFile);
[112]2221detect=1;
[2]2222while detect==1
2223    namefigfull=[namedoc '.fig'];
2224    hh=dir(namefigfull);
2225    if ~isempty(hh)
2226        detect=1;
2227        namedoc=[namedoc '.0'];
2228    else
2229        detect=0;
2230    end
2231end
2232saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
2233
[227]2234%------------------------------------------------------------------------
2235% --- determine the list of reference indices of processing file
2236function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
2237%------------------------------------------------------------------------
2238errormsg=''; %default error message
2239first_i=str2double(get(handles.first_i,'String'));%first index i
2240last_i=str2double(get(handles.last_i,'String'));%last index i
2241incr_i=str2double(get(handles.incr_i,'String'));% increment
2242if isequal(get(handles.first_j,'Visible'),'on')
2243    first_j=str2double(get(handles.first_j,'String'));%first index j
2244    last_j=str2double(get(handles.last_j,'String'));%last index j
2245    incr_j=str2double(get(handles.incr_j,'String'));% increment
2246else
2247    first_j=1;
2248    last_j=1;
2249    incr_j=1;
2250end
2251ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
2252ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
2253if isnan(first_i)||isnan(first_j)
2254    errormsg='first field number not defined';
2255elseif isnan(last_i)||isnan(last_j)
2256    errormsg='last field number not defined';
2257elseif isnan(incr_i)||isnan(incr_j)
2258    errormsg='increment in field number not defined';
2259elseif last_i < first_i || last_j < first_j
2260    errormsg='last field number must be larger than the first one';
2261end
[134]2262
[227]2263%------------------------------------------------------------------------
2264% --- determine the list of filenames and indices needed for launch_job
[2]2265function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
[227]2266    set_civ_filenames(handles,ref_i,ref_j,box_test)
[12]2267%------------------------------------------------------------------------
[85]2268filecell=[];%default
[136]2269
2270%% get the root names nomenclature and numbers
[71]2271filebase=get(handles.RootName,'String');
[136]2272
2273if isempty(filebase)||isequal(filebase,'')
2274    msgbox_uvmat('ERROR','no input files')
2275    return
2276end
2277
[137]2278%filebase=regexprep(filebase,'\.fsnet','fsnet');% temporary fix for cluster Coriolis
[136]2279filecell.filebase=filebase;
2280
[2]2281browse=get(handles.browse_root,'UserData');
2282compare_list=get(handles.compare,'String');
2283val=get(handles.compare,'Value');
2284compare=compare_list{val};
2285if strcmp(compare,'displacement')
2286    mode='displacement';
2287else
2288    mode_list=get(handles.mode,'String');
2289    mode_value=get(handles.mode,'Value');
2290    mode=mode_list{mode_value};
2291end
[137]2292%time=get(handles.RootName,'UserData'); %get the set of times
[71]2293ext_ima=get(handles.ImaExt,'String');
[2]2294nom_type_nc=browse.nom_type_nc;
[122]2295if isfield(browse,'nom_type_ima')
2296    nom_type_ima2=browse.nom_type_ima;
2297end
2298if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
2299if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
[2]2300[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
[227]2301    find_pair_indices(handles,ref_i,ref_j,mode);
[2]2302%determine the new filebase for 'displacement' mode (comparison of two series)
2303filebase_B=filebase;% root name of the second field series for stereo
2304if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
[127]2305%     test_disp=1;
[2]2306    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
2307    [Path2,Name2]=fileparts(filebase_B);
2308    Path1=Path2;
[71]2309    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
[2]2310    filebase_A=fullfile(Path1,Name1);
2311    if length(Name1)>6
2312        Name1=Name1(end-5:end);
2313    end
2314    if length(Name2)>6
2315        Name2=Name2(end-5:end);
2316    end
2317    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
2318else
[127]2319%     test_disp=0;
[2]2320    filebase_A=filebase;
2321    nom_type_ima1=nom_type_ima2;
2322    filebase_AB=filebase;
2323end
2324if strcmp(compare,'displacement')
[112]2325    filebase_ima1=filebase_A;
2326    filebase_ima2=filebase_B;
2327    filebase_nc=filebase_AB; %root name for the result of civ2
[2]2328else
[112]2329    filebase_ima1=filebase_B;
2330    filebase_ima2=filebase_B;
2331    filebase_nc=filebase_B;
2332end
[2]2333
2334%determine reference files for fix:
2335file_ref_fix1={};%default
2336file_ref_fix2={};
2337nbfield=length(num1_civ1);
2338nbslice=length(num_a_civ1);
2339if box_test(2)==1% fix1 performed
2340    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
2341    if ~isempty(ref)
[137]2342        first_i=str2double(get(handles.first_i,'String'));
2343        last_i=str2double(get(handles.last_i,'String'));
2344        incr_i=str2double(get(handles.incr_i,'String'));
2345        first_j=str2double(get(handles.first_j,'String'));
2346        last_j=str2double(get(handles.last_j,'String'));
2347        incr_j=str2double(get(handles.incr_j,'String'));
[127]2348        num_i_ref=first_i:incr_i:last_i;
2349        num_j_ref=first_j:incr_j:last_j;
[2]2350        if isequal(mode,'displacement')
2351            num_i1=num_i_ref;
2352            num_i2=num_i_ref;
2353            num_j1=num_j_ref;
2354            num_j2=num_j_ref;
2355        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
2356            num_i1=num_i_ref;
2357            num_i2=num_i1;
2358            num_j1=ref.num_a*ones(size(num_i_ref));
2359            num_j2=ref.num_b*ones(size(num_i_ref));
2360        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
2361            delta1=floor((ref.num2-ref.num1)/2);
2362            delta2=ceil((ref.num2-ref.num1)/2);
2363            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2364            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2365            if isempty(ref.num_a)
2366                ref.num_a=1;
2367            end
2368            num_j1=ref.num_a*ones(size(num_i1));
2369            num_j2=num_j1;
2370        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
2371            delta1=floor((ref.num_b-ref.num_a)/2);
2372            delta2=ceil((ref.num_b-ref.num_a)/2);
2373            num_i1=ref.num1*ones(size(num_i_ref));
2374            num_i2=num_i1;
2375            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2376            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2377        end
2378        for ifile=1:nbfield
2379            for j=1:nbslice
2380                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2381                file_ref_fix1(ifile,j)={file_ref};
2382                if ~exist(file_ref,'file')
2383                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
[12]2384                    filecell=[];
[2]2385                    return
2386                end
2387            end
2388        end
2389    end
2390end
2391
2392%determine reference files for fix2:
2393if box_test(5)==1% fix2 performed
2394    ref=get(handles.ref_fix2,'UserData');
2395    if ~isempty(ref)
[127]2396        first_i=str2double(get(handles.first_i,'String'));
2397        last_i=str2double(get(handles.last_i,'String'));
2398        incr_i=str2double(get(handles.incr_i,'String'));
2399        first_j=str2double(get(handles.first_j,'String'));
2400        last_j=str2double(get(handles.last_j,'String'));
2401        incr_j=str2double(get(handles.incr_j,'String'));
[229]2402        num_i_ref=first_i:incr_i:last_i;
2403        num_j_ref=first_j:incr_j:last_j;
[2]2404        if isequal(mode,'displacement')
2405            num_i1=num_i_ref;
2406            num_i2=num_i_ref;
2407            num_j1=num_j_ref;
2408            num_j2=num_j_ref;
2409        elseif isequal(mode,'pair j1-j2')
2410            num_i1=num_i_ref;
2411            num_i2=num_i1;
2412            num_j1=ref.num_a;
2413            num_j2=ref.num_b;
2414        elseif isequal(mode,'series(Di)')
2415            delta1=floor((ref.num2-ref.num1)/2);
2416            delta2=ceil((ref.num2-ref.num1)/2);
2417            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2418            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2419            num_j1=ref.num_a*ones(size(num_i1));
2420            num_j2=num_j1;
2421        elseif isequal(mode,'series(Dj)')
2422            delta1=floor((ref.num_b-ref.num_a)/2);
2423            delta2=ceil((ref.num_b-ref.num_a)/2);
2424            num_i1=ref.num1*ones(size(num_i_ref));
2425            num_i2=num_i1;
2426            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2427            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2428        end
2429        for ifile=1:nbfield
2430            for j=1:nbslice
2431                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2432                file_ref_fix2(ifile,j)={file_ref};
2433                if ~exist(file_ref,'file')
2434                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
[122]2435                    filecell={};
[2]2436                    return
2437                end
2438            end
2439        end
2440    end
2441end
2442
2443%check dir
2444subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
2445subdir_civ2=get(handles.subdir_civ2,'String');
[174]2446if isequal(subdir_civ1,''),subdir_civ1='CIV'; end% put default subdir
[2]2447if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
[135]2448currentdir=pwd;%store the current working directory
[2]2449[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
2450if ~exist(Path_ima,'dir')
[12]2451    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
[122]2452    filecell={};
[2]2453    return
2454end
[127]2455[xx,message]=fileattrib(Path_ima);
[122]2456if ~isempty(message) && ~isequal(message.UserWrite,1)
[112]2457    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
[122]2458    filecell={};
[112]2459    cd(currentdir);
2460    return
[2]2461end
2462
2463%check the existence of the netcdf and image files involved
2464% %%%%%%%%%%%%  case CIV1 activated   %%%%%%%%%%%%%
2465if box_test(1)==1;
[112]2466    detect=1;
[127]2467    vers=0;
2468    subdir_civ1_new=subdir_civ1;
[153]2469    while detect==1 %create a new subdir if the netcdf files already exist
[122]2470        for ifile=1:nbfield
[112]2471            for j=1:nbslice
[122]2472                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);
[112]2473                detect=exist(filename,'file')==2;
2474                if detect% if a netcdf file already exists
[137]2475                    indstr=regexp(subdir_civ1_new,'\D');
2476                    if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2477                        vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2478                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2479                    else
2480                        vers=vers+1;
[137]2481                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) '_' num2str(vers)];       
[127]2482                    end
[137]2483                    subdir_civ2=subdir_civ1_new;
[112]2484                    break
2485                end
2486                filecell.nc.civ1(ifile,j)={filename};
2487            end
2488            if detect% if a netcdf file already exists
2489                break
2490            end
2491        end
[134]2492 
[112]2493        %create the new subdir_civ1
[127]2494        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
[134]2495            cd(Path_ima);         
[128]2496            [xx,msg1]=mkdir(subdir_civ1_new);
[134]2497
[128]2498            if ~strcmp(msg1,'')
2499                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
[122]2500                filecell={};
2501                return
[163]2502            elseif isunix         
[128]2503                [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2504                if ~strcmp(msg2,'')
[134]2505                    msgbox_uvmat('ERROR',['pb of permission for  ' subdir_civ1_new ': ' msg2])%error message for directory creation
[128]2506                    filecell={};
2507                    return
2508                end
[112]2509            end
[134]2510            cd(currentdir);
[112]2511        end
2512        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
2513            for ifile=1:nbfield
2514                for j=1:nbslice
[122]2515                    filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);%
[112]2516                    detect=exist(filename,'file')==2;
[2]2517                    if detect% if a netcdf file already exists
[137]2518                       indstr=regexp(subdir_civ1_new,'\D');
2519                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2520                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2521                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2522                       else
2523                           vers=vers+1;
[137]2524                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
[127]2525                       end
2526                       subdir_civ2=subdir_civ1;
2527                       break
[2]2528                    end
[112]2529                    filecell.ncA.civ1(ifile,j)={filename};
2530                end
2531                if detect% if a netcdf file already exists
2532                    break
2533                end
2534            end
2535            %create the new subdir_civ1
[134]2536            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2537                   cd(Path_ima);         
[128]2538                [xx,msg1]=mkdir(subdir_civ1_new);
[134]2539                            cd(currentdir);
[252]2540                if ~strcmp(msg1,'')
[128]2541                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
[122]2542                    cd(currentdir)
2543                    filecell={};
2544                    return
[128]2545                else
2546                    [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2547                    if ~strcmp(msg2,'')
2548                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
2549                        cd(currentdir)
2550                        filecell={};
2551                        return
2552                    end
[112]2553                end
2554            end
2555        end
2556    end
[127]2557    subdir_civ1=subdir_civ1_new;
[2]2558    % get image names
2559    for ifile=1:nbfield
[112]2560        for j=1:nbslice
[2]2561            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2562            idetect(j)=exist(filename,'file')==2;
2563            filecell.ima1.civ1(ifile,j)={filename}; %first image
2564            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2565            idetect_1(j)=exist(filename,'file')==2;
2566            filecell.ima2.civ1(ifile,j)={filename};%second image
[112]2567        end
2568        [idetectmin,indexj]=min(idetect);
2569        if idetectmin==0,
2570            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
[122]2571            filecell={};
2572            cd(currentdir)
[112]2573            return
2574        end
2575        [idetectmin,indexj]=min(idetect_1);
2576        if idetectmin==0,
2577            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
[122]2578            filecell={};
[112]2579            cd(currentdir)
2580            return
2581        end
2582    end
2583    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2584        for ifile=1:nbfield
2585            for j=1:nbslice
2586                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2587                idetect(j)=exist(filename,'file')==2;
2588                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2589                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2590                idetect_1(j)=exist(filename,'file')==2;
2591                filecell.imaA2.civ1(ifile,j)={filename};%second image
2592            end
[2]2593            [idetectmin,indexj]=min(idetect);
[112]2594            if idetectmin==0,
2595                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
[122]2596                filecell={};
[112]2597                cd(currentdir)
[2]2598                return
[112]2599            end
[2]2600            [idetectmin,indexj]=min(idetect_1);
[112]2601            if idetectmin==0,
2602                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
[122]2603                filecell={};
[2]2604                cd(currentdir)
2605                return
[112]2606            end
2607        end
[2]2608    end
[112]2609   
2610    %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
2611elseif (box_test(2)==1 || box_test(3)==1);
[2]2612    for ifile=1:nbfield
2613        for j=1:nbslice
2614            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
[112]2615                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2616            detect=exist(filename,'file')==2;
[122]2617            if detect==0
2618                msgbox_uvmat('ERROR',[filename ' not found'])
2619                filecell={};
2620                cd(currentdir)
2621                return
2622            end
[2]2623            filecell.nc.civ1(ifile,j)={filename};
2624        end
2625    end
2626    if strcmp(compare,'stereo PIV')
[112]2627        for ifile=1:nbfield
2628            for j=1:nbslice
2629                filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2630                filecell.ncA.civ1(ifile,j)={filename};
2631                if ~exist(filename,'file')
2632                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2633                    set(handles.RUN, 'Enable','On')
2634                    set(handles.RUN,'BackgroundColor',[1 0 0])
[122]2635                    filecell={};
[112]2636                    cd(currentdir)
2637                    return
[2]2638                end
2639            end
[112]2640        end
[2]2641    end
2642end
2643
2644%%%%%%%%%%%%%  if civ2 performed with pairs different than civ1  %%%%%%%%%%%%%
2645testdiff=0;
2646if (box_test(4)==1)&&...
[127]2647        ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
[2]2648    testdiff=1;
[112]2649    detect=1;
[127]2650    vers=0;
2651    subdir_civ2_new=subdir_civ2;
[2]2652    while detect==1 %create a new subdir if the netcdf files already exist
[112]2653        for ifile=1:nbfield
2654            for j=1:nbslice
[127]2655                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2_new);%
[112]2656                detect=exist(filename,'file')==2;
2657                if detect% if a netcdf file already exists
[127]2658                    indstr=regexp(subdir_civ2,'\D');
2659                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2660                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2661                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2662                    else
2663                        vers=vers+1;
2664                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2665                    end
[112]2666                    break
2667                end
2668                filecell.nc.civ2(ifile,j)={filename};
2669            end
2670            if detect% if a netcdf file already exists
2671                break
2672            end
2673        end
[128]2674        %create the new subdir_civ2_new
2675        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
[174]2676            [xx,m2]=mkdir(fullfile(Path_ima,subdir_civ2_new));
[128]2677            [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2678            if ~isequal(m2,'')
[128]2679                msgbox_uvmat('ERROR',['cannot create ' subdir_civ2_new ': ' m2])
[122]2680                filecell={};
2681                cd(currentdir)
2682                return
[112]2683            end
2684        end
2685        if strcmp(compare,'stereo PIV')%check second nc series
2686            for ifile=1:nbfield
2687                for j=1:nbslice
2688                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[122]2689                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
[112]2690                    detect=exist(filename,'file')==2;
[2]2691                    if detect% if a netcdf file already exists
[127]2692                        indstr=regexp(subdir_civ2,'\D');
2693                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2694                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2695                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2696                        else
2697                           vers=vers+1;
2698                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2699                        end
[112]2700                        break
[2]2701                    end
[112]2702                    filecell.ncA.civ2(ifile,j)={filename};
2703                end
2704                if detect% if a netcdf file already exists
2705                    break
2706                end
2707            end
[122]2708            subdir_civ2=subdir_civ2_new;
[112]2709            %create the new subdir_civ1
[127]2710            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2711                [xx,m2]=mkdir(subdir_civ2_new);
[128]2712                 [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2713                if ~isequal(m2,'')
[128]2714                    msgbox_uvmat('ERROR', ['cannot create ' subdir_civ2_new ': ' m2])%error message for directory creation
[122]2715                    cd(currentdir)
2716                    filecell={};
2717                    return
[112]2718                end
2719            end
2720        end
2721    end
[127]2722    subdir_civ2=subdir_civ2_new;
[2]2723end
2724cd(currentdir);%come back to the current working directory
2725
2726%%%%%%%%%%%%%  if civ2 results are obtained or used  %%%%%%%%%%%%%
2727if box_test(4)==1 || box_test(5)==1 || box_test(6)==1 %civ2
2728    %check source netcdf file of civ1 estimates
2729    if box_test(1)==0; %no civ1 performed
2730        for ifile=1:nbfield
2731            for j=1:nbslice
2732                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2733                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2734                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2735                if ~exist(filename,'file')
2736                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[122]2737                    filecell={};
[2]2738                    return
2739                end
2740                if ~testdiff % civ2 or patch2 are written in the same file as civ1
2741                    if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
[248]2742                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2743                        if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
[2]2744                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2745                            filecell=[];
[2]2746                            return
[248]2747                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
2748                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2749                            filecell=[];
2750                            return
[112]2751                        end
[2]2752                    elseif box_test(3)==0; %check the existence of patch if it is not calculated
[248]2753                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch')
2754                        if ~isempty(Data.CivStage)
2755                            if Data.CivStage<3 %test for civ files
2756                                msgbox_uvmat('ERROR',['no patch data in ' filename])
2757                                filecell=[];
2758                                return
2759                            end
2760                        elseif isempty(Data.patch)||isequal(Data.patch,0)
[2]2761                            msgbox_uvmat('ERROR',['no patch data in ' filename])
[12]2762                            filecell=[];
[2]2763                            return
2764                        end
[112]2765                    end
[2]2766                end
2767            end
2768        end
2769        if strcmp(compare,'stereo PIV')
2770            for ifile=1:nbfield
2771                for j=1:nbslice
2772                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2773                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2774                    filecell.ncA.civ2(ifile,j)={filename};
2775                    if ~exist(filename,'file')
2776                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2777                        set(handles.RUN, 'Enable','On')
2778                        set(handles.RUN,'BackgroundColor',[1 0 0])
2779                        return
2780                    end
2781                end
2782            end
2783        end
2784    end
[112]2785   
2786    detect=1;
2787    %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
2788    for ifile=1:nbfield
2789        for j=1:nbslice
2790            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[2]2791                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
[112]2792            detect=exist(filename,'file')==2;
2793            filecell.nc.civ2(ifile,j)={filename};
[2]2794        end
[112]2795    end
[2]2796    %get first image names for civ2
2797    if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
2798        filecell.ima1.civ2=filecell.ima1.civ1;
2799    elseif box_test(4)==1
2800        for ifile=1:nbfield
2801            for j=1:nbslice
2802                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2803                idetect_2(j)=exist(filename,'file')==2;
2804                filecell.ima1.civ2(ifile,j)={filename};%first image
2805            end
[112]2806            [idetectmin,indexj]=min(idetect_2);
[2]2807            if idetectmin==0,
[112]2808                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2809                filecell=[];
2810                return
[2]2811            end
2812        end
2813    end
2814   
2815    %get second image names for civ2
2816    if box_test(1)==1 & isequal(num2_civ1,num2_civ2) & isequal(num_b_civ1,num_b_civ2)
2817        filecell.ima2.civ2=filecell.ima2.civ1;
2818    elseif box_test(4)==1
2819        for ifile=1:nbfield
2820            for j=1:nbslice
2821                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2822                idetect_3(j)=exist(filename,'file')==2;
2823                filecell.ima2.civ2(ifile,j)={filename};%first image
2824            end
[112]2825            [idetectmin,indexj]=min(idetect_3);
[2]2826            if idetectmin==0,
[112]2827                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2828                filecell=[];
2829                return
[2]2830            end
2831        end
2832    end
2833end
2834if (box_test(5)==1 || box_test(6)==1 ) && box_test(4)==0  % need to read an existing netcdf civ2 file
2835    if ~testdiff
2836        filecell.nc.civ2=filecell.nc.civ1;% file already checked
[112]2837    else     % check the civ2 files
[2]2838        for ifile=1:nbfield
2839            for j=1:nbslice
2840                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[112]2841                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
[2]2842                filecell.nc.civ2(ifile,j)={filename};
2843                if ~exist(filename,'file')
2844                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[12]2845                    filecell=[];
[2]2846                    return
2847                else
[248]2848                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2849                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
2850                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2851                            filecell=[];
2852                            return
2853                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
[2]2854                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2855                        filecell=[];
[2]2856                        return
2857                    end
2858                end
2859            end
2860        end
2861    end
2862end
2863
2864%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2865if strcmp(compare,'stereo PIV')
[127]2866    if  box_test(3)==1 && isequal(get(handles.test_stereo1,'Value'),1)
[2]2867        for ifile=1:nbfield
2868            for j=1:nbslice
2869                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2870                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2871                filecell.st(ifile,j)={filename};
2872            end
2873        end
2874    end
[127]2875    if  box_test(6)==1 && isequal(get(handles.test_stereo2,'Value'),1)
[2]2876        for ifile=1:nbfield
2877            for j=1:nbslice
2878                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2879                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2880                filecell.st(ifile,j)={filename};
2881            end
2882        end
[112]2883    end
[2]2884end
2885set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
2886set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
2887browse.nom_type_nc=nom_type_nc;
2888set(handles.browse_root,'UserData',browse); %update the nomenclature type for uvmat
2889
2890
2891%COPY IMAGES TO THE FORMAT .png IF NEEDED
[45]2892if isequal(nom_type_ima1,'*')%case of movie files
2893    nom_type_imanew1='_i';
[2]2894else
2895    nom_type_imanew1=nom_type_ima1;
2896end
[45]2897if isequal(nom_type_ima2,'*')%case of movie files
2898    nom_type_imanew2='_i';
[2]2899else
2900    nom_type_imanew2=nom_type_ima2;
2901end
2902if ~isequal(ext_ima,'.png')
[45]2903    %%type of image file
2904    type_ima1='none';%default
2905    movieobject1=[];%default
[133]2906    if strcmpi(ext_ima,'.avi')
[45]2907        hhh=which('mmreader');
2908        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2909            type_ima1='movie';
2910            movieobject1=mmreader([filebase_ima2 ext_ima]);
2911        else
2912            type_ima1='avi';
2913        end
[133]2914    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2915        form=imformats(ext_ima(2:end));
2916        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2917            if isequal(nom_type_ima1,'*');
2918                type_ima1='multimage';%image series in a single image file
2919            else
2920                type_ima1='image';
2921            end
2922        end
[45]2923    end
2924    type_ima2='none';%default
2925    movieobject2=[];
[133]2926    if strcmpi(ext_ima,'.avi')
[45]2927        hhh=which('mmreader');
2928        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2929            type_ima2='movie';
2930            movieobject2=mmreader([filebase_ima2 ext_ima]);
2931        else
2932            type_ima2='avi';
2933        end
[133]2934    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2935        form=imformats(ext_ima(2:end));
2936        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2937            if isequal(nom_type_ima1,'*');
2938                type_ima2='multimage';%image series in a single image file
2939            else
2940                type_ima2='image';
2941            end
2942        end
[45]2943    end
[71]2944    %npxy=get(handles.ImaExt,'UserData');
[112]2945    % %     if numel(npxy)<2
2946    %
2947    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
2948    %         A=imread(filename);
2949    %         npxy=size(A);
2950    % %     end
2951    %     npy=npxy(1);
2952    %     npx=npxy(2);
[2]2953    if box_test(1)==1 %if civ1 is performed
[224]2954        h = waitbar(0,'copy images to the .png format for civ1');% display a wait bar
[112]2955        for ifile=1:nbfield
[2]2956            waitbar(ifile/nbfield);
2957            for j=1:nbslice
[112]2958                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
2959                if ~exist(filename,'file')
2960                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
2961                    imwrite(A,filename,'BitDepth',16);
2962                end
2963                filecell.ima1.civ1(ifile,j)={filename};
2964                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
2965                if ~exist(filename,'file')
2966                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
2967                    imwrite(A,filename,'BitDepth',16);
2968                end
2969                filecell.ima2.civ1(ifile,j)={filename};
[2]2970            end
2971        end
2972        close(h)
2973    end
2974    if box_test(4)==1 %if civ2 is performed
[229]2975        h = waitbar(0,'copy images to the .png format for civ2');% display a wait bar
[2]2976        for ifile=1:nbfield
2977            waitbar(ifile/nbfield);
2978            for j=1:nbslice
[112]2979                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
2980                if ~exist(filename,'file')
2981                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
2982                    imwrite(A,filename,'BitDepth',16);
2983                end
2984                filecell.ima1.civ2(ifile,j)={filename};
2985                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
2986                if ~exist(filename,'file')
2987                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
2988                    imwrite(A,filename,'BitDepth',16);
2989                end
2990                filecell.ima2.civ2(ifile,j)={filename};
[2]2991            end
2992        end
2993        close(h);
2994    end
2995end
2996
[12]2997%------------------------------------------------------------------------
[227]2998% --- determine the list of index pairs of processing file
2999function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
3000    find_pair_indices(handles,ref_i,ref_j,mode)
3001%------------------------------------------------------------------------
3002
3003list_civ1=get(handles.list_pair_civ1,'String');
3004index_civ1=get(handles.list_pair_civ1,'Value');
3005str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
3006if isempty(str_civ1)||isequal(str_civ1,'')
3007    msgbox_uvmat('ERROR','no image pair selected for civ1')
3008    return
3009end
3010list_civ2=get(handles.list_pair_civ2,'String');
3011index_civ2=get(handles.list_pair_civ2,'Value');
3012if index_civ2>length(list_civ2)
3013    list_civ2=list_civ1;
3014    index_civ2=index_civ1;
3015end
3016str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
3017
3018if isequal (mode,'series(Di)')
3019    lastfield=str2double(get(handles.nb_field,'String'));
3020    num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers
3021    num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i));
3022    num_a_civ1=ref_j;
3023    num_b_civ1=ref_j;
[229]3024    num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));
[227]3025    num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
3026    num_a_civ2=ref_j;
3027    num_b_civ2=ref_j;   
3028   
3029    % adjust the first and last field number
3030    lastfield=str2double(get(handles.nb_field,'String'));
3031    if isnan(lastfield)
3032        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
3033    else
3034        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
3035    end
3036    if length(indsel)>=1
3037        firstind=indsel(1);
3038        lastind=indsel(end);
3039        set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields
3040        set(handles.last_i,'String',num2str(ref_i(lastind)))
3041        ref_i=ref_i(indsel);
3042        num1_civ1=num1_civ1(indsel);
3043        num1_civ2=num1_civ2(indsel);
3044        num2_civ1=num2_civ1(indsel);
3045        num2_civ2=num2_civ2(indsel);
3046    end
3047elseif isequal (mode,'series(Dj)')
3048    lastfield_j=str2double(get(handles.nb_field2,'String'));
3049    num1_civ1=ref_i;% set of first image numbers
3050    num2_civ1=ref_i;
3051    num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j));
3052    num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j));
3053    num1_civ2=ref_i;
3054    num2_civ2=ref_i;
3055    num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j));
3056    num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j));
3057    % adjust the first and last field number
3058    if isnan(lastfield_j)
3059        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3060    else
3061        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3062    end
3063    if length(indsel)>=1
3064        firstind=indsel(1);
3065        lastind=indsel(end);
3066        set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields
3067        set(handles.last_j,'String',num2str(ref_j(lastind)))
3068        ref_j=ref_j(indsel);
3069        num_a_civ1=num_a_civ1(indsel);
3070        num_b_civ1=num_b_civ1(indsel);
3071        num_a_civ2=num_a_civ2(indsel);
3072        num_b_civ2=num_b_civ2(indsel);
3073    end
3074elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
3075    displ_num=get(handles.list_pair_civ1,'UserData');
3076    num1_civ1=ref_i;
3077    num2_civ1=ref_i;
3078    num_a_civ1=displ_num(1,index_civ1);
3079    num_b_civ1=displ_num(2,index_civ1);
3080    num1_civ2=ref_i;
3081    num2_civ2=ref_i;
3082    num_a_civ2=displ_num(1,index_civ2);
3083    num_b_civ2=displ_num(2,index_civ2);
3084elseif isequal(mode,'displacement')
3085    num1_civ1=ref_i;
3086    num2_civ1=ref_i;
3087    num_a_civ1=ref_j;
3088    num_b_civ1=ref_j;
3089    num1_civ2=ref_i;
3090    num2_civ2=ref_i;
3091    num_a_civ2=ref_j;
3092    num_b_civ2=ref_j;
3093end
3094
3095
3096%------------------------------------------------------------------------
[12]3097% --- PATCH
[94]3098function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
[12]3099%------------------------------------------------------------------------
[224]3100namelog=[filename_nc(1:end-3) '_patch.log'];
[112]3101if test_interp==0
[163]3102    if isunix
[112]3103    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3104        '  > ' namelog ' 2>&1']; % redirect standard output to the log file
[163]3105    else
3106      cmd_PATCH=['"' PatchBin '" -f "' filename_nc '" -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3107        '  > "' namelog '" 2>&1']; % redirect standard output to the log file
3108    end
[112]3109else %nouveau programme patch
3110    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
3111        ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3112end
[163]3113cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
[12]3114%------------------------------------------------------------------------
3115% --- STEREO Interp
[67]3116function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
[12]3117%------------------------------------------------------------------------
[224]3118namelog=[filename_nc(1:end-3) '_stinterp.log'];
[67]3119cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
[2]3120    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
3121
[12]3122%------------------------------------------------------------------------
[2]3123% --- Executes on button press in CIV1.
3124function CIV1_Callback(hObject, eventdata, handles)
[12]3125%------------------------------------------------------------------------
[2]3126val=get(handles.CIV1,'Value');
3127if isequal(val,1)
3128    enable_civ1(handles,'on')
3129    enable_pair1(handles,'on')
3130else
3131    enable_civ1(handles,'off')
3132end
3133find_netcpair_civ1(hObject, eventdata, handles);
3134
[12]3135%------------------------------------------------------------------------
[2]3136% --- Executes on button press in FIX1.
3137function FIX1_Callback(hObject, eventdata, handles)
[12]3138%------------------------------------------------------------------------
[2]3139enable_fix1(handles,get(handles.FIX1,'Value'))
3140
[12]3141%------------------------------------------------------------------------
[2]3142% --- Executes on button press in PATCH1.
3143function PATCH1_Callback(hObject, eventdata, handles)
[12]3144%------------------------------------------------------------------------
[2]3145if get(handles.PATCH1,'Value')==1
[12]3146    enable_patch1(handles)
[2]3147else
[12]3148    desable_patch1(handles)
[2]3149end
3150
[12]3151%------------------------------------------------------------------------
[2]3152% --- Executes on button press in CIV2.
3153function CIV2_Callback(hObject, eventdata, handles)
[12]3154%------------------------------------------------------------------------
[2]3155state=get(handles.CIV2,'Value');
3156enable_civ2(handles,state)
3157if state
3158    find_netcpair_civ2(hObject, eventdata, handles)
3159    enable_pair1(handles,'on')
3160end
3161
[12]3162%------------------------------------------------------------------------
[2]3163% --- Executes on button press in FIX2.
3164function FIX2_Callback(hObject, eventdata, handles)
[12]3165%------------------------------------------------------------------------
[2]3166if get(handles.FIX2,'Value')==1
3167    enable_fix2(handles)
3168    if get(handles.CIV2,'Value')==0
3169        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3170    end
3171else
3172    desable_fix2(handles)
3173end
3174
[12]3175%------------------------------------------------------------------------
[2]3176% --- Executes on button press in PATCH2.
3177function PATCH2_Callback(hObject, eventdata, handles)
[12]3178%------------------------------------------------------------------------
[2]3179if get(handles.PATCH2,'Value')==1
3180    enable_patch2(handles)
3181    if get(handles.CIV2,'Value')==0
3182        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3183    end
3184else
3185    desable_patch2(handles)
3186end
3187
[12]3188%------------------------------------------------------------------------
3189function first_i_Callback(hObject, eventdata, handles)
3190%------------------------------------------------------------------------
3191% last_i_Callback(hObject, eventdata, handles)
[137]3192first_i=str2double(get(handles.first_i,'String'));
[12]3193% last_i=str2num(get(handles.last_i,'String'));
3194% ref_i=ceil((first_i+last_i)/2);
3195set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
[71]3196set(handles.ref_i_civ2,'String', num2str(first_i))% reference index for pair dt = first index
[12]3197ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3198
[12]3199%------------------------------------------------------------------------
3200function first_j_Callback(hObject, eventdata, handles)
3201%------------------------------------------------------------------------
3202first_j=str2num(get(handles.first_j,'String'));
3203set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3204ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3205
[12]3206%------------------------------------------------------------------------
[2]3207% --- Executes on button press in calcul_search: determine the search range isx,isy
3208function calcul_search_Callback(hObject, eventdata, handles)
[12]3209%------------------------------------------------------------------------
[2]3210%determine pair numbers
3211list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
3212index=get(handles.list_pair_civ1,'Value');
3213displ_num=get(handles.list_pair_civ1,'UserData');
[71]3214time=get(handles.RootName,'UserData'); %get the set of times
[2]3215pxcm_xy=get(handles.calcul_search,'UserData');
3216pxcmx=pxcm_xy(1);
3217pxcmy=pxcm_xy(2);
3218mode_list=get(handles.mode,'String');
3219mode_value=get(handles.mode,'Value');
3220mode=mode_list{mode_value};
3221if isequal (mode, 'series(Di)' )
[137]3222    ref_i=str2double(get(handles.ref_i,'String'));
[2]3223    num1=ref_i-floor(index/2);%  first image numbers
3224    num2=ref_i+ceil(index/2);
3225    num_a=1;
3226    num_b=1;
[112]3227elseif isequal (mode, 'series(Dj)')
[2]3228    num1=1;
3229    num2=1;
[137]3230    ref_j=str2double(get(handles.ref_j,'String'));
[2]3231    num_a=ref_j-floor(index/2);%  first image numbers
3232    num_b=ref_j+ceil(index/2);
3233elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[137]3234    ref_i=str2double(get(handles.ref_i,'String'));
[2]3235    num1=ref_i;
3236    num2=ref_i;
3237    num_a=displ_num(1,index);
3238    num_b=displ_num(2,index);
3239end
3240dt=time(num2,num_b)-time(num1,num_a);
[137]3241ibx=str2double(get(handles.ibx,'String'));
3242iby=str2double(get(handles.iby,'String'));
3243umin=dt*pxcmx*str2double(get(handles.umin,'String'));
3244umax=dt*pxcmx*str2double(get(handles.umax,'String'));
3245vmin=dt*pxcmy*str2double(get(handles.vmin,'String'));
3246vmax=dt*pxcmy*str2double(get(handles.vmax,'String'));
[2]3247shiftx=round((umin+umax)/2);
3248shifty=round((vmin+vmax)/2);
3249isx=(umax+2-shiftx)*2+ibx;
3250isx=2*ceil(isx/2)+1;
3251isy=(vmax+2-shifty)*2+iby;
3252isy=2*ceil(isy/2)+1;
3253set(handles.shiftx,'String',num2str(shiftx));
3254set(handles.shifty,'String',num2str(shifty));
3255set(handles.isx,'String',num2str(isx));
3256set(handles.isy,'String',num2str(isy));
3257
[12]3258%------------------------------------------------------------------------
3259% --- Executes on carriage return on the subdir civ1 edit window
[2]3260function subdir_civ1_Callback(hObject, eventdata, handles)
[12]3261%------------------------------------------------------------------------
[2]3262subdir=get(handles.subdir_civ1,'String');
3263set(handles.subdir_civ2,'String',subdir);
[112]3264if get(handles.CIV1,'Value')==0
[2]3265    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
3266end
3267
[12]3268%------------------------------------------------------------------------
3269% --- Executes on carriage return on the subdir civ1 edit window
[2]3270function subdir_civ2_Callback(hObject, eventdata, handles)
[12]3271%------------------------------------------------------------------------
[2]3272%update the list of available pairs from netcdf files in the new directory
3273if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
3274    find_netcpair_civ2(hObject, eventdata, handles);
3275end
3276
[12]3277%------------------------------------------------------------------------
[133]3278% --- Executes on button press in get_mask_civ1: select box for mask option
[2]3279function get_mask_civ1_Callback(hObject, eventdata, handles)
[12]3280%------------------------------------------------------------------------
[252]3281maskval=get(handles.get_mask_civ1,'Value')
[2]3282if isequal(maskval,0)
3283    set(handles.mask_civ1,'String','')
3284else
3285    mask_displ='no mask'; %default
[71]3286    filebase=get(handles.RootName,'String');
[2]3287    [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
3288    if isequal(flag_mask,1)
[112]3289        mask_displ=[num2str(nbslice_mask) 'mask'];
[2]3290    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3291        common_path=fileparts(filebase);
3292        filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
3293        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3294        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
3295            mask_displ='no mask';
3296        end
[2]3297    end
3298    if isequal(mask_displ,'no mask')
[12]3299        [FileName, PathName, filterindex] = uigetfile( ...
[112]3300            {'*.png', ' (*.png)';
3301            '*.png',  '.png files '; ...
3302            '*.*', 'All Files (*.*)'}, ...
3303            'Pick a mask file *.png',filebase);
3304        mask_displ=fullfile(PathName,FileName);
[12]3305        if ~exist(mask_displ,'file')
3306            mask_displ='no mask';
3307        end
3308    end
3309    if isequal(mask_displ,'no mask')
[2]3310        set(handles.get_mask_civ1,'Value',0)
3311        set(handles.get_mask_fix1,'Value',0)
3312        set(handles.get_mask_civ2,'Value',0)
3313        set(handles.get_mask_fix2,'Value',0)
3314    else
3315        set(handles.get_mask_fix1,'Value',1)
3316        set(handles.get_mask_fix2,'Value',1)
3317    end
3318    set(handles.mask_civ1,'String',mask_displ)
3319    set(handles.mask_fix1,'String',mask_displ)
3320    set(handles.mask_civ2,'String',mask_displ)
3321    set(handles.mask_fix2,'String',mask_displ)
3322end
[133]3323set(handles.get_mask_civ2,'Value',maskval)%update the civ2 mask with the same option as civ1
[2]3324
[12]3325%------------------------------------------------------------------------
[2]3326% --- Executes on button press in get_mask_fix1.
3327function get_mask_fix1_Callback(hObject, eventdata, handles)
[12]3328%------------------------------------------------------------------------
[2]3329maskval=get(handles.get_mask_fix1,'Value');
3330if isequal(maskval,0)
3331    set(handles.mask_fix1,'String','')
3332else
[112]3333    mask_displ='no mask'; %default
3334    filebase=get(handles.RootName,'String');
3335    [nbslice, flag_mask]=get_mask(filebase,handles);
3336    if isequal(flag_mask,1)
3337        mask_displ=[num2str(nbslice) 'mask'];
3338    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3339        filebase_a=get(handles.RootName_1,'String');
[2]3340        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3341        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3342            mask_displ='no mask';
3343        end
[112]3344    end
3345    if isequal(mask_displ,'no mask')
3346        [FileName, PathName, filterindex] = uigetfile( ...
3347            {'*.png', ' (*.png)';
[12]3348            '*.png',  '.png files '; ...
3349            '*.*', 'All Files (*.*)'}, ...
3350            'Pick a mask file *.png',filebase);
[112]3351        mask_displ=fullfile(PathName,FileName);
3352        if ~exist(mask_displ,'file')
3353            mask_displ='no mask';
3354        end
[12]3355    end
[112]3356    if isequal(mask_displ,'no mask')
3357        set(handles.get_mask_fix1,'Value',0)
3358        set(handles.get_mask_civ2,'Value',0)
3359        set(handles.get_mask_fix2,'Value',0)
3360    else
3361        %set(handles.get_mask_civ2,'Value',1)
3362        set(handles.get_mask_fix2,'Value',1)
3363    end
3364    set(handles.mask_fix1,'String',mask_displ)
3365    set(handles.mask_civ2,'String',mask_displ)
3366    set(handles.mask_fix2,'String',mask_displ)
[12]3367end
3368
3369%------------------------------------------------------------------------
[133]3370% --- Executes on button press in get_mask_civ2: select box for mask option
[2]3371function get_mask_civ2_Callback(hObject, eventdata, handles)
[12]3372%------------------------------------------------------------------------
[2]3373maskval=get(handles.get_mask_civ2,'Value');
3374if isequal(maskval,0)
3375    set(handles.mask_civ2,'String','')
3376else
[112]3377    mask_displ='no mask'; %default
3378    filebase=get(handles.RootName,'String');
3379    [nbslice, flag_mask]=get_mask(filebase,handles);
3380    if isequal(flag_mask,1)
3381        mask_displ=[num2str(nbslice) 'mask'];
3382    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3383        filebase_a=get(handles.RootName_1,'String');
[2]3384        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3385        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3386            mask_displ='no mask';
3387        end
[112]3388    end
3389    if isequal(mask_displ,'no mask')
3390        [FileName, PathName, filterindex] = uigetfile( ...
3391            {'*.png', ' (*.png)';
[12]3392            '*.png',  '.png files '; ...
3393            '*.*', 'All Files (*.*)'}, ...
3394            'Pick a mask file *.png',filebase);
[112]3395        mask_displ=fullfile(PathName,FileName);
3396        if ~exist(mask_displ,'file')
3397            mask_displ='no mask';
3398        end
[12]3399    end
[112]3400    if isequal(mask_displ,'no mask')
3401        set(handles.get_mask_civ2,'Value',0)
3402        set(handles.get_mask_fix2,'Value',0)
3403    else
3404        set(handles.get_mask_fix2,'Value',1)
3405    end
3406    set(handles.mask_civ2,'String',mask_displ)
3407    set(handles.mask_fix2,'String',mask_displ)
[12]3408end
3409
3410%------------------------------------------------------------------------
[2]3411% --- Executes on button press in get_mask_fix2.
3412function get_mask_fix2_Callback(hObject, eventdata, handles)
[12]3413%------------------------------------------------------------------------
[2]3414maskval=get(handles.get_mask_fix2,'Value');
3415if isequal(maskval,0)
3416    set(handles.mask_fix2,'String','')
3417else
[12]3418    mask_displ='no mask'; %default
[71]3419    filebase=get(handles.RootName,'String');
[12]3420    [nbslice, flag_mask]=get_mask(filebase,handles);
3421    if isequal(flag_mask,1)
[112]3422        mask_displ=[num2str(nbslice) 'mask'];
[12]3423    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3424        filebase_a=get(handles.RootName_1,'String');
3425        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3426        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[112]3427            mask_displ='no mask';
3428        end
[12]3429    end
3430    if isequal(mask_displ,'no mask')
3431        [FileName, PathName, filterindex] = uigetfile( ...
[112]3432            {'*.png', ' (*.png)';
3433            '*.png',  '.png files '; ...
3434            '*.*', 'All Files (*.*)'}, ...
3435            'Pick a mask file *.png',filebase);
3436        mask_displ=fullfile(PathName,FileName);
[12]3437        if ~exist(mask_displ,'file')
[2]3438            mask_displ='no mask';
3439        end
[12]3440    end
3441    if isequal(mask_displ,'no mask')
3442        set(handles.get_mask_fix2,'Value',0)
[112]3443    end
[12]3444    set(handles.mask_fix2,'String',mask_displ)
[2]3445end
3446
[12]3447%------------------------------------------------------------------------
3448% --- function called to look for mask files
[2]3449function [nbslice, flag_mask]=get_mask(filebase,handles)
[12]3450%------------------------------------------------------------------------
[112]3451%detect mask files, images with appropriate file base
[2]3452%[filebase '_' xx 'mask'], xx=nbslice
3453%flag_mask=1 indicates detection
3454
3455flag_mask=0;%default
3456nbslice=1;
3457
3458% subdir=get(handles.subdir_civ1,'String');
3459[Path,Name]=fileparts(filebase);
[12]3460if ~isdir(Path)
3461    msgbox_uvmat('ERROR','no path for input files')
3462    return
3463end
[2]3464currentdir=pwd;
3465cd(Path);%move in the dir of the root name filebase
3466maskfiles=dir([Name '_*mask_*.png']);%look for mask files
3467cd(currentdir);%come back to the current working directory
[12]3468if ~isempty(maskfiles)
[112]3469    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3470    % else
[2]3471    flag_mask=1;
3472    maskname=maskfiles(1).name;% take the first mask file in the list
3473    [Path2,Name,ext]=fileparts(maskname);
3474    Namedouble=double(Name);
3475    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3476    ind_mask=findstr('mask',Name);
3477    i=ind_mask-1;
[137]3478    while val(i)==0 && i>0
[112]3479        i=i-1;
[2]3480    end
[137]3481    nbslice=str2double(Name(i+1:ind_mask-1));
3482    if ~isnan(nbslice) && Name(i)=='_'
[112]3483        flag_mask=1;
[2]3484    else
[112]3485        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3486        return
3487        nbslice=1;
[2]3488    end
[112]3489end
[2]3490
[12]3491%------------------------------------------------------------------------
3492% --- function called to look for grid files
[2]3493function [nbslice, flag_mask]=get_grid(filebase,handles)
[12]3494%------------------------------------------------------------------------
[2]3495flag_mask=0;%default
3496nbslice=1;
3497[Path,Name]=fileparts(filebase);
3498currentdir=pwd;
3499cd(Path);%move in the dir of the root name filebase
3500maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3501cd(currentdir);%come back to the current working directory
3502if ~isempty(maskfiles)
3503    flag_mask=1;
3504    maskname=maskfiles(1).name;% take the first mask file in the list
3505    [Path2,Name,ext]=fileparts(maskname);
3506    Namedouble=double(Name);
3507    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3508    ind_mask=findstr('grid',Name);
3509    i=ind_mask-1;
[137]3510    while val(i)==0 && i>0
[112]3511        i=i-1;
[2]3512    end
[137]3513    nbslice=str2double(Name(i+1:ind_mask-1));
3514    if ~isnan(nbslice) && Name(i)=='_'
[112]3515        flag_mask=1;
[2]3516    else
[112]3517        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3518        return
3519        nbslice=1;
[2]3520    end
[12]3521end
[2]3522
[12]3523%------------------------------------------------------------------------
3524% --- transform numbers to letters
[122]3525function str=num2stra(num,nom_type)
[12]3526%------------------------------------------------------------------------
[122]3527if isempty(nom_type)
3528    str='';
3529elseif strcmp(nom_type(end),'a')
[2]3530    str=char(96+num);
[122]3531elseif strcmp(nom_type(end),'A')
3532    str=char(96+num);
3533elseif isempty(nom_type(2:end))%a single index
[2]3534    str='';
3535else
3536    str=num2str(num);
3537end
[12]3538
3539%------------------------------------------------------------------------
[2]3540% --- Executes on button press in list_subdir_civ1.
3541function list_subdir_civ1_Callback(hObject, eventdata, handles)
[12]3542%------------------------------------------------------------------------
[2]3543list_subdir_civ1=get(handles.list_subdir_civ1,'String');
3544val=get(handles.list_subdir_civ1,'Value');
3545if val>1
3546    subdir=list_subdir_civ1{val};
3547    set(handles.subdir_civ1,'String',subdir);
3548    set(handles.list_subdir_civ1,'Value',1);
3549end
3550
[12]3551%------------------------------------------------------------------------
[2]3552% --- Executes on button press in list_subdir_civ2.
3553function list_subdir_civ2_Callback(hObject, eventdata, handles)
[12]3554%------------------------------------------------------------------------
[2]3555list_subdir_civ2=get(handles.list_subdir_civ2,'String');
3556val=get(handles.list_subdir_civ2,'Value');
3557if val>1
3558    subdir=list_subdir_civ2{val};
3559    set(handles.subdir_civ2,'String',subdir);
3560    set(handles.list_subdir_civ2,'Value',1);
3561end
3562
[12]3563%------------------------------------------------------------------------
[2]3564% --- Executes on button press in browse_gridciv1.
3565function browse_gridciv1_Callback(hObject, eventdata, handles)
[12]3566%------------------------------------------------------------------------
[2]3567value=get(handles.browse_gridciv1,'Value');
3568testgrid=0;
3569if value
[112]3570    filebase=get(handles.RootName,'String');
[39]3571    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3572    if isequal(flag_grid,1)
[112]3573        filegrid=[num2str(nbslice) 'grid'];
3574        testgrid=1;
3575    else
[2]3576        [FileName, PathName, filterindex] = uigetfile( ...
[112]3577            {'*.grid', ' (*.grid)';
3578            '*.grid',  '.grid files '; ...
3579            '*.*', 'All Files (*.*)'}, ...
3580            'Pick a file',filebase);
[2]3581        filegrid=fullfile(PathName,FileName);
3582        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3583            testgrid=1;
3584        end
[112]3585    end
[2]3586end
3587if testgrid
[112]3588    set(handles.browse_gridciv2,'Value',1)
3589    set(handles.get_gridpatch1,'Value',1)
3590    set(handles.get_gridpatch2,'Value',1)
3591    set(handles.dx_civ1,'Visible','off');
3592    set(handles.dy_civ1,'Visible','off');
3593    set(handles.dx_civ2,'Visible','off');
3594    set(handles.dy_civ2,'Visible','off');
3595    set(handles.grid_civ1,'String',filegrid)
3596    set(handles.grid_patch1,'String',filegrid)
3597    set(handles.grid_civ2,'String',filegrid)
3598    set(handles.grid_patch2,'String',filegrid)
3599else
3600    set(handles.browse_gridciv1,'Value',0);
3601    set(handles.browse_gridciv2,'Value',0);
3602    set(handles.get_gridpatch1,'Value',0)
3603    set(handles.get_gridpatch2,'Value',0)
3604    set(handles.dx_civ1,'Visible','on');
3605    set(handles.dy_civ1,'Visible','on');
3606    set(handles.dx_civ2,'Visible','on');
3607    set(handles.dy_civ2,'Visible','on');
3608    set(handles.grid_civ1,'String','')
3609    set(handles.grid_patch1,'String','')
3610    set(handles.grid_civ2,'String','')
3611    set(handles.grid_patch2,'String','')
[2]3612end
3613
[12]3614%------------------------------------------------------------------------
[2]3615% --- Executes on button press in browse_gridciv1.
3616function browse_gridciv2_Callback(hObject, eventdata, handles)
[12]3617%------------------------------------------------------------------------
[2]3618value=get(handles.browse_gridciv2,'Value');
3619if value
[112]3620    filebase=get(handles.RootName,'String');
[39]3621    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3622    if isequal(flag_grid,1)
3623        mask_displ=[num2str(nbslice) 'grid'];
3624        set(handles.grid_civ2,'String',mask_displ)
3625        set(handles.dx_civ2,'Visible','off');
3626        set(handles.dy_civ2,'Visible','off');
[112]3627    else
[2]3628        [FileName, PathName, filterindex] = uigetfile( ...
[112]3629            {'*.grid', ' (*.grid)';
3630            '*.grid',  '.grid files '; ...
3631            '*.*', 'All Files (*.*)'}, ...
3632            'Pick a file',filebase);
[2]3633        filegrid=fullfile(PathName,FileName);
[229]3634        if isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file')
[2]3635            set(handles.browse_gridciv2,'Value',0);
3636            set(handles.grid_civ2,'string','');
3637            set(handles.dx_civ2,'Visible','on');
3638            set(handles.dy_civ2,'Visible','on');
3639            set(handles.grid_civ2,'string','');
3640        else
3641            set(handles.grid_civ2,'string',filegrid);
3642            set(handles.dx_civ2,'Visible','off');
3643            set(handles.dy_civ2,'Visible','off');
3644            set(handles.grid_civ2,'string',filegrid);
3645        end
3646    end
3647else
3648    set(handles.grid_civ2,'string','');
[112]3649    set(handles.dx_civ2,'Visible','on');
3650    set(handles.dy_civ2,'Visible','on');
3651    set(handles.grid_civ2,'string','');
[2]3652end
3653
3654% % --- Executes on button press in browse_gridciv2.
3655% function browse_gridciv2_Callback(hObject, eventdata, handles)
[112]3656%
[71]3657% filebase=get(handles.RootName,'String');
[2]3658% [FileName, PathName, filterindex] = uigetfile( ...
3659%        {'*.grid', ' (*.grid)';
3660%         '*.grid',  '.grid files '; ...
3661%         '*.*', 'All Files (*.*)'}, ...
3662%         'Pick a file',filebase);
3663% filegrid=fullfile(PathName,FileName);
3664% set(handles.grid_civ2,'string',filegrid);
3665% set(handles.dx_civ2,'String',' ');
3666% set(handles.dy_civ2,'String',' ');
3667% % set(handles.grid_patch2,'string',filegrid);
3668
3669% --- Executes on button press in get_gridpatch1.
3670function get_gridpatch1_Callback(hObject, eventdata, handles)
3671% hObject    handle to get_gridpatch1 (see GCBO)
3672% eventdata  reserved - to be defined in a future version of MATLAB
3673% handles    structure with handles and user data (see GUIDATA)
3674
[71]3675filebase=get(handles.RootName,'String');
[2]3676[FileName, PathName, filterindex] = uigetfile( ...
[112]3677    {'*.grid', ' (*.grid)';
3678    '*.grid',  '.grid files '; ...
3679    '*.*', 'All Files (*.*)'}, ...
3680    'Pick a file',filebase);
[2]3681filegrid=fullfile(PathName,FileName);
3682set(handles.grid_patch1,'string',filegrid);
3683% set(handles.grid_patch2,'string',filegrid
3684
[12]3685%------------------------------------------------------------------------
[2]3686% --- Executes on button press in get_gridpatch2.
3687function get_gridpatch2_Callback(hObject, eventdata, handles)
[12]3688%------------------------------------------------------------------------
[2]3689
[12]3690%------------------------------------------------------------------------
[2]3691function enable_civ1(handles,state)
[12]3692%------------------------------------------------------------------------
[2]3693if isequal(state,'on')
3694    set(handles.frame_civ1,'BackgroundColor',[1 1 0])
3695    set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
3696    set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
3697else
3698    set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
3699    set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
3700    set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
3701end
3702set(handles.ibx,'Visible',state)
3703set(handles.iby,'Visible',state)
3704set(handles.isx,'Visible',state)
3705set(handles.isy,'Visible',state)
3706set(handles.shiftx,'Visible',state)
3707set(handles.shifty,'Visible',state)
3708set(handles.rho,'Visible',state)
3709set(handles.dx_civ1,'Visible',state)
3710set(handles.dy_civ1,'Visible',state)
3711set(handles.calcul_search,'Visible',state)
3712set(handles.u_text,'Visible',state)
3713set(handles.v_text,'Visible',state)
3714set(handles.min,'Visible',state)
3715set(handles.max,'Visible',state)
3716set(handles.umin,'Visible',state)
3717set(handles.umax,'Visible',state)
3718set(handles.vmin,'Visible',state)
3719set(handles.vmax,'Visible',state)
3720set(handles.grid_civ1,'Visible',state)
3721set(handles.mask_civ1,'Visible',state)
3722set(handles.browse_gridciv1,'Visible',state)
3723set(handles.get_mask_civ1,'Visible',state)
3724set(handles.parameters,'Visible',state)
3725set(handles.grid,'Visible',state)
3726set(handles.dx_civ1,'Visible',state)
3727set(handles.dy_civ1,'Visible',state)
3728set(handles.ImaThreshold,'Visible',state)
3729if isequal(state,'off')
3730    set(handles.MinIma,'Visible','off')
3731    set(handles.MaxIma,'Visible','off')
3732    set(handles.ImaThreshold,'Value',0)
3733end
3734set(handles.dx_civ1_title,'Visible',state)
3735set(handles.dy_civ1_title,'Visible',state)
3736set(handles.ImaThreshold_title,'Visible',state)
3737set(handles.ib_title,'Visible',state)
3738set(handles.is_title,'Visible',state)
3739set(handles.shift_title,'Visible',state)
3740set(handles.rho_title,'Visible',state)
[224]3741set(handles.TestCiv1,'Visible',state)
3742%set(handles.CivAll,'Visible',state)
[2]3743
[12]3744%------------------------------------------------------------------------
[2]3745function enable_fix1(handles,state)
[12]3746%------------------------------------------------------------------------
[2]3747if isequal(state,0)
3748    state='off';
3749end
3750if isequal(state,1)
3751    state='on';
3752end
3753if isequal(state,'on')
3754    set(handles.frame_fix1,'BackgroundColor',[1 1 0])
3755else
3756    set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
3757end
3758set(handles.REMOVE,'Visible',state)
3759set(handles.vec_Fmin2,'Visible',state)
3760set(handles.vec_F2,'Visible',state)
3761set(handles.vec_F3,'Visible',state)
3762set(handles.thresh_vecC,'Visible',state)
3763set(handles.thresh_vecC_title,'Visible',state)
3764set(handles.thresh_vel,'Visible',state)
3765set(handles.thresh_vel_text,'Visible',state)
3766set(handles.mask_fix1,'Visible',state)
3767set(handles.get_mask_fix1,'Visible',state)
3768set(handles.get_ref_fix1,'Visible',state)
3769set(handles.ref_fix1,'Visible',state)
3770set(handles.inf_sup1,'Visible',state)
3771set(handles.field_ref1,'Visible',state)
3772
[12]3773%------------------------------------------------------------------------
[2]3774function enable_patch1(handles)
[12]3775%------------------------------------------------------------------------
[2]3776set(handles.frame_patch1,'BackgroundColor',[1 1 0])
3777set(handles.rho_patch1,'Visible','on')
3778set(handles.rho_text1,'Visible','on')
[225]3779if get(handles.CivAll,'Value')==2
[224]3780    set(handles.thresh_patch1,'Visible','on')
3781    set(handles.thresh_text1,'Visible','on')
3782end
[2]3783set(handles.subdomain_patch1,'Visible','on')
3784set(handles.subdomain_text1,'Visible','on')
3785set(handles.nx_patch1,'Visible','on')
3786set(handles.ny_patch1,'Visible','on')
3787set(handles.nx_patch1_title,'Visible','on')
3788set(handles.ny_patch1_title,'Visible','on')
[112]3789% if ~isempty(patch_newBin)
[224]3790set(handles.test_interp,'Visible','off');
[252]3791stereo_test=get(handles.compare,'Value');
3792if stereo_test==3
3793    set(handles.test_stereo1,'Visible','on')
3794end
[100]3795% end
[252]3796%set(handles.get_gridpatch1,'Visible','on')
3797%set(handles.grid_patch1,'string','none');
3798%set(handles.grid_patch1,'Visible','on')
[2]3799
[12]3800%------------------------------------------------------------------------
[2]3801function desable_patch1(handles)
[12]3802%------------------------------------------------------------------------
[2]3803set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
3804set(handles.rho_patch1,'Visible','off')
3805set(handles.rho_text1,'Visible','off')
3806set(handles.thresh_patch1,'Visible','off')
3807set(handles.thresh_text1,'Visible','off')
3808set(handles.subdomain_patch1,'Visible','off')
3809set(handles.subdomain_text1,'Visible','off')
3810set(handles.nx_patch1,'Visible','off')
3811set(handles.ny_patch1,'Visible','off')
3812set(handles.nx_patch1_title,'Visible','off')
3813set(handles.ny_patch1_title,'Visible','off')
[252]3814set(handles.test_stereo1,'Visible','off')
[100]3815%set(handles.test_interp,'Visible','off')
[252]3816%set(handles.get_gridpatch1,'Visible','off')
3817%set(handles.grid_patch1,'Visible','off')
[2]3818
[12]3819%------------------------------------------------------------------------
[2]3820function enable_civ2(handles,state)
[12]3821%------------------------------------------------------------------------
[2]3822if isequal(state,0)
3823    state='off';
3824end
3825if isequal(state,1)
3826    state='on';
3827end
3828if isequal(state,'on')
3829    set(handles.frame_civ2,'BackgroundColor',[1 1 0])
3830    set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
3831    set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
3832    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
3833else
3834    set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
3835    set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
3836    set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
3837    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
3838end
3839set(handles.ibx_civ2,'Visible',state)
3840set(handles.iby_civ2,'Visible',state)
3841set(handles.decimal,'Visible',state)
3842set(handles.deformation,'Visible',state)
3843set(handles.rho_civ2,'Visible',state)
3844set(handles.dx_civ2,'Visible',state)
3845set(handles.dy_civ2,'Visible',state)
3846set(handles.browse_gridciv2,'Visible',state)
3847set(handles.get_mask_civ2,'Visible',state)
3848set(handles.parameters,'Visible',state)
3849set(handles.grid,'Visible',state)
3850set(handles.parameters_text,'Visible',state)
3851set(handles.grid_text,'Visible',state)
3852set(handles.grid_civ2,'Visible',state)
3853set(handles.mask_civ2,'Visible',state)
3854set(handles.dx_civ2_title,'Visible',state)
3855set(handles.dy_civ2_title,'Visible',state)
3856set(handles.ibx_civ2_text,'Visible',state)
3857set(handles.rho_civ2_title,'Visible',state)
3858set(handles.ImaThreshold2,'Visible',state)
3859set(handles.ImaThreshold_title2,'Visible',state)
3860if isequal(state,'off')
3861    set(handles.MinIma2,'Visible','off')
3862    set(handles.MaxIma2,'Visible','off')
3863    set(handles.ImaThreshold2,'Value',0)
[112]3864    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3865        set(handles.list_pair_civ2,'Visible','off')
3866        set(handles.subdir_civ2,'Visible','off')
3867        set(handles.subdir_civ2_text,'Visible','off')
[71]3868        set(handles.dt_unit_civ2,'Visible','off')
3869        set(handles.ref_i_civ2,'Visible','off')
3870        set(handles.i_ref_civ2_title,'Visible','off')
3871        set(handles.j_ref_civ2_title,'Visible','off')
3872        set(handles.ref_j_civ2,'Visible','off')
[2]3873    end
3874else
3875    set(handles.list_pair_civ2,'Visible','on')
3876    set(handles.subdir_civ2,'Visible','on')
3877    set(handles.subdir_civ2_text,'Visible','on')
[71]3878    set(handles.dt_unit_civ2,'Visible','on')
3879    set(handles.ref_i_civ2,'Visible','on')
3880    set(handles.i_ref_civ2_title,'Visible','on')
3881    set(handles.j_ref_civ2_title,'Visible','on')
3882    set(handles.ref_j_civ2,'Visible','on')
[2]3883end
[71]3884set(handles.rho_civ2_title,'Visible',state)
[2]3885
[12]3886%------------------------------------------------------------------------
[2]3887function enable_fix2(handles)
[12]3888%------------------------------------------------------------------------
[2]3889set(handles.frame_fix2,'BackgroundColor',[1 1 0])
3890set(handles.REMOVE2,'Visible','on')
3891set(handles.vec_Fmin2_2,'Visible','on')
3892set(handles.vec_F4,'Visible','on')
3893set(handles.vec_F3_2,'Visible','on')
3894set(handles.thresh_vec2C,'Visible','on')
3895set(handles.thresh_vec2C_text,'Visible','on')
3896set(handles.thresh_vel2,'Visible','on')
3897set(handles.thresh_vel2_text,'Visible','on')
3898set(handles.mask_fix2,'Visible','on')
3899set(handles.get_mask_fix2,'Visible','on')
3900set(handles.list_pair_civ2,'Visible','on')
3901set(handles.subdir_civ2,'Visible','on')
3902set(handles.subdir_civ2_text,'Visible','on')
3903set(handles.get_ref_fix2,'Visible','on')
3904set(handles.ref_fix2,'Visible','on')
3905set(handles.inf_sup2,'Visible','on')
3906set(handles.field_ref2,'Visible','on')
3907
[12]3908%------------------------------------------------------------------------
[2]3909function desable_fix2(handles)
[12]3910%------------------------------------------------------------------------
[2]3911set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
3912set(handles.REMOVE2,'Visible','off')
3913set(handles.vec_Fmin2_2,'Visible','off')
3914set(handles.vec_F4,'Visible','off')
3915set(handles.vec_F3_2,'Visible','off')
3916set(handles.thresh_vec2C,'Visible','off')
3917set(handles.thresh_vec2C_text,'Visible','off')
3918set(handles.thresh_vel2,'Visible','off')
3919set(handles.thresh_vel2_text,'Visible','off')
3920set(handles.mask_fix2,'Visible','off')
3921set(handles.get_mask_fix2,'Visible','off')
3922set(handles.get_ref_fix2,'Visible','off')
3923set(handles.ref_fix2,'Visible','off')
3924set(handles.inf_sup2,'Visible','off')
3925set(handles.field_ref2,'Visible','off')
[112]3926if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3927    set(handles.list_pair_civ2,'Visible','off')
3928    set(handles.subdir_civ2,'Visible','off')
3929    set(handles.subdir_civ2_text,'Visible','off')
3930end
3931
[12]3932%------------------------------------------------------------------------
[2]3933function enable_patch2(handles)
[12]3934%------------------------------------------------------------------------
[2]3935set(handles.frame_patch2,'BackgroundColor',[1 1 0])
[119]3936set(handles.rho_patch2,'Visible','on')
[2]3937set(handles.rho_text2,'Visible','on')
3938set(handles.thresh_patch2,'Visible','on')
3939set(handles.thresh_text2,'Visible','on')
3940set(handles.subdomain_patch2,'Visible','on')
3941set(handles.subdomain_text2,'Visible','on')
3942set(handles.nx_patch2,'Visible','on')
3943set(handles.ny_patch2,'Visible','on')
3944set(handles.nx_patch2_title,'Visible','on')
3945set(handles.ny_patch2_title,'Visible','on')
[252]3946% set(handles.get_gridpatch2,'Visible','on')
3947% set(handles.grid_patch2,'Visible','on')
[2]3948set(handles.list_pair_civ2,'Visible','on')
3949set(handles.subdir_civ2,'Visible','on')
3950set(handles.subdir_civ2_text,'Visible','on')
[252]3951stereo_test=get(handles.compare,'Value');
3952if stereo_test==3
3953    set(handles.test_stereo2,'Visible','on')
3954end
[2]3955
[12]3956%------------------------------------------------------------------------
[2]3957function desable_patch2(handles)
[12]3958%------------------------------------------------------------------------
[2]3959set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
3960set(handles.rho_patch2,'Visible','off')
3961set(handles.rho_text2,'Visible','off')
3962set(handles.thresh_patch2,'Visible','off')
3963set(handles.thresh_text2,'Visible','off')
3964set(handles.subdomain_patch2,'Visible','off')
3965set(handles.subdomain_text2,'Visible','off')
3966set(handles.nx_patch2,'Visible','off')
3967set(handles.ny_patch2,'Visible','off')
3968set(handles.nx_patch2_title,'Visible','off')
3969set(handles.ny_patch2_title,'Visible','off')
[252]3970% set(handles.get_gridpatch2,'Visible','off')
3971% set(handles.grid_patch2,'Visible','off')
[112]3972if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
[2]3973    set(handles.list_pair_civ2,'Visible','off')
3974    set(handles.subdir_civ2,'Visible','off')
3975    set(handles.subdir_civ2_text,'Visible','off')
3976end
[252]3977set(handles.test_stereo2,'Visible','off')
[12]3978%------------------------------------------------------------------------
[2]3979function enable_pair1(handles,state)
[12]3980%------------------------------------------------------------------------
[2]3981set(handles.subdir_civ1,'Visible',state)
3982set(handles.list_subdir_civ1,'Visible',state)
3983set(handles.SUBDIR_CIV1_txt,'Visible',state)
3984set(handles.frame_subdirciv1,'Visible',state)
3985set(handles.list_pair_civ1,'Visible',state)
3986set(handles.PAIR_txt,'Visible',state)
[71]3987%set(handles.dt_unit,'Visible',state)
[2]3988set(handles.PAIR_frame,'Visible',state)
3989
[12]3990%------------------------------------------------------------------------
3991% --- Read the parameters for civ1 on the interface
[2]3992function par=read_param_civ1(handles,file_ima)
[12]3993%------------------------------------------------------------------------
[127]3994ibx_val=str2double(get(handles.ibx,'String'));
[2]3995par.ibx=num2str(ibx_val);
[127]3996iby_val=str2double(get(handles.iby,'String'));
[2]3997par.iby=num2str(iby_val);
3998isx=get(handles.isx,'String');
[127]3999if isnan(str2double(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
4000if str2double(isx)<ibx_val+8,isx=num2str(ibx_val+8); set(handles.isx,'String',num2str(ibx_val+8)); end
[2]4001isy=get(handles.isy,'String');
[127]4002if isnan(str2double(isy)), isy='41'; set(handles.isy,'String','41'), end;%default
4003if str2double(isy)<iby_val+8,isy=num2str(iby_val+8); set(handles.isy,'String',num2str(iby_val+8)); end
[2]4004par.isx=get(handles.isx,'String');
4005par.isy=get(handles.isy,'String');
4006par.shiftx=get(handles.shiftx,'String');
4007par.shifty=get(handles.shifty,'String');
[127]4008if isnan(str2double(par.isx))
[112]4009    par.isx='41';%default
4010    set(handles.isx,'String','41');
[2]4011end
[127]4012if isnan(str2double(par.isy))
[112]4013    par.isy='41'; %default
4014    set(handles.isy,'String','41');
[12]4015end
[127]4016if isnan(str2double(par.shiftx))
[112]4017    par.shiftx='0';%default
4018    set(handles.shiftx,'String','0');
4019end
[127]4020if isnan(str2double(par.shifty))
[112]4021    par.shifty='0'; %default
4022    set(handles.shifty,'String','0');
[12]4023end
[112]4024par.rho=get(handles.rho,'String');
[238]4025if isequal(get(handles.rho,'Style'),'popupmenu')
4026    index=get(handles.rho,'Value');
4027    par.rho=par.rho{index};
4028end
[112]4029par.dx=get(handles.dx_civ1,'String');
4030par.dy=get(handles.dy_civ1,'String');
[127]4031if isnan(str2double(par.dx))
[112]4032    if isempty(get(handles.grid_civ1,'String'));
4033        par.dx='0'; %just read by civ program, not used
4034    else
[12]4035        par.dx='20';%default
4036        set(handles.dx_civ1,'String','20');
[112]4037    end
4038end
[127]4039if isnan(str2double(par.dy))
[112]4040    if isempty(get(handles.grid_civ1,'String'));
4041        par.dy='0';%just read by civ program, not used
4042    else
[12]4043        par.dy='20';%default
4044        set(handles.dy_civ1_title,'String','20');
[112]4045    end
4046end
4047par.pxcmx='1'; %velocities are expressed in pixel dispalcement
4048par.pxcmy='1';
[150]4049if exist('file_ima','var')
[112]4050A=imread(file_ima);%read the first image to get the size
4051sizim=size(A);
4052par.npx=num2str(sizim(2));
4053par.npy=num2str(sizim(1));
[150]4054end
[127]4055%time=get(handles.RootName,'UserData'); %get the set of times
[112]4056par.gridname=get(handles.grid_civ1,'String');
4057par.gridflag='y';
[127]4058if strcmp(par.gridname,'')|| isempty(par.gridname)
[112]4059    par.gridname='nogrid';
4060    par.gridflag='n';
4061end
[12]4062
4063%------------------------------------------------------------------------
[2]4064function par=read_param_civ2(handles,file_ima)
[12]4065%------------------------------------------------------------------------
4066par.ibx=get(handles.ibx_civ2,'String');
4067par.iby=get(handles.iby_civ2,'String');
4068par.rho=get(handles.rho_civ2,'String');
4069par.decimal=int2str(get(handles.decimal,'Value'));
4070par.deformation=int2str(get(handles.deformation,'Value'));
4071par.dx=get(handles.dx_civ2,'String');
4072par.dy=get(handles.dy_civ2,'String');
[127]4073if isnan(str2double(par.dx))
[112]4074    if isempty(get(handles.grid_civ2,'String'));
4075        par.dx='0'; %just read by civ program, not used
4076    else
[12]4077        par.dx='20';%default
4078        set(handles.dx_civ2,'String','20');
[112]4079    end
4080end
[127]4081if isnan(str2double(par.dy))
[112]4082    if isempty(get(handles.grid_civ2,'String'));
4083        par.dy='0';%just read by civ program, not used
4084    else
[12]4085        par.dy='20';%default
4086        set(handles.dy_civ2,'String','20');
[112]4087    end
4088end
4089par.pxcmx='1';
4090par.pxcmy='1';
[12]4091A=imread(file_ima);%read the first image to get the size
4092sizim=size(A);
4093par.npx=num2str(sizim(2));
4094par.npy=num2str(sizim(1));
[127]4095%time=get(handles.RootName,'UserData'); %get the set of times
[12]4096par.gridname=get(handles.grid_civ2,'String');
4097par.gridflag='y';
[127]4098if strcmp(par.gridname,'')|| isempty(par.gridname)
[12]4099    par.gridname='nogrid';
4100    par.gridflag='n';
4101end
[2]4102
[12]4103%------------------------------------------------------------------------
4104% --- CIV1  CIV1  CIV1 CIV1
[94]4105function cmd_CIV1=CIV1_CMD(filename,namelog,par,handles,sparam)
[12]4106%------------------------------------------------------------------------
[2]4107%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4108
4109%changes : filename_cmx -> filename ( no extension )
[174]4110% input namelog not used
[112]4111if isequal(par.Dt,'0')
4112    par.Dt='1' ;%case of 'displacement' mode
4113end
[90]4114par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
[94]4115par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');
[230]4116fid=fopen([filename '.civ1.cmx'],'w');
[12]4117fprintf(fid,['##############   CMX file' '\n' ]);
[112]4118fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4119fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4120fprintf(fid,  ['XX' '\n' ]);
4121fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
4122fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
4123fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4124fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4125fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
4126fprintf(fid,   ['RO ' par.rho '\n' ]);
4127fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
4128fprintf(fid,   ['XX 1.0' '\n' ]);
4129fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4130fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4131fprintf(fid,  ['XX 1' '\n' ]);
4132fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
4133fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
4134fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
4135fprintf(fid,   ['XX 85' '\n' ]);
4136fprintf(fid,   ['XX 1.0' '\n' ]);
4137fprintf(fid,   ['XX 1.0' '\n' ]);
4138fprintf(fid,   ['Hart 1' '\n' ]);
4139fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4140fprintf(fid,   ['Deformation 0' '\n' ]);
4141fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4142fprintf(fid,   ['IntensityMin 0' '\n' ]);
4143fprintf(fid,  ['SeuilImage n' '\n' ]);
4144fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4145fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4146fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
[12]4147fclose(fid);
[112]4148
[163]4149% cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
4150% cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4151% namelog=regexprep(namelog,'\\','\\\\');
[12]4152if(isunix)
[230]4153    cmd_CIV1=['cp -f ' filename '.civ1.cmx ' filename '.cmx\n'];
4154    cmd_CIV1=[cmd_CIV1 sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
[219]4155    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' filename '.log' ' ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.nc'];%rename .log as .civ1.log and set the netcdf result file for group user writting
[230]4156   % cmd_CIV1=[cmd_CIV1 '\n' 'mv ' filename '.cmx' ' ' filename '.civ1.cmx' '\n'];%rename .cmx as .civ1.cmx
[163]4157else %Windows system
[230]4158                    flname=regexprep(flname,'\\','\\\\');
4159%                     cmd=[cmd 'copy /Y "' flname '.civ1.cmx" "' flname '.cmx"\n'];
[174]4160    filename=regexprep(filename,'\\','\\\\');
[230]4161    cmd_CIV1=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx"\n'];% copy the .civ1.cmx parameter file to .cmx
[163]4162    cmd_CIV1=['"' sparam.Civ1Bin '" -f "' filename '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
4163    cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4164    namelog=regexprep(namelog,'\\','\\\\');
[230]4165    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y "' filename '.log' '" "' filename '.civ1.log"']; %preserve the log file as .civ1.log
4166  %  cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.civ1.cmx"'];
[12]4167end
[2]4168
[12]4169%------------------------------------------------------------------------
4170% --- CIV1  Unified
[94]4171function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
[12]4172%------------------------------------------------------------------------
[2]4173%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4174%global CivBin%name of the executable for civ1 calculation
[2]4175
[112]4176civ1.image1=par.filename_ima_a;
4177civ1.image2=par.filename_ima_b;
4178civ1.imageSize_X=par.npx;
4179civ1.imageSize_Y=par.npy;
4180civ1.outputFileName=[filename '.nc'];
4181civ1.correlationBoxesSize_X=par.ibx;
4182civ1.correlationBoxesSize_Y=par.iby;
4183civ1.searchBoxesSize_X=par.isx;
4184civ1.searchBoxesSize_Y=par.isy;
4185civ1.globalShift_X=par.shiftx;
4186civ1.globalShift_Y=par.shifty;
4187civ1.ro=par.rho;
4188civ1.hart='y';
4189if isequal(par.gridflag,'y')
4190    civ1.grid=par.gridname;
4191else
4192    civ1.grid='n';
4193    civ1.gridSpacing_X=par.dx;
4194    civ1.gridSpacing_Y=par.dy;
4195end
4196if isequal(par.maskflag,'y')
4197    civ1.mask=par.maskname;
4198end
[229]4199civ1.dt=par.Dt;
[112]4200civ1.unit='pixel';
4201civ1.absolut_time_T0=par.T0;
4202civ1.pixcmx=par.pxcmx;
4203civ1.pixcmy=par.pxcmy;
4204civ1.convectFlow='n';
[12]4205
[112]4206xml_civ1_parameters=civ1;
4207
[12]4208%------------------------------------------------------------------------
4209% --- CIV2  Unified
[94]4210function civ2=CIV2_CMD_Unified(filename,namelog,par)
[12]4211%------------------------------------------------------------------------
[2]4212%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4213%global CivBin%name of the executable for civ1 calculation
[2]4214
4215civ2.image1=par.filename_ima_a;
4216civ2.image2=par.filename_ima_b;
[112]4217civ2.imageSize_X=par.npx;
[2]4218civ2.imageSize_Y=par.npy;
4219civ2.inputFileName=[par.filename_nc1 '.nc'];
4220civ2.outputFileName=[filename '.nc'];
4221civ2.correlationBoxesSize_X=par.ibx;
4222civ2.correlationBoxesSize_Y=par.iby;
4223civ2.ro=par.rho;
4224%civ2.decimalShift=par.decimal;
4225%civ2.deformation=par.deformation;
4226if isequal(par.decimal,'1')
4227    civ2.decimalShift='y';
4228else
4229    civ2.decimalShift='n';
4230end
4231if isequal(par.deformation,'1')
4232    civ2.deformation='y';
4233else
4234    civ2.deformation='n';
4235end
4236if isequal(par.gridflag,'y')
4237    civ2.grid=par.gridname;
4238else
4239    civ2.grid='n';
4240    civ2.gridSpacing_X=par.dx;
4241    civ2.gridSpacing_Y=par.dy;
4242end
4243civ2.gridSpacing_X='10';
4244civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4245if isequal(par.maskflag,'y')
4246    civ2.mask=par.maskname;
4247else
4248    civ2.mask='n';
4249end
4250civ2.dt=par.Dt;
4251civ2.unit='pixel';
4252civ2.absolut_time_T0=par.T0;
4253civ2.pixcmx=par.pxcmx;
4254civ2.pixcmy=par.pxcmy;
4255civ2.convectFlow='n';
4256civ2.pixcmx=par.pxcmx;
4257civ2.pixcmy=par.pxcmy;
4258civ2.convectFlow='n';
4259
[12]4260%------------------------------------------------------------------------
4261% --- CIV2  CIV2  CIV2 CIV2
[134]4262function cmd_CIV2=CIV2_CMD(filename,namelog,par,sparam)
[12]4263%------------------------------------------------------------------------
[2]4264%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[67]4265% global civ2Bin sge%name of the executable for civ1 calculation
[112]4266if isequal(par.Dt,'0')
4267    par.Dt='1' ;%case of 'displacement' mode
4268end
[94]4269par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
4270par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
[174]4271[fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
4272if isequal(fid,-1)
4273    msgbox_uvmat('ERROR',errormsg)
4274    cmd_CIV2='';
4275    return
4276end
[94]4277fprintf(fid,['##############   CMX file' '\n' ]);
4278fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4279fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4280fprintf(fid,  ['XX' '\n' ]);
4281fprintf(fid, ['Mask ' par.maskflag '\n' ]);
4282fprintf(fid, ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);% for windows compatibility
4283fprintf(fid, ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4284fprintf(fid, ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4285fprintf(fid, ['SearchBoxeSize ' par.ibx ' ' par.iby '\n']);
4286fprintf(fid, ['RO ' par.rho '\n']);
4287fprintf(fid, ['GridSpacing ' par.dx ' ' par.dy '\n']);
4288fprintf(fid, ['XX 1.0' '\n' ]);
4289fprintf(fid, ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4290fprintf(fid, ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4291fprintf(fid, ['XX 1' '\n' ]);
[122]4292fprintf(fid, 'ShiftXY 0 0\n');
[94]4293fprintf(fid, ['Grid ' par.gridflag '\n' ]);
4294fprintf(fid, ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n']);
4295fprintf(fid, ['XX 85' '\n' ]);
4296fprintf(fid, ['XX 1.0' '\n' ]);
4297fprintf(fid, ['XX 1.0' '\n' ]);
4298fprintf(fid, ['Hart 1' '\n' ]);
4299fprintf(fid, ['DecimalShift ' par.decimal '\n']);
4300fprintf(fid, ['Deformation ' par.deformation '\n']);
4301fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4302fprintf(fid,   ['IntensityMin 0' '\n' ]);
4303fprintf(fid,  ['SeuilImage n' '\n' ]);
4304fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4305fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4306fprintf(fid, ['ImageUsedBefore ' regexprep(par.filename_nc1,'\\','\\\\') '\n']);
4307fclose(fid);
4308
[134]4309if(isunix)
[230]4310    cmd_CIV2=['cp -f ' filename '.civ2.cmx ' filename '.cmx\n'];
4311    cmd_CIV2=[cmd_CIV2 sparam.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
4312    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' filename '.log' ' ' filename '.civ2.log' '\n' 'chmod g+w ' filename '.nc'];%preserve the log file as .civ2.log
4313%    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' filename '.cmx' ' ' filename '.civ2.cmx' '\n'];%rename .cmx as .civ2.cmx, the result file is named [filename '.nc'] by CIVx
4314
[163]4315else
[174]4316    filename=regexprep(filename,'\\','\\\\');
[230]4317    cmd_CIV2=['copy /Y "' filename '.civ2.cmx" "' filename '.cmx"\n'];
4318    cmd_CIV2=[cmd_CIV2 '"' sparam.Civ2Bin '" -f "' filename  '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
[163]4319    cmd_CIV2=regexprep(cmd_CIV2,'\\','\\\\');
[174]4320    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y "' filename '.log' '" "' filename '.civ2.log"'];
[230]4321 %    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.civ2.cmx"'];
[134]4322end
4323
[238]4324% %------------------------------------------------------------------------
4325% % --- civ using pivlab
4326% function Data=civ_uvmat(par_civ1)
4327% %------------------------------------------------------------------------
4328% image1=imread(par_civ1.filename_ima_a);
4329% image2=imread(par_civ1.filename_ima_b);
4330% stepx=str2num(par_civ1.dx);
4331% stepy=str2num(par_civ1.dy);
4332% ibx2=ceil(str2num(par_civ1.ibx)/2);
4333% iby2=ceil(str2num(par_civ1.iby)/2);
4334% isx2=ceil(str2num(par_civ1.isx)/2);
4335% isy2=ceil(str2num(par_civ1.isy)/2);
4336% shiftx=str2num(par_civ1.shiftx);
4337% shifty=str2num(par_civ1.shifty);
4338% miniy=max(1+isy2-shifty,1+iby2);
4339% minix=max(1+isx2-shiftx,1+ibx2);
4340% maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
4341% maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
4342% [GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
4343% PointCoord(:,1)=reshape(GridX,[],1);
4344% PointCoord(:,2)=reshape(GridY,[],1);
4345% % caluclate velocity data (y and v in indices, reverse to y component)
4346% [xtable ytable utable vtable ctable F] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []);
4347% Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} {'Time','Dt'}];
4348% Data.Conventions='uvmat/civdata';
4349% Data.Program='civ_uvmat';
4350% Data.CivStage=1;
4351% % list_param=fieldnames(Param.Civ1);
4352% % for ilist=1:length(list_param)
4353% %     eval(['Data.Civ1_' list_param{ilist} '=Param.Civ1.' list_param{ilist} ';'])
4354% % end
4355% Data.Time=str2double(par_civ1.T0);
4356% Data.Dt=str2double(par_civ1.Dt);
4357% Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F'};%  cell array containing the names of the fields to record
4358% Data.VarDimName={'nbvec','nbvec','nbvec','nbvec','nbvec','nbvec'};
4359% Data.VarAttribute{1}.Role='coord_x';
4360% Data.VarAttribute{2}.Role='coord_y';
4361% Data.VarAttribute{3}.Role='vector_x';
4362% Data.VarAttribute{4}.Role='vector_y';
4363% Data.VarAttribute{5}.Role='warnflag';
4364% Data.Civ1_X=reshape(xtable,[],1);
4365% Data.Civ1_Y=reshape(size(image1,1)-ytable+1,[],1);
4366% Data.Civ1_U=reshape(utable,[],1);
4367% Data.Civ1_V=reshape(-vtable,[],1);
4368% Data.Civ1_C=reshape(ctable,[],1);
4369% Data.Civ1_F=reshape(F,[],1);
[134]4370
[12]4371%------------------------------------------------------------------------
[2]4372% --- Executes on button press in HELP.
4373function HELP_Callback(hObject, eventdata, handles)
[12]4374%------------------------------------------------------------------------
[2]4375path_to_uvmat=which ('uvmat');% check the path of uvmat
4376pathelp=fileparts(path_to_uvmat);
[85]4377helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
[36]4378if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[2]4379else
[36]4380    addpath (fullfile(pathelp,'uvmat_doc'))
[112]4381    web([helpfile '#civ'])
[2]4382end
4383
[12]4384%------------------------------------------------------------------------
[2]4385%--read images and convert them to the uint16 format used for PIV
[45]4386function A=read_image(filename,type_ima,num,movieobject)
[12]4387%------------------------------------------------------------------------
[2]4388%num is the view number needed for an avi movie
[45]4389switch type_ima
4390    case 'movie'
4391        A=read(movieobject,num);
4392    case 'avi'
[112]4393        mov=aviread(filename,num);
4394        A=frame2im(mov(1));
[45]4395    case 'multimage'
4396        A=imread(filename,num);
[112]4397    case 'image'
[45]4398        A=imread(filename);
4399end
4400siz=size(A);
4401if length(siz)==3;%color images
[2]4402    A=sum(double(A),3);
4403    A=uint16(A);
4404end
4405
[12]4406%------------------------------------------------------------------------
[2]4407function ref_i_Callback(hObject, eventdata, handles)
[12]4408%------------------------------------------------------------------------
[2]4409mode_list=get(handles.mode,'String');
4410mode_value=get(handles.mode,'Value');
4411mode=mode_list{mode_value};
[45]4412find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
[12]4413if isequal(mode,'series(Di)') || ...% we do patch2 only
[112]4414        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4415    find_netcpair_civ2(hObject, eventdata, handles);
4416end
4417
[12]4418%------------------------------------------------------------------------
[2]4419function ref_j_Callback(hObject, eventdata, handles)
[12]4420%------------------------------------------------------------------------
[2]4421mode_list=get(handles.mode,'String');
4422mode_value=get(handles.mode,'Value');
4423mode=mode_list{mode_value};
[112]4424if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)')
[2]4425    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4426end
[45]4427if isequal(mode,'series(Dj)') || ...
[112]4428        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4429    find_netcpair_civ2(hObject, eventdata, handles);
4430end
[12]4431
4432%------------------------------------------------------------------------
[71]4433function ref_i_civ2_Callback(hObject, eventdata, handles)
4434%------------------------------------------------------------------------
4435mode_list=get(handles.mode,'String');
4436mode_value=get(handles.mode,'Value');
4437mode=mode_list{mode_value};
4438find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4439
4440%------------------------------------------------------------------------
4441function ref_j_civ2_Callback(hObject, eventdata, handles)
4442%------------------------------------------------------------------------
4443mode_list=get(handles.mode,'String');
4444mode_value=get(handles.mode,'Value');
4445mode=mode_list{mode_value};
[112]4446if  isequal(mode,'series(Dj)')
[71]4447    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4448end
4449
4450%------------------------------------------------------------------------
[2]4451% --- Executes on button press in compare.
4452function compare_Callback(hObject, eventdata, handles)
[12]4453%------------------------------------------------------------------------
[2]4454test=get(handles.compare,'Value');
[112]4455if test==2 || test==3
[71]4456    filebase=get(handles.RootName,'String');
[2]4457    browse=get(handles.browse_root,'Userdata');
4458    browse.nom_type_ima1=browse.nom_type_ima;
4459    set(handles.browse_root,'UserData',browse);
4460    set(handles.sub_txt,'Visible','on')
[112]4461    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
[2]4462    mode_store=get(handles.mode,'String');%get the present 'mode'
[112]4463    set(handles.compare,'UserData',mode_store);%store the mode display
[2]4464    set(handles.mode,'Visible','off')
4465    if test==2
[112]4466        set(handles.mode,'Visible','off')
[2]4467    else
4468        set(handles.mode,'Visible','on')
4469    end
4470   
[229]4471    %% open an image file with the browser
[2]4472    ind_opening=1;%default
4473    browse.incr_pair=[0 0]; %default
[71]4474    oldfile=get(handles.RootName,'String');
[229]4475     menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
4476       '*.xml',  '.xml files '; ...
4477        '*.civ',  '.civ files '; ...
4478        '*.png','.png image files'; ...
4479        '*.jpg',' jpeg image files'; ...
4480        '*.tif','.tif image files'; ...
4481        '*.avi;*.AVI','.avi movie files'; ...
4482        '*.nc','.netcdf files'; ...
4483        '*.*',  'All Files (*.*)'};
4484    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file of the second series',oldfile);
[112]4485    fileinput=[PathName FileName];%complete file name
[2]4486    sizf=size(fileinput);
[229]4487    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4488    [path,name,ext]=fileparts(fileinput);
4489    [path1]=fileparts(filebase);
[229]4490%     if isunix
4491%         ['readlink ' path]
4492%         [status,path]=system(['readlink ' path])
4493%         [status,path1]=system(['readlink ' path1])% look for the true path in case of symbolic paths
4494%     end
[2]4495    if ~strcmp(path1,path)
[112]4496        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
[2]4497        return
4498    end
[71]4499    set(handles.RootName_1,'String',name);
[2]4500    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
4501    browse=get(handles.browse_root,'UserData');
4502    browse.nom_type_ima_1=nom_type;
[112]4503    set(handles.browse_root,'UserData',browse)
[2]4504   
4505    %check image extension
[71]4506    if ~strcmp(ext,get(handles.ImaExt,'String'))
[229]4507        msgbox_uvmat('ERROR','The two  input image series must have the same extension name')
[2]4508        return
4509    end
4510   
[229]4511    %% check coincidence of image sizes
4512    ref_i=get(handles.ref_i,'string');
4513    ref_j=get(handles.ref_j,'string');
4514    [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
4515    A=imread(filecell.ima1.civ1{1});
4516    A_1=imread(fileinput);
4517    npxy=size(A);
4518    npxy_1=size(A_1);
4519    if ~isequal(size(A),size(A_1))
4520        msgbox_uvmat('ERROR','The two input image series do not have the same size')
[2]4521        return
4522    end
4523else
4524    set(handles.mode,'Visible','on')
[71]4525    set(handles.RootName_1,'Visible','Off');
[2]4526    set(handles.sub_txt,'Visible','off')
[71]4527    set(handles.RootName_1,'String',[]);
[2]4528    mode_store=get(handles.compare,'UserData');
[177]4529    set(handles.mode,'Value',1)
[2]4530    set(handles.mode,'String',mode_store)
4531    set(handles.test_stereo1,'Value',0)
4532    set(handles.test_stereo2,'Value',0)
4533end
[252]4534if test==3 && get(handles.PATCH1,'Value')
4535    set(handles.stereo1,'Visible','on')
4536else
4537    set(handles.stereo1,'Visible','off')
4538end
4539if test==3 && get(handles.PATCH2,'Value')
4540    set(handles.stereo2,'Visible','on')
4541else
4542    set(handles.stereo2,'Visible','off')
4543end
[2]4544mode_Callback(hObject, eventdata, handles)
4545
[12]4546%------------------------------------------------------------------------
[2]4547% --- Executes on button press in get_ref_fix1.
4548function get_ref_fix1_Callback(hObject, eventdata, handles)
[12]4549%------------------------------------------------------------------------
[71]4550filebase=get(handles.RootName,'String');
[2]4551[FileName, PathName, filterindex] = uigetfile( ...
[112]4552    {'*.nc', ' (*.nc)';
4553    '*.nc',  'netcdf files '; ...
4554    '*.*', 'All Files (*.*)'}, ...
4555    'Pick a file',filebase);
4556
[2]4557fileinput=[PathName FileName];
4558sizf=size(fileinput);
[122]4559if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4560[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4561ref.filebase=fullfile(Path,File);
4562ref.num_a=stra2num(str_a);
4563ref.num_b=stra2num(str_b);
[89]4564ref.num1=str2double(field_count);
4565ref.num2=str2double(str2);
[2]4566browse=[];%initialisation
4567if ~isequal(ref.ext,'.nc')
4568    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4569    return
4570end
4571set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
4572set(handles.ref_fix1,'UserData',ref)
4573menu_field{1}='civ1';
4574Data=nc2struct(fileinput,[]);
[45]4575if isfield(Data,'patch') && isequal(Data.patch,1)
[2]4576    menu_field{2}='filter1';
4577end
[45]4578if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]4579    menu_field{3}='civ2';
4580end
[45]4581if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]4582    menu_field{4}='filter2';
4583end
4584set(handles.field_ref1,'String',menu_field);
4585set(handles.field_ref1,'Value',length(menu_field));
4586set(handles.inf_sup1,'Value',2);
4587set(handles.thresh_vel,'String','1');%default threshold
4588set(handles.ref_fix1,'Enable','on')
[12]4589
4590%------------------------------------------------------------------------
[2]4591% --- Executes on button press in get_ref_fix2.
4592function get_ref_fix2_Callback(hObject, eventdata, handles)
[12]4593%------------------------------------------------------------------------
[2]4594if isequal(get(handles.get_ref_fix2,'Value'),1)
[71]4595    filebase=get(handles.RootName,'String');
[2]4596    [FileName, PathName, filterindex] = uigetfile( ...
[112]4597        {'*.nc', ' (*.nc)';
4598        '*.nc',  'netcdf files '; ...
4599        '*.*', 'All Files (*.*)'}, ...
4600        'Pick a file',filebase);
[2]4601    fileinput=[PathName FileName];
4602    sizf=size(fileinput);
[45]4603    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4604    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4605    ref.filebase=fullfile(Path,File);
4606    ref.num_a=stra2num(str_a);
4607    ref.num_b=stra2num(str_b);
4608    ref.num1=str2num(field_count);
4609    ref.num2=str2num(str2);
4610    browse=[];%initialisation
4611    if ~isequal(ref.ext,'.nc')
4612        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4613        return
4614    end
4615    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
[112]4616    set(handles.ref_fix2,'UserData',ref)
[2]4617    menu_field{1}='civ1';
4618    Data=nc2struct(fileinput,[]);
4619    if isfield(Data,'patch') & isequal(Data.patch,1)
4620        menu_field{2}='filter1';
4621    end
4622    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4623        menu_field{3}='civ2';
4624    end
4625    if isfield(Data,'patch2') & isequal(Data.patch2,1)
4626        menu_field{4}='filter2';
4627    end
4628    set(handles.field_ref2,'String',menu_field);
4629    set(handles.field_ref2,'Value',length(menu_field));
4630    set(handles.inf_sup2,'Value',2);
4631    set(handles.thresh_vel2,'String','1');%default threshold
4632    set(handles.ref_fix2,'Enable','on')
4633    set(handles.ref_fix2,'Visible','on')
4634    set(handles.field_ref2,'Visible','on')
4635else
4636    set(handles.ref_fix2,'Visible','off')
4637    set(handles.field_ref2,'Visible','off')
4638end
4639
[12]4640%------------------------------------------------------------------------
[2]4641function ref_fix1_Callback(hObject, eventdata, handles)
[12]4642%------------------------------------------------------------------------
4643set(handles.inf_sup1,'Value',1);
4644set(handles.field_ref1,'Value',1)
4645set(handles.field_ref1,'String',{' '})
4646set(handles.ref_fix1,'UserData',[]);
4647set(handles.ref_fix1,'String','');
4648set(handles.thresh_vel1,'String','0');
[112]4649
[12]4650%------------------------------------------------------------------------
[2]4651function ref_fix2_Callback(hObject, eventdata, handles)
[12]4652%------------------------------------------------------------------------
4653set(handles.inf_sup2,'Value',1);
4654set(handles.field_ref2,'Value',1)
4655set(handles.field_ref2,'String',{' '})
4656set(handles.ref_fix2,'UserData',[]);
4657set(handles.ref_fix2,'String','');
4658set(handles.thresh_vel2,'String','0');
[2]4659
[12]4660%------------------------------------------------------------------------
[2]4661% --- Executes on button press in test_stereo1.
4662function test_stereo1_Callback(hObject, eventdata, handles)
[12]4663%------------------------------------------------------------------------
[2]4664if isequal(get(handles.test_stereo1,'Value'),0)
4665    set(handles.subdomain_patch1,'Visible','on')
4666    set(handles.rho_patch1,'Visible','on')
4667else
4668    set(handles.subdomain_patch1,'Visible','off')
4669    set(handles.rho_patch1,'Visible','off')
4670end
4671
[12]4672%------------------------------------------------------------------------
[2]4673% --- Executes on button press in test_stereo2.
4674function test_stereo2_Callback(hObject, eventdata, handles)
[12]4675%------------------------------------------------------------------------
[2]4676if isequal(get(handles.test_stereo2,'Value'),0)
4677    set(handles.subdomain_patch2,'Visible','on')
4678    set(handles.rho_patch2,'Visible','on')
4679else
4680    set(handles.subdomain_patch2,'Visible','off')
4681    set(handles.rho_patch2,'Visible','off')
4682end
4683
[12]4684%------------------------------------------------------------------------
[2]4685% --- Executes on button press in ImaThreshold.
4686function ImaThreshold_Callback(hObject, eventdata, handles)
[12]4687%------------------------------------------------------------------------
[2]4688if isequal(get(handles.ImaThreshold,'Value'),1)
4689    set(handles.MinIma,'Visible','on')
4690    set(handles.MaxIma,'Visible','on')
4691else
4692    set(handles.MinIma,'Visible','off')
4693    set(handles.MaxIma,'Visible','off')
4694end
4695
[12]4696%------------------------------------------------------------------------
[2]4697% --- Executes on button press in ImaThreshold2.
4698function ImaThreshold2_Callback(hObject, eventdata, handles)
[12]4699%------------------------------------------------------------------------
[2]4700if isequal(get(handles.ImaThreshold2,'Value'),1)
4701    set(handles.MinIma2,'Visible','on')
4702    set(handles.MaxIma2,'Visible','on')
4703else
4704    set(handles.MinIma2,'Visible','off')
4705    set(handles.MaxIma2,'Visible','off')
4706end
4707
[224]4708%------------------------------------------------------------------------
[225]4709% --- Executes on button press in TestCiv1: display image correlation function
[150]4710function TestCiv1_Callback(hObject, eventdata, handles)
[224]4711%------------------------------------------------------------------------
[233]4712set(handles.TestCiv1,'BackgroundColor',[1 1 0])
4713drawnow
[150]4714test_civ1=get(handles.TestCiv1,'Value');
4715if test_civ1
[227]4716    ref_i=str2double(get(handles.ref_i,'String'));
4717    if strcmp(get(handles.ref_j,'Visible'),'on')
4718        ref_j=str2double(get(handles.ref_j,'String'));
4719    else
4720        ref_j=1;%default
4721    end
[224]4722    [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
[248]4723        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0])
[224]4724    Data.ListVarName={'ny','nx','A'};
4725    Data.VarDimName={'ny','nx',{'ny','nx'}};
4726    Data.A=imread(filecell.ima1.civ1{1});
4727    Data.ny=[size(Data.A,1) 1];
4728    Data.nx=[1 size(Data.A,2)];
[227]4729    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1});
[231]4730    par_civ1.filename_ima_a=filecell.ima1.civ1{1};
4731    par_civ1.filename_ima_b=filecell.ima2.civ1{1};
4732    par_civ1.T0=0;
4733    par_civ1.Dt=1;
[246]4734    Param.Civ1=par_civ1;
4735    Data=civ_uvmat(Param);
[231]4736    Data.ListVarName=[Data.ListVarName {'ny','nx','A'}];
4737    Data.VarDimName=[Data.VarDimName {'ny','nx',{'ny','nx'}}];
4738    Data.A=imread(filecell.ima1.civ1{1});
4739    Data.ny=[size(Data.A,1) 1];
4740    Data.nx=[1 size(Data.A,2)];
4741    hview_field=view_field(Data);
4742    set(0,'CurrentFigure',hview_field)
4743    hhview_field=guihandles(hview_field);
4744    set(hview_field,'CurrentAxes',hhview_field.axes3)
4745    ViewData=get(hview_field,'UserData');
4746    ViewData.CivHandle=handles.civ;% indicate the handle of the civ GUI in view_field
[224]4747    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
[236]4748    ViewData.axes3.X=Data.Civ1_X; %keep the set of points in memeory
4749    ViewData.axes3.Y=Data.Civ1_Y;
[231]4750    set(hview_field,'UserData',ViewData)
[224]4751    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4752    if isempty(corrfig)
4753        corrfig=figure;
4754        set(corrfig,'tag','corrfig')
4755        set(corrfig,'name','image correlation')
4756        set(corrfig,'DeleteFcn',{@closeview_field})%
4757    end
[233]4758    set(handles.TestCiv1,'BackgroundColor',[1 0 0])
[224]4759else
4760    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4761    if ~isempty(corrfig)
4762        delete(corrfig)
4763    end
4764    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4765    if ~isempty(hview_field)
4766        delete(hview_field)
4767    end
[150]4768end
[71]4769
[224]4770function closeview_field(gcbo,eventdata)
4771hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4772    if ~isempty(hview_field)
4773        delete(hview_field)
4774    end
[177]4775%-------------------------------------------------------------------
4776% --- Executes on button press in status.
4777function status_Callback(hObject, eventdata, handles)
4778%-------------------------------------------------------------------
4779val=get(handles.status,'Value');
4780if val==0
[252]4781    set(handles.status,'BackgroundColor',[0 1 0])
[177]4782    hfig=findobj(allchild(0),'name','civ_status');
4783    if ~isempty(hfig)
4784        delete(hfig)
4785    end
4786    return
4787end
[252]4788set(handles.status,'BackgroundColor',[1 1 0])
4789drawnow
[177]4790listtype={'civ1','fix1','patch1','civ2','fix2','patch2'};
4791box_test(1)=get(handles.CIV1,'Value');
4792box_test(2)=get(handles.FIX1,'Value');
4793box_test(3)=get(handles.PATCH1,'Value');
4794box_test(4)=get(handles.CIV2,'Value');
4795box_test(5)=get(handles.FIX2,'Value');
[180]4796box_test(6)=get(handles.PATCH2,'Value');
4797option_civ=find(box_test,1,'last');%last selected option (non-zero index of box_test)
[252]4798filecell=get(handles.civ,'UserData');%retrieve the list of output files expected for PIV
4799test_new=0;
[177]4800if ~isfield(filecell,'nc')
[252]4801    test_new=1;
[227]4802    [ref_i,ref_j,errormsg]=find_ref_indices(handles);
4803    if ~isempty(errormsg)
4804        msgbox_uvmat('ERROR',errormsg)
4805        return
4806    end
[252]4807    filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the output file expected from the GUI status
[177]4808end
4809if ~isequal(box_test(4:6),[0 0 0])
[252]4810    civ_files=filecell.nc.civ2;%case of civ2 operations
[177]4811else
4812    civ_files=filecell.nc.civ1;
4813end
4814[root,filename,ext]=fileparts(civ_files{1});
4815[rootroot,subdir,extdir]=fileparts(root);
4816hfig=findobj(allchild(0),'name','civ_status');
4817if isempty(hfig)
[252]4818    hfig=figure('DeleteFcn',@stop_status);
[177]4819    set(hfig,'name','civ_status')
[182]4820    hlist=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @open_view_field,'tag','list');
[252]4821    uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','msgbox','Max',2,'String','checking files...');
[177]4822    uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
[182]4823    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','OK','FontWeight','bold','FontUnits','normalized','FontSize',0.9,'Callback',@close_GUI);
[177]4824    BarPosition=[0.05 0.81 0.01 0.05];
4825    hwaitbar=uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
[252]4826    drawnow
[177]4827end
[188]4828% datnum=[];
[177]4829Tabchar={};
4830nbfiles=numel(civ_files);
4831count=0;
[188]4832testrecent=0;
[177]4833while count<nbfiles
4834    count=0;
[188]4835    datnum=zeros(1,nbfiles);
[177]4836    for ifile=1:nbfiles
4837        detect=exist(civ_files{ifile},'file'); % check the existence of the file
[179]4838        option=0;
[177]4839        if detect==0
[179]4840            option_str='not created';
[177]4841        else
[219]4842            datfile=dir(civ_files{ifile});
[188]4843            if isfield(datfile,'datenum')
4844                datnum(ifile)=datfile.datenum;%only available in recent matlab versions
4845                testrecent=1;
4846            end
[177]4847            filefound(ifile)={datfile.name};
4848            lastfield='';
4849            % check the content  netcdf file
4850            Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','patch2','fix2','civ2','patch','fix');
4851            if ~isempty(Data.patch2) && isequal(Data.patch2,1)
[179]4852                option=6;
4853                option_str='patch2';
[177]4854            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
[179]4855                option=5;
4856                option_str='fix2';
[177]4857            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
[179]4858                option=4;
4859                option_str='civ2';
[177]4860            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
[179]4861                option=3;
4862                option_str='patch1';
[177]4863            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
[179]4864                option=2;
4865                option_str='fix1';
[177]4866            else
[179]4867                option=1;
4868                option_str='civ1';
[177]4869            end
4870        end
[179]4871        if option >= option_civ
[177]4872            count=count+1;
4873        end
4874        [rr,filename,ext]=fileparts(civ_files{ifile});
[179]4875        Tabchar{ifile,1}=[fullfile([subdir extdir],filename) ext  '...' option_str];
[177]4876    end
[219]4877    datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[188]4878    if isempty(datnum)
4879        if testrecent
4880            message='no civ result created yet';
4881        else
4882            message='';
4883        end
[177]4884    else
[219]4885        datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[177]4886        [first,ind]=min(datnum);
4887        [last,indlast]=max(datnum);
[252]4888        if test_new
4889            message='existing file status, no processing launched yet';
4890        else
[177]4891        message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
4892            ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
[252]4893        end
[177]4894    end
4895    hfig=findobj(allchild(0),'name','civ_status');
[252]4896    if isempty(hfig)% the status list has been deleted
[177]4897        return
4898    else
4899        hlist=findobj(hfig,'tag','list');
4900        hmsgbox=findobj(hfig,'tag','msgbox');
4901        hwaitbar=findobj(hfig,'tag','waitbar');
4902        set(hlist,'String',Tabchar)
4903        set(hmsgbox,'String', message)
[252]4904        if count>0 && ~test_new
[177]4905            BarPosition(3)=0.9*count/nbfiles;
4906            set(hwaitbar,'Position',BarPosition)
4907        end
4908    end
4909    set(hlist,'UserData',rootroot)
[252]4910    pause(10)% wait 10 seconds for next check
[177]4911end
[150]4912
[177]4913   
[252]4914%------------------------------------------------------------------------   
4915% call 'view_field.fig' to display the  field selected in the list of 'status'
[177]4916function open_view_field(hObject, eventdata)
[252]4917%------------------------------------------------------------------------
4918list=get(hObject,'String');
4919index=get(hObject,'Value');
4920rootroot=get(hObject,'UserData');
4921filename=list{index};
4922ind_dot=findstr(filename,'...');
4923filename=filename(1:ind_dot-1);
4924filename=fullfile(rootroot,filename);
4925delete(get(hObject,'parent'))%delete the display figure to stop the check process
4926if exist(filename,'file')%visualise the vel field if it exists
4927    uvmat(filename)
4928    set(gcbo,'Value',1)
4929end
[150]4930
[252]4931%------------------------------------------------------------------------   
4932% launched by pressing OK on the status figure
[182]4933function close_GUI(hObject, eventdata)
[252]4934%------------------------------------------------------------------------
4935    delete(gcbf)
4936   
4937%------------------------------------------------------------------------   
4938% launched by deleting the status figure
4939function stop_status(hObject, eventdata)
4940%------------------------------------------------------------------------
4941hciv=findobj(allchild(0),'tag','civ');
4942hhciv=guidata(hciv);
4943set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
4944set(hhciv.status,'BackgroundColor',[0 1 0])
[220]4945
[252]4946%------------------------------------------------------------------------
[220]4947% --- Executes on button press in CivAll.
4948function CivAll_Callback(hObject, eventdata, handles)
[252]4949%------------------------------------------------------------------------
[238]4950Listprog=get(handles.CivAll,'String');
4951index=get(handles.CivAll,'Value');
4952prog=Listprog{index};
4953switch prog
4954    case 'CivX'
4955        set(handles.thresh_patch1,'Visible','off')
4956        set(handles.thresh_text1,'Visible','off')
[252]4957        set(handles.thresh_patch2,'Visible','off')
4958        set(handles.thresh_text2,'Visible','off')
[238]4959        set(handles.rho,'Style','edit')
4960        set(handles.rho,'String','1')
[252]4961        set(handles.BATCH,'Enable','on')
[238]4962    case 'CivAll'
4963        if get(handles.PATCH1,'Value')
4964            set(handles.thresh_patch1,'Visible','on')
4965            set(handles.thresh_text1,'Visible','on')
4966        end
4967        set(handles.rho,'Style','edit')
4968        set(handles.rho,'String','1')
[252]4969        set(handles.BATCH,'Enable','on')
[238]4970    case 'CivUvmat'
4971        if get(handles.PATCH1,'Value')
4972            set(handles.thresh_patch1,'Visible','on')
4973            set(handles.thresh_text1,'Visible','on')
4974        end
[252]4975        if get(handles.PATCH2,'Value')
4976            set(handles.thresh_patch2,'Visible','on')
4977            set(handles.thresh_text2,'Visible','on')
4978        end
[238]4979        set(handles.rho,'Style','popupmenu')
4980        set(handles.rho,'Value',1)
4981        set(handles.rho,'String',{'1';'2'})
[252]4982        set(handles.BATCH,'Enable','off')
[224]4983end
[220]4984
Note: See TracBrowser for help on using the repository browser.