source: trunk/src/civ.m @ 136

Last change on this file since 136 was 136, checked in by gostiaux, 14 years ago

.fsnet automatically replaced by fsnet in filenames (useful at Coriolis only);
filebase variable replaced by filecell.filebase for clarity

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