source: trunk/src/civ.m @ 153

Last change on this file since 153 was 153, checked in by sommeria, 10 years ago

civ.m: bug on field numbers repaired
other: various cleaning and bug repair for the creation of a new object

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